three.module.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948
  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 = '117';
  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 Uncharted2ToneMapping = 3;
  104. const CineonToneMapping = 4;
  105. const ACESFilmicToneMapping = 5;
  106. const UVMapping = 300;
  107. const CubeReflectionMapping = 301;
  108. const CubeRefractionMapping = 302;
  109. const EquirectangularReflectionMapping = 303;
  110. const EquirectangularRefractionMapping = 304;
  111. const SphericalReflectionMapping = 305;
  112. const CubeUVReflectionMapping = 306;
  113. const CubeUVRefractionMapping = 307;
  114. const RepeatWrapping = 1000;
  115. const ClampToEdgeWrapping = 1001;
  116. const MirroredRepeatWrapping = 1002;
  117. const NearestFilter = 1003;
  118. const NearestMipmapNearestFilter = 1004;
  119. const NearestMipMapNearestFilter = 1004;
  120. const NearestMipmapLinearFilter = 1005;
  121. const NearestMipMapLinearFilter = 1005;
  122. const LinearFilter = 1006;
  123. const LinearMipmapNearestFilter = 1007;
  124. const LinearMipMapNearestFilter = 1007;
  125. const LinearMipmapLinearFilter = 1008;
  126. const LinearMipMapLinearFilter = 1008;
  127. const UnsignedByteType = 1009;
  128. const ByteType = 1010;
  129. const ShortType = 1011;
  130. const UnsignedShortType = 1012;
  131. const IntType = 1013;
  132. const UnsignedIntType = 1014;
  133. const FloatType = 1015;
  134. const HalfFloatType = 1016;
  135. const UnsignedShort4444Type = 1017;
  136. const UnsignedShort5551Type = 1018;
  137. const UnsignedShort565Type = 1019;
  138. const UnsignedInt248Type = 1020;
  139. const AlphaFormat = 1021;
  140. const RGBFormat = 1022;
  141. const RGBAFormat = 1023;
  142. const LuminanceFormat = 1024;
  143. const LuminanceAlphaFormat = 1025;
  144. const RGBEFormat = RGBAFormat;
  145. const DepthFormat = 1026;
  146. const DepthStencilFormat = 1027;
  147. const RedFormat = 1028;
  148. const RedIntegerFormat = 1029;
  149. const RGFormat = 1030;
  150. const RGIntegerFormat = 1031;
  151. const RGBIntegerFormat = 1032;
  152. const RGBAIntegerFormat = 1033;
  153. const RGB_S3TC_DXT1_Format = 33776;
  154. const RGBA_S3TC_DXT1_Format = 33777;
  155. const RGBA_S3TC_DXT3_Format = 33778;
  156. const RGBA_S3TC_DXT5_Format = 33779;
  157. const RGB_PVRTC_4BPPV1_Format = 35840;
  158. const RGB_PVRTC_2BPPV1_Format = 35841;
  159. const RGBA_PVRTC_4BPPV1_Format = 35842;
  160. const RGBA_PVRTC_2BPPV1_Format = 35843;
  161. const RGB_ETC1_Format = 36196;
  162. const RGB_ETC2_Format = 37492;
  163. const RGBA_ETC2_EAC_Format = 37496;
  164. const RGBA_ASTC_4x4_Format = 37808;
  165. const RGBA_ASTC_5x4_Format = 37809;
  166. const RGBA_ASTC_5x5_Format = 37810;
  167. const RGBA_ASTC_6x5_Format = 37811;
  168. const RGBA_ASTC_6x6_Format = 37812;
  169. const RGBA_ASTC_8x5_Format = 37813;
  170. const RGBA_ASTC_8x6_Format = 37814;
  171. const RGBA_ASTC_8x8_Format = 37815;
  172. const RGBA_ASTC_10x5_Format = 37816;
  173. const RGBA_ASTC_10x6_Format = 37817;
  174. const RGBA_ASTC_10x8_Format = 37818;
  175. const RGBA_ASTC_10x10_Format = 37819;
  176. const RGBA_ASTC_12x10_Format = 37820;
  177. const RGBA_ASTC_12x12_Format = 37821;
  178. const RGBA_BPTC_Format = 36492;
  179. const SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  180. const SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  181. const SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  182. const SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  183. const SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  184. const SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  185. const SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  186. const SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  187. const SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  188. const SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  189. const SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  190. const SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  191. const SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  192. const SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  193. const LoopOnce = 2200;
  194. const LoopRepeat = 2201;
  195. const LoopPingPong = 2202;
  196. const InterpolateDiscrete = 2300;
  197. const InterpolateLinear = 2301;
  198. const InterpolateSmooth = 2302;
  199. const ZeroCurvatureEnding = 2400;
  200. const ZeroSlopeEnding = 2401;
  201. const WrapAroundEnding = 2402;
  202. const NormalAnimationBlendMode = 2500;
  203. const AdditiveAnimationBlendMode = 2501;
  204. const TrianglesDrawMode = 0;
  205. const TriangleStripDrawMode = 1;
  206. const TriangleFanDrawMode = 2;
  207. const LinearEncoding = 3000;
  208. const sRGBEncoding = 3001;
  209. const GammaEncoding = 3007;
  210. const RGBEEncoding = 3002;
  211. const LogLuvEncoding = 3003;
  212. const RGBM7Encoding = 3004;
  213. const RGBM16Encoding = 3005;
  214. const RGBDEncoding = 3006;
  215. const BasicDepthPacking = 3200;
  216. const RGBADepthPacking = 3201;
  217. const TangentSpaceNormalMap = 0;
  218. const ObjectSpaceNormalMap = 1;
  219. const ZeroStencilOp = 0;
  220. const KeepStencilOp = 7680;
  221. const ReplaceStencilOp = 7681;
  222. const IncrementStencilOp = 7682;
  223. const DecrementStencilOp = 7683;
  224. const IncrementWrapStencilOp = 34055;
  225. const DecrementWrapStencilOp = 34056;
  226. const InvertStencilOp = 5386;
  227. const NeverStencilFunc = 512;
  228. const LessStencilFunc = 513;
  229. const EqualStencilFunc = 514;
  230. const LessEqualStencilFunc = 515;
  231. const GreaterStencilFunc = 516;
  232. const NotEqualStencilFunc = 517;
  233. const GreaterEqualStencilFunc = 518;
  234. const AlwaysStencilFunc = 519;
  235. const StaticDrawUsage = 35044;
  236. const DynamicDrawUsage = 35048;
  237. const StreamDrawUsage = 35040;
  238. const StaticReadUsage = 35045;
  239. const DynamicReadUsage = 35049;
  240. const StreamReadUsage = 35041;
  241. const StaticCopyUsage = 35046;
  242. const DynamicCopyUsage = 35050;
  243. const StreamCopyUsage = 35042;
  244. /**
  245. * https://github.com/mrdoob/eventdispatcher.js/
  246. */
  247. function EventDispatcher() {}
  248. Object.assign( EventDispatcher.prototype, {
  249. addEventListener: function ( type, listener ) {
  250. if ( this._listeners === undefined ) this._listeners = {};
  251. var listeners = this._listeners;
  252. if ( listeners[ type ] === undefined ) {
  253. listeners[ type ] = [];
  254. }
  255. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  256. listeners[ type ].push( listener );
  257. }
  258. },
  259. hasEventListener: function ( type, listener ) {
  260. if ( this._listeners === undefined ) return false;
  261. var listeners = this._listeners;
  262. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  263. },
  264. removeEventListener: function ( type, listener ) {
  265. if ( this._listeners === undefined ) return;
  266. var listeners = this._listeners;
  267. var listenerArray = listeners[ type ];
  268. if ( listenerArray !== undefined ) {
  269. var index = listenerArray.indexOf( listener );
  270. if ( index !== - 1 ) {
  271. listenerArray.splice( index, 1 );
  272. }
  273. }
  274. },
  275. dispatchEvent: function ( event ) {
  276. if ( this._listeners === undefined ) return;
  277. var listeners = this._listeners;
  278. var listenerArray = listeners[ event.type ];
  279. if ( listenerArray !== undefined ) {
  280. event.target = this;
  281. // Make a copy, in case listeners are removed while iterating.
  282. var array = listenerArray.slice( 0 );
  283. for ( var i = 0, l = array.length; i < l; i ++ ) {
  284. array[ i ].call( this, event );
  285. }
  286. }
  287. }
  288. } );
  289. /**
  290. * @author alteredq / http://alteredqualia.com/
  291. * @author mrdoob / http://mrdoob.com/
  292. * @author WestLangley / http://github.com/WestLangley
  293. * @author thezwap
  294. */
  295. var _lut = [];
  296. for ( var i = 0; i < 256; i ++ ) {
  297. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  298. }
  299. var MathUtils = {
  300. DEG2RAD: Math.PI / 180,
  301. RAD2DEG: 180 / Math.PI,
  302. generateUUID: function () {
  303. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  304. var d0 = Math.random() * 0xffffffff | 0;
  305. var d1 = Math.random() * 0xffffffff | 0;
  306. var d2 = Math.random() * 0xffffffff | 0;
  307. var d3 = Math.random() * 0xffffffff | 0;
  308. var uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  309. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  310. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  311. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  312. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  313. return uuid.toUpperCase();
  314. },
  315. clamp: function ( value, min, max ) {
  316. return Math.max( min, Math.min( max, value ) );
  317. },
  318. // compute euclidian modulo of m % n
  319. // https://en.wikipedia.org/wiki/Modulo_operation
  320. euclideanModulo: function ( n, m ) {
  321. return ( ( n % m ) + m ) % m;
  322. },
  323. // Linear mapping from range <a1, a2> to range <b1, b2>
  324. mapLinear: function ( x, a1, a2, b1, b2 ) {
  325. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  326. },
  327. // https://en.wikipedia.org/wiki/Linear_interpolation
  328. lerp: function ( x, y, t ) {
  329. return ( 1 - t ) * x + t * y;
  330. },
  331. // http://en.wikipedia.org/wiki/Smoothstep
  332. smoothstep: function ( x, min, max ) {
  333. if ( x <= min ) return 0;
  334. if ( x >= max ) return 1;
  335. x = ( x - min ) / ( max - min );
  336. return x * x * ( 3 - 2 * x );
  337. },
  338. smootherstep: function ( x, min, max ) {
  339. if ( x <= min ) return 0;
  340. if ( x >= max ) return 1;
  341. x = ( x - min ) / ( max - min );
  342. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  343. },
  344. // Random integer from <low, high> interval
  345. randInt: function ( low, high ) {
  346. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  347. },
  348. // Random float from <low, high> interval
  349. randFloat: function ( low, high ) {
  350. return low + Math.random() * ( high - low );
  351. },
  352. // Random float from <-range/2, range/2> interval
  353. randFloatSpread: function ( range ) {
  354. return range * ( 0.5 - Math.random() );
  355. },
  356. degToRad: function ( degrees ) {
  357. return degrees * MathUtils.DEG2RAD;
  358. },
  359. radToDeg: function ( radians ) {
  360. return radians * MathUtils.RAD2DEG;
  361. },
  362. isPowerOfTwo: function ( value ) {
  363. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  364. },
  365. ceilPowerOfTwo: function ( value ) {
  366. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  367. },
  368. floorPowerOfTwo: function ( value ) {
  369. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  370. },
  371. setQuaternionFromProperEuler: function ( q, a, b, c, order ) {
  372. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  373. // rotations are applied to the axes in the order specified by 'order'
  374. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  375. // angles are in radians
  376. var cos = Math.cos;
  377. var sin = Math.sin;
  378. var c2 = cos( b / 2 );
  379. var s2 = sin( b / 2 );
  380. var c13 = cos( ( a + c ) / 2 );
  381. var s13 = sin( ( a + c ) / 2 );
  382. var c1_3 = cos( ( a - c ) / 2 );
  383. var s1_3 = sin( ( a - c ) / 2 );
  384. var c3_1 = cos( ( c - a ) / 2 );
  385. var s3_1 = sin( ( c - a ) / 2 );
  386. switch ( order ) {
  387. case 'XYX':
  388. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  389. break;
  390. case 'YZY':
  391. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  392. break;
  393. case 'ZXZ':
  394. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  395. break;
  396. case 'XZX':
  397. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  398. break;
  399. case 'YXY':
  400. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  401. break;
  402. case 'ZYZ':
  403. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  404. break;
  405. default:
  406. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  407. }
  408. }
  409. };
  410. /**
  411. * @author mrdoob / http://mrdoob.com/
  412. * @author philogb / http://blog.thejit.org/
  413. * @author egraether / http://egraether.com/
  414. * @author zz85 / http://www.lab4games.net/zz85/blog
  415. */
  416. function Vector2( x, y ) {
  417. this.x = x || 0;
  418. this.y = y || 0;
  419. }
  420. Object.defineProperties( Vector2.prototype, {
  421. "width": {
  422. get: function () {
  423. return this.x;
  424. },
  425. set: function ( value ) {
  426. this.x = value;
  427. }
  428. },
  429. "height": {
  430. get: function () {
  431. return this.y;
  432. },
  433. set: function ( value ) {
  434. this.y = value;
  435. }
  436. }
  437. } );
  438. Object.assign( Vector2.prototype, {
  439. isVector2: true,
  440. set: function ( x, y ) {
  441. this.x = x;
  442. this.y = y;
  443. return this;
  444. },
  445. setScalar: function ( scalar ) {
  446. this.x = scalar;
  447. this.y = scalar;
  448. return this;
  449. },
  450. setX: function ( x ) {
  451. this.x = x;
  452. return this;
  453. },
  454. setY: function ( y ) {
  455. this.y = y;
  456. return this;
  457. },
  458. setComponent: function ( index, value ) {
  459. switch ( index ) {
  460. case 0: this.x = value; break;
  461. case 1: this.y = value; break;
  462. default: throw new Error( 'index is out of range: ' + index );
  463. }
  464. return this;
  465. },
  466. getComponent: function ( index ) {
  467. switch ( index ) {
  468. case 0: return this.x;
  469. case 1: return this.y;
  470. default: throw new Error( 'index is out of range: ' + index );
  471. }
  472. },
  473. clone: function () {
  474. return new this.constructor( this.x, this.y );
  475. },
  476. copy: function ( v ) {
  477. this.x = v.x;
  478. this.y = v.y;
  479. return this;
  480. },
  481. add: function ( v, w ) {
  482. if ( w !== undefined ) {
  483. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  484. return this.addVectors( v, w );
  485. }
  486. this.x += v.x;
  487. this.y += v.y;
  488. return this;
  489. },
  490. addScalar: function ( s ) {
  491. this.x += s;
  492. this.y += s;
  493. return this;
  494. },
  495. addVectors: function ( a, b ) {
  496. this.x = a.x + b.x;
  497. this.y = a.y + b.y;
  498. return this;
  499. },
  500. addScaledVector: function ( v, s ) {
  501. this.x += v.x * s;
  502. this.y += v.y * s;
  503. return this;
  504. },
  505. sub: function ( v, w ) {
  506. if ( w !== undefined ) {
  507. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  508. return this.subVectors( v, w );
  509. }
  510. this.x -= v.x;
  511. this.y -= v.y;
  512. return this;
  513. },
  514. subScalar: function ( s ) {
  515. this.x -= s;
  516. this.y -= s;
  517. return this;
  518. },
  519. subVectors: function ( a, b ) {
  520. this.x = a.x - b.x;
  521. this.y = a.y - b.y;
  522. return this;
  523. },
  524. multiply: function ( v ) {
  525. this.x *= v.x;
  526. this.y *= v.y;
  527. return this;
  528. },
  529. multiplyScalar: function ( scalar ) {
  530. this.x *= scalar;
  531. this.y *= scalar;
  532. return this;
  533. },
  534. divide: function ( v ) {
  535. this.x /= v.x;
  536. this.y /= v.y;
  537. return this;
  538. },
  539. divideScalar: function ( scalar ) {
  540. return this.multiplyScalar( 1 / scalar );
  541. },
  542. applyMatrix3: function ( m ) {
  543. var x = this.x, y = this.y;
  544. var e = m.elements;
  545. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  546. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  547. return this;
  548. },
  549. min: function ( v ) {
  550. this.x = Math.min( this.x, v.x );
  551. this.y = Math.min( this.y, v.y );
  552. return this;
  553. },
  554. max: function ( v ) {
  555. this.x = Math.max( this.x, v.x );
  556. this.y = Math.max( this.y, v.y );
  557. return this;
  558. },
  559. clamp: function ( min, max ) {
  560. // assumes min < max, componentwise
  561. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  562. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  563. return this;
  564. },
  565. clampScalar: function ( minVal, maxVal ) {
  566. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  567. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  568. return this;
  569. },
  570. clampLength: function ( min, max ) {
  571. var length = this.length();
  572. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  573. },
  574. floor: function () {
  575. this.x = Math.floor( this.x );
  576. this.y = Math.floor( this.y );
  577. return this;
  578. },
  579. ceil: function () {
  580. this.x = Math.ceil( this.x );
  581. this.y = Math.ceil( this.y );
  582. return this;
  583. },
  584. round: function () {
  585. this.x = Math.round( this.x );
  586. this.y = Math.round( this.y );
  587. return this;
  588. },
  589. roundToZero: function () {
  590. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  591. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  592. return this;
  593. },
  594. negate: function () {
  595. this.x = - this.x;
  596. this.y = - this.y;
  597. return this;
  598. },
  599. dot: function ( v ) {
  600. return this.x * v.x + this.y * v.y;
  601. },
  602. cross: function ( v ) {
  603. return this.x * v.y - this.y * v.x;
  604. },
  605. lengthSq: function () {
  606. return this.x * this.x + this.y * this.y;
  607. },
  608. length: function () {
  609. return Math.sqrt( this.x * this.x + this.y * this.y );
  610. },
  611. manhattanLength: function () {
  612. return Math.abs( this.x ) + Math.abs( this.y );
  613. },
  614. normalize: function () {
  615. return this.divideScalar( this.length() || 1 );
  616. },
  617. angle: function () {
  618. // computes the angle in radians with respect to the positive x-axis
  619. var angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  620. return angle;
  621. },
  622. distanceTo: function ( v ) {
  623. return Math.sqrt( this.distanceToSquared( v ) );
  624. },
  625. distanceToSquared: function ( v ) {
  626. var dx = this.x - v.x, dy = this.y - v.y;
  627. return dx * dx + dy * dy;
  628. },
  629. manhattanDistanceTo: function ( v ) {
  630. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  631. },
  632. setLength: function ( length ) {
  633. return this.normalize().multiplyScalar( length );
  634. },
  635. lerp: function ( v, alpha ) {
  636. this.x += ( v.x - this.x ) * alpha;
  637. this.y += ( v.y - this.y ) * alpha;
  638. return this;
  639. },
  640. lerpVectors: function ( v1, v2, alpha ) {
  641. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  642. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  643. return this;
  644. },
  645. equals: function ( v ) {
  646. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  647. },
  648. fromArray: function ( array, offset ) {
  649. if ( offset === undefined ) offset = 0;
  650. this.x = array[ offset ];
  651. this.y = array[ offset + 1 ];
  652. return this;
  653. },
  654. toArray: function ( array, offset ) {
  655. if ( array === undefined ) array = [];
  656. if ( offset === undefined ) offset = 0;
  657. array[ offset ] = this.x;
  658. array[ offset + 1 ] = this.y;
  659. return array;
  660. },
  661. fromBufferAttribute: function ( attribute, index, offset ) {
  662. if ( offset !== undefined ) {
  663. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  664. }
  665. this.x = attribute.getX( index );
  666. this.y = attribute.getY( index );
  667. return this;
  668. },
  669. rotateAround: function ( center, angle ) {
  670. var c = Math.cos( angle ), s = Math.sin( angle );
  671. var x = this.x - center.x;
  672. var y = this.y - center.y;
  673. this.x = x * c - y * s + center.x;
  674. this.y = x * s + y * c + center.y;
  675. return this;
  676. },
  677. random: function () {
  678. this.x = Math.random();
  679. this.y = Math.random();
  680. return this;
  681. }
  682. } );
  683. /**
  684. * @author alteredq / http://alteredqualia.com/
  685. * @author WestLangley / http://github.com/WestLangley
  686. * @author bhouston / http://clara.io
  687. * @author tschw
  688. */
  689. function Matrix3() {
  690. this.elements = [
  691. 1, 0, 0,
  692. 0, 1, 0,
  693. 0, 0, 1
  694. ];
  695. if ( arguments.length > 0 ) {
  696. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  697. }
  698. }
  699. Object.assign( Matrix3.prototype, {
  700. isMatrix3: true,
  701. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  702. var te = this.elements;
  703. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  704. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  705. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  706. return this;
  707. },
  708. identity: function () {
  709. this.set(
  710. 1, 0, 0,
  711. 0, 1, 0,
  712. 0, 0, 1
  713. );
  714. return this;
  715. },
  716. clone: function () {
  717. return new this.constructor().fromArray( this.elements );
  718. },
  719. copy: function ( m ) {
  720. var te = this.elements;
  721. var me = m.elements;
  722. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  723. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  724. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  725. return this;
  726. },
  727. extractBasis: function ( xAxis, yAxis, zAxis ) {
  728. xAxis.setFromMatrix3Column( this, 0 );
  729. yAxis.setFromMatrix3Column( this, 1 );
  730. zAxis.setFromMatrix3Column( this, 2 );
  731. return this;
  732. },
  733. setFromMatrix4: function ( m ) {
  734. var me = m.elements;
  735. this.set(
  736. me[ 0 ], me[ 4 ], me[ 8 ],
  737. me[ 1 ], me[ 5 ], me[ 9 ],
  738. me[ 2 ], me[ 6 ], me[ 10 ]
  739. );
  740. return this;
  741. },
  742. multiply: function ( m ) {
  743. return this.multiplyMatrices( this, m );
  744. },
  745. premultiply: function ( m ) {
  746. return this.multiplyMatrices( m, this );
  747. },
  748. multiplyMatrices: function ( a, b ) {
  749. var ae = a.elements;
  750. var be = b.elements;
  751. var te = this.elements;
  752. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  753. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  754. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  755. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  756. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  757. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  758. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  759. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  760. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  761. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  762. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  763. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  764. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  765. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  766. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  767. return this;
  768. },
  769. multiplyScalar: function ( s ) {
  770. var te = this.elements;
  771. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  772. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  773. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  774. return this;
  775. },
  776. determinant: function () {
  777. var te = this.elements;
  778. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  779. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  780. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  781. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  782. },
  783. getInverse: function ( matrix, throwOnDegenerate ) {
  784. if ( throwOnDegenerate !== undefined ) {
  785. console.warn( "THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate." );
  786. }
  787. var me = matrix.elements,
  788. te = this.elements,
  789. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  790. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  791. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  792. t11 = n33 * n22 - n32 * n23,
  793. t12 = n32 * n13 - n33 * n12,
  794. t13 = n23 * n12 - n22 * n13,
  795. det = n11 * t11 + n21 * t12 + n31 * t13;
  796. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  797. var detInv = 1 / det;
  798. te[ 0 ] = t11 * detInv;
  799. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  800. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  801. te[ 3 ] = t12 * detInv;
  802. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  803. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  804. te[ 6 ] = t13 * detInv;
  805. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  806. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  807. return this;
  808. },
  809. transpose: function () {
  810. var tmp, 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. var 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. var c = Math.cos( rotation );
  834. var 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. var 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. var c = Math.cos( theta );
  849. var s = Math.sin( theta );
  850. var te = this.elements;
  851. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  852. var 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. var 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. var te = this.elements;
  869. var me = matrix.elements;
  870. for ( var 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 ( var 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. var 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. var _canvas;
  904. var ImageUtils = {
  905. getDataURL: function ( image ) {
  906. var canvas;
  907. if ( typeof HTMLCanvasElement == 'undefined' ) {
  908. return image.src;
  909. } else if ( image instanceof HTMLCanvasElement ) {
  910. canvas = image;
  911. } else {
  912. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  913. _canvas.width = image.width;
  914. _canvas.height = image.height;
  915. var context = _canvas.getContext( '2d' );
  916. if ( image instanceof ImageData ) {
  917. context.putImageData( image, 0, 0 );
  918. } else {
  919. context.drawImage( image, 0, 0, image.width, image.height );
  920. }
  921. canvas = _canvas;
  922. }
  923. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  924. return canvas.toDataURL( 'image/jpeg', 0.6 );
  925. } else {
  926. return canvas.toDataURL( 'image/png' );
  927. }
  928. }
  929. };
  930. /**
  931. * @author mrdoob / http://mrdoob.com/
  932. * @author alteredq / http://alteredqualia.com/
  933. * @author szimek / https://github.com/szimek/
  934. */
  935. var textureId = 0;
  936. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  937. Object.defineProperty( this, 'id', { value: textureId ++ } );
  938. this.uuid = MathUtils.generateUUID();
  939. this.name = '';
  940. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  941. this.mipmaps = [];
  942. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  943. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  944. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  945. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  946. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  947. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  948. this.format = format !== undefined ? format : RGBAFormat;
  949. this.internalFormat = null;
  950. this.type = type !== undefined ? type : UnsignedByteType;
  951. this.offset = new Vector2( 0, 0 );
  952. this.repeat = new Vector2( 1, 1 );
  953. this.center = new Vector2( 0, 0 );
  954. this.rotation = 0;
  955. this.matrixAutoUpdate = true;
  956. this.matrix = new Matrix3();
  957. this.generateMipmaps = true;
  958. this.premultiplyAlpha = false;
  959. this.flipY = true;
  960. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  961. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  962. //
  963. // Also changing the encoding after already used by a Material will not automatically make the Material
  964. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  965. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  966. this.version = 0;
  967. this.onUpdate = null;
  968. }
  969. Texture.DEFAULT_IMAGE = undefined;
  970. Texture.DEFAULT_MAPPING = UVMapping;
  971. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  972. constructor: Texture,
  973. isTexture: true,
  974. updateMatrix: function () {
  975. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  976. },
  977. clone: function () {
  978. return new this.constructor().copy( this );
  979. },
  980. copy: function ( source ) {
  981. this.name = source.name;
  982. this.image = source.image;
  983. this.mipmaps = source.mipmaps.slice( 0 );
  984. this.mapping = source.mapping;
  985. this.wrapS = source.wrapS;
  986. this.wrapT = source.wrapT;
  987. this.magFilter = source.magFilter;
  988. this.minFilter = source.minFilter;
  989. this.anisotropy = source.anisotropy;
  990. this.format = source.format;
  991. this.internalFormat = source.internalFormat;
  992. this.type = source.type;
  993. this.offset.copy( source.offset );
  994. this.repeat.copy( source.repeat );
  995. this.center.copy( source.center );
  996. this.rotation = source.rotation;
  997. this.matrixAutoUpdate = source.matrixAutoUpdate;
  998. this.matrix.copy( source.matrix );
  999. this.generateMipmaps = source.generateMipmaps;
  1000. this.premultiplyAlpha = source.premultiplyAlpha;
  1001. this.flipY = source.flipY;
  1002. this.unpackAlignment = source.unpackAlignment;
  1003. this.encoding = source.encoding;
  1004. return this;
  1005. },
  1006. toJSON: function ( meta ) {
  1007. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1008. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1009. return meta.textures[ this.uuid ];
  1010. }
  1011. var output = {
  1012. metadata: {
  1013. version: 4.5,
  1014. type: 'Texture',
  1015. generator: 'Texture.toJSON'
  1016. },
  1017. uuid: this.uuid,
  1018. name: this.name,
  1019. mapping: this.mapping,
  1020. repeat: [ this.repeat.x, this.repeat.y ],
  1021. offset: [ this.offset.x, this.offset.y ],
  1022. center: [ this.center.x, this.center.y ],
  1023. rotation: this.rotation,
  1024. wrap: [ this.wrapS, this.wrapT ],
  1025. format: this.format,
  1026. type: this.type,
  1027. encoding: this.encoding,
  1028. minFilter: this.minFilter,
  1029. magFilter: this.magFilter,
  1030. anisotropy: this.anisotropy,
  1031. flipY: this.flipY,
  1032. premultiplyAlpha: this.premultiplyAlpha,
  1033. unpackAlignment: this.unpackAlignment
  1034. };
  1035. if ( this.image !== undefined ) {
  1036. // TODO: Move to THREE.Image
  1037. var image = this.image;
  1038. if ( image.uuid === undefined ) {
  1039. image.uuid = MathUtils.generateUUID(); // UGH
  1040. }
  1041. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1042. var url;
  1043. if ( Array.isArray( image ) ) {
  1044. // process array of images e.g. CubeTexture
  1045. url = [];
  1046. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1047. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1048. }
  1049. } else {
  1050. // process single image
  1051. url = ImageUtils.getDataURL( image );
  1052. }
  1053. meta.images[ image.uuid ] = {
  1054. uuid: image.uuid,
  1055. url: url
  1056. };
  1057. }
  1058. output.image = image.uuid;
  1059. }
  1060. if ( ! isRootObject ) {
  1061. meta.textures[ this.uuid ] = output;
  1062. }
  1063. return output;
  1064. },
  1065. dispose: function () {
  1066. this.dispatchEvent( { type: 'dispose' } );
  1067. },
  1068. transformUv: function ( uv ) {
  1069. if ( this.mapping !== UVMapping ) return uv;
  1070. uv.applyMatrix3( this.matrix );
  1071. if ( uv.x < 0 || uv.x > 1 ) {
  1072. switch ( this.wrapS ) {
  1073. case RepeatWrapping:
  1074. uv.x = uv.x - Math.floor( uv.x );
  1075. break;
  1076. case ClampToEdgeWrapping:
  1077. uv.x = uv.x < 0 ? 0 : 1;
  1078. break;
  1079. case MirroredRepeatWrapping:
  1080. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1081. uv.x = Math.ceil( uv.x ) - uv.x;
  1082. } else {
  1083. uv.x = uv.x - Math.floor( uv.x );
  1084. }
  1085. break;
  1086. }
  1087. }
  1088. if ( uv.y < 0 || uv.y > 1 ) {
  1089. switch ( this.wrapT ) {
  1090. case RepeatWrapping:
  1091. uv.y = uv.y - Math.floor( uv.y );
  1092. break;
  1093. case ClampToEdgeWrapping:
  1094. uv.y = uv.y < 0 ? 0 : 1;
  1095. break;
  1096. case MirroredRepeatWrapping:
  1097. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1098. uv.y = Math.ceil( uv.y ) - uv.y;
  1099. } else {
  1100. uv.y = uv.y - Math.floor( uv.y );
  1101. }
  1102. break;
  1103. }
  1104. }
  1105. if ( this.flipY ) {
  1106. uv.y = 1 - uv.y;
  1107. }
  1108. return uv;
  1109. }
  1110. } );
  1111. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1112. set: function ( value ) {
  1113. if ( value === true ) this.version ++;
  1114. }
  1115. } );
  1116. /**
  1117. * @author supereggbert / http://www.paulbrunt.co.uk/
  1118. * @author philogb / http://blog.thejit.org/
  1119. * @author mikael emtinger / http://gomo.se/
  1120. * @author egraether / http://egraether.com/
  1121. * @author WestLangley / http://github.com/WestLangley
  1122. */
  1123. function Vector4( x, y, z, w ) {
  1124. this.x = x || 0;
  1125. this.y = y || 0;
  1126. this.z = z || 0;
  1127. this.w = ( w !== undefined ) ? w : 1;
  1128. }
  1129. Object.defineProperties( Vector4.prototype, {
  1130. "width": {
  1131. get: function () {
  1132. return this.z;
  1133. },
  1134. set: function ( value ) {
  1135. this.z = value;
  1136. }
  1137. },
  1138. "height": {
  1139. get: function () {
  1140. return this.w;
  1141. },
  1142. set: function ( value ) {
  1143. this.w = value;
  1144. }
  1145. }
  1146. } );
  1147. Object.assign( Vector4.prototype, {
  1148. isVector4: true,
  1149. set: function ( x, y, z, w ) {
  1150. this.x = x;
  1151. this.y = y;
  1152. this.z = z;
  1153. this.w = w;
  1154. return this;
  1155. },
  1156. setScalar: function ( scalar ) {
  1157. this.x = scalar;
  1158. this.y = scalar;
  1159. this.z = scalar;
  1160. this.w = scalar;
  1161. return this;
  1162. },
  1163. setX: function ( x ) {
  1164. this.x = x;
  1165. return this;
  1166. },
  1167. setY: function ( y ) {
  1168. this.y = y;
  1169. return this;
  1170. },
  1171. setZ: function ( z ) {
  1172. this.z = z;
  1173. return this;
  1174. },
  1175. setW: function ( w ) {
  1176. this.w = w;
  1177. return this;
  1178. },
  1179. setComponent: function ( index, value ) {
  1180. switch ( index ) {
  1181. case 0: this.x = value; break;
  1182. case 1: this.y = value; break;
  1183. case 2: this.z = value; break;
  1184. case 3: this.w = value; break;
  1185. default: throw new Error( 'index is out of range: ' + index );
  1186. }
  1187. return this;
  1188. },
  1189. getComponent: function ( index ) {
  1190. switch ( index ) {
  1191. case 0: return this.x;
  1192. case 1: return this.y;
  1193. case 2: return this.z;
  1194. case 3: return this.w;
  1195. default: throw new Error( 'index is out of range: ' + index );
  1196. }
  1197. },
  1198. clone: function () {
  1199. return new this.constructor( this.x, this.y, this.z, this.w );
  1200. },
  1201. copy: function ( v ) {
  1202. this.x = v.x;
  1203. this.y = v.y;
  1204. this.z = v.z;
  1205. this.w = ( v.w !== undefined ) ? v.w : 1;
  1206. return this;
  1207. },
  1208. add: function ( v, w ) {
  1209. if ( w !== undefined ) {
  1210. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1211. return this.addVectors( v, w );
  1212. }
  1213. this.x += v.x;
  1214. this.y += v.y;
  1215. this.z += v.z;
  1216. this.w += v.w;
  1217. return this;
  1218. },
  1219. addScalar: function ( s ) {
  1220. this.x += s;
  1221. this.y += s;
  1222. this.z += s;
  1223. this.w += s;
  1224. return this;
  1225. },
  1226. addVectors: function ( a, b ) {
  1227. this.x = a.x + b.x;
  1228. this.y = a.y + b.y;
  1229. this.z = a.z + b.z;
  1230. this.w = a.w + b.w;
  1231. return this;
  1232. },
  1233. addScaledVector: function ( v, s ) {
  1234. this.x += v.x * s;
  1235. this.y += v.y * s;
  1236. this.z += v.z * s;
  1237. this.w += v.w * s;
  1238. return this;
  1239. },
  1240. sub: function ( v, w ) {
  1241. if ( w !== undefined ) {
  1242. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1243. return this.subVectors( v, w );
  1244. }
  1245. this.x -= v.x;
  1246. this.y -= v.y;
  1247. this.z -= v.z;
  1248. this.w -= v.w;
  1249. return this;
  1250. },
  1251. subScalar: function ( s ) {
  1252. this.x -= s;
  1253. this.y -= s;
  1254. this.z -= s;
  1255. this.w -= s;
  1256. return this;
  1257. },
  1258. subVectors: function ( a, b ) {
  1259. this.x = a.x - b.x;
  1260. this.y = a.y - b.y;
  1261. this.z = a.z - b.z;
  1262. this.w = a.w - b.w;
  1263. return this;
  1264. },
  1265. multiplyScalar: function ( scalar ) {
  1266. this.x *= scalar;
  1267. this.y *= scalar;
  1268. this.z *= scalar;
  1269. this.w *= scalar;
  1270. return this;
  1271. },
  1272. applyMatrix4: function ( m ) {
  1273. var x = this.x, y = this.y, z = this.z, w = this.w;
  1274. var e = m.elements;
  1275. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1276. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1277. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1278. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1279. return this;
  1280. },
  1281. divideScalar: function ( scalar ) {
  1282. return this.multiplyScalar( 1 / scalar );
  1283. },
  1284. setAxisAngleFromQuaternion: function ( q ) {
  1285. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1286. // q is assumed to be normalized
  1287. this.w = 2 * Math.acos( q.w );
  1288. var s = Math.sqrt( 1 - q.w * q.w );
  1289. if ( s < 0.0001 ) {
  1290. this.x = 1;
  1291. this.y = 0;
  1292. this.z = 0;
  1293. } else {
  1294. this.x = q.x / s;
  1295. this.y = q.y / s;
  1296. this.z = q.z / s;
  1297. }
  1298. return this;
  1299. },
  1300. setAxisAngleFromRotationMatrix: function ( m ) {
  1301. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1302. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1303. var angle, x, y, z, // variables for result
  1304. epsilon = 0.01, // margin to allow for rounding errors
  1305. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1306. te = m.elements,
  1307. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1308. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1309. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1310. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1311. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1312. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1313. // singularity found
  1314. // first check for identity matrix which must have +1 for all terms
  1315. // in leading diagonal and zero in other terms
  1316. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1317. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1318. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1319. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1320. // this singularity is identity matrix so angle = 0
  1321. this.set( 1, 0, 0, 0 );
  1322. return this; // zero angle, arbitrary axis
  1323. }
  1324. // otherwise this singularity is angle = 180
  1325. angle = Math.PI;
  1326. var xx = ( m11 + 1 ) / 2;
  1327. var yy = ( m22 + 1 ) / 2;
  1328. var zz = ( m33 + 1 ) / 2;
  1329. var xy = ( m12 + m21 ) / 4;
  1330. var xz = ( m13 + m31 ) / 4;
  1331. var yz = ( m23 + m32 ) / 4;
  1332. if ( ( xx > yy ) && ( xx > zz ) ) {
  1333. // m11 is the largest diagonal term
  1334. if ( xx < epsilon ) {
  1335. x = 0;
  1336. y = 0.707106781;
  1337. z = 0.707106781;
  1338. } else {
  1339. x = Math.sqrt( xx );
  1340. y = xy / x;
  1341. z = xz / x;
  1342. }
  1343. } else if ( yy > zz ) {
  1344. // m22 is the largest diagonal term
  1345. if ( yy < epsilon ) {
  1346. x = 0.707106781;
  1347. y = 0;
  1348. z = 0.707106781;
  1349. } else {
  1350. y = Math.sqrt( yy );
  1351. x = xy / y;
  1352. z = yz / y;
  1353. }
  1354. } else {
  1355. // m33 is the largest diagonal term so base result on this
  1356. if ( zz < epsilon ) {
  1357. x = 0.707106781;
  1358. y = 0.707106781;
  1359. z = 0;
  1360. } else {
  1361. z = Math.sqrt( zz );
  1362. x = xz / z;
  1363. y = yz / z;
  1364. }
  1365. }
  1366. this.set( x, y, z, angle );
  1367. return this; // return 180 deg rotation
  1368. }
  1369. // as we have reached here there are no singularities so we can handle normally
  1370. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1371. ( m13 - m31 ) * ( m13 - m31 ) +
  1372. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1373. if ( Math.abs( s ) < 0.001 ) s = 1;
  1374. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1375. // caught by singularity test above, but I've left it in just in case
  1376. this.x = ( m32 - m23 ) / s;
  1377. this.y = ( m13 - m31 ) / s;
  1378. this.z = ( m21 - m12 ) / s;
  1379. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1380. return this;
  1381. },
  1382. min: function ( v ) {
  1383. this.x = Math.min( this.x, v.x );
  1384. this.y = Math.min( this.y, v.y );
  1385. this.z = Math.min( this.z, v.z );
  1386. this.w = Math.min( this.w, v.w );
  1387. return this;
  1388. },
  1389. max: function ( v ) {
  1390. this.x = Math.max( this.x, v.x );
  1391. this.y = Math.max( this.y, v.y );
  1392. this.z = Math.max( this.z, v.z );
  1393. this.w = Math.max( this.w, v.w );
  1394. return this;
  1395. },
  1396. clamp: function ( min, max ) {
  1397. // assumes min < max, componentwise
  1398. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1399. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1400. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1401. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1402. return this;
  1403. },
  1404. clampScalar: function ( minVal, maxVal ) {
  1405. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1406. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1407. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1408. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  1409. return this;
  1410. },
  1411. clampLength: function ( min, max ) {
  1412. var length = this.length();
  1413. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1414. },
  1415. floor: function () {
  1416. this.x = Math.floor( this.x );
  1417. this.y = Math.floor( this.y );
  1418. this.z = Math.floor( this.z );
  1419. this.w = Math.floor( this.w );
  1420. return this;
  1421. },
  1422. ceil: function () {
  1423. this.x = Math.ceil( this.x );
  1424. this.y = Math.ceil( this.y );
  1425. this.z = Math.ceil( this.z );
  1426. this.w = Math.ceil( this.w );
  1427. return this;
  1428. },
  1429. round: function () {
  1430. this.x = Math.round( this.x );
  1431. this.y = Math.round( this.y );
  1432. this.z = Math.round( this.z );
  1433. this.w = Math.round( this.w );
  1434. return this;
  1435. },
  1436. roundToZero: function () {
  1437. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1438. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1439. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1440. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1441. return this;
  1442. },
  1443. negate: function () {
  1444. this.x = - this.x;
  1445. this.y = - this.y;
  1446. this.z = - this.z;
  1447. this.w = - this.w;
  1448. return this;
  1449. },
  1450. dot: function ( v ) {
  1451. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1452. },
  1453. lengthSq: function () {
  1454. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1455. },
  1456. length: function () {
  1457. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1458. },
  1459. manhattanLength: function () {
  1460. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1461. },
  1462. normalize: function () {
  1463. return this.divideScalar( this.length() || 1 );
  1464. },
  1465. setLength: function ( length ) {
  1466. return this.normalize().multiplyScalar( length );
  1467. },
  1468. lerp: function ( v, alpha ) {
  1469. this.x += ( v.x - this.x ) * alpha;
  1470. this.y += ( v.y - this.y ) * alpha;
  1471. this.z += ( v.z - this.z ) * alpha;
  1472. this.w += ( v.w - this.w ) * alpha;
  1473. return this;
  1474. },
  1475. lerpVectors: function ( v1, v2, alpha ) {
  1476. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1477. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1478. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1479. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1480. return this;
  1481. },
  1482. equals: function ( v ) {
  1483. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1484. },
  1485. fromArray: function ( array, offset ) {
  1486. if ( offset === undefined ) offset = 0;
  1487. this.x = array[ offset ];
  1488. this.y = array[ offset + 1 ];
  1489. this.z = array[ offset + 2 ];
  1490. this.w = array[ offset + 3 ];
  1491. return this;
  1492. },
  1493. toArray: function ( array, offset ) {
  1494. if ( array === undefined ) array = [];
  1495. if ( offset === undefined ) offset = 0;
  1496. array[ offset ] = this.x;
  1497. array[ offset + 1 ] = this.y;
  1498. array[ offset + 2 ] = this.z;
  1499. array[ offset + 3 ] = this.w;
  1500. return array;
  1501. },
  1502. fromBufferAttribute: function ( attribute, index, offset ) {
  1503. if ( offset !== undefined ) {
  1504. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1505. }
  1506. this.x = attribute.getX( index );
  1507. this.y = attribute.getY( index );
  1508. this.z = attribute.getZ( index );
  1509. this.w = attribute.getW( index );
  1510. return this;
  1511. },
  1512. random: function () {
  1513. this.x = Math.random();
  1514. this.y = Math.random();
  1515. this.z = Math.random();
  1516. this.w = Math.random();
  1517. return this;
  1518. }
  1519. } );
  1520. /**
  1521. * @author szimek / https://github.com/szimek/
  1522. * @author alteredq / http://alteredqualia.com/
  1523. * @author Marius Kintel / https://github.com/kintel
  1524. */
  1525. /*
  1526. In options, we can specify:
  1527. * Texture parameters for an auto-generated target texture
  1528. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1529. */
  1530. function WebGLRenderTarget( width, height, options ) {
  1531. this.width = width;
  1532. this.height = height;
  1533. this.scissor = new Vector4( 0, 0, width, height );
  1534. this.scissorTest = false;
  1535. this.viewport = new Vector4( 0, 0, width, height );
  1536. options = options || {};
  1537. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1538. this.texture.image = {};
  1539. this.texture.image.width = width;
  1540. this.texture.image.height = height;
  1541. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1542. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1543. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1544. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  1545. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1546. }
  1547. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1548. constructor: WebGLRenderTarget,
  1549. isWebGLRenderTarget: true,
  1550. setSize: function ( width, height ) {
  1551. if ( this.width !== width || this.height !== height ) {
  1552. this.width = width;
  1553. this.height = height;
  1554. this.texture.image.width = width;
  1555. this.texture.image.height = height;
  1556. this.dispose();
  1557. }
  1558. this.viewport.set( 0, 0, width, height );
  1559. this.scissor.set( 0, 0, width, height );
  1560. },
  1561. clone: function () {
  1562. return new this.constructor().copy( this );
  1563. },
  1564. copy: function ( source ) {
  1565. this.width = source.width;
  1566. this.height = source.height;
  1567. this.viewport.copy( source.viewport );
  1568. this.texture = source.texture.clone();
  1569. this.depthBuffer = source.depthBuffer;
  1570. this.stencilBuffer = source.stencilBuffer;
  1571. this.depthTexture = source.depthTexture;
  1572. return this;
  1573. },
  1574. dispose: function () {
  1575. this.dispatchEvent( { type: 'dispose' } );
  1576. }
  1577. } );
  1578. /**
  1579. * @author Mugen87 / https://github.com/Mugen87
  1580. * @author Matt DesLauriers / @mattdesl
  1581. */
  1582. function WebGLMultisampleRenderTarget( width, height, options ) {
  1583. WebGLRenderTarget.call( this, width, height, options );
  1584. this.samples = 4;
  1585. }
  1586. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  1587. constructor: WebGLMultisampleRenderTarget,
  1588. isWebGLMultisampleRenderTarget: true,
  1589. copy: function ( source ) {
  1590. WebGLRenderTarget.prototype.copy.call( this, source );
  1591. this.samples = source.samples;
  1592. return this;
  1593. }
  1594. } );
  1595. /**
  1596. * @author mikael emtinger / http://gomo.se/
  1597. * @author alteredq / http://alteredqualia.com/
  1598. * @author WestLangley / http://github.com/WestLangley
  1599. * @author bhouston / http://clara.io
  1600. */
  1601. function Quaternion( x, y, z, w ) {
  1602. this._x = x || 0;
  1603. this._y = y || 0;
  1604. this._z = z || 0;
  1605. this._w = ( w !== undefined ) ? w : 1;
  1606. }
  1607. Object.assign( Quaternion, {
  1608. slerp: function ( qa, qb, qm, t ) {
  1609. return qm.copy( qa ).slerp( qb, t );
  1610. },
  1611. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1612. // fuzz-free, array-based Quaternion SLERP operation
  1613. var x0 = src0[ srcOffset0 + 0 ],
  1614. y0 = src0[ srcOffset0 + 1 ],
  1615. z0 = src0[ srcOffset0 + 2 ],
  1616. w0 = src0[ srcOffset0 + 3 ],
  1617. x1 = src1[ srcOffset1 + 0 ],
  1618. y1 = src1[ srcOffset1 + 1 ],
  1619. z1 = src1[ srcOffset1 + 2 ],
  1620. w1 = src1[ srcOffset1 + 3 ];
  1621. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1622. var s = 1 - t,
  1623. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1624. dir = ( cos >= 0 ? 1 : - 1 ),
  1625. sqrSin = 1 - cos * cos;
  1626. // Skip the Slerp for tiny steps to avoid numeric problems:
  1627. if ( sqrSin > Number.EPSILON ) {
  1628. var sin = Math.sqrt( sqrSin ),
  1629. len = Math.atan2( sin, cos * dir );
  1630. s = Math.sin( s * len ) / sin;
  1631. t = Math.sin( t * len ) / sin;
  1632. }
  1633. var tDir = t * dir;
  1634. x0 = x0 * s + x1 * tDir;
  1635. y0 = y0 * s + y1 * tDir;
  1636. z0 = z0 * s + z1 * tDir;
  1637. w0 = w0 * s + w1 * tDir;
  1638. // Normalize in case we just did a lerp:
  1639. if ( s === 1 - t ) {
  1640. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1641. x0 *= f;
  1642. y0 *= f;
  1643. z0 *= f;
  1644. w0 *= f;
  1645. }
  1646. }
  1647. dst[ dstOffset ] = x0;
  1648. dst[ dstOffset + 1 ] = y0;
  1649. dst[ dstOffset + 2 ] = z0;
  1650. dst[ dstOffset + 3 ] = w0;
  1651. },
  1652. multiplyQuaternionsFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  1653. var x0 = src0[ srcOffset0 ];
  1654. var y0 = src0[ srcOffset0 + 1 ];
  1655. var z0 = src0[ srcOffset0 + 2 ];
  1656. var w0 = src0[ srcOffset0 + 3 ];
  1657. var x1 = src1[ srcOffset1 ];
  1658. var y1 = src1[ srcOffset1 + 1 ];
  1659. var z1 = src1[ srcOffset1 + 2 ];
  1660. var w1 = src1[ srcOffset1 + 3 ];
  1661. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1662. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1663. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1664. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1665. return dst;
  1666. }
  1667. } );
  1668. Object.defineProperties( Quaternion.prototype, {
  1669. x: {
  1670. get: function () {
  1671. return this._x;
  1672. },
  1673. set: function ( value ) {
  1674. this._x = value;
  1675. this._onChangeCallback();
  1676. }
  1677. },
  1678. y: {
  1679. get: function () {
  1680. return this._y;
  1681. },
  1682. set: function ( value ) {
  1683. this._y = value;
  1684. this._onChangeCallback();
  1685. }
  1686. },
  1687. z: {
  1688. get: function () {
  1689. return this._z;
  1690. },
  1691. set: function ( value ) {
  1692. this._z = value;
  1693. this._onChangeCallback();
  1694. }
  1695. },
  1696. w: {
  1697. get: function () {
  1698. return this._w;
  1699. },
  1700. set: function ( value ) {
  1701. this._w = value;
  1702. this._onChangeCallback();
  1703. }
  1704. }
  1705. } );
  1706. Object.assign( Quaternion.prototype, {
  1707. isQuaternion: true,
  1708. set: function ( x, y, z, w ) {
  1709. this._x = x;
  1710. this._y = y;
  1711. this._z = z;
  1712. this._w = w;
  1713. this._onChangeCallback();
  1714. return this;
  1715. },
  1716. clone: function () {
  1717. return new this.constructor( this._x, this._y, this._z, this._w );
  1718. },
  1719. copy: function ( quaternion ) {
  1720. this._x = quaternion.x;
  1721. this._y = quaternion.y;
  1722. this._z = quaternion.z;
  1723. this._w = quaternion.w;
  1724. this._onChangeCallback();
  1725. return this;
  1726. },
  1727. setFromEuler: function ( euler, update ) {
  1728. if ( ! ( euler && euler.isEuler ) ) {
  1729. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1730. }
  1731. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1732. // http://www.mathworks.com/matlabcentral/fileexchange/
  1733. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1734. // content/SpinCalc.m
  1735. var cos = Math.cos;
  1736. var sin = Math.sin;
  1737. var c1 = cos( x / 2 );
  1738. var c2 = cos( y / 2 );
  1739. var c3 = cos( z / 2 );
  1740. var s1 = sin( x / 2 );
  1741. var s2 = sin( y / 2 );
  1742. var s3 = sin( z / 2 );
  1743. switch ( order ) {
  1744. case 'XYZ':
  1745. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1746. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1747. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1748. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1749. break;
  1750. case 'YXZ':
  1751. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1752. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1753. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1754. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1755. break;
  1756. case 'ZXY':
  1757. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1758. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1759. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1760. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1761. break;
  1762. case 'ZYX':
  1763. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1764. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1765. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1766. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1767. break;
  1768. case 'YZX':
  1769. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1770. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1771. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1772. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1773. break;
  1774. case 'XZY':
  1775. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1776. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1777. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1778. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1779. break;
  1780. default:
  1781. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  1782. }
  1783. if ( update !== false ) this._onChangeCallback();
  1784. return this;
  1785. },
  1786. setFromAxisAngle: function ( axis, angle ) {
  1787. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1788. // assumes axis is normalized
  1789. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1790. this._x = axis.x * s;
  1791. this._y = axis.y * s;
  1792. this._z = axis.z * s;
  1793. this._w = Math.cos( halfAngle );
  1794. this._onChangeCallback();
  1795. return this;
  1796. },
  1797. setFromRotationMatrix: function ( m ) {
  1798. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1799. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1800. var te = m.elements,
  1801. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1802. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1803. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1804. trace = m11 + m22 + m33,
  1805. s;
  1806. if ( trace > 0 ) {
  1807. s = 0.5 / Math.sqrt( trace + 1.0 );
  1808. this._w = 0.25 / s;
  1809. this._x = ( m32 - m23 ) * s;
  1810. this._y = ( m13 - m31 ) * s;
  1811. this._z = ( m21 - m12 ) * s;
  1812. } else if ( m11 > m22 && m11 > m33 ) {
  1813. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1814. this._w = ( m32 - m23 ) / s;
  1815. this._x = 0.25 * s;
  1816. this._y = ( m12 + m21 ) / s;
  1817. this._z = ( m13 + m31 ) / s;
  1818. } else if ( m22 > m33 ) {
  1819. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1820. this._w = ( m13 - m31 ) / s;
  1821. this._x = ( m12 + m21 ) / s;
  1822. this._y = 0.25 * s;
  1823. this._z = ( m23 + m32 ) / s;
  1824. } else {
  1825. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1826. this._w = ( m21 - m12 ) / s;
  1827. this._x = ( m13 + m31 ) / s;
  1828. this._y = ( m23 + m32 ) / s;
  1829. this._z = 0.25 * s;
  1830. }
  1831. this._onChangeCallback();
  1832. return this;
  1833. },
  1834. setFromUnitVectors: function ( vFrom, vTo ) {
  1835. // assumes direction vectors vFrom and vTo are normalized
  1836. var EPS = 0.000001;
  1837. var r = vFrom.dot( vTo ) + 1;
  1838. if ( r < EPS ) {
  1839. r = 0;
  1840. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1841. this._x = - vFrom.y;
  1842. this._y = vFrom.x;
  1843. this._z = 0;
  1844. this._w = r;
  1845. } else {
  1846. this._x = 0;
  1847. this._y = - vFrom.z;
  1848. this._z = vFrom.y;
  1849. this._w = r;
  1850. }
  1851. } else {
  1852. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1853. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1854. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1855. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1856. this._w = r;
  1857. }
  1858. return this.normalize();
  1859. },
  1860. angleTo: function ( q ) {
  1861. return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) );
  1862. },
  1863. rotateTowards: function ( q, step ) {
  1864. var angle = this.angleTo( q );
  1865. if ( angle === 0 ) return this;
  1866. var t = Math.min( 1, step / angle );
  1867. this.slerp( q, t );
  1868. return this;
  1869. },
  1870. inverse: function () {
  1871. // quaternion is assumed to have unit length
  1872. return this.conjugate();
  1873. },
  1874. conjugate: function () {
  1875. this._x *= - 1;
  1876. this._y *= - 1;
  1877. this._z *= - 1;
  1878. this._onChangeCallback();
  1879. return this;
  1880. },
  1881. dot: function ( v ) {
  1882. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1883. },
  1884. lengthSq: function () {
  1885. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1886. },
  1887. length: function () {
  1888. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1889. },
  1890. normalize: function () {
  1891. var l = this.length();
  1892. if ( l === 0 ) {
  1893. this._x = 0;
  1894. this._y = 0;
  1895. this._z = 0;
  1896. this._w = 1;
  1897. } else {
  1898. l = 1 / l;
  1899. this._x = this._x * l;
  1900. this._y = this._y * l;
  1901. this._z = this._z * l;
  1902. this._w = this._w * l;
  1903. }
  1904. this._onChangeCallback();
  1905. return this;
  1906. },
  1907. multiply: function ( q, p ) {
  1908. if ( p !== undefined ) {
  1909. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1910. return this.multiplyQuaternions( q, p );
  1911. }
  1912. return this.multiplyQuaternions( this, q );
  1913. },
  1914. premultiply: function ( q ) {
  1915. return this.multiplyQuaternions( q, this );
  1916. },
  1917. multiplyQuaternions: function ( a, b ) {
  1918. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1919. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1920. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1921. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1922. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1923. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1924. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1925. this._onChangeCallback();
  1926. return this;
  1927. },
  1928. slerp: function ( qb, t ) {
  1929. if ( t === 0 ) return this;
  1930. if ( t === 1 ) return this.copy( qb );
  1931. var x = this._x, y = this._y, z = this._z, w = this._w;
  1932. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1933. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1934. if ( cosHalfTheta < 0 ) {
  1935. this._w = - qb._w;
  1936. this._x = - qb._x;
  1937. this._y = - qb._y;
  1938. this._z = - qb._z;
  1939. cosHalfTheta = - cosHalfTheta;
  1940. } else {
  1941. this.copy( qb );
  1942. }
  1943. if ( cosHalfTheta >= 1.0 ) {
  1944. this._w = w;
  1945. this._x = x;
  1946. this._y = y;
  1947. this._z = z;
  1948. return this;
  1949. }
  1950. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1951. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1952. var s = 1 - t;
  1953. this._w = s * w + t * this._w;
  1954. this._x = s * x + t * this._x;
  1955. this._y = s * y + t * this._y;
  1956. this._z = s * z + t * this._z;
  1957. this.normalize();
  1958. this._onChangeCallback();
  1959. return this;
  1960. }
  1961. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1962. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1963. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1964. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1965. this._w = ( w * ratioA + this._w * ratioB );
  1966. this._x = ( x * ratioA + this._x * ratioB );
  1967. this._y = ( y * ratioA + this._y * ratioB );
  1968. this._z = ( z * ratioA + this._z * ratioB );
  1969. this._onChangeCallback();
  1970. return this;
  1971. },
  1972. equals: function ( quaternion ) {
  1973. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1974. },
  1975. fromArray: function ( array, offset ) {
  1976. if ( offset === undefined ) offset = 0;
  1977. this._x = array[ offset ];
  1978. this._y = array[ offset + 1 ];
  1979. this._z = array[ offset + 2 ];
  1980. this._w = array[ offset + 3 ];
  1981. this._onChangeCallback();
  1982. return this;
  1983. },
  1984. toArray: function ( array, offset ) {
  1985. if ( array === undefined ) array = [];
  1986. if ( offset === undefined ) offset = 0;
  1987. array[ offset ] = this._x;
  1988. array[ offset + 1 ] = this._y;
  1989. array[ offset + 2 ] = this._z;
  1990. array[ offset + 3 ] = this._w;
  1991. return array;
  1992. },
  1993. fromBufferAttribute: function ( attribute, index ) {
  1994. this._x = attribute.getX( index );
  1995. this._y = attribute.getY( index );
  1996. this._z = attribute.getZ( index );
  1997. this._w = attribute.getW( index );
  1998. return this;
  1999. },
  2000. _onChange: function ( callback ) {
  2001. this._onChangeCallback = callback;
  2002. return this;
  2003. },
  2004. _onChangeCallback: function () {}
  2005. } );
  2006. /**
  2007. * @author mrdoob / http://mrdoob.com/
  2008. * @author kile / http://kile.stravaganza.org/
  2009. * @author philogb / http://blog.thejit.org/
  2010. * @author mikael emtinger / http://gomo.se/
  2011. * @author egraether / http://egraether.com/
  2012. * @author WestLangley / http://github.com/WestLangley
  2013. */
  2014. var _vector = new Vector3();
  2015. var _quaternion = new Quaternion();
  2016. function Vector3( x, y, z ) {
  2017. this.x = x || 0;
  2018. this.y = y || 0;
  2019. this.z = z || 0;
  2020. }
  2021. Object.assign( Vector3.prototype, {
  2022. isVector3: true,
  2023. set: function ( x, y, z ) {
  2024. this.x = x;
  2025. this.y = y;
  2026. this.z = z;
  2027. return this;
  2028. },
  2029. setScalar: function ( scalar ) {
  2030. this.x = scalar;
  2031. this.y = scalar;
  2032. this.z = scalar;
  2033. return this;
  2034. },
  2035. setX: function ( x ) {
  2036. this.x = x;
  2037. return this;
  2038. },
  2039. setY: function ( y ) {
  2040. this.y = y;
  2041. return this;
  2042. },
  2043. setZ: function ( z ) {
  2044. this.z = z;
  2045. return this;
  2046. },
  2047. setComponent: function ( index, value ) {
  2048. switch ( index ) {
  2049. case 0: this.x = value; break;
  2050. case 1: this.y = value; break;
  2051. case 2: this.z = value; break;
  2052. default: throw new Error( 'index is out of range: ' + index );
  2053. }
  2054. return this;
  2055. },
  2056. getComponent: function ( index ) {
  2057. switch ( index ) {
  2058. case 0: return this.x;
  2059. case 1: return this.y;
  2060. case 2: return this.z;
  2061. default: throw new Error( 'index is out of range: ' + index );
  2062. }
  2063. },
  2064. clone: function () {
  2065. return new this.constructor( this.x, this.y, this.z );
  2066. },
  2067. copy: function ( v ) {
  2068. this.x = v.x;
  2069. this.y = v.y;
  2070. this.z = v.z;
  2071. return this;
  2072. },
  2073. add: function ( v, w ) {
  2074. if ( w !== undefined ) {
  2075. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2076. return this.addVectors( v, w );
  2077. }
  2078. this.x += v.x;
  2079. this.y += v.y;
  2080. this.z += v.z;
  2081. return this;
  2082. },
  2083. addScalar: function ( s ) {
  2084. this.x += s;
  2085. this.y += s;
  2086. this.z += s;
  2087. return this;
  2088. },
  2089. addVectors: function ( a, b ) {
  2090. this.x = a.x + b.x;
  2091. this.y = a.y + b.y;
  2092. this.z = a.z + b.z;
  2093. return this;
  2094. },
  2095. addScaledVector: function ( v, s ) {
  2096. this.x += v.x * s;
  2097. this.y += v.y * s;
  2098. this.z += v.z * s;
  2099. return this;
  2100. },
  2101. sub: function ( v, w ) {
  2102. if ( w !== undefined ) {
  2103. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2104. return this.subVectors( v, w );
  2105. }
  2106. this.x -= v.x;
  2107. this.y -= v.y;
  2108. this.z -= v.z;
  2109. return this;
  2110. },
  2111. subScalar: function ( s ) {
  2112. this.x -= s;
  2113. this.y -= s;
  2114. this.z -= s;
  2115. return this;
  2116. },
  2117. subVectors: function ( a, b ) {
  2118. this.x = a.x - b.x;
  2119. this.y = a.y - b.y;
  2120. this.z = a.z - b.z;
  2121. return this;
  2122. },
  2123. multiply: function ( v, w ) {
  2124. if ( w !== undefined ) {
  2125. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  2126. return this.multiplyVectors( v, w );
  2127. }
  2128. this.x *= v.x;
  2129. this.y *= v.y;
  2130. this.z *= v.z;
  2131. return this;
  2132. },
  2133. multiplyScalar: function ( scalar ) {
  2134. this.x *= scalar;
  2135. this.y *= scalar;
  2136. this.z *= scalar;
  2137. return this;
  2138. },
  2139. multiplyVectors: function ( a, b ) {
  2140. this.x = a.x * b.x;
  2141. this.y = a.y * b.y;
  2142. this.z = a.z * b.z;
  2143. return this;
  2144. },
  2145. applyEuler: function ( euler ) {
  2146. if ( ! ( euler && euler.isEuler ) ) {
  2147. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  2148. }
  2149. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  2150. },
  2151. applyAxisAngle: function ( axis, angle ) {
  2152. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  2153. },
  2154. applyMatrix3: function ( m ) {
  2155. var x = this.x, y = this.y, z = this.z;
  2156. var e = m.elements;
  2157. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2158. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2159. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2160. return this;
  2161. },
  2162. applyNormalMatrix: function ( m ) {
  2163. return this.applyMatrix3( m ).normalize();
  2164. },
  2165. applyMatrix4: function ( m ) {
  2166. var x = this.x, y = this.y, z = this.z;
  2167. var e = m.elements;
  2168. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2169. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2170. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2171. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2172. return this;
  2173. },
  2174. applyQuaternion: function ( q ) {
  2175. var x = this.x, y = this.y, z = this.z;
  2176. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2177. // calculate quat * vector
  2178. var ix = qw * x + qy * z - qz * y;
  2179. var iy = qw * y + qz * x - qx * z;
  2180. var iz = qw * z + qx * y - qy * x;
  2181. var iw = - qx * x - qy * y - qz * z;
  2182. // calculate result * inverse quat
  2183. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  2184. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  2185. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  2186. return this;
  2187. },
  2188. project: function ( camera ) {
  2189. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2190. },
  2191. unproject: function ( camera ) {
  2192. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2193. },
  2194. transformDirection: function ( m ) {
  2195. // input: THREE.Matrix4 affine matrix
  2196. // vector interpreted as a direction
  2197. var x = this.x, y = this.y, z = this.z;
  2198. var e = m.elements;
  2199. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2200. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2201. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2202. return this.normalize();
  2203. },
  2204. divide: function ( v ) {
  2205. this.x /= v.x;
  2206. this.y /= v.y;
  2207. this.z /= v.z;
  2208. return this;
  2209. },
  2210. divideScalar: function ( scalar ) {
  2211. return this.multiplyScalar( 1 / scalar );
  2212. },
  2213. min: function ( v ) {
  2214. this.x = Math.min( this.x, v.x );
  2215. this.y = Math.min( this.y, v.y );
  2216. this.z = Math.min( this.z, v.z );
  2217. return this;
  2218. },
  2219. max: function ( v ) {
  2220. this.x = Math.max( this.x, v.x );
  2221. this.y = Math.max( this.y, v.y );
  2222. this.z = Math.max( this.z, v.z );
  2223. return this;
  2224. },
  2225. clamp: function ( min, max ) {
  2226. // assumes min < max, componentwise
  2227. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2228. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2229. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2230. return this;
  2231. },
  2232. clampScalar: function ( minVal, maxVal ) {
  2233. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2234. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2235. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2236. return this;
  2237. },
  2238. clampLength: function ( min, max ) {
  2239. var length = this.length();
  2240. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2241. },
  2242. floor: function () {
  2243. this.x = Math.floor( this.x );
  2244. this.y = Math.floor( this.y );
  2245. this.z = Math.floor( this.z );
  2246. return this;
  2247. },
  2248. ceil: function () {
  2249. this.x = Math.ceil( this.x );
  2250. this.y = Math.ceil( this.y );
  2251. this.z = Math.ceil( this.z );
  2252. return this;
  2253. },
  2254. round: function () {
  2255. this.x = Math.round( this.x );
  2256. this.y = Math.round( this.y );
  2257. this.z = Math.round( this.z );
  2258. return this;
  2259. },
  2260. roundToZero: function () {
  2261. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2262. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2263. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2264. return this;
  2265. },
  2266. negate: function () {
  2267. this.x = - this.x;
  2268. this.y = - this.y;
  2269. this.z = - this.z;
  2270. return this;
  2271. },
  2272. dot: function ( v ) {
  2273. return this.x * v.x + this.y * v.y + this.z * v.z;
  2274. },
  2275. // TODO lengthSquared?
  2276. lengthSq: function () {
  2277. return this.x * this.x + this.y * this.y + this.z * this.z;
  2278. },
  2279. length: function () {
  2280. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2281. },
  2282. manhattanLength: function () {
  2283. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2284. },
  2285. normalize: function () {
  2286. return this.divideScalar( this.length() || 1 );
  2287. },
  2288. setLength: function ( length ) {
  2289. return this.normalize().multiplyScalar( length );
  2290. },
  2291. lerp: function ( v, alpha ) {
  2292. this.x += ( v.x - this.x ) * alpha;
  2293. this.y += ( v.y - this.y ) * alpha;
  2294. this.z += ( v.z - this.z ) * alpha;
  2295. return this;
  2296. },
  2297. lerpVectors: function ( v1, v2, alpha ) {
  2298. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2299. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2300. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2301. return this;
  2302. },
  2303. cross: function ( v, w ) {
  2304. if ( w !== undefined ) {
  2305. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  2306. return this.crossVectors( v, w );
  2307. }
  2308. return this.crossVectors( this, v );
  2309. },
  2310. crossVectors: function ( a, b ) {
  2311. var ax = a.x, ay = a.y, az = a.z;
  2312. var bx = b.x, by = b.y, bz = b.z;
  2313. this.x = ay * bz - az * by;
  2314. this.y = az * bx - ax * bz;
  2315. this.z = ax * by - ay * bx;
  2316. return this;
  2317. },
  2318. projectOnVector: function ( v ) {
  2319. var denominator = v.lengthSq();
  2320. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2321. var scalar = v.dot( this ) / denominator;
  2322. return this.copy( v ).multiplyScalar( scalar );
  2323. },
  2324. projectOnPlane: function ( planeNormal ) {
  2325. _vector.copy( this ).projectOnVector( planeNormal );
  2326. return this.sub( _vector );
  2327. },
  2328. reflect: function ( normal ) {
  2329. // reflect incident vector off plane orthogonal to normal
  2330. // normal is assumed to have unit length
  2331. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2332. },
  2333. angleTo: function ( v ) {
  2334. var denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2335. if ( denominator === 0 ) return Math.PI / 2;
  2336. var theta = this.dot( v ) / denominator;
  2337. // clamp, to handle numerical problems
  2338. return Math.acos( MathUtils.clamp( theta, - 1, 1 ) );
  2339. },
  2340. distanceTo: function ( v ) {
  2341. return Math.sqrt( this.distanceToSquared( v ) );
  2342. },
  2343. distanceToSquared: function ( v ) {
  2344. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2345. return dx * dx + dy * dy + dz * dz;
  2346. },
  2347. manhattanDistanceTo: function ( v ) {
  2348. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2349. },
  2350. setFromSpherical: function ( s ) {
  2351. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2352. },
  2353. setFromSphericalCoords: function ( radius, phi, theta ) {
  2354. var sinPhiRadius = Math.sin( phi ) * radius;
  2355. this.x = sinPhiRadius * Math.sin( theta );
  2356. this.y = Math.cos( phi ) * radius;
  2357. this.z = sinPhiRadius * Math.cos( theta );
  2358. return this;
  2359. },
  2360. setFromCylindrical: function ( c ) {
  2361. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2362. },
  2363. setFromCylindricalCoords: function ( radius, theta, y ) {
  2364. this.x = radius * Math.sin( theta );
  2365. this.y = y;
  2366. this.z = radius * Math.cos( theta );
  2367. return this;
  2368. },
  2369. setFromMatrixPosition: function ( m ) {
  2370. var e = m.elements;
  2371. this.x = e[ 12 ];
  2372. this.y = e[ 13 ];
  2373. this.z = e[ 14 ];
  2374. return this;
  2375. },
  2376. setFromMatrixScale: function ( m ) {
  2377. var sx = this.setFromMatrixColumn( m, 0 ).length();
  2378. var sy = this.setFromMatrixColumn( m, 1 ).length();
  2379. var sz = this.setFromMatrixColumn( m, 2 ).length();
  2380. this.x = sx;
  2381. this.y = sy;
  2382. this.z = sz;
  2383. return this;
  2384. },
  2385. setFromMatrixColumn: function ( m, index ) {
  2386. return this.fromArray( m.elements, index * 4 );
  2387. },
  2388. setFromMatrix3Column: function ( m, index ) {
  2389. return this.fromArray( m.elements, index * 3 );
  2390. },
  2391. equals: function ( v ) {
  2392. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2393. },
  2394. fromArray: function ( array, offset ) {
  2395. if ( offset === undefined ) offset = 0;
  2396. this.x = array[ offset ];
  2397. this.y = array[ offset + 1 ];
  2398. this.z = array[ offset + 2 ];
  2399. return this;
  2400. },
  2401. toArray: function ( array, offset ) {
  2402. if ( array === undefined ) array = [];
  2403. if ( offset === undefined ) offset = 0;
  2404. array[ offset ] = this.x;
  2405. array[ offset + 1 ] = this.y;
  2406. array[ offset + 2 ] = this.z;
  2407. return array;
  2408. },
  2409. fromBufferAttribute: function ( attribute, index, offset ) {
  2410. if ( offset !== undefined ) {
  2411. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  2412. }
  2413. this.x = attribute.getX( index );
  2414. this.y = attribute.getY( index );
  2415. this.z = attribute.getZ( index );
  2416. return this;
  2417. },
  2418. random: function () {
  2419. this.x = Math.random();
  2420. this.y = Math.random();
  2421. this.z = Math.random();
  2422. return this;
  2423. }
  2424. } );
  2425. var _v1 = new Vector3();
  2426. var _m1 = new Matrix4();
  2427. var _zero = new Vector3( 0, 0, 0 );
  2428. var _one = new Vector3( 1, 1, 1 );
  2429. var _x = new Vector3();
  2430. var _y = new Vector3();
  2431. var _z = new Vector3();
  2432. /**
  2433. * @author mrdoob / http://mrdoob.com/
  2434. * @author supereggbert / http://www.paulbrunt.co.uk/
  2435. * @author philogb / http://blog.thejit.org/
  2436. * @author jordi_ros / http://plattsoft.com
  2437. * @author D1plo1d / http://github.com/D1plo1d
  2438. * @author alteredq / http://alteredqualia.com/
  2439. * @author mikael emtinger / http://gomo.se/
  2440. * @author timknip / http://www.floorplanner.com/
  2441. * @author bhouston / http://clara.io
  2442. * @author WestLangley / http://github.com/WestLangley
  2443. */
  2444. function Matrix4() {
  2445. this.elements = [
  2446. 1, 0, 0, 0,
  2447. 0, 1, 0, 0,
  2448. 0, 0, 1, 0,
  2449. 0, 0, 0, 1
  2450. ];
  2451. if ( arguments.length > 0 ) {
  2452. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2453. }
  2454. }
  2455. Object.assign( Matrix4.prototype, {
  2456. isMatrix4: true,
  2457. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2458. var te = this.elements;
  2459. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2460. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2461. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2462. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2463. return this;
  2464. },
  2465. identity: function () {
  2466. this.set(
  2467. 1, 0, 0, 0,
  2468. 0, 1, 0, 0,
  2469. 0, 0, 1, 0,
  2470. 0, 0, 0, 1
  2471. );
  2472. return this;
  2473. },
  2474. clone: function () {
  2475. return new Matrix4().fromArray( this.elements );
  2476. },
  2477. copy: function ( m ) {
  2478. var te = this.elements;
  2479. var me = m.elements;
  2480. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2481. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2482. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2483. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2484. return this;
  2485. },
  2486. copyPosition: function ( m ) {
  2487. var te = this.elements, me = m.elements;
  2488. te[ 12 ] = me[ 12 ];
  2489. te[ 13 ] = me[ 13 ];
  2490. te[ 14 ] = me[ 14 ];
  2491. return this;
  2492. },
  2493. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2494. xAxis.setFromMatrixColumn( this, 0 );
  2495. yAxis.setFromMatrixColumn( this, 1 );
  2496. zAxis.setFromMatrixColumn( this, 2 );
  2497. return this;
  2498. },
  2499. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2500. this.set(
  2501. xAxis.x, yAxis.x, zAxis.x, 0,
  2502. xAxis.y, yAxis.y, zAxis.y, 0,
  2503. xAxis.z, yAxis.z, zAxis.z, 0,
  2504. 0, 0, 0, 1
  2505. );
  2506. return this;
  2507. },
  2508. extractRotation: function ( m ) {
  2509. // this method does not support reflection matrices
  2510. var te = this.elements;
  2511. var me = m.elements;
  2512. var scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length();
  2513. var scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length();
  2514. var scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length();
  2515. te[ 0 ] = me[ 0 ] * scaleX;
  2516. te[ 1 ] = me[ 1 ] * scaleX;
  2517. te[ 2 ] = me[ 2 ] * scaleX;
  2518. te[ 3 ] = 0;
  2519. te[ 4 ] = me[ 4 ] * scaleY;
  2520. te[ 5 ] = me[ 5 ] * scaleY;
  2521. te[ 6 ] = me[ 6 ] * scaleY;
  2522. te[ 7 ] = 0;
  2523. te[ 8 ] = me[ 8 ] * scaleZ;
  2524. te[ 9 ] = me[ 9 ] * scaleZ;
  2525. te[ 10 ] = me[ 10 ] * scaleZ;
  2526. te[ 11 ] = 0;
  2527. te[ 12 ] = 0;
  2528. te[ 13 ] = 0;
  2529. te[ 14 ] = 0;
  2530. te[ 15 ] = 1;
  2531. return this;
  2532. },
  2533. makeRotationFromEuler: function ( euler ) {
  2534. if ( ! ( euler && euler.isEuler ) ) {
  2535. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2536. }
  2537. var te = this.elements;
  2538. var x = euler.x, y = euler.y, z = euler.z;
  2539. var a = Math.cos( x ), b = Math.sin( x );
  2540. var c = Math.cos( y ), d = Math.sin( y );
  2541. var e = Math.cos( z ), f = Math.sin( z );
  2542. if ( euler.order === 'XYZ' ) {
  2543. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2544. te[ 0 ] = c * e;
  2545. te[ 4 ] = - c * f;
  2546. te[ 8 ] = d;
  2547. te[ 1 ] = af + be * d;
  2548. te[ 5 ] = ae - bf * d;
  2549. te[ 9 ] = - b * c;
  2550. te[ 2 ] = bf - ae * d;
  2551. te[ 6 ] = be + af * d;
  2552. te[ 10 ] = a * c;
  2553. } else if ( euler.order === 'YXZ' ) {
  2554. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2555. te[ 0 ] = ce + df * b;
  2556. te[ 4 ] = de * b - cf;
  2557. te[ 8 ] = a * d;
  2558. te[ 1 ] = a * f;
  2559. te[ 5 ] = a * e;
  2560. te[ 9 ] = - b;
  2561. te[ 2 ] = cf * b - de;
  2562. te[ 6 ] = df + ce * b;
  2563. te[ 10 ] = a * c;
  2564. } else if ( euler.order === 'ZXY' ) {
  2565. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2566. te[ 0 ] = ce - df * b;
  2567. te[ 4 ] = - a * f;
  2568. te[ 8 ] = de + cf * b;
  2569. te[ 1 ] = cf + de * b;
  2570. te[ 5 ] = a * e;
  2571. te[ 9 ] = df - ce * b;
  2572. te[ 2 ] = - a * d;
  2573. te[ 6 ] = b;
  2574. te[ 10 ] = a * c;
  2575. } else if ( euler.order === 'ZYX' ) {
  2576. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2577. te[ 0 ] = c * e;
  2578. te[ 4 ] = be * d - af;
  2579. te[ 8 ] = ae * d + bf;
  2580. te[ 1 ] = c * f;
  2581. te[ 5 ] = bf * d + ae;
  2582. te[ 9 ] = af * d - be;
  2583. te[ 2 ] = - d;
  2584. te[ 6 ] = b * c;
  2585. te[ 10 ] = a * c;
  2586. } else if ( euler.order === 'YZX' ) {
  2587. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2588. te[ 0 ] = c * e;
  2589. te[ 4 ] = bd - ac * f;
  2590. te[ 8 ] = bc * f + ad;
  2591. te[ 1 ] = f;
  2592. te[ 5 ] = a * e;
  2593. te[ 9 ] = - b * e;
  2594. te[ 2 ] = - d * e;
  2595. te[ 6 ] = ad * f + bc;
  2596. te[ 10 ] = ac - bd * f;
  2597. } else if ( euler.order === 'XZY' ) {
  2598. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2599. te[ 0 ] = c * e;
  2600. te[ 4 ] = - f;
  2601. te[ 8 ] = d * e;
  2602. te[ 1 ] = ac * f + bd;
  2603. te[ 5 ] = a * e;
  2604. te[ 9 ] = ad * f - bc;
  2605. te[ 2 ] = bc * f - ad;
  2606. te[ 6 ] = b * e;
  2607. te[ 10 ] = bd * f + ac;
  2608. }
  2609. // bottom row
  2610. te[ 3 ] = 0;
  2611. te[ 7 ] = 0;
  2612. te[ 11 ] = 0;
  2613. // last column
  2614. te[ 12 ] = 0;
  2615. te[ 13 ] = 0;
  2616. te[ 14 ] = 0;
  2617. te[ 15 ] = 1;
  2618. return this;
  2619. },
  2620. makeRotationFromQuaternion: function ( q ) {
  2621. return this.compose( _zero, q, _one );
  2622. },
  2623. lookAt: function ( eye, target, up ) {
  2624. var te = this.elements;
  2625. _z.subVectors( eye, target );
  2626. if ( _z.lengthSq() === 0 ) {
  2627. // eye and target are in the same position
  2628. _z.z = 1;
  2629. }
  2630. _z.normalize();
  2631. _x.crossVectors( up, _z );
  2632. if ( _x.lengthSq() === 0 ) {
  2633. // up and z are parallel
  2634. if ( Math.abs( up.z ) === 1 ) {
  2635. _z.x += 0.0001;
  2636. } else {
  2637. _z.z += 0.0001;
  2638. }
  2639. _z.normalize();
  2640. _x.crossVectors( up, _z );
  2641. }
  2642. _x.normalize();
  2643. _y.crossVectors( _z, _x );
  2644. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  2645. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  2646. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  2647. return this;
  2648. },
  2649. multiply: function ( m, n ) {
  2650. if ( n !== undefined ) {
  2651. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2652. return this.multiplyMatrices( m, n );
  2653. }
  2654. return this.multiplyMatrices( this, m );
  2655. },
  2656. premultiply: function ( m ) {
  2657. return this.multiplyMatrices( m, this );
  2658. },
  2659. multiplyMatrices: function ( a, b ) {
  2660. var ae = a.elements;
  2661. var be = b.elements;
  2662. var te = this.elements;
  2663. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2664. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2665. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2666. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2667. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2668. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2669. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2670. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2671. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2672. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2673. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2674. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2675. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2676. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2677. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2678. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2679. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2680. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2681. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2682. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2683. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2684. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2685. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2686. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2687. return this;
  2688. },
  2689. multiplyScalar: function ( s ) {
  2690. var te = this.elements;
  2691. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2692. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2693. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2694. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2695. return this;
  2696. },
  2697. determinant: function () {
  2698. var te = this.elements;
  2699. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2700. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2701. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2702. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2703. //TODO: make this more efficient
  2704. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2705. return (
  2706. n41 * (
  2707. + n14 * n23 * n32
  2708. - n13 * n24 * n32
  2709. - n14 * n22 * n33
  2710. + n12 * n24 * n33
  2711. + n13 * n22 * n34
  2712. - n12 * n23 * n34
  2713. ) +
  2714. n42 * (
  2715. + n11 * n23 * n34
  2716. - n11 * n24 * n33
  2717. + n14 * n21 * n33
  2718. - n13 * n21 * n34
  2719. + n13 * n24 * n31
  2720. - n14 * n23 * n31
  2721. ) +
  2722. n43 * (
  2723. + n11 * n24 * n32
  2724. - n11 * n22 * n34
  2725. - n14 * n21 * n32
  2726. + n12 * n21 * n34
  2727. + n14 * n22 * n31
  2728. - n12 * n24 * n31
  2729. ) +
  2730. n44 * (
  2731. - n13 * n22 * n31
  2732. - n11 * n23 * n32
  2733. + n11 * n22 * n33
  2734. + n13 * n21 * n32
  2735. - n12 * n21 * n33
  2736. + n12 * n23 * n31
  2737. )
  2738. );
  2739. },
  2740. transpose: function () {
  2741. var te = this.elements;
  2742. var tmp;
  2743. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2744. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2745. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2746. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2747. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2748. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2749. return this;
  2750. },
  2751. setPosition: function ( x, y, z ) {
  2752. var te = this.elements;
  2753. if ( x.isVector3 ) {
  2754. te[ 12 ] = x.x;
  2755. te[ 13 ] = x.y;
  2756. te[ 14 ] = x.z;
  2757. } else {
  2758. te[ 12 ] = x;
  2759. te[ 13 ] = y;
  2760. te[ 14 ] = z;
  2761. }
  2762. return this;
  2763. },
  2764. getInverse: function ( m, throwOnDegenerate ) {
  2765. if ( throwOnDegenerate !== undefined ) {
  2766. console.warn( "THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate." );
  2767. }
  2768. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2769. var te = this.elements,
  2770. me = m.elements,
  2771. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2772. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2773. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2774. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2775. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2776. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2777. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2778. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2779. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2780. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  2781. var detInv = 1 / det;
  2782. te[ 0 ] = t11 * detInv;
  2783. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2784. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2785. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2786. te[ 4 ] = t12 * detInv;
  2787. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2788. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2789. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2790. te[ 8 ] = t13 * detInv;
  2791. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2792. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2793. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2794. te[ 12 ] = t14 * detInv;
  2795. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2796. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2797. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2798. return this;
  2799. },
  2800. scale: function ( v ) {
  2801. var te = this.elements;
  2802. var x = v.x, y = v.y, z = v.z;
  2803. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2804. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2805. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2806. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2807. return this;
  2808. },
  2809. getMaxScaleOnAxis: function () {
  2810. var te = this.elements;
  2811. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2812. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2813. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2814. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2815. },
  2816. makeTranslation: function ( x, y, z ) {
  2817. this.set(
  2818. 1, 0, 0, x,
  2819. 0, 1, 0, y,
  2820. 0, 0, 1, z,
  2821. 0, 0, 0, 1
  2822. );
  2823. return this;
  2824. },
  2825. makeRotationX: function ( theta ) {
  2826. var c = Math.cos( theta ), s = Math.sin( theta );
  2827. this.set(
  2828. 1, 0, 0, 0,
  2829. 0, c, - s, 0,
  2830. 0, s, c, 0,
  2831. 0, 0, 0, 1
  2832. );
  2833. return this;
  2834. },
  2835. makeRotationY: function ( theta ) {
  2836. var c = Math.cos( theta ), s = Math.sin( theta );
  2837. this.set(
  2838. c, 0, s, 0,
  2839. 0, 1, 0, 0,
  2840. - s, 0, c, 0,
  2841. 0, 0, 0, 1
  2842. );
  2843. return this;
  2844. },
  2845. makeRotationZ: function ( theta ) {
  2846. var c = Math.cos( theta ), s = Math.sin( theta );
  2847. this.set(
  2848. c, - s, 0, 0,
  2849. s, c, 0, 0,
  2850. 0, 0, 1, 0,
  2851. 0, 0, 0, 1
  2852. );
  2853. return this;
  2854. },
  2855. makeRotationAxis: function ( axis, angle ) {
  2856. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2857. var c = Math.cos( angle );
  2858. var s = Math.sin( angle );
  2859. var t = 1 - c;
  2860. var x = axis.x, y = axis.y, z = axis.z;
  2861. var tx = t * x, ty = t * y;
  2862. this.set(
  2863. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2864. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2865. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2866. 0, 0, 0, 1
  2867. );
  2868. return this;
  2869. },
  2870. makeScale: function ( x, y, z ) {
  2871. this.set(
  2872. x, 0, 0, 0,
  2873. 0, y, 0, 0,
  2874. 0, 0, z, 0,
  2875. 0, 0, 0, 1
  2876. );
  2877. return this;
  2878. },
  2879. makeShear: function ( x, y, z ) {
  2880. this.set(
  2881. 1, y, z, 0,
  2882. x, 1, z, 0,
  2883. x, y, 1, 0,
  2884. 0, 0, 0, 1
  2885. );
  2886. return this;
  2887. },
  2888. compose: function ( position, quaternion, scale ) {
  2889. var te = this.elements;
  2890. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2891. var x2 = x + x, y2 = y + y, z2 = z + z;
  2892. var xx = x * x2, xy = x * y2, xz = x * z2;
  2893. var yy = y * y2, yz = y * z2, zz = z * z2;
  2894. var wx = w * x2, wy = w * y2, wz = w * z2;
  2895. var sx = scale.x, sy = scale.y, sz = scale.z;
  2896. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2897. te[ 1 ] = ( xy + wz ) * sx;
  2898. te[ 2 ] = ( xz - wy ) * sx;
  2899. te[ 3 ] = 0;
  2900. te[ 4 ] = ( xy - wz ) * sy;
  2901. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2902. te[ 6 ] = ( yz + wx ) * sy;
  2903. te[ 7 ] = 0;
  2904. te[ 8 ] = ( xz + wy ) * sz;
  2905. te[ 9 ] = ( yz - wx ) * sz;
  2906. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2907. te[ 11 ] = 0;
  2908. te[ 12 ] = position.x;
  2909. te[ 13 ] = position.y;
  2910. te[ 14 ] = position.z;
  2911. te[ 15 ] = 1;
  2912. return this;
  2913. },
  2914. decompose: function ( position, quaternion, scale ) {
  2915. var te = this.elements;
  2916. var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2917. var sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2918. var sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2919. // if determine is negative, we need to invert one scale
  2920. var det = this.determinant();
  2921. if ( det < 0 ) sx = - sx;
  2922. position.x = te[ 12 ];
  2923. position.y = te[ 13 ];
  2924. position.z = te[ 14 ];
  2925. // scale the rotation part
  2926. _m1.copy( this );
  2927. var invSX = 1 / sx;
  2928. var invSY = 1 / sy;
  2929. var invSZ = 1 / sz;
  2930. _m1.elements[ 0 ] *= invSX;
  2931. _m1.elements[ 1 ] *= invSX;
  2932. _m1.elements[ 2 ] *= invSX;
  2933. _m1.elements[ 4 ] *= invSY;
  2934. _m1.elements[ 5 ] *= invSY;
  2935. _m1.elements[ 6 ] *= invSY;
  2936. _m1.elements[ 8 ] *= invSZ;
  2937. _m1.elements[ 9 ] *= invSZ;
  2938. _m1.elements[ 10 ] *= invSZ;
  2939. quaternion.setFromRotationMatrix( _m1 );
  2940. scale.x = sx;
  2941. scale.y = sy;
  2942. scale.z = sz;
  2943. return this;
  2944. },
  2945. makePerspective: function ( left, right, top, bottom, near, far ) {
  2946. if ( far === undefined ) {
  2947. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2948. }
  2949. var te = this.elements;
  2950. var x = 2 * near / ( right - left );
  2951. var y = 2 * near / ( top - bottom );
  2952. var a = ( right + left ) / ( right - left );
  2953. var b = ( top + bottom ) / ( top - bottom );
  2954. var c = - ( far + near ) / ( far - near );
  2955. var d = - 2 * far * near / ( far - near );
  2956. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2957. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2958. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2959. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2960. return this;
  2961. },
  2962. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2963. var te = this.elements;
  2964. var w = 1.0 / ( right - left );
  2965. var h = 1.0 / ( top - bottom );
  2966. var p = 1.0 / ( far - near );
  2967. var x = ( right + left ) * w;
  2968. var y = ( top + bottom ) * h;
  2969. var z = ( far + near ) * p;
  2970. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2971. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2972. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2973. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2974. return this;
  2975. },
  2976. equals: function ( matrix ) {
  2977. var te = this.elements;
  2978. var me = matrix.elements;
  2979. for ( var i = 0; i < 16; i ++ ) {
  2980. if ( te[ i ] !== me[ i ] ) return false;
  2981. }
  2982. return true;
  2983. },
  2984. fromArray: function ( array, offset ) {
  2985. if ( offset === undefined ) offset = 0;
  2986. for ( var i = 0; i < 16; i ++ ) {
  2987. this.elements[ i ] = array[ i + offset ];
  2988. }
  2989. return this;
  2990. },
  2991. toArray: function ( array, offset ) {
  2992. if ( array === undefined ) array = [];
  2993. if ( offset === undefined ) offset = 0;
  2994. var te = this.elements;
  2995. array[ offset ] = te[ 0 ];
  2996. array[ offset + 1 ] = te[ 1 ];
  2997. array[ offset + 2 ] = te[ 2 ];
  2998. array[ offset + 3 ] = te[ 3 ];
  2999. array[ offset + 4 ] = te[ 4 ];
  3000. array[ offset + 5 ] = te[ 5 ];
  3001. array[ offset + 6 ] = te[ 6 ];
  3002. array[ offset + 7 ] = te[ 7 ];
  3003. array[ offset + 8 ] = te[ 8 ];
  3004. array[ offset + 9 ] = te[ 9 ];
  3005. array[ offset + 10 ] = te[ 10 ];
  3006. array[ offset + 11 ] = te[ 11 ];
  3007. array[ offset + 12 ] = te[ 12 ];
  3008. array[ offset + 13 ] = te[ 13 ];
  3009. array[ offset + 14 ] = te[ 14 ];
  3010. array[ offset + 15 ] = te[ 15 ];
  3011. return array;
  3012. }
  3013. } );
  3014. /**
  3015. * @author mrdoob / http://mrdoob.com/
  3016. * @author WestLangley / http://github.com/WestLangley
  3017. * @author bhouston / http://clara.io
  3018. */
  3019. var _matrix = new Matrix4();
  3020. var _quaternion$1 = new Quaternion();
  3021. function Euler( x, y, z, order ) {
  3022. this._x = x || 0;
  3023. this._y = y || 0;
  3024. this._z = z || 0;
  3025. this._order = order || Euler.DefaultOrder;
  3026. }
  3027. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  3028. Euler.DefaultOrder = 'XYZ';
  3029. Object.defineProperties( Euler.prototype, {
  3030. x: {
  3031. get: function () {
  3032. return this._x;
  3033. },
  3034. set: function ( value ) {
  3035. this._x = value;
  3036. this._onChangeCallback();
  3037. }
  3038. },
  3039. y: {
  3040. get: function () {
  3041. return this._y;
  3042. },
  3043. set: function ( value ) {
  3044. this._y = value;
  3045. this._onChangeCallback();
  3046. }
  3047. },
  3048. z: {
  3049. get: function () {
  3050. return this._z;
  3051. },
  3052. set: function ( value ) {
  3053. this._z = value;
  3054. this._onChangeCallback();
  3055. }
  3056. },
  3057. order: {
  3058. get: function () {
  3059. return this._order;
  3060. },
  3061. set: function ( value ) {
  3062. this._order = value;
  3063. this._onChangeCallback();
  3064. }
  3065. }
  3066. } );
  3067. Object.assign( Euler.prototype, {
  3068. isEuler: true,
  3069. set: function ( x, y, z, order ) {
  3070. this._x = x;
  3071. this._y = y;
  3072. this._z = z;
  3073. this._order = order || this._order;
  3074. this._onChangeCallback();
  3075. return this;
  3076. },
  3077. clone: function () {
  3078. return new this.constructor( this._x, this._y, this._z, this._order );
  3079. },
  3080. copy: function ( euler ) {
  3081. this._x = euler._x;
  3082. this._y = euler._y;
  3083. this._z = euler._z;
  3084. this._order = euler._order;
  3085. this._onChangeCallback();
  3086. return this;
  3087. },
  3088. setFromRotationMatrix: function ( m, order, update ) {
  3089. var clamp = MathUtils.clamp;
  3090. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3091. var te = m.elements;
  3092. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3093. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3094. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3095. order = order || this._order;
  3096. switch ( order ) {
  3097. case 'XYZ':
  3098. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3099. if ( Math.abs( m13 ) < 0.9999999 ) {
  3100. this._x = Math.atan2( - m23, m33 );
  3101. this._z = Math.atan2( - m12, m11 );
  3102. } else {
  3103. this._x = Math.atan2( m32, m22 );
  3104. this._z = 0;
  3105. }
  3106. break;
  3107. case 'YXZ':
  3108. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3109. if ( Math.abs( m23 ) < 0.9999999 ) {
  3110. this._y = Math.atan2( m13, m33 );
  3111. this._z = Math.atan2( m21, m22 );
  3112. } else {
  3113. this._y = Math.atan2( - m31, m11 );
  3114. this._z = 0;
  3115. }
  3116. break;
  3117. case 'ZXY':
  3118. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3119. if ( Math.abs( m32 ) < 0.9999999 ) {
  3120. this._y = Math.atan2( - m31, m33 );
  3121. this._z = Math.atan2( - m12, m22 );
  3122. } else {
  3123. this._y = 0;
  3124. this._z = Math.atan2( m21, m11 );
  3125. }
  3126. break;
  3127. case 'ZYX':
  3128. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3129. if ( Math.abs( m31 ) < 0.9999999 ) {
  3130. this._x = Math.atan2( m32, m33 );
  3131. this._z = Math.atan2( m21, m11 );
  3132. } else {
  3133. this._x = 0;
  3134. this._z = Math.atan2( - m12, m22 );
  3135. }
  3136. break;
  3137. case 'YZX':
  3138. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3139. if ( Math.abs( m21 ) < 0.9999999 ) {
  3140. this._x = Math.atan2( - m23, m22 );
  3141. this._y = Math.atan2( - m31, m11 );
  3142. } else {
  3143. this._x = 0;
  3144. this._y = Math.atan2( m13, m33 );
  3145. }
  3146. break;
  3147. case 'XZY':
  3148. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3149. if ( Math.abs( m12 ) < 0.9999999 ) {
  3150. this._x = Math.atan2( m32, m22 );
  3151. this._y = Math.atan2( m13, m11 );
  3152. } else {
  3153. this._x = Math.atan2( - m23, m33 );
  3154. this._y = 0;
  3155. }
  3156. break;
  3157. default:
  3158. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  3159. }
  3160. this._order = order;
  3161. if ( update !== false ) this._onChangeCallback();
  3162. return this;
  3163. },
  3164. setFromQuaternion: function ( q, order, update ) {
  3165. _matrix.makeRotationFromQuaternion( q );
  3166. return this.setFromRotationMatrix( _matrix, order, update );
  3167. },
  3168. setFromVector3: function ( v, order ) {
  3169. return this.set( v.x, v.y, v.z, order || this._order );
  3170. },
  3171. reorder: function ( newOrder ) {
  3172. // WARNING: this discards revolution information -bhouston
  3173. _quaternion$1.setFromEuler( this );
  3174. return this.setFromQuaternion( _quaternion$1, newOrder );
  3175. },
  3176. equals: function ( euler ) {
  3177. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3178. },
  3179. fromArray: function ( array ) {
  3180. this._x = array[ 0 ];
  3181. this._y = array[ 1 ];
  3182. this._z = array[ 2 ];
  3183. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3184. this._onChangeCallback();
  3185. return this;
  3186. },
  3187. toArray: function ( array, offset ) {
  3188. if ( array === undefined ) array = [];
  3189. if ( offset === undefined ) offset = 0;
  3190. array[ offset ] = this._x;
  3191. array[ offset + 1 ] = this._y;
  3192. array[ offset + 2 ] = this._z;
  3193. array[ offset + 3 ] = this._order;
  3194. return array;
  3195. },
  3196. toVector3: function ( optionalResult ) {
  3197. if ( optionalResult ) {
  3198. return optionalResult.set( this._x, this._y, this._z );
  3199. } else {
  3200. return new Vector3( this._x, this._y, this._z );
  3201. }
  3202. },
  3203. _onChange: function ( callback ) {
  3204. this._onChangeCallback = callback;
  3205. return this;
  3206. },
  3207. _onChangeCallback: function () {}
  3208. } );
  3209. /**
  3210. * @author mrdoob / http://mrdoob.com/
  3211. */
  3212. function Layers() {
  3213. this.mask = 1 | 0;
  3214. }
  3215. Object.assign( Layers.prototype, {
  3216. set: function ( channel ) {
  3217. this.mask = 1 << channel | 0;
  3218. },
  3219. enable: function ( channel ) {
  3220. this.mask |= 1 << channel | 0;
  3221. },
  3222. enableAll: function () {
  3223. this.mask = 0xffffffff | 0;
  3224. },
  3225. toggle: function ( channel ) {
  3226. this.mask ^= 1 << channel | 0;
  3227. },
  3228. disable: function ( channel ) {
  3229. this.mask &= ~ ( 1 << channel | 0 );
  3230. },
  3231. disableAll: function () {
  3232. this.mask = 0;
  3233. },
  3234. test: function ( layers ) {
  3235. return ( this.mask & layers.mask ) !== 0;
  3236. }
  3237. } );
  3238. let _object3DId = 0;
  3239. const _v1$1 = new Vector3();
  3240. const _q1 = new Quaternion();
  3241. const _m1$1 = new Matrix4();
  3242. const _target = new Vector3();
  3243. const _position = new Vector3();
  3244. const _scale = new Vector3();
  3245. const _quaternion$2 = new Quaternion();
  3246. const _xAxis = new Vector3( 1, 0, 0 );
  3247. const _yAxis = new Vector3( 0, 1, 0 );
  3248. const _zAxis = new Vector3( 0, 0, 1 );
  3249. const _addedEvent = { type: 'added' };
  3250. const _removedEvent = { type: 'removed' };
  3251. /**
  3252. * @author mrdoob / http://mrdoob.com/
  3253. * @author mikael emtinger / http://gomo.se/
  3254. * @author alteredq / http://alteredqualia.com/
  3255. * @author WestLangley / http://github.com/WestLangley
  3256. * @author elephantatwork / www.elephantatwork.ch
  3257. */
  3258. function Object3D() {
  3259. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3260. this.uuid = MathUtils.generateUUID();
  3261. this.name = '';
  3262. this.type = 'Object3D';
  3263. this.parent = null;
  3264. this.children = [];
  3265. this.up = Object3D.DefaultUp.clone();
  3266. var position = new Vector3();
  3267. var rotation = new Euler();
  3268. var quaternion = new Quaternion();
  3269. var scale = new Vector3( 1, 1, 1 );
  3270. function onRotationChange() {
  3271. quaternion.setFromEuler( rotation, false );
  3272. }
  3273. function onQuaternionChange() {
  3274. rotation.setFromQuaternion( quaternion, undefined, false );
  3275. }
  3276. rotation._onChange( onRotationChange );
  3277. quaternion._onChange( onQuaternionChange );
  3278. Object.defineProperties( this, {
  3279. position: {
  3280. configurable: true,
  3281. enumerable: true,
  3282. value: position
  3283. },
  3284. rotation: {
  3285. configurable: true,
  3286. enumerable: true,
  3287. value: rotation
  3288. },
  3289. quaternion: {
  3290. configurable: true,
  3291. enumerable: true,
  3292. value: quaternion
  3293. },
  3294. scale: {
  3295. configurable: true,
  3296. enumerable: true,
  3297. value: scale
  3298. },
  3299. modelViewMatrix: {
  3300. value: new Matrix4()
  3301. },
  3302. normalMatrix: {
  3303. value: new Matrix3()
  3304. }
  3305. } );
  3306. this.matrix = new Matrix4();
  3307. this.matrixWorld = new Matrix4();
  3308. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3309. this.matrixWorldNeedsUpdate = false;
  3310. this.layers = new Layers();
  3311. this.visible = true;
  3312. this.castShadow = false;
  3313. this.receiveShadow = false;
  3314. this.frustumCulled = true;
  3315. this.renderOrder = 0;
  3316. this.userData = {};
  3317. }
  3318. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3319. Object3D.DefaultMatrixAutoUpdate = true;
  3320. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3321. constructor: Object3D,
  3322. isObject3D: true,
  3323. onBeforeRender: function () {},
  3324. onAfterRender: function () {},
  3325. applyMatrix4: function ( matrix ) {
  3326. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3327. this.matrix.premultiply( matrix );
  3328. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3329. },
  3330. applyQuaternion: function ( q ) {
  3331. this.quaternion.premultiply( q );
  3332. return this;
  3333. },
  3334. setRotationFromAxisAngle: function ( axis, angle ) {
  3335. // assumes axis is normalized
  3336. this.quaternion.setFromAxisAngle( axis, angle );
  3337. },
  3338. setRotationFromEuler: function ( euler ) {
  3339. this.quaternion.setFromEuler( euler, true );
  3340. },
  3341. setRotationFromMatrix: function ( m ) {
  3342. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3343. this.quaternion.setFromRotationMatrix( m );
  3344. },
  3345. setRotationFromQuaternion: function ( q ) {
  3346. // assumes q is normalized
  3347. this.quaternion.copy( q );
  3348. },
  3349. rotateOnAxis: function ( axis, angle ) {
  3350. // rotate object on axis in object space
  3351. // axis is assumed to be normalized
  3352. _q1.setFromAxisAngle( axis, angle );
  3353. this.quaternion.multiply( _q1 );
  3354. return this;
  3355. },
  3356. rotateOnWorldAxis: function ( axis, angle ) {
  3357. // rotate object on axis in world space
  3358. // axis is assumed to be normalized
  3359. // method assumes no rotated parent
  3360. _q1.setFromAxisAngle( axis, angle );
  3361. this.quaternion.premultiply( _q1 );
  3362. return this;
  3363. },
  3364. rotateX: function ( angle ) {
  3365. return this.rotateOnAxis( _xAxis, angle );
  3366. },
  3367. rotateY: function ( angle ) {
  3368. return this.rotateOnAxis( _yAxis, angle );
  3369. },
  3370. rotateZ: function ( angle ) {
  3371. return this.rotateOnAxis( _zAxis, angle );
  3372. },
  3373. translateOnAxis: function ( axis, distance ) {
  3374. // translate object by distance along axis in object space
  3375. // axis is assumed to be normalized
  3376. _v1$1.copy( axis ).applyQuaternion( this.quaternion );
  3377. this.position.add( _v1$1.multiplyScalar( distance ) );
  3378. return this;
  3379. },
  3380. translateX: function ( distance ) {
  3381. return this.translateOnAxis( _xAxis, distance );
  3382. },
  3383. translateY: function ( distance ) {
  3384. return this.translateOnAxis( _yAxis, distance );
  3385. },
  3386. translateZ: function ( distance ) {
  3387. return this.translateOnAxis( _zAxis, distance );
  3388. },
  3389. localToWorld: function ( vector ) {
  3390. return vector.applyMatrix4( this.matrixWorld );
  3391. },
  3392. worldToLocal: function ( vector ) {
  3393. return vector.applyMatrix4( _m1$1.getInverse( this.matrixWorld ) );
  3394. },
  3395. lookAt: function ( x, y, z ) {
  3396. // This method does not support objects having non-uniformly-scaled parent(s)
  3397. if ( x.isVector3 ) {
  3398. _target.copy( x );
  3399. } else {
  3400. _target.set( x, y, z );
  3401. }
  3402. var parent = this.parent;
  3403. this.updateWorldMatrix( true, false );
  3404. _position.setFromMatrixPosition( this.matrixWorld );
  3405. if ( this.isCamera || this.isLight ) {
  3406. _m1$1.lookAt( _position, _target, this.up );
  3407. } else {
  3408. _m1$1.lookAt( _target, _position, this.up );
  3409. }
  3410. this.quaternion.setFromRotationMatrix( _m1$1 );
  3411. if ( parent ) {
  3412. _m1$1.extractRotation( parent.matrixWorld );
  3413. _q1.setFromRotationMatrix( _m1$1 );
  3414. this.quaternion.premultiply( _q1.inverse() );
  3415. }
  3416. },
  3417. add: function ( object ) {
  3418. if ( arguments.length > 1 ) {
  3419. for ( var i = 0; i < arguments.length; i ++ ) {
  3420. this.add( arguments[ i ] );
  3421. }
  3422. return this;
  3423. }
  3424. if ( object === this ) {
  3425. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3426. return this;
  3427. }
  3428. if ( ( object && object.isObject3D ) ) {
  3429. if ( object.parent !== null ) {
  3430. object.parent.remove( object );
  3431. }
  3432. object.parent = this;
  3433. this.children.push( object );
  3434. object.dispatchEvent( _addedEvent );
  3435. } else {
  3436. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3437. }
  3438. return this;
  3439. },
  3440. remove: function ( object ) {
  3441. if ( arguments.length > 1 ) {
  3442. for ( var i = 0; i < arguments.length; i ++ ) {
  3443. this.remove( arguments[ i ] );
  3444. }
  3445. return this;
  3446. }
  3447. var index = this.children.indexOf( object );
  3448. if ( index !== - 1 ) {
  3449. object.parent = null;
  3450. this.children.splice( index, 1 );
  3451. object.dispatchEvent( _removedEvent );
  3452. }
  3453. return this;
  3454. },
  3455. attach: function ( object ) {
  3456. // adds object as a child of this, while maintaining the object's world transform
  3457. this.updateWorldMatrix( true, false );
  3458. _m1$1.getInverse( this.matrixWorld );
  3459. if ( object.parent !== null ) {
  3460. object.parent.updateWorldMatrix( true, false );
  3461. _m1$1.multiply( object.parent.matrixWorld );
  3462. }
  3463. object.applyMatrix4( _m1$1 );
  3464. object.updateWorldMatrix( false, false );
  3465. this.add( object );
  3466. return this;
  3467. },
  3468. getObjectById: function ( id ) {
  3469. return this.getObjectByProperty( 'id', id );
  3470. },
  3471. getObjectByName: function ( name ) {
  3472. return this.getObjectByProperty( 'name', name );
  3473. },
  3474. getObjectByProperty: function ( name, value ) {
  3475. if ( this[ name ] === value ) return this;
  3476. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3477. var child = this.children[ i ];
  3478. var object = child.getObjectByProperty( name, value );
  3479. if ( object !== undefined ) {
  3480. return object;
  3481. }
  3482. }
  3483. return undefined;
  3484. },
  3485. getWorldPosition: function ( target ) {
  3486. if ( target === undefined ) {
  3487. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3488. target = new Vector3();
  3489. }
  3490. this.updateMatrixWorld( true );
  3491. return target.setFromMatrixPosition( this.matrixWorld );
  3492. },
  3493. getWorldQuaternion: function ( target ) {
  3494. if ( target === undefined ) {
  3495. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3496. target = new Quaternion();
  3497. }
  3498. this.updateMatrixWorld( true );
  3499. this.matrixWorld.decompose( _position, target, _scale );
  3500. return target;
  3501. },
  3502. getWorldScale: function ( target ) {
  3503. if ( target === undefined ) {
  3504. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3505. target = new Vector3();
  3506. }
  3507. this.updateMatrixWorld( true );
  3508. this.matrixWorld.decompose( _position, _quaternion$2, target );
  3509. return target;
  3510. },
  3511. getWorldDirection: function ( target ) {
  3512. if ( target === undefined ) {
  3513. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3514. target = new Vector3();
  3515. }
  3516. this.updateMatrixWorld( true );
  3517. var e = this.matrixWorld.elements;
  3518. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3519. },
  3520. raycast: function () {},
  3521. traverse: function ( callback ) {
  3522. callback( this );
  3523. var children = this.children;
  3524. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3525. children[ i ].traverse( callback );
  3526. }
  3527. },
  3528. traverseVisible: function ( callback ) {
  3529. if ( this.visible === false ) return;
  3530. callback( this );
  3531. var children = this.children;
  3532. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3533. children[ i ].traverseVisible( callback );
  3534. }
  3535. },
  3536. traverseAncestors: function ( callback ) {
  3537. var parent = this.parent;
  3538. if ( parent !== null ) {
  3539. callback( parent );
  3540. parent.traverseAncestors( callback );
  3541. }
  3542. },
  3543. updateMatrix: function () {
  3544. this.matrix.compose( this.position, this.quaternion, this.scale );
  3545. this.matrixWorldNeedsUpdate = true;
  3546. },
  3547. updateMatrixWorld: function ( force ) {
  3548. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3549. if ( this.matrixWorldNeedsUpdate || force ) {
  3550. if ( this.parent === null ) {
  3551. this.matrixWorld.copy( this.matrix );
  3552. } else {
  3553. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3554. }
  3555. this.matrixWorldNeedsUpdate = false;
  3556. force = true;
  3557. }
  3558. // update children
  3559. var children = this.children;
  3560. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3561. children[ i ].updateMatrixWorld( force );
  3562. }
  3563. },
  3564. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3565. var parent = this.parent;
  3566. if ( updateParents === true && parent !== null ) {
  3567. parent.updateWorldMatrix( true, false );
  3568. }
  3569. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3570. if ( this.parent === null ) {
  3571. this.matrixWorld.copy( this.matrix );
  3572. } else {
  3573. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3574. }
  3575. // update children
  3576. if ( updateChildren === true ) {
  3577. var children = this.children;
  3578. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3579. children[ i ].updateWorldMatrix( false, true );
  3580. }
  3581. }
  3582. },
  3583. toJSON: function ( meta ) {
  3584. // meta is a string when called from JSON.stringify
  3585. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3586. var output = {};
  3587. // meta is a hash used to collect geometries, materials.
  3588. // not providing it implies that this is the root object
  3589. // being serialized.
  3590. if ( isRootObject ) {
  3591. // initialize meta obj
  3592. meta = {
  3593. geometries: {},
  3594. materials: {},
  3595. textures: {},
  3596. images: {},
  3597. shapes: {}
  3598. };
  3599. output.metadata = {
  3600. version: 4.5,
  3601. type: 'Object',
  3602. generator: 'Object3D.toJSON'
  3603. };
  3604. }
  3605. // standard Object3D serialization
  3606. var object = {};
  3607. object.uuid = this.uuid;
  3608. object.type = this.type;
  3609. if ( this.name !== '' ) object.name = this.name;
  3610. if ( this.castShadow === true ) object.castShadow = true;
  3611. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3612. if ( this.visible === false ) object.visible = false;
  3613. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3614. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3615. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3616. object.layers = this.layers.mask;
  3617. object.matrix = this.matrix.toArray();
  3618. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3619. // object specific properties
  3620. if ( this.isInstancedMesh ) {
  3621. object.type = 'InstancedMesh';
  3622. object.count = this.count;
  3623. object.instanceMatrix = this.instanceMatrix.toJSON();
  3624. }
  3625. //
  3626. function serialize( library, element ) {
  3627. if ( library[ element.uuid ] === undefined ) {
  3628. library[ element.uuid ] = element.toJSON( meta );
  3629. }
  3630. return element.uuid;
  3631. }
  3632. if ( this.isMesh || this.isLine || this.isPoints ) {
  3633. object.geometry = serialize( meta.geometries, this.geometry );
  3634. var parameters = this.geometry.parameters;
  3635. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3636. var shapes = parameters.shapes;
  3637. if ( Array.isArray( shapes ) ) {
  3638. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3639. var shape = shapes[ i ];
  3640. serialize( meta.shapes, shape );
  3641. }
  3642. } else {
  3643. serialize( meta.shapes, shapes );
  3644. }
  3645. }
  3646. }
  3647. if ( this.material !== undefined ) {
  3648. if ( Array.isArray( this.material ) ) {
  3649. var uuids = [];
  3650. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  3651. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3652. }
  3653. object.material = uuids;
  3654. } else {
  3655. object.material = serialize( meta.materials, this.material );
  3656. }
  3657. }
  3658. //
  3659. if ( this.children.length > 0 ) {
  3660. object.children = [];
  3661. for ( var i = 0; i < this.children.length; i ++ ) {
  3662. object.children.push( this.children[ i ].toJSON( meta ).object );
  3663. }
  3664. }
  3665. if ( isRootObject ) {
  3666. var geometries = extractFromCache( meta.geometries );
  3667. var materials = extractFromCache( meta.materials );
  3668. var textures = extractFromCache( meta.textures );
  3669. var images = extractFromCache( meta.images );
  3670. var shapes = extractFromCache( meta.shapes );
  3671. if ( geometries.length > 0 ) output.geometries = geometries;
  3672. if ( materials.length > 0 ) output.materials = materials;
  3673. if ( textures.length > 0 ) output.textures = textures;
  3674. if ( images.length > 0 ) output.images = images;
  3675. if ( shapes.length > 0 ) output.shapes = shapes;
  3676. }
  3677. output.object = object;
  3678. return output;
  3679. // extract data from the cache hash
  3680. // remove metadata on each item
  3681. // and return as array
  3682. function extractFromCache( cache ) {
  3683. var values = [];
  3684. for ( var key in cache ) {
  3685. var data = cache[ key ];
  3686. delete data.metadata;
  3687. values.push( data );
  3688. }
  3689. return values;
  3690. }
  3691. },
  3692. clone: function ( recursive ) {
  3693. return new this.constructor().copy( this, recursive );
  3694. },
  3695. copy: function ( source, recursive ) {
  3696. if ( recursive === undefined ) recursive = true;
  3697. this.name = source.name;
  3698. this.up.copy( source.up );
  3699. this.position.copy( source.position );
  3700. this.quaternion.copy( source.quaternion );
  3701. this.scale.copy( source.scale );
  3702. this.matrix.copy( source.matrix );
  3703. this.matrixWorld.copy( source.matrixWorld );
  3704. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3705. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3706. this.layers.mask = source.layers.mask;
  3707. this.visible = source.visible;
  3708. this.castShadow = source.castShadow;
  3709. this.receiveShadow = source.receiveShadow;
  3710. this.frustumCulled = source.frustumCulled;
  3711. this.renderOrder = source.renderOrder;
  3712. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3713. if ( recursive === true ) {
  3714. for ( var i = 0; i < source.children.length; i ++ ) {
  3715. var child = source.children[ i ];
  3716. this.add( child.clone() );
  3717. }
  3718. }
  3719. return this;
  3720. }
  3721. } );
  3722. /**
  3723. * @author mrdoob / http://mrdoob.com/
  3724. */
  3725. function Scene() {
  3726. Object3D.call( this );
  3727. this.type = 'Scene';
  3728. this.background = null;
  3729. this.environment = null;
  3730. this.fog = null;
  3731. this.overrideMaterial = null;
  3732. this.autoUpdate = true; // checked by the renderer
  3733. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3734. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3735. }
  3736. }
  3737. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3738. constructor: Scene,
  3739. isScene: true,
  3740. copy: function ( source, recursive ) {
  3741. Object3D.prototype.copy.call( this, source, recursive );
  3742. if ( source.background !== null ) this.background = source.background.clone();
  3743. if ( source.environment !== null ) this.environment = source.environment.clone();
  3744. if ( source.fog !== null ) this.fog = source.fog.clone();
  3745. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3746. this.autoUpdate = source.autoUpdate;
  3747. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3748. return this;
  3749. },
  3750. toJSON: function ( meta ) {
  3751. var data = Object3D.prototype.toJSON.call( this, meta );
  3752. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3753. if ( this.environment !== null ) data.object.environment = this.environment.toJSON( meta );
  3754. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3755. return data;
  3756. },
  3757. dispose: function () {
  3758. this.dispatchEvent( { type: 'dispose' } );
  3759. }
  3760. } );
  3761. var _points = [
  3762. new Vector3(),
  3763. new Vector3(),
  3764. new Vector3(),
  3765. new Vector3(),
  3766. new Vector3(),
  3767. new Vector3(),
  3768. new Vector3(),
  3769. new Vector3()
  3770. ];
  3771. var _vector$1 = new Vector3();
  3772. var _box = new Box3();
  3773. // triangle centered vertices
  3774. var _v0 = new Vector3();
  3775. var _v1$2 = new Vector3();
  3776. var _v2 = new Vector3();
  3777. // triangle edge vectors
  3778. var _f0 = new Vector3();
  3779. var _f1 = new Vector3();
  3780. var _f2 = new Vector3();
  3781. var _center = new Vector3();
  3782. var _extents = new Vector3();
  3783. var _triangleNormal = new Vector3();
  3784. var _testAxis = new Vector3();
  3785. /**
  3786. * @author bhouston / http://clara.io
  3787. * @author WestLangley / http://github.com/WestLangley
  3788. */
  3789. function Box3( min, max ) {
  3790. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3791. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3792. }
  3793. Object.assign( Box3.prototype, {
  3794. isBox3: true,
  3795. set: function ( min, max ) {
  3796. this.min.copy( min );
  3797. this.max.copy( max );
  3798. return this;
  3799. },
  3800. setFromArray: function ( array ) {
  3801. var minX = + Infinity;
  3802. var minY = + Infinity;
  3803. var minZ = + Infinity;
  3804. var maxX = - Infinity;
  3805. var maxY = - Infinity;
  3806. var maxZ = - Infinity;
  3807. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3808. var x = array[ i ];
  3809. var y = array[ i + 1 ];
  3810. var z = array[ i + 2 ];
  3811. if ( x < minX ) minX = x;
  3812. if ( y < minY ) minY = y;
  3813. if ( z < minZ ) minZ = z;
  3814. if ( x > maxX ) maxX = x;
  3815. if ( y > maxY ) maxY = y;
  3816. if ( z > maxZ ) maxZ = z;
  3817. }
  3818. this.min.set( minX, minY, minZ );
  3819. this.max.set( maxX, maxY, maxZ );
  3820. return this;
  3821. },
  3822. setFromBufferAttribute: function ( attribute ) {
  3823. var minX = + Infinity;
  3824. var minY = + Infinity;
  3825. var minZ = + Infinity;
  3826. var maxX = - Infinity;
  3827. var maxY = - Infinity;
  3828. var maxZ = - Infinity;
  3829. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3830. var x = attribute.getX( i );
  3831. var y = attribute.getY( i );
  3832. var z = attribute.getZ( i );
  3833. if ( x < minX ) minX = x;
  3834. if ( y < minY ) minY = y;
  3835. if ( z < minZ ) minZ = z;
  3836. if ( x > maxX ) maxX = x;
  3837. if ( y > maxY ) maxY = y;
  3838. if ( z > maxZ ) maxZ = z;
  3839. }
  3840. this.min.set( minX, minY, minZ );
  3841. this.max.set( maxX, maxY, maxZ );
  3842. return this;
  3843. },
  3844. setFromPoints: function ( points ) {
  3845. this.makeEmpty();
  3846. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3847. this.expandByPoint( points[ i ] );
  3848. }
  3849. return this;
  3850. },
  3851. setFromCenterAndSize: function ( center, size ) {
  3852. var halfSize = _vector$1.copy( size ).multiplyScalar( 0.5 );
  3853. this.min.copy( center ).sub( halfSize );
  3854. this.max.copy( center ).add( halfSize );
  3855. return this;
  3856. },
  3857. setFromObject: function ( object ) {
  3858. this.makeEmpty();
  3859. return this.expandByObject( object );
  3860. },
  3861. clone: function () {
  3862. return new this.constructor().copy( this );
  3863. },
  3864. copy: function ( box ) {
  3865. this.min.copy( box.min );
  3866. this.max.copy( box.max );
  3867. return this;
  3868. },
  3869. makeEmpty: function () {
  3870. this.min.x = this.min.y = this.min.z = + Infinity;
  3871. this.max.x = this.max.y = this.max.z = - Infinity;
  3872. return this;
  3873. },
  3874. isEmpty: function () {
  3875. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3876. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3877. },
  3878. getCenter: function ( target ) {
  3879. if ( target === undefined ) {
  3880. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3881. target = new Vector3();
  3882. }
  3883. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3884. },
  3885. getSize: function ( target ) {
  3886. if ( target === undefined ) {
  3887. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3888. target = new Vector3();
  3889. }
  3890. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3891. },
  3892. expandByPoint: function ( point ) {
  3893. this.min.min( point );
  3894. this.max.max( point );
  3895. return this;
  3896. },
  3897. expandByVector: function ( vector ) {
  3898. this.min.sub( vector );
  3899. this.max.add( vector );
  3900. return this;
  3901. },
  3902. expandByScalar: function ( scalar ) {
  3903. this.min.addScalar( - scalar );
  3904. this.max.addScalar( scalar );
  3905. return this;
  3906. },
  3907. expandByObject: function ( object ) {
  3908. // Computes the world-axis-aligned bounding box of an object (including its children),
  3909. // accounting for both the object's, and children's, world transforms
  3910. object.updateWorldMatrix( false, false );
  3911. var geometry = object.geometry;
  3912. if ( geometry !== undefined ) {
  3913. if ( geometry.boundingBox === null ) {
  3914. geometry.computeBoundingBox();
  3915. }
  3916. _box.copy( geometry.boundingBox );
  3917. _box.applyMatrix4( object.matrixWorld );
  3918. this.union( _box );
  3919. }
  3920. var children = object.children;
  3921. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3922. this.expandByObject( children[ i ] );
  3923. }
  3924. return this;
  3925. },
  3926. containsPoint: function ( point ) {
  3927. return point.x < this.min.x || point.x > this.max.x ||
  3928. point.y < this.min.y || point.y > this.max.y ||
  3929. point.z < this.min.z || point.z > this.max.z ? false : true;
  3930. },
  3931. containsBox: function ( box ) {
  3932. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3933. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3934. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3935. },
  3936. getParameter: function ( point, target ) {
  3937. // This can potentially have a divide by zero if the box
  3938. // has a size dimension of 0.
  3939. if ( target === undefined ) {
  3940. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3941. target = new Vector3();
  3942. }
  3943. return target.set(
  3944. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3945. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3946. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3947. );
  3948. },
  3949. intersectsBox: function ( box ) {
  3950. // using 6 splitting planes to rule out intersections.
  3951. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3952. box.max.y < this.min.y || box.min.y > this.max.y ||
  3953. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3954. },
  3955. intersectsSphere: function ( sphere ) {
  3956. // Find the point on the AABB closest to the sphere center.
  3957. this.clampPoint( sphere.center, _vector$1 );
  3958. // If that point is inside the sphere, the AABB and sphere intersect.
  3959. return _vector$1.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3960. },
  3961. intersectsPlane: function ( plane ) {
  3962. // We compute the minimum and maximum dot product values. If those values
  3963. // are on the same side (back or front) of the plane, then there is no intersection.
  3964. var min, max;
  3965. if ( plane.normal.x > 0 ) {
  3966. min = plane.normal.x * this.min.x;
  3967. max = plane.normal.x * this.max.x;
  3968. } else {
  3969. min = plane.normal.x * this.max.x;
  3970. max = plane.normal.x * this.min.x;
  3971. }
  3972. if ( plane.normal.y > 0 ) {
  3973. min += plane.normal.y * this.min.y;
  3974. max += plane.normal.y * this.max.y;
  3975. } else {
  3976. min += plane.normal.y * this.max.y;
  3977. max += plane.normal.y * this.min.y;
  3978. }
  3979. if ( plane.normal.z > 0 ) {
  3980. min += plane.normal.z * this.min.z;
  3981. max += plane.normal.z * this.max.z;
  3982. } else {
  3983. min += plane.normal.z * this.max.z;
  3984. max += plane.normal.z * this.min.z;
  3985. }
  3986. return ( min <= - plane.constant && max >= - plane.constant );
  3987. },
  3988. intersectsTriangle: function ( triangle ) {
  3989. if ( this.isEmpty() ) {
  3990. return false;
  3991. }
  3992. // compute box center and extents
  3993. this.getCenter( _center );
  3994. _extents.subVectors( this.max, _center );
  3995. // translate triangle to aabb origin
  3996. _v0.subVectors( triangle.a, _center );
  3997. _v1$2.subVectors( triangle.b, _center );
  3998. _v2.subVectors( triangle.c, _center );
  3999. // compute edge vectors for triangle
  4000. _f0.subVectors( _v1$2, _v0 );
  4001. _f1.subVectors( _v2, _v1$2 );
  4002. _f2.subVectors( _v0, _v2 );
  4003. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  4004. // 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
  4005. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  4006. var axes = [
  4007. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  4008. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  4009. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  4010. ];
  4011. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  4012. return false;
  4013. }
  4014. // test 3 face normals from the aabb
  4015. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  4016. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  4017. return false;
  4018. }
  4019. // finally testing the face normal of the triangle
  4020. // use already existing triangle edge vectors here
  4021. _triangleNormal.crossVectors( _f0, _f1 );
  4022. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  4023. return satForAxes( axes, _v0, _v1$2, _v2, _extents );
  4024. },
  4025. clampPoint: function ( point, target ) {
  4026. if ( target === undefined ) {
  4027. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  4028. target = new Vector3();
  4029. }
  4030. return target.copy( point ).clamp( this.min, this.max );
  4031. },
  4032. distanceToPoint: function ( point ) {
  4033. var clampedPoint = _vector$1.copy( point ).clamp( this.min, this.max );
  4034. return clampedPoint.sub( point ).length();
  4035. },
  4036. getBoundingSphere: function ( target ) {
  4037. if ( target === undefined ) {
  4038. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  4039. //target = new Sphere(); // removed to avoid cyclic dependency
  4040. }
  4041. this.getCenter( target.center );
  4042. target.radius = this.getSize( _vector$1 ).length() * 0.5;
  4043. return target;
  4044. },
  4045. intersect: function ( box ) {
  4046. this.min.max( box.min );
  4047. this.max.min( box.max );
  4048. // 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.
  4049. if ( this.isEmpty() ) this.makeEmpty();
  4050. return this;
  4051. },
  4052. union: function ( box ) {
  4053. this.min.min( box.min );
  4054. this.max.max( box.max );
  4055. return this;
  4056. },
  4057. applyMatrix4: function ( matrix ) {
  4058. // transform of empty box is an empty box.
  4059. if ( this.isEmpty() ) return this;
  4060. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4061. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4062. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4063. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4064. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4065. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4066. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4067. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4068. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4069. this.setFromPoints( _points );
  4070. return this;
  4071. },
  4072. translate: function ( offset ) {
  4073. this.min.add( offset );
  4074. this.max.add( offset );
  4075. return this;
  4076. },
  4077. equals: function ( box ) {
  4078. return box.min.equals( this.min ) && box.max.equals( this.max );
  4079. }
  4080. } );
  4081. function satForAxes( axes, v0, v1, v2, extents ) {
  4082. var i, j;
  4083. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  4084. _testAxis.fromArray( axes, i );
  4085. // project the aabb onto the seperating axis
  4086. var r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  4087. // project all 3 vertices of the triangle onto the seperating axis
  4088. var p0 = v0.dot( _testAxis );
  4089. var p1 = v1.dot( _testAxis );
  4090. var p2 = v2.dot( _testAxis );
  4091. // actual test, basically see if either of the most extreme of the triangle points intersects r
  4092. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  4093. // points of the projected triangle are outside the projected half-length of the aabb
  4094. // the axis is seperating and we can exit
  4095. return false;
  4096. }
  4097. }
  4098. return true;
  4099. }
  4100. var _box$1 = new Box3();
  4101. /**
  4102. * @author bhouston / http://clara.io
  4103. * @author mrdoob / http://mrdoob.com/
  4104. */
  4105. function Sphere( center, radius ) {
  4106. this.center = ( center !== undefined ) ? center : new Vector3();
  4107. this.radius = ( radius !== undefined ) ? radius : - 1;
  4108. }
  4109. Object.assign( Sphere.prototype, {
  4110. set: function ( center, radius ) {
  4111. this.center.copy( center );
  4112. this.radius = radius;
  4113. return this;
  4114. },
  4115. setFromPoints: function ( points, optionalCenter ) {
  4116. var center = this.center;
  4117. if ( optionalCenter !== undefined ) {
  4118. center.copy( optionalCenter );
  4119. } else {
  4120. _box$1.setFromPoints( points ).getCenter( center );
  4121. }
  4122. var maxRadiusSq = 0;
  4123. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4124. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4125. }
  4126. this.radius = Math.sqrt( maxRadiusSq );
  4127. return this;
  4128. },
  4129. clone: function () {
  4130. return new this.constructor().copy( this );
  4131. },
  4132. copy: function ( sphere ) {
  4133. this.center.copy( sphere.center );
  4134. this.radius = sphere.radius;
  4135. return this;
  4136. },
  4137. isEmpty: function () {
  4138. return ( this.radius < 0 );
  4139. },
  4140. makeEmpty: function () {
  4141. this.center.set( 0, 0, 0 );
  4142. this.radius = - 1;
  4143. return this;
  4144. },
  4145. containsPoint: function ( point ) {
  4146. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4147. },
  4148. distanceToPoint: function ( point ) {
  4149. return ( point.distanceTo( this.center ) - this.radius );
  4150. },
  4151. intersectsSphere: function ( sphere ) {
  4152. var radiusSum = this.radius + sphere.radius;
  4153. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4154. },
  4155. intersectsBox: function ( box ) {
  4156. return box.intersectsSphere( this );
  4157. },
  4158. intersectsPlane: function ( plane ) {
  4159. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4160. },
  4161. clampPoint: function ( point, target ) {
  4162. var deltaLengthSq = this.center.distanceToSquared( point );
  4163. if ( target === undefined ) {
  4164. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4165. target = new Vector3();
  4166. }
  4167. target.copy( point );
  4168. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4169. target.sub( this.center ).normalize();
  4170. target.multiplyScalar( this.radius ).add( this.center );
  4171. }
  4172. return target;
  4173. },
  4174. getBoundingBox: function ( target ) {
  4175. if ( target === undefined ) {
  4176. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4177. target = new Box3();
  4178. }
  4179. if ( this.isEmpty() ) {
  4180. // Empty sphere produces empty bounding box
  4181. target.makeEmpty();
  4182. return target;
  4183. }
  4184. target.set( this.center, this.center );
  4185. target.expandByScalar( this.radius );
  4186. return target;
  4187. },
  4188. applyMatrix4: function ( matrix ) {
  4189. this.center.applyMatrix4( matrix );
  4190. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4191. return this;
  4192. },
  4193. translate: function ( offset ) {
  4194. this.center.add( offset );
  4195. return this;
  4196. },
  4197. equals: function ( sphere ) {
  4198. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4199. }
  4200. } );
  4201. var _vector$2 = new Vector3();
  4202. var _segCenter = new Vector3();
  4203. var _segDir = new Vector3();
  4204. var _diff = new Vector3();
  4205. var _edge1 = new Vector3();
  4206. var _edge2 = new Vector3();
  4207. var _normal = new Vector3();
  4208. /**
  4209. * @author bhouston / http://clara.io
  4210. */
  4211. function Ray( origin, direction ) {
  4212. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4213. this.direction = ( direction !== undefined ) ? direction : new Vector3( 0, 0, - 1 );
  4214. }
  4215. Object.assign( Ray.prototype, {
  4216. set: function ( origin, direction ) {
  4217. this.origin.copy( origin );
  4218. this.direction.copy( direction );
  4219. return this;
  4220. },
  4221. clone: function () {
  4222. return new this.constructor().copy( this );
  4223. },
  4224. copy: function ( ray ) {
  4225. this.origin.copy( ray.origin );
  4226. this.direction.copy( ray.direction );
  4227. return this;
  4228. },
  4229. at: function ( t, target ) {
  4230. if ( target === undefined ) {
  4231. console.warn( 'THREE.Ray: .at() target is now required' );
  4232. target = new Vector3();
  4233. }
  4234. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4235. },
  4236. lookAt: function ( v ) {
  4237. this.direction.copy( v ).sub( this.origin ).normalize();
  4238. return this;
  4239. },
  4240. recast: function ( t ) {
  4241. this.origin.copy( this.at( t, _vector$2 ) );
  4242. return this;
  4243. },
  4244. closestPointToPoint: function ( point, target ) {
  4245. if ( target === undefined ) {
  4246. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4247. target = new Vector3();
  4248. }
  4249. target.subVectors( point, this.origin );
  4250. var directionDistance = target.dot( this.direction );
  4251. if ( directionDistance < 0 ) {
  4252. return target.copy( this.origin );
  4253. }
  4254. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4255. },
  4256. distanceToPoint: function ( point ) {
  4257. return Math.sqrt( this.distanceSqToPoint( point ) );
  4258. },
  4259. distanceSqToPoint: function ( point ) {
  4260. var directionDistance = _vector$2.subVectors( point, this.origin ).dot( this.direction );
  4261. // point behind the ray
  4262. if ( directionDistance < 0 ) {
  4263. return this.origin.distanceToSquared( point );
  4264. }
  4265. _vector$2.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4266. return _vector$2.distanceToSquared( point );
  4267. },
  4268. distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4269. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4270. // It returns the min distance between the ray and the segment
  4271. // defined by v0 and v1
  4272. // It can also set two optional targets :
  4273. // - The closest point on the ray
  4274. // - The closest point on the segment
  4275. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4276. _segDir.copy( v1 ).sub( v0 ).normalize();
  4277. _diff.copy( this.origin ).sub( _segCenter );
  4278. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4279. var a01 = - this.direction.dot( _segDir );
  4280. var b0 = _diff.dot( this.direction );
  4281. var b1 = - _diff.dot( _segDir );
  4282. var c = _diff.lengthSq();
  4283. var det = Math.abs( 1 - a01 * a01 );
  4284. var s0, s1, sqrDist, extDet;
  4285. if ( det > 0 ) {
  4286. // The ray and segment are not parallel.
  4287. s0 = a01 * b1 - b0;
  4288. s1 = a01 * b0 - b1;
  4289. extDet = segExtent * det;
  4290. if ( s0 >= 0 ) {
  4291. if ( s1 >= - extDet ) {
  4292. if ( s1 <= extDet ) {
  4293. // region 0
  4294. // Minimum at interior points of ray and segment.
  4295. var invDet = 1 / det;
  4296. s0 *= invDet;
  4297. s1 *= invDet;
  4298. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4299. } else {
  4300. // region 1
  4301. s1 = segExtent;
  4302. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4303. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4304. }
  4305. } else {
  4306. // region 5
  4307. s1 = - segExtent;
  4308. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4309. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4310. }
  4311. } else {
  4312. if ( s1 <= - extDet ) {
  4313. // region 4
  4314. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4315. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4316. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4317. } else if ( s1 <= extDet ) {
  4318. // region 3
  4319. s0 = 0;
  4320. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4321. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4322. } else {
  4323. // region 2
  4324. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4325. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4326. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4327. }
  4328. }
  4329. } else {
  4330. // Ray and segment are parallel.
  4331. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4332. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4333. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4334. }
  4335. if ( optionalPointOnRay ) {
  4336. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4337. }
  4338. if ( optionalPointOnSegment ) {
  4339. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  4340. }
  4341. return sqrDist;
  4342. },
  4343. intersectSphere: function ( sphere, target ) {
  4344. _vector$2.subVectors( sphere.center, this.origin );
  4345. var tca = _vector$2.dot( this.direction );
  4346. var d2 = _vector$2.dot( _vector$2 ) - tca * tca;
  4347. var radius2 = sphere.radius * sphere.radius;
  4348. if ( d2 > radius2 ) return null;
  4349. var thc = Math.sqrt( radius2 - d2 );
  4350. // t0 = first intersect point - entrance on front of sphere
  4351. var t0 = tca - thc;
  4352. // t1 = second intersect point - exit point on back of sphere
  4353. var t1 = tca + thc;
  4354. // test to see if both t0 and t1 are behind the ray - if so, return null
  4355. if ( t0 < 0 && t1 < 0 ) return null;
  4356. // test to see if t0 is behind the ray:
  4357. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4358. // in order to always return an intersect point that is in front of the ray.
  4359. if ( t0 < 0 ) return this.at( t1, target );
  4360. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4361. return this.at( t0, target );
  4362. },
  4363. intersectsSphere: function ( sphere ) {
  4364. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4365. },
  4366. distanceToPlane: function ( plane ) {
  4367. var denominator = plane.normal.dot( this.direction );
  4368. if ( denominator === 0 ) {
  4369. // line is coplanar, return origin
  4370. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4371. return 0;
  4372. }
  4373. // Null is preferable to undefined since undefined means.... it is undefined
  4374. return null;
  4375. }
  4376. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4377. // Return if the ray never intersects the plane
  4378. return t >= 0 ? t : null;
  4379. },
  4380. intersectPlane: function ( plane, target ) {
  4381. var t = this.distanceToPlane( plane );
  4382. if ( t === null ) {
  4383. return null;
  4384. }
  4385. return this.at( t, target );
  4386. },
  4387. intersectsPlane: function ( plane ) {
  4388. // check if the ray lies on the plane first
  4389. var distToPoint = plane.distanceToPoint( this.origin );
  4390. if ( distToPoint === 0 ) {
  4391. return true;
  4392. }
  4393. var denominator = plane.normal.dot( this.direction );
  4394. if ( denominator * distToPoint < 0 ) {
  4395. return true;
  4396. }
  4397. // ray origin is behind the plane (and is pointing behind it)
  4398. return false;
  4399. },
  4400. intersectBox: function ( box, target ) {
  4401. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4402. var invdirx = 1 / this.direction.x,
  4403. invdiry = 1 / this.direction.y,
  4404. invdirz = 1 / this.direction.z;
  4405. var origin = this.origin;
  4406. if ( invdirx >= 0 ) {
  4407. tmin = ( box.min.x - origin.x ) * invdirx;
  4408. tmax = ( box.max.x - origin.x ) * invdirx;
  4409. } else {
  4410. tmin = ( box.max.x - origin.x ) * invdirx;
  4411. tmax = ( box.min.x - origin.x ) * invdirx;
  4412. }
  4413. if ( invdiry >= 0 ) {
  4414. tymin = ( box.min.y - origin.y ) * invdiry;
  4415. tymax = ( box.max.y - origin.y ) * invdiry;
  4416. } else {
  4417. tymin = ( box.max.y - origin.y ) * invdiry;
  4418. tymax = ( box.min.y - origin.y ) * invdiry;
  4419. }
  4420. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4421. // These lines also handle the case where tmin or tmax is NaN
  4422. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4423. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4424. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4425. if ( invdirz >= 0 ) {
  4426. tzmin = ( box.min.z - origin.z ) * invdirz;
  4427. tzmax = ( box.max.z - origin.z ) * invdirz;
  4428. } else {
  4429. tzmin = ( box.max.z - origin.z ) * invdirz;
  4430. tzmax = ( box.min.z - origin.z ) * invdirz;
  4431. }
  4432. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4433. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4434. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4435. //return point closest to the ray (positive side)
  4436. if ( tmax < 0 ) return null;
  4437. return this.at( tmin >= 0 ? tmin : tmax, target );
  4438. },
  4439. intersectsBox: function ( box ) {
  4440. return this.intersectBox( box, _vector$2 ) !== null;
  4441. },
  4442. intersectTriangle: function ( a, b, c, backfaceCulling, target ) {
  4443. // Compute the offset origin, edges, and normal.
  4444. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4445. _edge1.subVectors( b, a );
  4446. _edge2.subVectors( c, a );
  4447. _normal.crossVectors( _edge1, _edge2 );
  4448. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4449. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4450. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4451. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4452. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4453. var DdN = this.direction.dot( _normal );
  4454. var sign;
  4455. if ( DdN > 0 ) {
  4456. if ( backfaceCulling ) return null;
  4457. sign = 1;
  4458. } else if ( DdN < 0 ) {
  4459. sign = - 1;
  4460. DdN = - DdN;
  4461. } else {
  4462. return null;
  4463. }
  4464. _diff.subVectors( this.origin, a );
  4465. var DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  4466. // b1 < 0, no intersection
  4467. if ( DdQxE2 < 0 ) {
  4468. return null;
  4469. }
  4470. var DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  4471. // b2 < 0, no intersection
  4472. if ( DdE1xQ < 0 ) {
  4473. return null;
  4474. }
  4475. // b1+b2 > 1, no intersection
  4476. if ( DdQxE2 + DdE1xQ > DdN ) {
  4477. return null;
  4478. }
  4479. // Line intersects triangle, check if ray does.
  4480. var QdN = - sign * _diff.dot( _normal );
  4481. // t < 0, no intersection
  4482. if ( QdN < 0 ) {
  4483. return null;
  4484. }
  4485. // Ray intersects triangle.
  4486. return this.at( QdN / DdN, target );
  4487. },
  4488. applyMatrix4: function ( matrix4 ) {
  4489. this.origin.applyMatrix4( matrix4 );
  4490. this.direction.transformDirection( matrix4 );
  4491. return this;
  4492. },
  4493. equals: function ( ray ) {
  4494. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4495. }
  4496. } );
  4497. /**
  4498. * @author bhouston / http://clara.io
  4499. */
  4500. var _vector1 = new Vector3();
  4501. var _vector2 = new Vector3();
  4502. var _normalMatrix = new Matrix3();
  4503. function Plane( normal, constant ) {
  4504. // normal is assumed to be normalized
  4505. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  4506. this.constant = ( constant !== undefined ) ? constant : 0;
  4507. }
  4508. Object.assign( Plane.prototype, {
  4509. isPlane: true,
  4510. set: function ( normal, constant ) {
  4511. this.normal.copy( normal );
  4512. this.constant = constant;
  4513. return this;
  4514. },
  4515. setComponents: function ( x, y, z, w ) {
  4516. this.normal.set( x, y, z );
  4517. this.constant = w;
  4518. return this;
  4519. },
  4520. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  4521. this.normal.copy( normal );
  4522. this.constant = - point.dot( this.normal );
  4523. return this;
  4524. },
  4525. setFromCoplanarPoints: function ( a, b, c ) {
  4526. var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  4527. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4528. this.setFromNormalAndCoplanarPoint( normal, a );
  4529. return this;
  4530. },
  4531. clone: function () {
  4532. return new this.constructor().copy( this );
  4533. },
  4534. copy: function ( plane ) {
  4535. this.normal.copy( plane.normal );
  4536. this.constant = plane.constant;
  4537. return this;
  4538. },
  4539. normalize: function () {
  4540. // Note: will lead to a divide by zero if the plane is invalid.
  4541. var inverseNormalLength = 1.0 / this.normal.length();
  4542. this.normal.multiplyScalar( inverseNormalLength );
  4543. this.constant *= inverseNormalLength;
  4544. return this;
  4545. },
  4546. negate: function () {
  4547. this.constant *= - 1;
  4548. this.normal.negate();
  4549. return this;
  4550. },
  4551. distanceToPoint: function ( point ) {
  4552. return this.normal.dot( point ) + this.constant;
  4553. },
  4554. distanceToSphere: function ( sphere ) {
  4555. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4556. },
  4557. projectPoint: function ( point, target ) {
  4558. if ( target === undefined ) {
  4559. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  4560. target = new Vector3();
  4561. }
  4562. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  4563. },
  4564. intersectLine: function ( line, target ) {
  4565. if ( target === undefined ) {
  4566. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  4567. target = new Vector3();
  4568. }
  4569. var direction = line.delta( _vector1 );
  4570. var denominator = this.normal.dot( direction );
  4571. if ( denominator === 0 ) {
  4572. // line is coplanar, return origin
  4573. if ( this.distanceToPoint( line.start ) === 0 ) {
  4574. return target.copy( line.start );
  4575. }
  4576. // Unsure if this is the correct method to handle this case.
  4577. return undefined;
  4578. }
  4579. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4580. if ( t < 0 || t > 1 ) {
  4581. return undefined;
  4582. }
  4583. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  4584. },
  4585. intersectsLine: function ( line ) {
  4586. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4587. var startSign = this.distanceToPoint( line.start );
  4588. var endSign = this.distanceToPoint( line.end );
  4589. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4590. },
  4591. intersectsBox: function ( box ) {
  4592. return box.intersectsPlane( this );
  4593. },
  4594. intersectsSphere: function ( sphere ) {
  4595. return sphere.intersectsPlane( this );
  4596. },
  4597. coplanarPoint: function ( target ) {
  4598. if ( target === undefined ) {
  4599. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  4600. target = new Vector3();
  4601. }
  4602. return target.copy( this.normal ).multiplyScalar( - this.constant );
  4603. },
  4604. applyMatrix4: function ( matrix, optionalNormalMatrix ) {
  4605. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  4606. var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  4607. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4608. this.constant = - referencePoint.dot( normal );
  4609. return this;
  4610. },
  4611. translate: function ( offset ) {
  4612. this.constant -= offset.dot( this.normal );
  4613. return this;
  4614. },
  4615. equals: function ( plane ) {
  4616. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4617. }
  4618. } );
  4619. /**
  4620. * @author bhouston / http://clara.io
  4621. * @author mrdoob / http://mrdoob.com/
  4622. */
  4623. var _v0$1 = new Vector3();
  4624. var _v1$3 = new Vector3();
  4625. var _v2$1 = new Vector3();
  4626. var _v3 = new Vector3();
  4627. var _vab = new Vector3();
  4628. var _vac = new Vector3();
  4629. var _vbc = new Vector3();
  4630. var _vap = new Vector3();
  4631. var _vbp = new Vector3();
  4632. var _vcp = new Vector3();
  4633. function Triangle( a, b, c ) {
  4634. this.a = ( a !== undefined ) ? a : new Vector3();
  4635. this.b = ( b !== undefined ) ? b : new Vector3();
  4636. this.c = ( c !== undefined ) ? c : new Vector3();
  4637. }
  4638. Object.assign( Triangle, {
  4639. getNormal: function ( a, b, c, target ) {
  4640. if ( target === undefined ) {
  4641. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4642. target = new Vector3();
  4643. }
  4644. target.subVectors( c, b );
  4645. _v0$1.subVectors( a, b );
  4646. target.cross( _v0$1 );
  4647. var targetLengthSq = target.lengthSq();
  4648. if ( targetLengthSq > 0 ) {
  4649. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4650. }
  4651. return target.set( 0, 0, 0 );
  4652. },
  4653. // static/instance method to calculate barycentric coordinates
  4654. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4655. getBarycoord: function ( point, a, b, c, target ) {
  4656. _v0$1.subVectors( c, a );
  4657. _v1$3.subVectors( b, a );
  4658. _v2$1.subVectors( point, a );
  4659. var dot00 = _v0$1.dot( _v0$1 );
  4660. var dot01 = _v0$1.dot( _v1$3 );
  4661. var dot02 = _v0$1.dot( _v2$1 );
  4662. var dot11 = _v1$3.dot( _v1$3 );
  4663. var dot12 = _v1$3.dot( _v2$1 );
  4664. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4665. if ( target === undefined ) {
  4666. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4667. target = new Vector3();
  4668. }
  4669. // collinear or singular triangle
  4670. if ( denom === 0 ) {
  4671. // arbitrary location outside of triangle?
  4672. // not sure if this is the best idea, maybe should be returning undefined
  4673. return target.set( - 2, - 1, - 1 );
  4674. }
  4675. var invDenom = 1 / denom;
  4676. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4677. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4678. // barycentric coordinates must always sum to 1
  4679. return target.set( 1 - u - v, v, u );
  4680. },
  4681. containsPoint: function ( point, a, b, c ) {
  4682. Triangle.getBarycoord( point, a, b, c, _v3 );
  4683. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4684. },
  4685. getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4686. this.getBarycoord( point, p1, p2, p3, _v3 );
  4687. target.set( 0, 0 );
  4688. target.addScaledVector( uv1, _v3.x );
  4689. target.addScaledVector( uv2, _v3.y );
  4690. target.addScaledVector( uv3, _v3.z );
  4691. return target;
  4692. },
  4693. isFrontFacing: function ( a, b, c, direction ) {
  4694. _v0$1.subVectors( c, b );
  4695. _v1$3.subVectors( a, b );
  4696. // strictly front facing
  4697. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4698. }
  4699. } );
  4700. Object.assign( Triangle.prototype, {
  4701. set: function ( a, b, c ) {
  4702. this.a.copy( a );
  4703. this.b.copy( b );
  4704. this.c.copy( c );
  4705. return this;
  4706. },
  4707. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4708. this.a.copy( points[ i0 ] );
  4709. this.b.copy( points[ i1 ] );
  4710. this.c.copy( points[ i2 ] );
  4711. return this;
  4712. },
  4713. clone: function () {
  4714. return new this.constructor().copy( this );
  4715. },
  4716. copy: function ( triangle ) {
  4717. this.a.copy( triangle.a );
  4718. this.b.copy( triangle.b );
  4719. this.c.copy( triangle.c );
  4720. return this;
  4721. },
  4722. getArea: function () {
  4723. _v0$1.subVectors( this.c, this.b );
  4724. _v1$3.subVectors( this.a, this.b );
  4725. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4726. },
  4727. getMidpoint: function ( target ) {
  4728. if ( target === undefined ) {
  4729. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4730. target = new Vector3();
  4731. }
  4732. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4733. },
  4734. getNormal: function ( target ) {
  4735. return Triangle.getNormal( this.a, this.b, this.c, target );
  4736. },
  4737. getPlane: function ( target ) {
  4738. if ( target === undefined ) {
  4739. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4740. target = new Plane();
  4741. }
  4742. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4743. },
  4744. getBarycoord: function ( point, target ) {
  4745. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4746. },
  4747. getUV: function ( point, uv1, uv2, uv3, target ) {
  4748. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4749. },
  4750. containsPoint: function ( point ) {
  4751. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4752. },
  4753. isFrontFacing: function ( direction ) {
  4754. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4755. },
  4756. intersectsBox: function ( box ) {
  4757. return box.intersectsTriangle( this );
  4758. },
  4759. closestPointToPoint: function ( p, target ) {
  4760. if ( target === undefined ) {
  4761. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4762. target = new Vector3();
  4763. }
  4764. var a = this.a, b = this.b, c = this.c;
  4765. var v, w;
  4766. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4767. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4768. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4769. // basically, we're distinguishing which of the voronoi regions of the triangle
  4770. // the point lies in with the minimum amount of redundant computation.
  4771. _vab.subVectors( b, a );
  4772. _vac.subVectors( c, a );
  4773. _vap.subVectors( p, a );
  4774. var d1 = _vab.dot( _vap );
  4775. var d2 = _vac.dot( _vap );
  4776. if ( d1 <= 0 && d2 <= 0 ) {
  4777. // vertex region of A; barycentric coords (1, 0, 0)
  4778. return target.copy( a );
  4779. }
  4780. _vbp.subVectors( p, b );
  4781. var d3 = _vab.dot( _vbp );
  4782. var d4 = _vac.dot( _vbp );
  4783. if ( d3 >= 0 && d4 <= d3 ) {
  4784. // vertex region of B; barycentric coords (0, 1, 0)
  4785. return target.copy( b );
  4786. }
  4787. var vc = d1 * d4 - d3 * d2;
  4788. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4789. v = d1 / ( d1 - d3 );
  4790. // edge region of AB; barycentric coords (1-v, v, 0)
  4791. return target.copy( a ).addScaledVector( _vab, v );
  4792. }
  4793. _vcp.subVectors( p, c );
  4794. var d5 = _vab.dot( _vcp );
  4795. var d6 = _vac.dot( _vcp );
  4796. if ( d6 >= 0 && d5 <= d6 ) {
  4797. // vertex region of C; barycentric coords (0, 0, 1)
  4798. return target.copy( c );
  4799. }
  4800. var vb = d5 * d2 - d1 * d6;
  4801. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4802. w = d2 / ( d2 - d6 );
  4803. // edge region of AC; barycentric coords (1-w, 0, w)
  4804. return target.copy( a ).addScaledVector( _vac, w );
  4805. }
  4806. var va = d3 * d6 - d5 * d4;
  4807. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4808. _vbc.subVectors( c, b );
  4809. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4810. // edge region of BC; barycentric coords (0, 1-w, w)
  4811. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4812. }
  4813. // face region
  4814. var denom = 1 / ( va + vb + vc );
  4815. // u = va * denom
  4816. v = vb * denom;
  4817. w = vc * denom;
  4818. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4819. },
  4820. equals: function ( triangle ) {
  4821. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4822. }
  4823. } );
  4824. /**
  4825. * @author mrdoob / http://mrdoob.com/
  4826. */
  4827. var _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4828. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4829. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4830. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4831. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4832. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4833. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4834. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4835. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4836. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4837. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4838. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4839. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4840. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4841. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4842. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4843. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4844. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4845. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4846. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4847. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4848. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4849. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4850. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4851. var _hslA = { h: 0, s: 0, l: 0 };
  4852. var _hslB = { h: 0, s: 0, l: 0 };
  4853. function Color( r, g, b ) {
  4854. if ( g === undefined && b === undefined ) {
  4855. // r is THREE.Color, hex or string
  4856. return this.set( r );
  4857. }
  4858. return this.setRGB( r, g, b );
  4859. }
  4860. function hue2rgb( p, q, t ) {
  4861. if ( t < 0 ) t += 1;
  4862. if ( t > 1 ) t -= 1;
  4863. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4864. if ( t < 1 / 2 ) return q;
  4865. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4866. return p;
  4867. }
  4868. function SRGBToLinear( c ) {
  4869. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4870. }
  4871. function LinearToSRGB( c ) {
  4872. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4873. }
  4874. Object.assign( Color.prototype, {
  4875. isColor: true,
  4876. r: 1, g: 1, b: 1,
  4877. set: function ( value ) {
  4878. if ( value && value.isColor ) {
  4879. this.copy( value );
  4880. } else if ( typeof value === 'number' ) {
  4881. this.setHex( value );
  4882. } else if ( typeof value === 'string' ) {
  4883. this.setStyle( value );
  4884. }
  4885. return this;
  4886. },
  4887. setScalar: function ( scalar ) {
  4888. this.r = scalar;
  4889. this.g = scalar;
  4890. this.b = scalar;
  4891. return this;
  4892. },
  4893. setHex: function ( hex ) {
  4894. hex = Math.floor( hex );
  4895. this.r = ( hex >> 16 & 255 ) / 255;
  4896. this.g = ( hex >> 8 & 255 ) / 255;
  4897. this.b = ( hex & 255 ) / 255;
  4898. return this;
  4899. },
  4900. setRGB: function ( r, g, b ) {
  4901. this.r = r;
  4902. this.g = g;
  4903. this.b = b;
  4904. return this;
  4905. },
  4906. setHSL: function ( h, s, l ) {
  4907. // h,s,l ranges are in 0.0 - 1.0
  4908. h = MathUtils.euclideanModulo( h, 1 );
  4909. s = MathUtils.clamp( s, 0, 1 );
  4910. l = MathUtils.clamp( l, 0, 1 );
  4911. if ( s === 0 ) {
  4912. this.r = this.g = this.b = l;
  4913. } else {
  4914. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4915. var q = ( 2 * l ) - p;
  4916. this.r = hue2rgb( q, p, h + 1 / 3 );
  4917. this.g = hue2rgb( q, p, h );
  4918. this.b = hue2rgb( q, p, h - 1 / 3 );
  4919. }
  4920. return this;
  4921. },
  4922. setStyle: function ( style ) {
  4923. function handleAlpha( string ) {
  4924. if ( string === undefined ) return;
  4925. if ( parseFloat( string ) < 1 ) {
  4926. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4927. }
  4928. }
  4929. var m;
  4930. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4931. // rgb / hsl
  4932. var color;
  4933. var name = m[ 1 ];
  4934. var components = m[ 2 ];
  4935. switch ( name ) {
  4936. case 'rgb':
  4937. case 'rgba':
  4938. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4939. // rgb(255,0,0) rgba(255,0,0,0.5)
  4940. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4941. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4942. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4943. handleAlpha( color[ 5 ] );
  4944. return this;
  4945. }
  4946. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4947. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4948. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4949. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4950. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4951. handleAlpha( color[ 5 ] );
  4952. return this;
  4953. }
  4954. break;
  4955. case 'hsl':
  4956. case 'hsla':
  4957. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4958. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4959. var h = parseFloat( color[ 1 ] ) / 360;
  4960. var s = parseInt( color[ 2 ], 10 ) / 100;
  4961. var l = parseInt( color[ 3 ], 10 ) / 100;
  4962. handleAlpha( color[ 5 ] );
  4963. return this.setHSL( h, s, l );
  4964. }
  4965. break;
  4966. }
  4967. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4968. // hex color
  4969. var hex = m[ 1 ];
  4970. var size = hex.length;
  4971. if ( size === 3 ) {
  4972. // #ff0
  4973. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4974. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4975. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4976. return this;
  4977. } else if ( size === 6 ) {
  4978. // #ff0000
  4979. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4980. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4981. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4982. return this;
  4983. }
  4984. }
  4985. if ( style && style.length > 0 ) {
  4986. return this.setColorName( style );
  4987. }
  4988. return this;
  4989. },
  4990. setColorName: function ( style ) {
  4991. // color keywords
  4992. var hex = _colorKeywords[ style ];
  4993. if ( hex !== undefined ) {
  4994. // red
  4995. this.setHex( hex );
  4996. } else {
  4997. // unknown color
  4998. console.warn( 'THREE.Color: Unknown color ' + style );
  4999. }
  5000. return this;
  5001. },
  5002. clone: function () {
  5003. return new this.constructor( this.r, this.g, this.b );
  5004. },
  5005. copy: function ( color ) {
  5006. this.r = color.r;
  5007. this.g = color.g;
  5008. this.b = color.b;
  5009. return this;
  5010. },
  5011. copyGammaToLinear: function ( color, gammaFactor ) {
  5012. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  5013. this.r = Math.pow( color.r, gammaFactor );
  5014. this.g = Math.pow( color.g, gammaFactor );
  5015. this.b = Math.pow( color.b, gammaFactor );
  5016. return this;
  5017. },
  5018. copyLinearToGamma: function ( color, gammaFactor ) {
  5019. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  5020. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  5021. this.r = Math.pow( color.r, safeInverse );
  5022. this.g = Math.pow( color.g, safeInverse );
  5023. this.b = Math.pow( color.b, safeInverse );
  5024. return this;
  5025. },
  5026. convertGammaToLinear: function ( gammaFactor ) {
  5027. this.copyGammaToLinear( this, gammaFactor );
  5028. return this;
  5029. },
  5030. convertLinearToGamma: function ( gammaFactor ) {
  5031. this.copyLinearToGamma( this, gammaFactor );
  5032. return this;
  5033. },
  5034. copySRGBToLinear: function ( color ) {
  5035. this.r = SRGBToLinear( color.r );
  5036. this.g = SRGBToLinear( color.g );
  5037. this.b = SRGBToLinear( color.b );
  5038. return this;
  5039. },
  5040. copyLinearToSRGB: function ( color ) {
  5041. this.r = LinearToSRGB( color.r );
  5042. this.g = LinearToSRGB( color.g );
  5043. this.b = LinearToSRGB( color.b );
  5044. return this;
  5045. },
  5046. convertSRGBToLinear: function () {
  5047. this.copySRGBToLinear( this );
  5048. return this;
  5049. },
  5050. convertLinearToSRGB: function () {
  5051. this.copyLinearToSRGB( this );
  5052. return this;
  5053. },
  5054. getHex: function () {
  5055. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  5056. },
  5057. getHexString: function () {
  5058. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  5059. },
  5060. getHSL: function ( target ) {
  5061. // h,s,l ranges are in 0.0 - 1.0
  5062. if ( target === undefined ) {
  5063. console.warn( 'THREE.Color: .getHSL() target is now required' );
  5064. target = { h: 0, s: 0, l: 0 };
  5065. }
  5066. var r = this.r, g = this.g, b = this.b;
  5067. var max = Math.max( r, g, b );
  5068. var min = Math.min( r, g, b );
  5069. var hue, saturation;
  5070. var lightness = ( min + max ) / 2.0;
  5071. if ( min === max ) {
  5072. hue = 0;
  5073. saturation = 0;
  5074. } else {
  5075. var delta = max - min;
  5076. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5077. switch ( max ) {
  5078. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5079. case g: hue = ( b - r ) / delta + 2; break;
  5080. case b: hue = ( r - g ) / delta + 4; break;
  5081. }
  5082. hue /= 6;
  5083. }
  5084. target.h = hue;
  5085. target.s = saturation;
  5086. target.l = lightness;
  5087. return target;
  5088. },
  5089. getStyle: function () {
  5090. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  5091. },
  5092. offsetHSL: function ( h, s, l ) {
  5093. this.getHSL( _hslA );
  5094. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  5095. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  5096. return this;
  5097. },
  5098. add: function ( color ) {
  5099. this.r += color.r;
  5100. this.g += color.g;
  5101. this.b += color.b;
  5102. return this;
  5103. },
  5104. addColors: function ( color1, color2 ) {
  5105. this.r = color1.r + color2.r;
  5106. this.g = color1.g + color2.g;
  5107. this.b = color1.b + color2.b;
  5108. return this;
  5109. },
  5110. addScalar: function ( s ) {
  5111. this.r += s;
  5112. this.g += s;
  5113. this.b += s;
  5114. return this;
  5115. },
  5116. sub: function ( color ) {
  5117. this.r = Math.max( 0, this.r - color.r );
  5118. this.g = Math.max( 0, this.g - color.g );
  5119. this.b = Math.max( 0, this.b - color.b );
  5120. return this;
  5121. },
  5122. multiply: function ( color ) {
  5123. this.r *= color.r;
  5124. this.g *= color.g;
  5125. this.b *= color.b;
  5126. return this;
  5127. },
  5128. multiplyScalar: function ( s ) {
  5129. this.r *= s;
  5130. this.g *= s;
  5131. this.b *= s;
  5132. return this;
  5133. },
  5134. lerp: function ( color, alpha ) {
  5135. this.r += ( color.r - this.r ) * alpha;
  5136. this.g += ( color.g - this.g ) * alpha;
  5137. this.b += ( color.b - this.b ) * alpha;
  5138. return this;
  5139. },
  5140. lerpHSL: function ( color, alpha ) {
  5141. this.getHSL( _hslA );
  5142. color.getHSL( _hslB );
  5143. var h = MathUtils.lerp( _hslA.h, _hslB.h, alpha );
  5144. var s = MathUtils.lerp( _hslA.s, _hslB.s, alpha );
  5145. var l = MathUtils.lerp( _hslA.l, _hslB.l, alpha );
  5146. this.setHSL( h, s, l );
  5147. return this;
  5148. },
  5149. equals: function ( c ) {
  5150. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5151. },
  5152. fromArray: function ( array, offset ) {
  5153. if ( offset === undefined ) offset = 0;
  5154. this.r = array[ offset ];
  5155. this.g = array[ offset + 1 ];
  5156. this.b = array[ offset + 2 ];
  5157. return this;
  5158. },
  5159. toArray: function ( array, offset ) {
  5160. if ( array === undefined ) array = [];
  5161. if ( offset === undefined ) offset = 0;
  5162. array[ offset ] = this.r;
  5163. array[ offset + 1 ] = this.g;
  5164. array[ offset + 2 ] = this.b;
  5165. return array;
  5166. },
  5167. toJSON: function () {
  5168. return this.getHex();
  5169. }
  5170. } );
  5171. Color.NAMES = _colorKeywords;
  5172. /**
  5173. * @author mrdoob / http://mrdoob.com/
  5174. * @author alteredq / http://alteredqualia.com/
  5175. */
  5176. function Face3( a, b, c, normal, color, materialIndex ) {
  5177. this.a = a;
  5178. this.b = b;
  5179. this.c = c;
  5180. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5181. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5182. this.color = ( color && color.isColor ) ? color : new Color();
  5183. this.vertexColors = Array.isArray( color ) ? color : [];
  5184. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5185. }
  5186. Object.assign( Face3.prototype, {
  5187. clone: function () {
  5188. return new this.constructor().copy( this );
  5189. },
  5190. copy: function ( source ) {
  5191. this.a = source.a;
  5192. this.b = source.b;
  5193. this.c = source.c;
  5194. this.normal.copy( source.normal );
  5195. this.color.copy( source.color );
  5196. this.materialIndex = source.materialIndex;
  5197. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5198. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5199. }
  5200. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5201. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5202. }
  5203. return this;
  5204. }
  5205. } );
  5206. /**
  5207. * @author mrdoob / http://mrdoob.com/
  5208. * @author alteredq / http://alteredqualia.com/
  5209. */
  5210. var materialId = 0;
  5211. function Material() {
  5212. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5213. this.uuid = MathUtils.generateUUID();
  5214. this.name = '';
  5215. this.type = 'Material';
  5216. this.fog = true;
  5217. this.blending = NormalBlending;
  5218. this.side = FrontSide;
  5219. this.flatShading = false;
  5220. this.vertexColors = false;
  5221. this.opacity = 1;
  5222. this.transparent = false;
  5223. this.blendSrc = SrcAlphaFactor;
  5224. this.blendDst = OneMinusSrcAlphaFactor;
  5225. this.blendEquation = AddEquation;
  5226. this.blendSrcAlpha = null;
  5227. this.blendDstAlpha = null;
  5228. this.blendEquationAlpha = null;
  5229. this.depthFunc = LessEqualDepth;
  5230. this.depthTest = true;
  5231. this.depthWrite = true;
  5232. this.stencilWriteMask = 0xff;
  5233. this.stencilFunc = AlwaysStencilFunc;
  5234. this.stencilRef = 0;
  5235. this.stencilFuncMask = 0xff;
  5236. this.stencilFail = KeepStencilOp;
  5237. this.stencilZFail = KeepStencilOp;
  5238. this.stencilZPass = KeepStencilOp;
  5239. this.stencilWrite = false;
  5240. this.clippingPlanes = null;
  5241. this.clipIntersection = false;
  5242. this.clipShadows = false;
  5243. this.shadowSide = null;
  5244. this.colorWrite = true;
  5245. this.precision = null; // override the renderer's default precision for this material
  5246. this.polygonOffset = false;
  5247. this.polygonOffsetFactor = 0;
  5248. this.polygonOffsetUnits = 0;
  5249. this.dithering = false;
  5250. this.alphaTest = 0;
  5251. this.premultipliedAlpha = false;
  5252. this.visible = true;
  5253. this.toneMapped = true;
  5254. this.userData = {};
  5255. this.version = 0;
  5256. }
  5257. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5258. constructor: Material,
  5259. isMaterial: true,
  5260. onBeforeCompile: function () {},
  5261. setValues: function ( values ) {
  5262. if ( values === undefined ) return;
  5263. for ( var key in values ) {
  5264. var newValue = values[ key ];
  5265. if ( newValue === undefined ) {
  5266. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5267. continue;
  5268. }
  5269. // for backward compatability if shading is set in the constructor
  5270. if ( key === 'shading' ) {
  5271. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5272. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5273. continue;
  5274. }
  5275. var currentValue = this[ key ];
  5276. if ( currentValue === undefined ) {
  5277. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5278. continue;
  5279. }
  5280. if ( currentValue && currentValue.isColor ) {
  5281. currentValue.set( newValue );
  5282. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5283. currentValue.copy( newValue );
  5284. } else {
  5285. this[ key ] = newValue;
  5286. }
  5287. }
  5288. },
  5289. toJSON: function ( meta ) {
  5290. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5291. if ( isRoot ) {
  5292. meta = {
  5293. textures: {},
  5294. images: {}
  5295. };
  5296. }
  5297. var data = {
  5298. metadata: {
  5299. version: 4.5,
  5300. type: 'Material',
  5301. generator: 'Material.toJSON'
  5302. }
  5303. };
  5304. // standard Material serialization
  5305. data.uuid = this.uuid;
  5306. data.type = this.type;
  5307. if ( this.name !== '' ) data.name = this.name;
  5308. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5309. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5310. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5311. if ( this.sheen && this.sheen.isColor ) data.sheen = this.sheen.getHex();
  5312. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5313. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5314. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5315. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5316. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5317. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5318. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5319. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5320. }
  5321. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5322. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5323. }
  5324. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5325. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5326. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5327. }
  5328. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5329. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5330. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5331. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5332. if ( this.aoMap && this.aoMap.isTexture ) {
  5333. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5334. data.aoMapIntensity = this.aoMapIntensity;
  5335. }
  5336. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5337. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5338. data.bumpScale = this.bumpScale;
  5339. }
  5340. if ( this.normalMap && this.normalMap.isTexture ) {
  5341. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5342. data.normalMapType = this.normalMapType;
  5343. data.normalScale = this.normalScale.toArray();
  5344. }
  5345. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5346. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5347. data.displacementScale = this.displacementScale;
  5348. data.displacementBias = this.displacementBias;
  5349. }
  5350. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5351. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5352. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5353. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5354. if ( this.envMap && this.envMap.isTexture ) {
  5355. data.envMap = this.envMap.toJSON( meta ).uuid;
  5356. data.reflectivity = this.reflectivity; // Scale behind envMap
  5357. data.refractionRatio = this.refractionRatio;
  5358. if ( this.combine !== undefined ) data.combine = this.combine;
  5359. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5360. }
  5361. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5362. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5363. }
  5364. if ( this.size !== undefined ) data.size = this.size;
  5365. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5366. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5367. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5368. if ( this.side !== FrontSide ) data.side = this.side;
  5369. if ( this.vertexColors ) data.vertexColors = true;
  5370. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5371. if ( this.transparent === true ) data.transparent = this.transparent;
  5372. data.depthFunc = this.depthFunc;
  5373. data.depthTest = this.depthTest;
  5374. data.depthWrite = this.depthWrite;
  5375. data.stencilWrite = this.stencilWrite;
  5376. data.stencilWriteMask = this.stencilWriteMask;
  5377. data.stencilFunc = this.stencilFunc;
  5378. data.stencilRef = this.stencilRef;
  5379. data.stencilFuncMask = this.stencilFuncMask;
  5380. data.stencilFail = this.stencilFail;
  5381. data.stencilZFail = this.stencilZFail;
  5382. data.stencilZPass = this.stencilZPass;
  5383. // rotation (SpriteMaterial)
  5384. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5385. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5386. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5387. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5388. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5389. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5390. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5391. if ( this.scale !== undefined ) data.scale = this.scale;
  5392. if ( this.dithering === true ) data.dithering = true;
  5393. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5394. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5395. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5396. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5397. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5398. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5399. if ( this.morphTargets === true ) data.morphTargets = true;
  5400. if ( this.morphNormals === true ) data.morphNormals = true;
  5401. if ( this.skinning === true ) data.skinning = true;
  5402. if ( this.visible === false ) data.visible = false;
  5403. if ( this.toneMapped === false ) data.toneMapped = false;
  5404. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5405. // TODO: Copied from Object3D.toJSON
  5406. function extractFromCache( cache ) {
  5407. var values = [];
  5408. for ( var key in cache ) {
  5409. var data = cache[ key ];
  5410. delete data.metadata;
  5411. values.push( data );
  5412. }
  5413. return values;
  5414. }
  5415. if ( isRoot ) {
  5416. var textures = extractFromCache( meta.textures );
  5417. var images = extractFromCache( meta.images );
  5418. if ( textures.length > 0 ) data.textures = textures;
  5419. if ( images.length > 0 ) data.images = images;
  5420. }
  5421. return data;
  5422. },
  5423. clone: function () {
  5424. return new this.constructor().copy( this );
  5425. },
  5426. copy: function ( source ) {
  5427. this.name = source.name;
  5428. this.fog = source.fog;
  5429. this.blending = source.blending;
  5430. this.side = source.side;
  5431. this.flatShading = source.flatShading;
  5432. this.vertexColors = source.vertexColors;
  5433. this.opacity = source.opacity;
  5434. this.transparent = source.transparent;
  5435. this.blendSrc = source.blendSrc;
  5436. this.blendDst = source.blendDst;
  5437. this.blendEquation = source.blendEquation;
  5438. this.blendSrcAlpha = source.blendSrcAlpha;
  5439. this.blendDstAlpha = source.blendDstAlpha;
  5440. this.blendEquationAlpha = source.blendEquationAlpha;
  5441. this.depthFunc = source.depthFunc;
  5442. this.depthTest = source.depthTest;
  5443. this.depthWrite = source.depthWrite;
  5444. this.stencilWriteMask = source.stencilWriteMask;
  5445. this.stencilFunc = source.stencilFunc;
  5446. this.stencilRef = source.stencilRef;
  5447. this.stencilFuncMask = source.stencilFuncMask;
  5448. this.stencilFail = source.stencilFail;
  5449. this.stencilZFail = source.stencilZFail;
  5450. this.stencilZPass = source.stencilZPass;
  5451. this.stencilWrite = source.stencilWrite;
  5452. var srcPlanes = source.clippingPlanes,
  5453. dstPlanes = null;
  5454. if ( srcPlanes !== null ) {
  5455. var n = srcPlanes.length;
  5456. dstPlanes = new Array( n );
  5457. for ( var i = 0; i !== n; ++ i )
  5458. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5459. }
  5460. this.clippingPlanes = dstPlanes;
  5461. this.clipIntersection = source.clipIntersection;
  5462. this.clipShadows = source.clipShadows;
  5463. this.shadowSide = source.shadowSide;
  5464. this.colorWrite = source.colorWrite;
  5465. this.precision = source.precision;
  5466. this.polygonOffset = source.polygonOffset;
  5467. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5468. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5469. this.dithering = source.dithering;
  5470. this.alphaTest = source.alphaTest;
  5471. this.premultipliedAlpha = source.premultipliedAlpha;
  5472. this.visible = source.visible;
  5473. this.toneMapped = source.toneMapped;
  5474. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5475. return this;
  5476. },
  5477. dispose: function () {
  5478. this.dispatchEvent( { type: 'dispose' } );
  5479. }
  5480. } );
  5481. Object.defineProperty( Material.prototype, 'needsUpdate', {
  5482. set: function ( value ) {
  5483. if ( value === true ) this.version ++;
  5484. }
  5485. } );
  5486. /**
  5487. * @author mrdoob / http://mrdoob.com/
  5488. * @author alteredq / http://alteredqualia.com/
  5489. *
  5490. * parameters = {
  5491. * color: <hex>,
  5492. * opacity: <float>,
  5493. * map: new THREE.Texture( <Image> ),
  5494. *
  5495. * lightMap: new THREE.Texture( <Image> ),
  5496. * lightMapIntensity: <float>
  5497. *
  5498. * aoMap: new THREE.Texture( <Image> ),
  5499. * aoMapIntensity: <float>
  5500. *
  5501. * specularMap: new THREE.Texture( <Image> ),
  5502. *
  5503. * alphaMap: new THREE.Texture( <Image> ),
  5504. *
  5505. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5506. * combine: THREE.Multiply,
  5507. * reflectivity: <float>,
  5508. * refractionRatio: <float>,
  5509. *
  5510. * depthTest: <bool>,
  5511. * depthWrite: <bool>,
  5512. *
  5513. * wireframe: <boolean>,
  5514. * wireframeLinewidth: <float>,
  5515. *
  5516. * skinning: <bool>,
  5517. * morphTargets: <bool>
  5518. * }
  5519. */
  5520. function MeshBasicMaterial( parameters ) {
  5521. Material.call( this );
  5522. this.type = 'MeshBasicMaterial';
  5523. this.color = new Color( 0xffffff ); // emissive
  5524. this.map = null;
  5525. this.lightMap = null;
  5526. this.lightMapIntensity = 1.0;
  5527. this.aoMap = null;
  5528. this.aoMapIntensity = 1.0;
  5529. this.specularMap = null;
  5530. this.alphaMap = null;
  5531. this.envMap = null;
  5532. this.combine = MultiplyOperation;
  5533. this.reflectivity = 1;
  5534. this.refractionRatio = 0.98;
  5535. this.wireframe = false;
  5536. this.wireframeLinewidth = 1;
  5537. this.wireframeLinecap = 'round';
  5538. this.wireframeLinejoin = 'round';
  5539. this.skinning = false;
  5540. this.morphTargets = false;
  5541. this.setValues( parameters );
  5542. }
  5543. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5544. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5545. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5546. MeshBasicMaterial.prototype.copy = function ( source ) {
  5547. Material.prototype.copy.call( this, source );
  5548. this.color.copy( source.color );
  5549. this.map = source.map;
  5550. this.lightMap = source.lightMap;
  5551. this.lightMapIntensity = source.lightMapIntensity;
  5552. this.aoMap = source.aoMap;
  5553. this.aoMapIntensity = source.aoMapIntensity;
  5554. this.specularMap = source.specularMap;
  5555. this.alphaMap = source.alphaMap;
  5556. this.envMap = source.envMap;
  5557. this.combine = source.combine;
  5558. this.reflectivity = source.reflectivity;
  5559. this.refractionRatio = source.refractionRatio;
  5560. this.wireframe = source.wireframe;
  5561. this.wireframeLinewidth = source.wireframeLinewidth;
  5562. this.wireframeLinecap = source.wireframeLinecap;
  5563. this.wireframeLinejoin = source.wireframeLinejoin;
  5564. this.skinning = source.skinning;
  5565. this.morphTargets = source.morphTargets;
  5566. return this;
  5567. };
  5568. /**
  5569. * @author mrdoob / http://mrdoob.com/
  5570. */
  5571. var _vector$3 = new Vector3();
  5572. function BufferAttribute( array, itemSize, normalized ) {
  5573. if ( Array.isArray( array ) ) {
  5574. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5575. }
  5576. this.name = '';
  5577. this.array = array;
  5578. this.itemSize = itemSize;
  5579. this.count = array !== undefined ? array.length / itemSize : 0;
  5580. this.normalized = normalized === true;
  5581. this.usage = StaticDrawUsage;
  5582. this.updateRange = { offset: 0, count: - 1 };
  5583. this.version = 0;
  5584. }
  5585. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5586. set: function ( value ) {
  5587. if ( value === true ) this.version ++;
  5588. }
  5589. } );
  5590. Object.assign( BufferAttribute.prototype, {
  5591. isBufferAttribute: true,
  5592. onUploadCallback: function () {},
  5593. setUsage: function ( value ) {
  5594. this.usage = value;
  5595. return this;
  5596. },
  5597. copy: function ( source ) {
  5598. this.name = source.name;
  5599. this.array = new source.array.constructor( source.array );
  5600. this.itemSize = source.itemSize;
  5601. this.count = source.count;
  5602. this.normalized = source.normalized;
  5603. this.usage = source.usage;
  5604. return this;
  5605. },
  5606. copyAt: function ( index1, attribute, index2 ) {
  5607. index1 *= this.itemSize;
  5608. index2 *= attribute.itemSize;
  5609. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5610. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5611. }
  5612. return this;
  5613. },
  5614. copyArray: function ( array ) {
  5615. this.array.set( array );
  5616. return this;
  5617. },
  5618. copyColorsArray: function ( colors ) {
  5619. var array = this.array, offset = 0;
  5620. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5621. var color = colors[ i ];
  5622. if ( color === undefined ) {
  5623. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5624. color = new Color();
  5625. }
  5626. array[ offset ++ ] = color.r;
  5627. array[ offset ++ ] = color.g;
  5628. array[ offset ++ ] = color.b;
  5629. }
  5630. return this;
  5631. },
  5632. copyVector2sArray: function ( vectors ) {
  5633. var array = this.array, offset = 0;
  5634. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5635. var vector = vectors[ i ];
  5636. if ( vector === undefined ) {
  5637. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5638. vector = new Vector2();
  5639. }
  5640. array[ offset ++ ] = vector.x;
  5641. array[ offset ++ ] = vector.y;
  5642. }
  5643. return this;
  5644. },
  5645. copyVector3sArray: function ( vectors ) {
  5646. var array = this.array, offset = 0;
  5647. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5648. var vector = vectors[ i ];
  5649. if ( vector === undefined ) {
  5650. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5651. vector = new Vector3();
  5652. }
  5653. array[ offset ++ ] = vector.x;
  5654. array[ offset ++ ] = vector.y;
  5655. array[ offset ++ ] = vector.z;
  5656. }
  5657. return this;
  5658. },
  5659. copyVector4sArray: function ( vectors ) {
  5660. var array = this.array, offset = 0;
  5661. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5662. var vector = vectors[ i ];
  5663. if ( vector === undefined ) {
  5664. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5665. vector = new Vector4();
  5666. }
  5667. array[ offset ++ ] = vector.x;
  5668. array[ offset ++ ] = vector.y;
  5669. array[ offset ++ ] = vector.z;
  5670. array[ offset ++ ] = vector.w;
  5671. }
  5672. return this;
  5673. },
  5674. applyMatrix3: function ( m ) {
  5675. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5676. _vector$3.x = this.getX( i );
  5677. _vector$3.y = this.getY( i );
  5678. _vector$3.z = this.getZ( i );
  5679. _vector$3.applyMatrix3( m );
  5680. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5681. }
  5682. return this;
  5683. },
  5684. applyMatrix4: function ( m ) {
  5685. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5686. _vector$3.x = this.getX( i );
  5687. _vector$3.y = this.getY( i );
  5688. _vector$3.z = this.getZ( i );
  5689. _vector$3.applyMatrix4( m );
  5690. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5691. }
  5692. return this;
  5693. },
  5694. applyNormalMatrix: function ( m ) {
  5695. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5696. _vector$3.x = this.getX( i );
  5697. _vector$3.y = this.getY( i );
  5698. _vector$3.z = this.getZ( i );
  5699. _vector$3.applyNormalMatrix( m );
  5700. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5701. }
  5702. return this;
  5703. },
  5704. transformDirection: function ( m ) {
  5705. for ( var i = 0, l = this.count; i < l; i ++ ) {
  5706. _vector$3.x = this.getX( i );
  5707. _vector$3.y = this.getY( i );
  5708. _vector$3.z = this.getZ( i );
  5709. _vector$3.transformDirection( m );
  5710. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5711. }
  5712. return this;
  5713. },
  5714. set: function ( value, offset ) {
  5715. if ( offset === undefined ) offset = 0;
  5716. this.array.set( value, offset );
  5717. return this;
  5718. },
  5719. getX: function ( index ) {
  5720. return this.array[ index * this.itemSize ];
  5721. },
  5722. setX: function ( index, x ) {
  5723. this.array[ index * this.itemSize ] = x;
  5724. return this;
  5725. },
  5726. getY: function ( index ) {
  5727. return this.array[ index * this.itemSize + 1 ];
  5728. },
  5729. setY: function ( index, y ) {
  5730. this.array[ index * this.itemSize + 1 ] = y;
  5731. return this;
  5732. },
  5733. getZ: function ( index ) {
  5734. return this.array[ index * this.itemSize + 2 ];
  5735. },
  5736. setZ: function ( index, z ) {
  5737. this.array[ index * this.itemSize + 2 ] = z;
  5738. return this;
  5739. },
  5740. getW: function ( index ) {
  5741. return this.array[ index * this.itemSize + 3 ];
  5742. },
  5743. setW: function ( index, w ) {
  5744. this.array[ index * this.itemSize + 3 ] = w;
  5745. return this;
  5746. },
  5747. setXY: function ( index, x, y ) {
  5748. index *= this.itemSize;
  5749. this.array[ index + 0 ] = x;
  5750. this.array[ index + 1 ] = y;
  5751. return this;
  5752. },
  5753. setXYZ: function ( index, x, y, z ) {
  5754. index *= this.itemSize;
  5755. this.array[ index + 0 ] = x;
  5756. this.array[ index + 1 ] = y;
  5757. this.array[ index + 2 ] = z;
  5758. return this;
  5759. },
  5760. setXYZW: function ( index, x, y, z, w ) {
  5761. index *= this.itemSize;
  5762. this.array[ index + 0 ] = x;
  5763. this.array[ index + 1 ] = y;
  5764. this.array[ index + 2 ] = z;
  5765. this.array[ index + 3 ] = w;
  5766. return this;
  5767. },
  5768. onUpload: function ( callback ) {
  5769. this.onUploadCallback = callback;
  5770. return this;
  5771. },
  5772. clone: function () {
  5773. return new this.constructor( this.array, this.itemSize ).copy( this );
  5774. },
  5775. toJSON: function () {
  5776. return {
  5777. itemSize: this.itemSize,
  5778. type: this.array.constructor.name,
  5779. array: Array.prototype.slice.call( this.array ),
  5780. normalized: this.normalized
  5781. };
  5782. }
  5783. } );
  5784. //
  5785. function Int8BufferAttribute( array, itemSize, normalized ) {
  5786. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5787. }
  5788. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5789. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5790. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5791. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5792. }
  5793. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5794. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5795. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5796. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5797. }
  5798. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5799. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5800. function Int16BufferAttribute( array, itemSize, normalized ) {
  5801. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5802. }
  5803. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5804. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5805. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5806. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5807. }
  5808. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5809. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5810. function Int32BufferAttribute( array, itemSize, normalized ) {
  5811. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5812. }
  5813. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5814. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5815. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5816. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5817. }
  5818. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5819. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5820. function Float32BufferAttribute( array, itemSize, normalized ) {
  5821. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5822. }
  5823. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5824. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5825. function Float64BufferAttribute( array, itemSize, normalized ) {
  5826. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5827. }
  5828. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5829. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5830. /**
  5831. * @author mrdoob / http://mrdoob.com/
  5832. */
  5833. function DirectGeometry() {
  5834. this.vertices = [];
  5835. this.normals = [];
  5836. this.colors = [];
  5837. this.uvs = [];
  5838. this.uvs2 = [];
  5839. this.groups = [];
  5840. this.morphTargets = {};
  5841. this.skinWeights = [];
  5842. this.skinIndices = [];
  5843. // this.lineDistances = [];
  5844. this.boundingBox = null;
  5845. this.boundingSphere = null;
  5846. // update flags
  5847. this.verticesNeedUpdate = false;
  5848. this.normalsNeedUpdate = false;
  5849. this.colorsNeedUpdate = false;
  5850. this.uvsNeedUpdate = false;
  5851. this.groupsNeedUpdate = false;
  5852. }
  5853. Object.assign( DirectGeometry.prototype, {
  5854. computeGroups: function ( geometry ) {
  5855. var group;
  5856. var groups = [];
  5857. var materialIndex = undefined;
  5858. var faces = geometry.faces;
  5859. for ( var i = 0; i < faces.length; i ++ ) {
  5860. var face = faces[ i ];
  5861. // materials
  5862. if ( face.materialIndex !== materialIndex ) {
  5863. materialIndex = face.materialIndex;
  5864. if ( group !== undefined ) {
  5865. group.count = ( i * 3 ) - group.start;
  5866. groups.push( group );
  5867. }
  5868. group = {
  5869. start: i * 3,
  5870. materialIndex: materialIndex
  5871. };
  5872. }
  5873. }
  5874. if ( group !== undefined ) {
  5875. group.count = ( i * 3 ) - group.start;
  5876. groups.push( group );
  5877. }
  5878. this.groups = groups;
  5879. },
  5880. fromGeometry: function ( geometry ) {
  5881. var faces = geometry.faces;
  5882. var vertices = geometry.vertices;
  5883. var faceVertexUvs = geometry.faceVertexUvs;
  5884. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5885. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5886. // morphs
  5887. var morphTargets = geometry.morphTargets;
  5888. var morphTargetsLength = morphTargets.length;
  5889. var morphTargetsPosition;
  5890. if ( morphTargetsLength > 0 ) {
  5891. morphTargetsPosition = [];
  5892. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5893. morphTargetsPosition[ i ] = {
  5894. name: morphTargets[ i ].name,
  5895. data: []
  5896. };
  5897. }
  5898. this.morphTargets.position = morphTargetsPosition;
  5899. }
  5900. var morphNormals = geometry.morphNormals;
  5901. var morphNormalsLength = morphNormals.length;
  5902. var morphTargetsNormal;
  5903. if ( morphNormalsLength > 0 ) {
  5904. morphTargetsNormal = [];
  5905. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5906. morphTargetsNormal[ i ] = {
  5907. name: morphNormals[ i ].name,
  5908. data: []
  5909. };
  5910. }
  5911. this.morphTargets.normal = morphTargetsNormal;
  5912. }
  5913. // skins
  5914. var skinIndices = geometry.skinIndices;
  5915. var skinWeights = geometry.skinWeights;
  5916. var hasSkinIndices = skinIndices.length === vertices.length;
  5917. var hasSkinWeights = skinWeights.length === vertices.length;
  5918. //
  5919. if ( vertices.length > 0 && faces.length === 0 ) {
  5920. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5921. }
  5922. for ( var i = 0; i < faces.length; i ++ ) {
  5923. var face = faces[ i ];
  5924. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5925. var vertexNormals = face.vertexNormals;
  5926. if ( vertexNormals.length === 3 ) {
  5927. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5928. } else {
  5929. var normal = face.normal;
  5930. this.normals.push( normal, normal, normal );
  5931. }
  5932. var vertexColors = face.vertexColors;
  5933. if ( vertexColors.length === 3 ) {
  5934. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5935. } else {
  5936. var color = face.color;
  5937. this.colors.push( color, color, color );
  5938. }
  5939. if ( hasFaceVertexUv === true ) {
  5940. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5941. if ( vertexUvs !== undefined ) {
  5942. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5943. } else {
  5944. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5945. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5946. }
  5947. }
  5948. if ( hasFaceVertexUv2 === true ) {
  5949. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5950. if ( vertexUvs !== undefined ) {
  5951. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5952. } else {
  5953. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5954. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5955. }
  5956. }
  5957. // morphs
  5958. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5959. var morphTarget = morphTargets[ j ].vertices;
  5960. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5961. }
  5962. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5963. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5964. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5965. }
  5966. // skins
  5967. if ( hasSkinIndices ) {
  5968. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5969. }
  5970. if ( hasSkinWeights ) {
  5971. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5972. }
  5973. }
  5974. this.computeGroups( geometry );
  5975. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5976. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5977. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5978. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5979. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5980. if ( geometry.boundingSphere !== null ) {
  5981. this.boundingSphere = geometry.boundingSphere.clone();
  5982. }
  5983. if ( geometry.boundingBox !== null ) {
  5984. this.boundingBox = geometry.boundingBox.clone();
  5985. }
  5986. return this;
  5987. }
  5988. } );
  5989. /**
  5990. * @author mrdoob / http://mrdoob.com/
  5991. */
  5992. function arrayMax( array ) {
  5993. if ( array.length === 0 ) return - Infinity;
  5994. let max = array[ 0 ];
  5995. for ( let i = 1, l = array.length; i < l; ++ i ) {
  5996. if ( array[ i ] > max ) max = array[ i ];
  5997. }
  5998. return max;
  5999. }
  6000. /**
  6001. * @author alteredq / http://alteredqualia.com/
  6002. * @author mrdoob / http://mrdoob.com/
  6003. */
  6004. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6005. var _m1$2 = new Matrix4();
  6006. var _obj = new Object3D();
  6007. var _offset = new Vector3();
  6008. var _box$2 = new Box3();
  6009. var _boxMorphTargets = new Box3();
  6010. var _vector$4 = new Vector3();
  6011. function BufferGeometry() {
  6012. Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
  6013. this.uuid = MathUtils.generateUUID();
  6014. this.name = '';
  6015. this.type = 'BufferGeometry';
  6016. this.index = null;
  6017. this.attributes = {};
  6018. this.morphAttributes = {};
  6019. this.morphTargetsRelative = false;
  6020. this.groups = [];
  6021. this.boundingBox = null;
  6022. this.boundingSphere = null;
  6023. this.drawRange = { start: 0, count: Infinity };
  6024. this.userData = {};
  6025. }
  6026. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6027. constructor: BufferGeometry,
  6028. isBufferGeometry: true,
  6029. getIndex: function () {
  6030. return this.index;
  6031. },
  6032. setIndex: function ( index ) {
  6033. if ( Array.isArray( index ) ) {
  6034. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6035. } else {
  6036. this.index = index;
  6037. }
  6038. },
  6039. getAttribute: function ( name ) {
  6040. return this.attributes[ name ];
  6041. },
  6042. setAttribute: function ( name, attribute ) {
  6043. this.attributes[ name ] = attribute;
  6044. return this;
  6045. },
  6046. deleteAttribute: function ( name ) {
  6047. delete this.attributes[ name ];
  6048. return this;
  6049. },
  6050. addGroup: function ( start, count, materialIndex ) {
  6051. this.groups.push( {
  6052. start: start,
  6053. count: count,
  6054. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6055. } );
  6056. },
  6057. clearGroups: function () {
  6058. this.groups = [];
  6059. },
  6060. setDrawRange: function ( start, count ) {
  6061. this.drawRange.start = start;
  6062. this.drawRange.count = count;
  6063. },
  6064. applyMatrix4: function ( matrix ) {
  6065. var position = this.attributes.position;
  6066. if ( position !== undefined ) {
  6067. position.applyMatrix4( matrix );
  6068. position.needsUpdate = true;
  6069. }
  6070. var normal = this.attributes.normal;
  6071. if ( normal !== undefined ) {
  6072. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6073. normal.applyNormalMatrix( normalMatrix );
  6074. normal.needsUpdate = true;
  6075. }
  6076. var tangent = this.attributes.tangent;
  6077. if ( tangent !== undefined ) {
  6078. tangent.transformDirection( matrix );
  6079. tangent.needsUpdate = true;
  6080. }
  6081. if ( this.boundingBox !== null ) {
  6082. this.computeBoundingBox();
  6083. }
  6084. if ( this.boundingSphere !== null ) {
  6085. this.computeBoundingSphere();
  6086. }
  6087. return this;
  6088. },
  6089. rotateX: function ( angle ) {
  6090. // rotate geometry around world x-axis
  6091. _m1$2.makeRotationX( angle );
  6092. this.applyMatrix4( _m1$2 );
  6093. return this;
  6094. },
  6095. rotateY: function ( angle ) {
  6096. // rotate geometry around world y-axis
  6097. _m1$2.makeRotationY( angle );
  6098. this.applyMatrix4( _m1$2 );
  6099. return this;
  6100. },
  6101. rotateZ: function ( angle ) {
  6102. // rotate geometry around world z-axis
  6103. _m1$2.makeRotationZ( angle );
  6104. this.applyMatrix4( _m1$2 );
  6105. return this;
  6106. },
  6107. translate: function ( x, y, z ) {
  6108. // translate geometry
  6109. _m1$2.makeTranslation( x, y, z );
  6110. this.applyMatrix4( _m1$2 );
  6111. return this;
  6112. },
  6113. scale: function ( x, y, z ) {
  6114. // scale geometry
  6115. _m1$2.makeScale( x, y, z );
  6116. this.applyMatrix4( _m1$2 );
  6117. return this;
  6118. },
  6119. lookAt: function ( vector ) {
  6120. _obj.lookAt( vector );
  6121. _obj.updateMatrix();
  6122. this.applyMatrix4( _obj.matrix );
  6123. return this;
  6124. },
  6125. center: function () {
  6126. this.computeBoundingBox();
  6127. this.boundingBox.getCenter( _offset ).negate();
  6128. this.translate( _offset.x, _offset.y, _offset.z );
  6129. return this;
  6130. },
  6131. setFromObject: function ( object ) {
  6132. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6133. var geometry = object.geometry;
  6134. if ( object.isPoints || object.isLine ) {
  6135. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6136. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6137. this.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6138. this.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6139. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6140. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6141. this.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6142. }
  6143. if ( geometry.boundingSphere !== null ) {
  6144. this.boundingSphere = geometry.boundingSphere.clone();
  6145. }
  6146. if ( geometry.boundingBox !== null ) {
  6147. this.boundingBox = geometry.boundingBox.clone();
  6148. }
  6149. } else if ( object.isMesh ) {
  6150. if ( geometry && geometry.isGeometry ) {
  6151. this.fromGeometry( geometry );
  6152. }
  6153. }
  6154. return this;
  6155. },
  6156. setFromPoints: function ( points ) {
  6157. var position = [];
  6158. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6159. var point = points[ i ];
  6160. position.push( point.x, point.y, point.z || 0 );
  6161. }
  6162. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6163. return this;
  6164. },
  6165. updateFromObject: function ( object ) {
  6166. var geometry = object.geometry;
  6167. if ( object.isMesh ) {
  6168. var direct = geometry.__directGeometry;
  6169. if ( geometry.elementsNeedUpdate === true ) {
  6170. direct = undefined;
  6171. geometry.elementsNeedUpdate = false;
  6172. }
  6173. if ( direct === undefined ) {
  6174. return this.fromGeometry( geometry );
  6175. }
  6176. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6177. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6178. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6179. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6180. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6181. geometry.verticesNeedUpdate = false;
  6182. geometry.normalsNeedUpdate = false;
  6183. geometry.colorsNeedUpdate = false;
  6184. geometry.uvsNeedUpdate = false;
  6185. geometry.groupsNeedUpdate = false;
  6186. geometry = direct;
  6187. }
  6188. var attribute;
  6189. if ( geometry.verticesNeedUpdate === true ) {
  6190. attribute = this.attributes.position;
  6191. if ( attribute !== undefined ) {
  6192. attribute.copyVector3sArray( geometry.vertices );
  6193. attribute.needsUpdate = true;
  6194. }
  6195. geometry.verticesNeedUpdate = false;
  6196. }
  6197. if ( geometry.normalsNeedUpdate === true ) {
  6198. attribute = this.attributes.normal;
  6199. if ( attribute !== undefined ) {
  6200. attribute.copyVector3sArray( geometry.normals );
  6201. attribute.needsUpdate = true;
  6202. }
  6203. geometry.normalsNeedUpdate = false;
  6204. }
  6205. if ( geometry.colorsNeedUpdate === true ) {
  6206. attribute = this.attributes.color;
  6207. if ( attribute !== undefined ) {
  6208. attribute.copyColorsArray( geometry.colors );
  6209. attribute.needsUpdate = true;
  6210. }
  6211. geometry.colorsNeedUpdate = false;
  6212. }
  6213. if ( geometry.uvsNeedUpdate ) {
  6214. attribute = this.attributes.uv;
  6215. if ( attribute !== undefined ) {
  6216. attribute.copyVector2sArray( geometry.uvs );
  6217. attribute.needsUpdate = true;
  6218. }
  6219. geometry.uvsNeedUpdate = false;
  6220. }
  6221. if ( geometry.lineDistancesNeedUpdate ) {
  6222. attribute = this.attributes.lineDistance;
  6223. if ( attribute !== undefined ) {
  6224. attribute.copyArray( geometry.lineDistances );
  6225. attribute.needsUpdate = true;
  6226. }
  6227. geometry.lineDistancesNeedUpdate = false;
  6228. }
  6229. if ( geometry.groupsNeedUpdate ) {
  6230. geometry.computeGroups( object.geometry );
  6231. this.groups = geometry.groups;
  6232. geometry.groupsNeedUpdate = false;
  6233. }
  6234. return this;
  6235. },
  6236. fromGeometry: function ( geometry ) {
  6237. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6238. return this.fromDirectGeometry( geometry.__directGeometry );
  6239. },
  6240. fromDirectGeometry: function ( geometry ) {
  6241. var positions = new Float32Array( geometry.vertices.length * 3 );
  6242. this.setAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6243. if ( geometry.normals.length > 0 ) {
  6244. var normals = new Float32Array( geometry.normals.length * 3 );
  6245. this.setAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6246. }
  6247. if ( geometry.colors.length > 0 ) {
  6248. var colors = new Float32Array( geometry.colors.length * 3 );
  6249. this.setAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6250. }
  6251. if ( geometry.uvs.length > 0 ) {
  6252. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6253. this.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6254. }
  6255. if ( geometry.uvs2.length > 0 ) {
  6256. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6257. this.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6258. }
  6259. // groups
  6260. this.groups = geometry.groups;
  6261. // morphs
  6262. for ( var name in geometry.morphTargets ) {
  6263. var array = [];
  6264. var morphTargets = geometry.morphTargets[ name ];
  6265. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6266. var morphTarget = morphTargets[ i ];
  6267. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6268. attribute.name = morphTarget.name;
  6269. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6270. }
  6271. this.morphAttributes[ name ] = array;
  6272. }
  6273. // skinning
  6274. if ( geometry.skinIndices.length > 0 ) {
  6275. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6276. this.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6277. }
  6278. if ( geometry.skinWeights.length > 0 ) {
  6279. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6280. this.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6281. }
  6282. //
  6283. if ( geometry.boundingSphere !== null ) {
  6284. this.boundingSphere = geometry.boundingSphere.clone();
  6285. }
  6286. if ( geometry.boundingBox !== null ) {
  6287. this.boundingBox = geometry.boundingBox.clone();
  6288. }
  6289. return this;
  6290. },
  6291. computeBoundingBox: function () {
  6292. if ( this.boundingBox === null ) {
  6293. this.boundingBox = new Box3();
  6294. }
  6295. var position = this.attributes.position;
  6296. var morphAttributesPosition = this.morphAttributes.position;
  6297. if ( position !== undefined ) {
  6298. this.boundingBox.setFromBufferAttribute( position );
  6299. // process morph attributes if present
  6300. if ( morphAttributesPosition ) {
  6301. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6302. var morphAttribute = morphAttributesPosition[ i ];
  6303. _box$2.setFromBufferAttribute( morphAttribute );
  6304. if ( this.morphTargetsRelative ) {
  6305. _vector$4.addVectors( this.boundingBox.min, _box$2.min );
  6306. this.boundingBox.expandByPoint( _vector$4 );
  6307. _vector$4.addVectors( this.boundingBox.max, _box$2.max );
  6308. this.boundingBox.expandByPoint( _vector$4 );
  6309. } else {
  6310. this.boundingBox.expandByPoint( _box$2.min );
  6311. this.boundingBox.expandByPoint( _box$2.max );
  6312. }
  6313. }
  6314. }
  6315. } else {
  6316. this.boundingBox.makeEmpty();
  6317. }
  6318. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6319. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6320. }
  6321. },
  6322. computeBoundingSphere: function () {
  6323. if ( this.boundingSphere === null ) {
  6324. this.boundingSphere = new Sphere();
  6325. }
  6326. var position = this.attributes.position;
  6327. var morphAttributesPosition = this.morphAttributes.position;
  6328. if ( position ) {
  6329. // first, find the center of the bounding sphere
  6330. var center = this.boundingSphere.center;
  6331. _box$2.setFromBufferAttribute( position );
  6332. // process morph attributes if present
  6333. if ( morphAttributesPosition ) {
  6334. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6335. var morphAttribute = morphAttributesPosition[ i ];
  6336. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6337. if ( this.morphTargetsRelative ) {
  6338. _vector$4.addVectors( _box$2.min, _boxMorphTargets.min );
  6339. _box$2.expandByPoint( _vector$4 );
  6340. _vector$4.addVectors( _box$2.max, _boxMorphTargets.max );
  6341. _box$2.expandByPoint( _vector$4 );
  6342. } else {
  6343. _box$2.expandByPoint( _boxMorphTargets.min );
  6344. _box$2.expandByPoint( _boxMorphTargets.max );
  6345. }
  6346. }
  6347. }
  6348. _box$2.getCenter( center );
  6349. // second, try to find a boundingSphere with a radius smaller than the
  6350. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6351. var maxRadiusSq = 0;
  6352. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6353. _vector$4.fromBufferAttribute( position, i );
  6354. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6355. }
  6356. // process morph attributes if present
  6357. if ( morphAttributesPosition ) {
  6358. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6359. var morphAttribute = morphAttributesPosition[ i ];
  6360. var morphTargetsRelative = this.morphTargetsRelative;
  6361. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6362. _vector$4.fromBufferAttribute( morphAttribute, j );
  6363. if ( morphTargetsRelative ) {
  6364. _offset.fromBufferAttribute( position, j );
  6365. _vector$4.add( _offset );
  6366. }
  6367. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6368. }
  6369. }
  6370. }
  6371. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6372. if ( isNaN( this.boundingSphere.radius ) ) {
  6373. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6374. }
  6375. }
  6376. },
  6377. computeFaceNormals: function () {
  6378. // backwards compatibility
  6379. },
  6380. computeVertexNormals: function () {
  6381. var index = this.index;
  6382. var attributes = this.attributes;
  6383. if ( attributes.position ) {
  6384. var positions = attributes.position.array;
  6385. if ( attributes.normal === undefined ) {
  6386. this.setAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6387. } else {
  6388. // reset existing normals to zero
  6389. var array = attributes.normal.array;
  6390. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6391. array[ i ] = 0;
  6392. }
  6393. }
  6394. var normals = attributes.normal.array;
  6395. var vA, vB, vC;
  6396. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6397. var cb = new Vector3(), ab = new Vector3();
  6398. // indexed elements
  6399. if ( index ) {
  6400. var indices = index.array;
  6401. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  6402. vA = indices[ i + 0 ] * 3;
  6403. vB = indices[ i + 1 ] * 3;
  6404. vC = indices[ i + 2 ] * 3;
  6405. pA.fromArray( positions, vA );
  6406. pB.fromArray( positions, vB );
  6407. pC.fromArray( positions, vC );
  6408. cb.subVectors( pC, pB );
  6409. ab.subVectors( pA, pB );
  6410. cb.cross( ab );
  6411. normals[ vA ] += cb.x;
  6412. normals[ vA + 1 ] += cb.y;
  6413. normals[ vA + 2 ] += cb.z;
  6414. normals[ vB ] += cb.x;
  6415. normals[ vB + 1 ] += cb.y;
  6416. normals[ vB + 2 ] += cb.z;
  6417. normals[ vC ] += cb.x;
  6418. normals[ vC + 1 ] += cb.y;
  6419. normals[ vC + 2 ] += cb.z;
  6420. }
  6421. } else {
  6422. // non-indexed elements (unconnected triangle soup)
  6423. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6424. pA.fromArray( positions, i );
  6425. pB.fromArray( positions, i + 3 );
  6426. pC.fromArray( positions, i + 6 );
  6427. cb.subVectors( pC, pB );
  6428. ab.subVectors( pA, pB );
  6429. cb.cross( ab );
  6430. normals[ i ] = cb.x;
  6431. normals[ i + 1 ] = cb.y;
  6432. normals[ i + 2 ] = cb.z;
  6433. normals[ i + 3 ] = cb.x;
  6434. normals[ i + 4 ] = cb.y;
  6435. normals[ i + 5 ] = cb.z;
  6436. normals[ i + 6 ] = cb.x;
  6437. normals[ i + 7 ] = cb.y;
  6438. normals[ i + 8 ] = cb.z;
  6439. }
  6440. }
  6441. this.normalizeNormals();
  6442. attributes.normal.needsUpdate = true;
  6443. }
  6444. },
  6445. merge: function ( geometry, offset ) {
  6446. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6447. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6448. return;
  6449. }
  6450. if ( offset === undefined ) {
  6451. offset = 0;
  6452. console.warn(
  6453. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6454. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6455. );
  6456. }
  6457. var attributes = this.attributes;
  6458. for ( var key in attributes ) {
  6459. if ( geometry.attributes[ key ] === undefined ) continue;
  6460. var attribute1 = attributes[ key ];
  6461. var attributeArray1 = attribute1.array;
  6462. var attribute2 = geometry.attributes[ key ];
  6463. var attributeArray2 = attribute2.array;
  6464. var attributeOffset = attribute2.itemSize * offset;
  6465. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6466. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6467. attributeArray1[ j ] = attributeArray2[ i ];
  6468. }
  6469. }
  6470. return this;
  6471. },
  6472. normalizeNormals: function () {
  6473. var normals = this.attributes.normal;
  6474. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6475. _vector$4.x = normals.getX( i );
  6476. _vector$4.y = normals.getY( i );
  6477. _vector$4.z = normals.getZ( i );
  6478. _vector$4.normalize();
  6479. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6480. }
  6481. },
  6482. toNonIndexed: function () {
  6483. function convertBufferAttribute( attribute, indices ) {
  6484. var array = attribute.array;
  6485. var itemSize = attribute.itemSize;
  6486. var normalized = attribute.normalized;
  6487. var array2 = new array.constructor( indices.length * itemSize );
  6488. var index = 0, index2 = 0;
  6489. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6490. index = indices[ i ] * itemSize;
  6491. for ( var j = 0; j < itemSize; j ++ ) {
  6492. array2[ index2 ++ ] = array[ index ++ ];
  6493. }
  6494. }
  6495. return new BufferAttribute( array2, itemSize, normalized );
  6496. }
  6497. //
  6498. if ( this.index === null ) {
  6499. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6500. return this;
  6501. }
  6502. var geometry2 = new BufferGeometry();
  6503. var indices = this.index.array;
  6504. var attributes = this.attributes;
  6505. // attributes
  6506. for ( var name in attributes ) {
  6507. var attribute = attributes[ name ];
  6508. var newAttribute = convertBufferAttribute( attribute, indices );
  6509. geometry2.setAttribute( name, newAttribute );
  6510. }
  6511. // morph attributes
  6512. var morphAttributes = this.morphAttributes;
  6513. for ( name in morphAttributes ) {
  6514. var morphArray = [];
  6515. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6516. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6517. var attribute = morphAttribute[ i ];
  6518. var newAttribute = convertBufferAttribute( attribute, indices );
  6519. morphArray.push( newAttribute );
  6520. }
  6521. geometry2.morphAttributes[ name ] = morphArray;
  6522. }
  6523. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6524. // groups
  6525. var groups = this.groups;
  6526. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6527. var group = groups[ i ];
  6528. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6529. }
  6530. return geometry2;
  6531. },
  6532. toJSON: function () {
  6533. var data = {
  6534. metadata: {
  6535. version: 4.5,
  6536. type: 'BufferGeometry',
  6537. generator: 'BufferGeometry.toJSON'
  6538. }
  6539. };
  6540. // standard BufferGeometry serialization
  6541. data.uuid = this.uuid;
  6542. data.type = this.type;
  6543. if ( this.name !== '' ) data.name = this.name;
  6544. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6545. if ( this.parameters !== undefined ) {
  6546. var parameters = this.parameters;
  6547. for ( var key in parameters ) {
  6548. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6549. }
  6550. return data;
  6551. }
  6552. data.data = { attributes: {} };
  6553. var index = this.index;
  6554. if ( index !== null ) {
  6555. data.data.index = {
  6556. type: index.array.constructor.name,
  6557. array: Array.prototype.slice.call( index.array )
  6558. };
  6559. }
  6560. var attributes = this.attributes;
  6561. for ( var key in attributes ) {
  6562. var attribute = attributes[ key ];
  6563. var attributeData = attribute.toJSON();
  6564. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6565. data.data.attributes[ key ] = attributeData;
  6566. }
  6567. var morphAttributes = {};
  6568. var hasMorphAttributes = false;
  6569. for ( var key in this.morphAttributes ) {
  6570. var attributeArray = this.morphAttributes[ key ];
  6571. var array = [];
  6572. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6573. var attribute = attributeArray[ i ];
  6574. var attributeData = attribute.toJSON();
  6575. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6576. array.push( attributeData );
  6577. }
  6578. if ( array.length > 0 ) {
  6579. morphAttributes[ key ] = array;
  6580. hasMorphAttributes = true;
  6581. }
  6582. }
  6583. if ( hasMorphAttributes ) {
  6584. data.data.morphAttributes = morphAttributes;
  6585. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6586. }
  6587. var groups = this.groups;
  6588. if ( groups.length > 0 ) {
  6589. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6590. }
  6591. var boundingSphere = this.boundingSphere;
  6592. if ( boundingSphere !== null ) {
  6593. data.data.boundingSphere = {
  6594. center: boundingSphere.center.toArray(),
  6595. radius: boundingSphere.radius
  6596. };
  6597. }
  6598. return data;
  6599. },
  6600. clone: function () {
  6601. /*
  6602. // Handle primitives
  6603. var parameters = this.parameters;
  6604. if ( parameters !== undefined ) {
  6605. var values = [];
  6606. for ( var key in parameters ) {
  6607. values.push( parameters[ key ] );
  6608. }
  6609. var geometry = Object.create( this.constructor.prototype );
  6610. this.constructor.apply( geometry, values );
  6611. return geometry;
  6612. }
  6613. return new this.constructor().copy( this );
  6614. */
  6615. return new BufferGeometry().copy( this );
  6616. },
  6617. copy: function ( source ) {
  6618. var name, i, l;
  6619. // reset
  6620. this.index = null;
  6621. this.attributes = {};
  6622. this.morphAttributes = {};
  6623. this.groups = [];
  6624. this.boundingBox = null;
  6625. this.boundingSphere = null;
  6626. // name
  6627. this.name = source.name;
  6628. // index
  6629. var index = source.index;
  6630. if ( index !== null ) {
  6631. this.setIndex( index.clone() );
  6632. }
  6633. // attributes
  6634. var attributes = source.attributes;
  6635. for ( name in attributes ) {
  6636. var attribute = attributes[ name ];
  6637. this.setAttribute( name, attribute.clone() );
  6638. }
  6639. // morph attributes
  6640. var morphAttributes = source.morphAttributes;
  6641. for ( name in morphAttributes ) {
  6642. var array = [];
  6643. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6644. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6645. array.push( morphAttribute[ i ].clone() );
  6646. }
  6647. this.morphAttributes[ name ] = array;
  6648. }
  6649. this.morphTargetsRelative = source.morphTargetsRelative;
  6650. // groups
  6651. var groups = source.groups;
  6652. for ( i = 0, l = groups.length; i < l; i ++ ) {
  6653. var group = groups[ i ];
  6654. this.addGroup( group.start, group.count, group.materialIndex );
  6655. }
  6656. // bounding box
  6657. var boundingBox = source.boundingBox;
  6658. if ( boundingBox !== null ) {
  6659. this.boundingBox = boundingBox.clone();
  6660. }
  6661. // bounding sphere
  6662. var boundingSphere = source.boundingSphere;
  6663. if ( boundingSphere !== null ) {
  6664. this.boundingSphere = boundingSphere.clone();
  6665. }
  6666. // draw range
  6667. this.drawRange.start = source.drawRange.start;
  6668. this.drawRange.count = source.drawRange.count;
  6669. // user data
  6670. this.userData = source.userData;
  6671. return this;
  6672. },
  6673. dispose: function () {
  6674. this.dispatchEvent( { type: 'dispose' } );
  6675. }
  6676. } );
  6677. /**
  6678. * @author mrdoob / http://mrdoob.com/
  6679. * @author alteredq / http://alteredqualia.com/
  6680. * @author mikael emtinger / http://gomo.se/
  6681. * @author jonobr1 / http://jonobr1.com/
  6682. */
  6683. var _inverseMatrix = new Matrix4();
  6684. var _ray = new Ray();
  6685. var _sphere = new Sphere();
  6686. var _vA = new Vector3();
  6687. var _vB = new Vector3();
  6688. var _vC = new Vector3();
  6689. var _tempA = new Vector3();
  6690. var _tempB = new Vector3();
  6691. var _tempC = new Vector3();
  6692. var _morphA = new Vector3();
  6693. var _morphB = new Vector3();
  6694. var _morphC = new Vector3();
  6695. var _uvA = new Vector2();
  6696. var _uvB = new Vector2();
  6697. var _uvC = new Vector2();
  6698. var _intersectionPoint = new Vector3();
  6699. var _intersectionPointWorld = new Vector3();
  6700. function Mesh( geometry, material ) {
  6701. Object3D.call( this );
  6702. this.type = 'Mesh';
  6703. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6704. this.material = material !== undefined ? material : new MeshBasicMaterial();
  6705. this.updateMorphTargets();
  6706. }
  6707. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6708. constructor: Mesh,
  6709. isMesh: true,
  6710. copy: function ( source ) {
  6711. Object3D.prototype.copy.call( this, source );
  6712. if ( source.morphTargetInfluences !== undefined ) {
  6713. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6714. }
  6715. if ( source.morphTargetDictionary !== undefined ) {
  6716. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6717. }
  6718. return this;
  6719. },
  6720. updateMorphTargets: function () {
  6721. var geometry = this.geometry;
  6722. var m, ml, name;
  6723. if ( geometry.isBufferGeometry ) {
  6724. var morphAttributes = geometry.morphAttributes;
  6725. var keys = Object.keys( morphAttributes );
  6726. if ( keys.length > 0 ) {
  6727. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6728. if ( morphAttribute !== undefined ) {
  6729. this.morphTargetInfluences = [];
  6730. this.morphTargetDictionary = {};
  6731. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6732. name = morphAttribute[ m ].name || String( m );
  6733. this.morphTargetInfluences.push( 0 );
  6734. this.morphTargetDictionary[ name ] = m;
  6735. }
  6736. }
  6737. }
  6738. } else {
  6739. var morphTargets = geometry.morphTargets;
  6740. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6741. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6742. }
  6743. }
  6744. },
  6745. raycast: function ( raycaster, intersects ) {
  6746. var geometry = this.geometry;
  6747. var material = this.material;
  6748. var matrixWorld = this.matrixWorld;
  6749. if ( material === undefined ) return;
  6750. // Checking boundingSphere distance to ray
  6751. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6752. _sphere.copy( geometry.boundingSphere );
  6753. _sphere.applyMatrix4( matrixWorld );
  6754. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  6755. //
  6756. _inverseMatrix.getInverse( matrixWorld );
  6757. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6758. // Check boundingBox before continuing
  6759. if ( geometry.boundingBox !== null ) {
  6760. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6761. }
  6762. var intersection;
  6763. if ( geometry.isBufferGeometry ) {
  6764. var a, b, c;
  6765. var index = geometry.index;
  6766. var position = geometry.attributes.position;
  6767. var morphPosition = geometry.morphAttributes.position;
  6768. var morphTargetsRelative = geometry.morphTargetsRelative;
  6769. var uv = geometry.attributes.uv;
  6770. var uv2 = geometry.attributes.uv2;
  6771. var groups = geometry.groups;
  6772. var drawRange = geometry.drawRange;
  6773. var i, j, il, jl;
  6774. var group, groupMaterial;
  6775. var start, end;
  6776. if ( index !== null ) {
  6777. // indexed buffer geometry
  6778. if ( Array.isArray( material ) ) {
  6779. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6780. group = groups[ i ];
  6781. groupMaterial = material[ group.materialIndex ];
  6782. start = Math.max( group.start, drawRange.start );
  6783. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6784. for ( j = start, jl = end; j < jl; j += 3 ) {
  6785. a = index.getX( j );
  6786. b = index.getX( j + 1 );
  6787. c = index.getX( j + 2 );
  6788. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6789. if ( intersection ) {
  6790. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6791. intersection.face.materialIndex = group.materialIndex;
  6792. intersects.push( intersection );
  6793. }
  6794. }
  6795. }
  6796. } else {
  6797. start = Math.max( 0, drawRange.start );
  6798. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6799. for ( i = start, il = end; i < il; i += 3 ) {
  6800. a = index.getX( i );
  6801. b = index.getX( i + 1 );
  6802. c = index.getX( i + 2 );
  6803. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6804. if ( intersection ) {
  6805. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6806. intersects.push( intersection );
  6807. }
  6808. }
  6809. }
  6810. } else if ( position !== undefined ) {
  6811. // non-indexed buffer geometry
  6812. if ( Array.isArray( material ) ) {
  6813. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6814. group = groups[ i ];
  6815. groupMaterial = material[ group.materialIndex ];
  6816. start = Math.max( group.start, drawRange.start );
  6817. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6818. for ( j = start, jl = end; j < jl; j += 3 ) {
  6819. a = j;
  6820. b = j + 1;
  6821. c = j + 2;
  6822. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6823. if ( intersection ) {
  6824. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6825. intersection.face.materialIndex = group.materialIndex;
  6826. intersects.push( intersection );
  6827. }
  6828. }
  6829. }
  6830. } else {
  6831. start = Math.max( 0, drawRange.start );
  6832. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6833. for ( i = start, il = end; i < il; i += 3 ) {
  6834. a = i;
  6835. b = i + 1;
  6836. c = i + 2;
  6837. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6838. if ( intersection ) {
  6839. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6840. intersects.push( intersection );
  6841. }
  6842. }
  6843. }
  6844. }
  6845. } else if ( geometry.isGeometry ) {
  6846. var fvA, fvB, fvC;
  6847. var isMultiMaterial = Array.isArray( material );
  6848. var vertices = geometry.vertices;
  6849. var faces = geometry.faces;
  6850. var uvs;
  6851. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6852. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6853. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6854. var face = faces[ f ];
  6855. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6856. if ( faceMaterial === undefined ) continue;
  6857. fvA = vertices[ face.a ];
  6858. fvB = vertices[ face.b ];
  6859. fvC = vertices[ face.c ];
  6860. intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
  6861. if ( intersection ) {
  6862. if ( uvs && uvs[ f ] ) {
  6863. var uvs_f = uvs[ f ];
  6864. _uvA.copy( uvs_f[ 0 ] );
  6865. _uvB.copy( uvs_f[ 1 ] );
  6866. _uvC.copy( uvs_f[ 2 ] );
  6867. intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
  6868. }
  6869. intersection.face = face;
  6870. intersection.faceIndex = f;
  6871. intersects.push( intersection );
  6872. }
  6873. }
  6874. }
  6875. },
  6876. clone: function () {
  6877. return new this.constructor( this.geometry, this.material ).copy( this );
  6878. }
  6879. } );
  6880. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6881. var intersect;
  6882. if ( material.side === BackSide ) {
  6883. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6884. } else {
  6885. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6886. }
  6887. if ( intersect === null ) return null;
  6888. _intersectionPointWorld.copy( point );
  6889. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6890. var distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6891. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6892. return {
  6893. distance: distance,
  6894. point: _intersectionPointWorld.clone(),
  6895. object: object
  6896. };
  6897. }
  6898. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6899. _vA.fromBufferAttribute( position, a );
  6900. _vB.fromBufferAttribute( position, b );
  6901. _vC.fromBufferAttribute( position, c );
  6902. var morphInfluences = object.morphTargetInfluences;
  6903. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6904. _morphA.set( 0, 0, 0 );
  6905. _morphB.set( 0, 0, 0 );
  6906. _morphC.set( 0, 0, 0 );
  6907. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6908. var influence = morphInfluences[ i ];
  6909. var morphAttribute = morphPosition[ i ];
  6910. if ( influence === 0 ) continue;
  6911. _tempA.fromBufferAttribute( morphAttribute, a );
  6912. _tempB.fromBufferAttribute( morphAttribute, b );
  6913. _tempC.fromBufferAttribute( morphAttribute, c );
  6914. if ( morphTargetsRelative ) {
  6915. _morphA.addScaledVector( _tempA, influence );
  6916. _morphB.addScaledVector( _tempB, influence );
  6917. _morphC.addScaledVector( _tempC, influence );
  6918. } else {
  6919. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6920. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6921. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6922. }
  6923. }
  6924. _vA.add( _morphA );
  6925. _vB.add( _morphB );
  6926. _vC.add( _morphC );
  6927. }
  6928. if ( object.isSkinnedMesh ) {
  6929. object.boneTransform( a, _vA );
  6930. object.boneTransform( b, _vB );
  6931. object.boneTransform( c, _vC );
  6932. }
  6933. var intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6934. if ( intersection ) {
  6935. if ( uv ) {
  6936. _uvA.fromBufferAttribute( uv, a );
  6937. _uvB.fromBufferAttribute( uv, b );
  6938. _uvC.fromBufferAttribute( uv, c );
  6939. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6940. }
  6941. if ( uv2 ) {
  6942. _uvA.fromBufferAttribute( uv2, a );
  6943. _uvB.fromBufferAttribute( uv2, b );
  6944. _uvC.fromBufferAttribute( uv2, c );
  6945. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6946. }
  6947. var face = new Face3( a, b, c );
  6948. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6949. intersection.face = face;
  6950. }
  6951. return intersection;
  6952. }
  6953. /**
  6954. * @author mrdoob / http://mrdoob.com/
  6955. * @author kile / http://kile.stravaganza.org/
  6956. * @author alteredq / http://alteredqualia.com/
  6957. * @author mikael emtinger / http://gomo.se/
  6958. * @author zz85 / http://www.lab4games.net/zz85/blog
  6959. * @author bhouston / http://clara.io
  6960. */
  6961. var _geometryId = 0; // Geometry uses even numbers as Id
  6962. var _m1$3 = new Matrix4();
  6963. var _obj$1 = new Object3D();
  6964. var _offset$1 = new Vector3();
  6965. function Geometry() {
  6966. Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
  6967. this.uuid = MathUtils.generateUUID();
  6968. this.name = '';
  6969. this.type = 'Geometry';
  6970. this.vertices = [];
  6971. this.colors = [];
  6972. this.faces = [];
  6973. this.faceVertexUvs = [[]];
  6974. this.morphTargets = [];
  6975. this.morphNormals = [];
  6976. this.skinWeights = [];
  6977. this.skinIndices = [];
  6978. this.lineDistances = [];
  6979. this.boundingBox = null;
  6980. this.boundingSphere = null;
  6981. // update flags
  6982. this.elementsNeedUpdate = false;
  6983. this.verticesNeedUpdate = false;
  6984. this.uvsNeedUpdate = false;
  6985. this.normalsNeedUpdate = false;
  6986. this.colorsNeedUpdate = false;
  6987. this.lineDistancesNeedUpdate = false;
  6988. this.groupsNeedUpdate = false;
  6989. }
  6990. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6991. constructor: Geometry,
  6992. isGeometry: true,
  6993. applyMatrix4: function ( matrix ) {
  6994. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6995. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6996. var vertex = this.vertices[ i ];
  6997. vertex.applyMatrix4( matrix );
  6998. }
  6999. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  7000. var face = this.faces[ i ];
  7001. face.normal.applyMatrix3( normalMatrix ).normalize();
  7002. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  7003. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  7004. }
  7005. }
  7006. if ( this.boundingBox !== null ) {
  7007. this.computeBoundingBox();
  7008. }
  7009. if ( this.boundingSphere !== null ) {
  7010. this.computeBoundingSphere();
  7011. }
  7012. this.verticesNeedUpdate = true;
  7013. this.normalsNeedUpdate = true;
  7014. return this;
  7015. },
  7016. rotateX: function ( angle ) {
  7017. // rotate geometry around world x-axis
  7018. _m1$3.makeRotationX( angle );
  7019. this.applyMatrix4( _m1$3 );
  7020. return this;
  7021. },
  7022. rotateY: function ( angle ) {
  7023. // rotate geometry around world y-axis
  7024. _m1$3.makeRotationY( angle );
  7025. this.applyMatrix4( _m1$3 );
  7026. return this;
  7027. },
  7028. rotateZ: function ( angle ) {
  7029. // rotate geometry around world z-axis
  7030. _m1$3.makeRotationZ( angle );
  7031. this.applyMatrix4( _m1$3 );
  7032. return this;
  7033. },
  7034. translate: function ( x, y, z ) {
  7035. // translate geometry
  7036. _m1$3.makeTranslation( x, y, z );
  7037. this.applyMatrix4( _m1$3 );
  7038. return this;
  7039. },
  7040. scale: function ( x, y, z ) {
  7041. // scale geometry
  7042. _m1$3.makeScale( x, y, z );
  7043. this.applyMatrix4( _m1$3 );
  7044. return this;
  7045. },
  7046. lookAt: function ( vector ) {
  7047. _obj$1.lookAt( vector );
  7048. _obj$1.updateMatrix();
  7049. this.applyMatrix4( _obj$1.matrix );
  7050. return this;
  7051. },
  7052. fromBufferGeometry: function ( geometry ) {
  7053. var scope = this;
  7054. var indices = geometry.index !== null ? geometry.index.array : undefined;
  7055. var attributes = geometry.attributes;
  7056. if ( attributes.position === undefined ) {
  7057. console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
  7058. return this;
  7059. }
  7060. var positions = attributes.position.array;
  7061. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  7062. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  7063. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  7064. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  7065. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  7066. for ( var i = 0; i < positions.length; i += 3 ) {
  7067. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  7068. if ( colors !== undefined ) {
  7069. scope.colors.push( new Color().fromArray( colors, i ) );
  7070. }
  7071. }
  7072. function addFace( a, b, c, materialIndex ) {
  7073. var vertexColors = ( colors === undefined ) ? [] : [
  7074. scope.colors[ a ].clone(),
  7075. scope.colors[ b ].clone(),
  7076. scope.colors[ c ].clone() ];
  7077. var vertexNormals = ( normals === undefined ) ? [] : [
  7078. new Vector3().fromArray( normals, a * 3 ),
  7079. new Vector3().fromArray( normals, b * 3 ),
  7080. new Vector3().fromArray( normals, c * 3 )
  7081. ];
  7082. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  7083. scope.faces.push( face );
  7084. if ( uvs !== undefined ) {
  7085. scope.faceVertexUvs[ 0 ].push( [
  7086. new Vector2().fromArray( uvs, a * 2 ),
  7087. new Vector2().fromArray( uvs, b * 2 ),
  7088. new Vector2().fromArray( uvs, c * 2 )
  7089. ] );
  7090. }
  7091. if ( uvs2 !== undefined ) {
  7092. scope.faceVertexUvs[ 1 ].push( [
  7093. new Vector2().fromArray( uvs2, a * 2 ),
  7094. new Vector2().fromArray( uvs2, b * 2 ),
  7095. new Vector2().fromArray( uvs2, c * 2 )
  7096. ] );
  7097. }
  7098. }
  7099. var groups = geometry.groups;
  7100. if ( groups.length > 0 ) {
  7101. for ( var i = 0; i < groups.length; i ++ ) {
  7102. var group = groups[ i ];
  7103. var start = group.start;
  7104. var count = group.count;
  7105. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  7106. if ( indices !== undefined ) {
  7107. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  7108. } else {
  7109. addFace( j, j + 1, j + 2, group.materialIndex );
  7110. }
  7111. }
  7112. }
  7113. } else {
  7114. if ( indices !== undefined ) {
  7115. for ( var i = 0; i < indices.length; i += 3 ) {
  7116. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  7117. }
  7118. } else {
  7119. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  7120. addFace( i, i + 1, i + 2 );
  7121. }
  7122. }
  7123. }
  7124. this.computeFaceNormals();
  7125. if ( geometry.boundingBox !== null ) {
  7126. this.boundingBox = geometry.boundingBox.clone();
  7127. }
  7128. if ( geometry.boundingSphere !== null ) {
  7129. this.boundingSphere = geometry.boundingSphere.clone();
  7130. }
  7131. return this;
  7132. },
  7133. center: function () {
  7134. this.computeBoundingBox();
  7135. this.boundingBox.getCenter( _offset$1 ).negate();
  7136. this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
  7137. return this;
  7138. },
  7139. normalize: function () {
  7140. this.computeBoundingSphere();
  7141. var center = this.boundingSphere.center;
  7142. var radius = this.boundingSphere.radius;
  7143. var s = radius === 0 ? 1 : 1.0 / radius;
  7144. var matrix = new Matrix4();
  7145. matrix.set(
  7146. s, 0, 0, - s * center.x,
  7147. 0, s, 0, - s * center.y,
  7148. 0, 0, s, - s * center.z,
  7149. 0, 0, 0, 1
  7150. );
  7151. this.applyMatrix4( matrix );
  7152. return this;
  7153. },
  7154. computeFaceNormals: function () {
  7155. var cb = new Vector3(), ab = new Vector3();
  7156. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7157. var face = this.faces[ f ];
  7158. var vA = this.vertices[ face.a ];
  7159. var vB = this.vertices[ face.b ];
  7160. var vC = this.vertices[ face.c ];
  7161. cb.subVectors( vC, vB );
  7162. ab.subVectors( vA, vB );
  7163. cb.cross( ab );
  7164. cb.normalize();
  7165. face.normal.copy( cb );
  7166. }
  7167. },
  7168. computeVertexNormals: function ( areaWeighted ) {
  7169. if ( areaWeighted === undefined ) areaWeighted = true;
  7170. var v, vl, f, fl, face, vertices;
  7171. vertices = new Array( this.vertices.length );
  7172. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7173. vertices[ v ] = new Vector3();
  7174. }
  7175. if ( areaWeighted ) {
  7176. // vertex normals weighted by triangle areas
  7177. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7178. var vA, vB, vC;
  7179. var cb = new Vector3(), ab = new Vector3();
  7180. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7181. face = this.faces[ f ];
  7182. vA = this.vertices[ face.a ];
  7183. vB = this.vertices[ face.b ];
  7184. vC = this.vertices[ face.c ];
  7185. cb.subVectors( vC, vB );
  7186. ab.subVectors( vA, vB );
  7187. cb.cross( ab );
  7188. vertices[ face.a ].add( cb );
  7189. vertices[ face.b ].add( cb );
  7190. vertices[ face.c ].add( cb );
  7191. }
  7192. } else {
  7193. this.computeFaceNormals();
  7194. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7195. face = this.faces[ f ];
  7196. vertices[ face.a ].add( face.normal );
  7197. vertices[ face.b ].add( face.normal );
  7198. vertices[ face.c ].add( face.normal );
  7199. }
  7200. }
  7201. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7202. vertices[ v ].normalize();
  7203. }
  7204. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7205. face = this.faces[ f ];
  7206. var vertexNormals = face.vertexNormals;
  7207. if ( vertexNormals.length === 3 ) {
  7208. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7209. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7210. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7211. } else {
  7212. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7213. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7214. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7215. }
  7216. }
  7217. if ( this.faces.length > 0 ) {
  7218. this.normalsNeedUpdate = true;
  7219. }
  7220. },
  7221. computeFlatVertexNormals: function () {
  7222. var f, fl, face;
  7223. this.computeFaceNormals();
  7224. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7225. face = this.faces[ f ];
  7226. var vertexNormals = face.vertexNormals;
  7227. if ( vertexNormals.length === 3 ) {
  7228. vertexNormals[ 0 ].copy( face.normal );
  7229. vertexNormals[ 1 ].copy( face.normal );
  7230. vertexNormals[ 2 ].copy( face.normal );
  7231. } else {
  7232. vertexNormals[ 0 ] = face.normal.clone();
  7233. vertexNormals[ 1 ] = face.normal.clone();
  7234. vertexNormals[ 2 ] = face.normal.clone();
  7235. }
  7236. }
  7237. if ( this.faces.length > 0 ) {
  7238. this.normalsNeedUpdate = true;
  7239. }
  7240. },
  7241. computeMorphNormals: function () {
  7242. var i, il, f, fl, face;
  7243. // save original normals
  7244. // - create temp variables on first access
  7245. // otherwise just copy (for faster repeated calls)
  7246. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7247. face = this.faces[ f ];
  7248. if ( ! face.__originalFaceNormal ) {
  7249. face.__originalFaceNormal = face.normal.clone();
  7250. } else {
  7251. face.__originalFaceNormal.copy( face.normal );
  7252. }
  7253. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7254. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7255. if ( ! face.__originalVertexNormals[ i ] ) {
  7256. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7257. } else {
  7258. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7259. }
  7260. }
  7261. }
  7262. // use temp geometry to compute face and vertex normals for each morph
  7263. var tmpGeo = new Geometry();
  7264. tmpGeo.faces = this.faces;
  7265. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7266. // create on first access
  7267. if ( ! this.morphNormals[ i ] ) {
  7268. this.morphNormals[ i ] = {};
  7269. this.morphNormals[ i ].faceNormals = [];
  7270. this.morphNormals[ i ].vertexNormals = [];
  7271. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7272. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7273. var faceNormal, vertexNormals;
  7274. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7275. faceNormal = new Vector3();
  7276. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7277. dstNormalsFace.push( faceNormal );
  7278. dstNormalsVertex.push( vertexNormals );
  7279. }
  7280. }
  7281. var morphNormals = this.morphNormals[ i ];
  7282. // set vertices to morph target
  7283. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7284. // compute morph normals
  7285. tmpGeo.computeFaceNormals();
  7286. tmpGeo.computeVertexNormals();
  7287. // store morph normals
  7288. var faceNormal, vertexNormals;
  7289. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7290. face = this.faces[ f ];
  7291. faceNormal = morphNormals.faceNormals[ f ];
  7292. vertexNormals = morphNormals.vertexNormals[ f ];
  7293. faceNormal.copy( face.normal );
  7294. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7295. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7296. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7297. }
  7298. }
  7299. // restore original normals
  7300. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7301. face = this.faces[ f ];
  7302. face.normal = face.__originalFaceNormal;
  7303. face.vertexNormals = face.__originalVertexNormals;
  7304. }
  7305. },
  7306. computeBoundingBox: function () {
  7307. if ( this.boundingBox === null ) {
  7308. this.boundingBox = new Box3();
  7309. }
  7310. this.boundingBox.setFromPoints( this.vertices );
  7311. },
  7312. computeBoundingSphere: function () {
  7313. if ( this.boundingSphere === null ) {
  7314. this.boundingSphere = new Sphere();
  7315. }
  7316. this.boundingSphere.setFromPoints( this.vertices );
  7317. },
  7318. merge: function ( geometry, matrix, materialIndexOffset ) {
  7319. if ( ! ( geometry && geometry.isGeometry ) ) {
  7320. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7321. return;
  7322. }
  7323. var normalMatrix,
  7324. vertexOffset = this.vertices.length,
  7325. vertices1 = this.vertices,
  7326. vertices2 = geometry.vertices,
  7327. faces1 = this.faces,
  7328. faces2 = geometry.faces,
  7329. colors1 = this.colors,
  7330. colors2 = geometry.colors;
  7331. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7332. if ( matrix !== undefined ) {
  7333. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7334. }
  7335. // vertices
  7336. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7337. var vertex = vertices2[ i ];
  7338. var vertexCopy = vertex.clone();
  7339. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7340. vertices1.push( vertexCopy );
  7341. }
  7342. // colors
  7343. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7344. colors1.push( colors2[ i ].clone() );
  7345. }
  7346. // faces
  7347. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7348. var face = faces2[ i ], faceCopy, normal, color,
  7349. faceVertexNormals = face.vertexNormals,
  7350. faceVertexColors = face.vertexColors;
  7351. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7352. faceCopy.normal.copy( face.normal );
  7353. if ( normalMatrix !== undefined ) {
  7354. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7355. }
  7356. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7357. normal = faceVertexNormals[ j ].clone();
  7358. if ( normalMatrix !== undefined ) {
  7359. normal.applyMatrix3( normalMatrix ).normalize();
  7360. }
  7361. faceCopy.vertexNormals.push( normal );
  7362. }
  7363. faceCopy.color.copy( face.color );
  7364. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7365. color = faceVertexColors[ j ];
  7366. faceCopy.vertexColors.push( color.clone() );
  7367. }
  7368. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7369. faces1.push( faceCopy );
  7370. }
  7371. // uvs
  7372. for ( var i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7373. var faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7374. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7375. for ( var j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7376. var uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7377. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7378. uvsCopy.push( uvs2[ k ].clone() );
  7379. }
  7380. this.faceVertexUvs[ i ].push( uvsCopy );
  7381. }
  7382. }
  7383. },
  7384. mergeMesh: function ( mesh ) {
  7385. if ( ! ( mesh && mesh.isMesh ) ) {
  7386. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7387. return;
  7388. }
  7389. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7390. this.merge( mesh.geometry, mesh.matrix );
  7391. },
  7392. /*
  7393. * Checks for duplicate vertices with hashmap.
  7394. * Duplicated vertices are removed
  7395. * and faces' vertices are updated.
  7396. */
  7397. mergeVertices: function () {
  7398. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7399. var unique = [], changes = [];
  7400. var v, key;
  7401. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7402. var precision = Math.pow( 10, precisionPoints );
  7403. var i, il, face;
  7404. var indices, j, jl;
  7405. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7406. v = this.vertices[ i ];
  7407. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7408. if ( verticesMap[ key ] === undefined ) {
  7409. verticesMap[ key ] = i;
  7410. unique.push( this.vertices[ i ] );
  7411. changes[ i ] = unique.length - 1;
  7412. } else {
  7413. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7414. changes[ i ] = changes[ verticesMap[ key ] ];
  7415. }
  7416. }
  7417. // if faces are completely degenerate after merging vertices, we
  7418. // have to remove them from the geometry.
  7419. var faceIndicesToRemove = [];
  7420. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7421. face = this.faces[ i ];
  7422. face.a = changes[ face.a ];
  7423. face.b = changes[ face.b ];
  7424. face.c = changes[ face.c ];
  7425. indices = [ face.a, face.b, face.c ];
  7426. // if any duplicate vertices are found in a Face3
  7427. // we have to remove the face as nothing can be saved
  7428. for ( var n = 0; n < 3; n ++ ) {
  7429. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7430. faceIndicesToRemove.push( i );
  7431. break;
  7432. }
  7433. }
  7434. }
  7435. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7436. var idx = faceIndicesToRemove[ i ];
  7437. this.faces.splice( idx, 1 );
  7438. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7439. this.faceVertexUvs[ j ].splice( idx, 1 );
  7440. }
  7441. }
  7442. // Use unique set of vertices
  7443. var diff = this.vertices.length - unique.length;
  7444. this.vertices = unique;
  7445. return diff;
  7446. },
  7447. setFromPoints: function ( points ) {
  7448. this.vertices = [];
  7449. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7450. var point = points[ i ];
  7451. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7452. }
  7453. return this;
  7454. },
  7455. sortFacesByMaterialIndex: function () {
  7456. var faces = this.faces;
  7457. var length = faces.length;
  7458. // tag faces
  7459. for ( var i = 0; i < length; i ++ ) {
  7460. faces[ i ]._id = i;
  7461. }
  7462. // sort faces
  7463. function materialIndexSort( a, b ) {
  7464. return a.materialIndex - b.materialIndex;
  7465. }
  7466. faces.sort( materialIndexSort );
  7467. // sort uvs
  7468. var uvs1 = this.faceVertexUvs[ 0 ];
  7469. var uvs2 = this.faceVertexUvs[ 1 ];
  7470. var newUvs1, newUvs2;
  7471. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7472. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7473. for ( var i = 0; i < length; i ++ ) {
  7474. var id = faces[ i ]._id;
  7475. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7476. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7477. }
  7478. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7479. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7480. },
  7481. toJSON: function () {
  7482. var data = {
  7483. metadata: {
  7484. version: 4.5,
  7485. type: 'Geometry',
  7486. generator: 'Geometry.toJSON'
  7487. }
  7488. };
  7489. // standard Geometry serialization
  7490. data.uuid = this.uuid;
  7491. data.type = this.type;
  7492. if ( this.name !== '' ) data.name = this.name;
  7493. if ( this.parameters !== undefined ) {
  7494. var parameters = this.parameters;
  7495. for ( var key in parameters ) {
  7496. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7497. }
  7498. return data;
  7499. }
  7500. var vertices = [];
  7501. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7502. var vertex = this.vertices[ i ];
  7503. vertices.push( vertex.x, vertex.y, vertex.z );
  7504. }
  7505. var faces = [];
  7506. var normals = [];
  7507. var normalsHash = {};
  7508. var colors = [];
  7509. var colorsHash = {};
  7510. var uvs = [];
  7511. var uvsHash = {};
  7512. for ( var i = 0; i < this.faces.length; i ++ ) {
  7513. var face = this.faces[ i ];
  7514. var hasMaterial = true;
  7515. var hasFaceUv = false; // deprecated
  7516. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7517. var hasFaceNormal = face.normal.length() > 0;
  7518. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7519. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7520. var hasFaceVertexColor = face.vertexColors.length > 0;
  7521. var faceType = 0;
  7522. faceType = setBit( faceType, 0, 0 ); // isQuad
  7523. faceType = setBit( faceType, 1, hasMaterial );
  7524. faceType = setBit( faceType, 2, hasFaceUv );
  7525. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7526. faceType = setBit( faceType, 4, hasFaceNormal );
  7527. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7528. faceType = setBit( faceType, 6, hasFaceColor );
  7529. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7530. faces.push( faceType );
  7531. faces.push( face.a, face.b, face.c );
  7532. faces.push( face.materialIndex );
  7533. if ( hasFaceVertexUv ) {
  7534. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7535. faces.push(
  7536. getUvIndex( faceVertexUvs[ 0 ] ),
  7537. getUvIndex( faceVertexUvs[ 1 ] ),
  7538. getUvIndex( faceVertexUvs[ 2 ] )
  7539. );
  7540. }
  7541. if ( hasFaceNormal ) {
  7542. faces.push( getNormalIndex( face.normal ) );
  7543. }
  7544. if ( hasFaceVertexNormal ) {
  7545. var vertexNormals = face.vertexNormals;
  7546. faces.push(
  7547. getNormalIndex( vertexNormals[ 0 ] ),
  7548. getNormalIndex( vertexNormals[ 1 ] ),
  7549. getNormalIndex( vertexNormals[ 2 ] )
  7550. );
  7551. }
  7552. if ( hasFaceColor ) {
  7553. faces.push( getColorIndex( face.color ) );
  7554. }
  7555. if ( hasFaceVertexColor ) {
  7556. var vertexColors = face.vertexColors;
  7557. faces.push(
  7558. getColorIndex( vertexColors[ 0 ] ),
  7559. getColorIndex( vertexColors[ 1 ] ),
  7560. getColorIndex( vertexColors[ 2 ] )
  7561. );
  7562. }
  7563. }
  7564. function setBit( value, position, enabled ) {
  7565. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7566. }
  7567. function getNormalIndex( normal ) {
  7568. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7569. if ( normalsHash[ hash ] !== undefined ) {
  7570. return normalsHash[ hash ];
  7571. }
  7572. normalsHash[ hash ] = normals.length / 3;
  7573. normals.push( normal.x, normal.y, normal.z );
  7574. return normalsHash[ hash ];
  7575. }
  7576. function getColorIndex( color ) {
  7577. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7578. if ( colorsHash[ hash ] !== undefined ) {
  7579. return colorsHash[ hash ];
  7580. }
  7581. colorsHash[ hash ] = colors.length;
  7582. colors.push( color.getHex() );
  7583. return colorsHash[ hash ];
  7584. }
  7585. function getUvIndex( uv ) {
  7586. var hash = uv.x.toString() + uv.y.toString();
  7587. if ( uvsHash[ hash ] !== undefined ) {
  7588. return uvsHash[ hash ];
  7589. }
  7590. uvsHash[ hash ] = uvs.length / 2;
  7591. uvs.push( uv.x, uv.y );
  7592. return uvsHash[ hash ];
  7593. }
  7594. data.data = {};
  7595. data.data.vertices = vertices;
  7596. data.data.normals = normals;
  7597. if ( colors.length > 0 ) data.data.colors = colors;
  7598. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7599. data.data.faces = faces;
  7600. return data;
  7601. },
  7602. clone: function () {
  7603. /*
  7604. // Handle primitives
  7605. var parameters = this.parameters;
  7606. if ( parameters !== undefined ) {
  7607. var values = [];
  7608. for ( var key in parameters ) {
  7609. values.push( parameters[ key ] );
  7610. }
  7611. var geometry = Object.create( this.constructor.prototype );
  7612. this.constructor.apply( geometry, values );
  7613. return geometry;
  7614. }
  7615. return new this.constructor().copy( this );
  7616. */
  7617. return new Geometry().copy( this );
  7618. },
  7619. copy: function ( source ) {
  7620. var i, il, j, jl, k, kl;
  7621. // reset
  7622. this.vertices = [];
  7623. this.colors = [];
  7624. this.faces = [];
  7625. this.faceVertexUvs = [[]];
  7626. this.morphTargets = [];
  7627. this.morphNormals = [];
  7628. this.skinWeights = [];
  7629. this.skinIndices = [];
  7630. this.lineDistances = [];
  7631. this.boundingBox = null;
  7632. this.boundingSphere = null;
  7633. // name
  7634. this.name = source.name;
  7635. // vertices
  7636. var vertices = source.vertices;
  7637. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7638. this.vertices.push( vertices[ i ].clone() );
  7639. }
  7640. // colors
  7641. var colors = source.colors;
  7642. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7643. this.colors.push( colors[ i ].clone() );
  7644. }
  7645. // faces
  7646. var faces = source.faces;
  7647. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7648. this.faces.push( faces[ i ].clone() );
  7649. }
  7650. // face vertex uvs
  7651. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7652. var faceVertexUvs = source.faceVertexUvs[ i ];
  7653. if ( this.faceVertexUvs[ i ] === undefined ) {
  7654. this.faceVertexUvs[ i ] = [];
  7655. }
  7656. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7657. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7658. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7659. var uv = uvs[ k ];
  7660. uvsCopy.push( uv.clone() );
  7661. }
  7662. this.faceVertexUvs[ i ].push( uvsCopy );
  7663. }
  7664. }
  7665. // morph targets
  7666. var morphTargets = source.morphTargets;
  7667. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7668. var morphTarget = {};
  7669. morphTarget.name = morphTargets[ i ].name;
  7670. // vertices
  7671. if ( morphTargets[ i ].vertices !== undefined ) {
  7672. morphTarget.vertices = [];
  7673. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7674. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7675. }
  7676. }
  7677. // normals
  7678. if ( morphTargets[ i ].normals !== undefined ) {
  7679. morphTarget.normals = [];
  7680. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7681. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7682. }
  7683. }
  7684. this.morphTargets.push( morphTarget );
  7685. }
  7686. // morph normals
  7687. var morphNormals = source.morphNormals;
  7688. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7689. var morphNormal = {};
  7690. // vertex normals
  7691. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7692. morphNormal.vertexNormals = [];
  7693. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7694. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7695. var destVertexNormal = {};
  7696. destVertexNormal.a = srcVertexNormal.a.clone();
  7697. destVertexNormal.b = srcVertexNormal.b.clone();
  7698. destVertexNormal.c = srcVertexNormal.c.clone();
  7699. morphNormal.vertexNormals.push( destVertexNormal );
  7700. }
  7701. }
  7702. // face normals
  7703. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7704. morphNormal.faceNormals = [];
  7705. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7706. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7707. }
  7708. }
  7709. this.morphNormals.push( morphNormal );
  7710. }
  7711. // skin weights
  7712. var skinWeights = source.skinWeights;
  7713. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7714. this.skinWeights.push( skinWeights[ i ].clone() );
  7715. }
  7716. // skin indices
  7717. var skinIndices = source.skinIndices;
  7718. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7719. this.skinIndices.push( skinIndices[ i ].clone() );
  7720. }
  7721. // line distances
  7722. var lineDistances = source.lineDistances;
  7723. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7724. this.lineDistances.push( lineDistances[ i ] );
  7725. }
  7726. // bounding box
  7727. var boundingBox = source.boundingBox;
  7728. if ( boundingBox !== null ) {
  7729. this.boundingBox = boundingBox.clone();
  7730. }
  7731. // bounding sphere
  7732. var boundingSphere = source.boundingSphere;
  7733. if ( boundingSphere !== null ) {
  7734. this.boundingSphere = boundingSphere.clone();
  7735. }
  7736. // update flags
  7737. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7738. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7739. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7740. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7741. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7742. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7743. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7744. return this;
  7745. },
  7746. dispose: function () {
  7747. this.dispatchEvent( { type: 'dispose' } );
  7748. }
  7749. } );
  7750. /**
  7751. * @author mrdoob / http://mrdoob.com/
  7752. * @author Mugen87 / https://github.com/Mugen87
  7753. */
  7754. // BoxGeometry
  7755. class BoxGeometry extends Geometry {
  7756. constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7757. super();
  7758. this.type = 'BoxGeometry';
  7759. this.parameters = {
  7760. width: width,
  7761. height: height,
  7762. depth: depth,
  7763. widthSegments: widthSegments,
  7764. heightSegments: heightSegments,
  7765. depthSegments: depthSegments
  7766. };
  7767. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7768. this.mergeVertices();
  7769. }
  7770. }
  7771. // BoxBufferGeometry
  7772. class BoxBufferGeometry extends BufferGeometry {
  7773. constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7774. super();
  7775. this.type = 'BoxBufferGeometry';
  7776. this.parameters = {
  7777. width: width,
  7778. height: height,
  7779. depth: depth,
  7780. widthSegments: widthSegments,
  7781. heightSegments: heightSegments,
  7782. depthSegments: depthSegments
  7783. };
  7784. const scope = this;
  7785. width = width || 1;
  7786. height = height || 1;
  7787. depth = depth || 1;
  7788. // segments
  7789. widthSegments = Math.floor( widthSegments ) || 1;
  7790. heightSegments = Math.floor( heightSegments ) || 1;
  7791. depthSegments = Math.floor( depthSegments ) || 1;
  7792. // buffers
  7793. const indices = [];
  7794. const vertices = [];
  7795. const normals = [];
  7796. const uvs = [];
  7797. // helper variables
  7798. let numberOfVertices = 0;
  7799. let groupStart = 0;
  7800. // build each side of the box geometry
  7801. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7802. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7803. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7804. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7805. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7806. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7807. // build geometry
  7808. this.setIndex( indices );
  7809. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7810. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7811. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7812. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7813. const segmentWidth = width / gridX;
  7814. const segmentHeight = height / gridY;
  7815. const widthHalf = width / 2;
  7816. const heightHalf = height / 2;
  7817. const depthHalf = depth / 2;
  7818. const gridX1 = gridX + 1;
  7819. const gridY1 = gridY + 1;
  7820. let vertexCounter = 0;
  7821. let groupCount = 0;
  7822. const vector = new Vector3();
  7823. // generate vertices, normals and uvs
  7824. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7825. const y = iy * segmentHeight - heightHalf;
  7826. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7827. const x = ix * segmentWidth - widthHalf;
  7828. // set values to correct vector component
  7829. vector[ u ] = x * udir;
  7830. vector[ v ] = y * vdir;
  7831. vector[ w ] = depthHalf;
  7832. // now apply vector to vertex buffer
  7833. vertices.push( vector.x, vector.y, vector.z );
  7834. // set values to correct vector component
  7835. vector[ u ] = 0;
  7836. vector[ v ] = 0;
  7837. vector[ w ] = depth > 0 ? 1 : - 1;
  7838. // now apply vector to normal buffer
  7839. normals.push( vector.x, vector.y, vector.z );
  7840. // uvs
  7841. uvs.push( ix / gridX );
  7842. uvs.push( 1 - ( iy / gridY ) );
  7843. // counters
  7844. vertexCounter += 1;
  7845. }
  7846. }
  7847. // indices
  7848. // 1. you need three indices to draw a single face
  7849. // 2. a single segment consists of two faces
  7850. // 3. so we need to generate six (2*3) indices per segment
  7851. for ( let iy = 0; iy < gridY; iy ++ ) {
  7852. for ( let ix = 0; ix < gridX; ix ++ ) {
  7853. const a = numberOfVertices + ix + gridX1 * iy;
  7854. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7855. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7856. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7857. // faces
  7858. indices.push( a, b, d );
  7859. indices.push( b, c, d );
  7860. // increase counter
  7861. groupCount += 6;
  7862. }
  7863. }
  7864. // add a group to the geometry. this will ensure multi material support
  7865. scope.addGroup( groupStart, groupCount, materialIndex );
  7866. // calculate new start value for groups
  7867. groupStart += groupCount;
  7868. // update total number of vertices
  7869. numberOfVertices += vertexCounter;
  7870. }
  7871. }
  7872. }
  7873. /**
  7874. * Uniform Utilities
  7875. */
  7876. function cloneUniforms( src ) {
  7877. var dst = {};
  7878. for ( var u in src ) {
  7879. dst[ u ] = {};
  7880. for ( var p in src[ u ] ) {
  7881. var property = src[ u ][ p ];
  7882. if ( property && ( property.isColor ||
  7883. property.isMatrix3 || property.isMatrix4 ||
  7884. property.isVector2 || property.isVector3 || property.isVector4 ||
  7885. property.isTexture ) ) {
  7886. dst[ u ][ p ] = property.clone();
  7887. } else if ( Array.isArray( property ) ) {
  7888. dst[ u ][ p ] = property.slice();
  7889. } else {
  7890. dst[ u ][ p ] = property;
  7891. }
  7892. }
  7893. }
  7894. return dst;
  7895. }
  7896. function mergeUniforms( uniforms ) {
  7897. var merged = {};
  7898. for ( var u = 0; u < uniforms.length; u ++ ) {
  7899. var tmp = cloneUniforms( uniforms[ u ] );
  7900. for ( var p in tmp ) {
  7901. merged[ p ] = tmp[ p ];
  7902. }
  7903. }
  7904. return merged;
  7905. }
  7906. // Legacy
  7907. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7908. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7909. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7910. /**
  7911. * @author alteredq / http://alteredqualia.com/
  7912. *
  7913. * parameters = {
  7914. * defines: { "label" : "value" },
  7915. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7916. *
  7917. * fragmentShader: <string>,
  7918. * vertexShader: <string>,
  7919. *
  7920. * wireframe: <boolean>,
  7921. * wireframeLinewidth: <float>,
  7922. *
  7923. * lights: <bool>,
  7924. *
  7925. * skinning: <bool>,
  7926. * morphTargets: <bool>,
  7927. * morphNormals: <bool>
  7928. * }
  7929. */
  7930. function ShaderMaterial( parameters ) {
  7931. Material.call( this );
  7932. this.type = 'ShaderMaterial';
  7933. this.defines = {};
  7934. this.uniforms = {};
  7935. this.vertexShader = default_vertex;
  7936. this.fragmentShader = default_fragment;
  7937. this.linewidth = 1;
  7938. this.wireframe = false;
  7939. this.wireframeLinewidth = 1;
  7940. this.fog = false; // set to use scene fog
  7941. this.lights = false; // set to use scene lights
  7942. this.clipping = false; // set to use user-defined clipping planes
  7943. this.skinning = false; // set to use skinning attribute streams
  7944. this.morphTargets = false; // set to use morph targets
  7945. this.morphNormals = false; // set to use morph normals
  7946. this.extensions = {
  7947. derivatives: false, // set to use derivatives
  7948. fragDepth: false, // set to use fragment depth values
  7949. drawBuffers: false, // set to use draw buffers
  7950. shaderTextureLOD: false // set to use shader texture LOD
  7951. };
  7952. // When rendered geometry doesn't include these attributes but the material does,
  7953. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7954. this.defaultAttributeValues = {
  7955. 'color': [ 1, 1, 1 ],
  7956. 'uv': [ 0, 0 ],
  7957. 'uv2': [ 0, 0 ]
  7958. };
  7959. this.index0AttributeName = undefined;
  7960. this.uniformsNeedUpdate = false;
  7961. if ( parameters !== undefined ) {
  7962. if ( parameters.attributes !== undefined ) {
  7963. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7964. }
  7965. this.setValues( parameters );
  7966. }
  7967. }
  7968. ShaderMaterial.prototype = Object.create( Material.prototype );
  7969. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7970. ShaderMaterial.prototype.isShaderMaterial = true;
  7971. ShaderMaterial.prototype.copy = function ( source ) {
  7972. Material.prototype.copy.call( this, source );
  7973. this.fragmentShader = source.fragmentShader;
  7974. this.vertexShader = source.vertexShader;
  7975. this.uniforms = cloneUniforms( source.uniforms );
  7976. this.defines = Object.assign( {}, source.defines );
  7977. this.wireframe = source.wireframe;
  7978. this.wireframeLinewidth = source.wireframeLinewidth;
  7979. this.lights = source.lights;
  7980. this.clipping = source.clipping;
  7981. this.skinning = source.skinning;
  7982. this.morphTargets = source.morphTargets;
  7983. this.morphNormals = source.morphNormals;
  7984. this.extensions = Object.assign( {}, source.extensions );
  7985. return this;
  7986. };
  7987. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7988. var data = Material.prototype.toJSON.call( this, meta );
  7989. data.uniforms = {};
  7990. for ( var name in this.uniforms ) {
  7991. var uniform = this.uniforms[ name ];
  7992. var value = uniform.value;
  7993. if ( value && value.isTexture ) {
  7994. data.uniforms[ name ] = {
  7995. type: 't',
  7996. value: value.toJSON( meta ).uuid
  7997. };
  7998. } else if ( value && value.isColor ) {
  7999. data.uniforms[ name ] = {
  8000. type: 'c',
  8001. value: value.getHex()
  8002. };
  8003. } else if ( value && value.isVector2 ) {
  8004. data.uniforms[ name ] = {
  8005. type: 'v2',
  8006. value: value.toArray()
  8007. };
  8008. } else if ( value && value.isVector3 ) {
  8009. data.uniforms[ name ] = {
  8010. type: 'v3',
  8011. value: value.toArray()
  8012. };
  8013. } else if ( value && value.isVector4 ) {
  8014. data.uniforms[ name ] = {
  8015. type: 'v4',
  8016. value: value.toArray()
  8017. };
  8018. } else if ( value && value.isMatrix3 ) {
  8019. data.uniforms[ name ] = {
  8020. type: 'm3',
  8021. value: value.toArray()
  8022. };
  8023. } else if ( value && value.isMatrix4 ) {
  8024. data.uniforms[ name ] = {
  8025. type: 'm4',
  8026. value: value.toArray()
  8027. };
  8028. } else {
  8029. data.uniforms[ name ] = {
  8030. value: value
  8031. };
  8032. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8033. }
  8034. }
  8035. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  8036. data.vertexShader = this.vertexShader;
  8037. data.fragmentShader = this.fragmentShader;
  8038. var extensions = {};
  8039. for ( var key in this.extensions ) {
  8040. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  8041. }
  8042. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  8043. return data;
  8044. };
  8045. /**
  8046. * @author mrdoob / http://mrdoob.com/
  8047. * @author mikael emtinger / http://gomo.se/
  8048. * @author WestLangley / http://github.com/WestLangley
  8049. */
  8050. function Camera() {
  8051. Object3D.call( this );
  8052. this.type = 'Camera';
  8053. this.matrixWorldInverse = new Matrix4();
  8054. this.projectionMatrix = new Matrix4();
  8055. this.projectionMatrixInverse = new Matrix4();
  8056. }
  8057. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8058. constructor: Camera,
  8059. isCamera: true,
  8060. copy: function ( source, recursive ) {
  8061. Object3D.prototype.copy.call( this, source, recursive );
  8062. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  8063. this.projectionMatrix.copy( source.projectionMatrix );
  8064. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  8065. return this;
  8066. },
  8067. getWorldDirection: function ( target ) {
  8068. if ( target === undefined ) {
  8069. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  8070. target = new Vector3();
  8071. }
  8072. this.updateMatrixWorld( true );
  8073. var e = this.matrixWorld.elements;
  8074. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  8075. },
  8076. updateMatrixWorld: function ( force ) {
  8077. Object3D.prototype.updateMatrixWorld.call( this, force );
  8078. this.matrixWorldInverse.getInverse( this.matrixWorld );
  8079. },
  8080. updateWorldMatrix: function ( updateParents, updateChildren ) {
  8081. Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren );
  8082. this.matrixWorldInverse.getInverse( this.matrixWorld );
  8083. },
  8084. clone: function () {
  8085. return new this.constructor().copy( this );
  8086. }
  8087. } );
  8088. /**
  8089. * @author mrdoob / http://mrdoob.com/
  8090. * @author greggman / http://games.greggman.com/
  8091. * @author zz85 / http://www.lab4games.net/zz85/blog
  8092. * @author tschw
  8093. */
  8094. function PerspectiveCamera( fov, aspect, near, far ) {
  8095. Camera.call( this );
  8096. this.type = 'PerspectiveCamera';
  8097. this.fov = fov !== undefined ? fov : 50;
  8098. this.zoom = 1;
  8099. this.near = near !== undefined ? near : 0.1;
  8100. this.far = far !== undefined ? far : 2000;
  8101. this.focus = 10;
  8102. this.aspect = aspect !== undefined ? aspect : 1;
  8103. this.view = null;
  8104. this.filmGauge = 35; // width of the film (default in millimeters)
  8105. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8106. this.updateProjectionMatrix();
  8107. }
  8108. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  8109. constructor: PerspectiveCamera,
  8110. isPerspectiveCamera: true,
  8111. copy: function ( source, recursive ) {
  8112. Camera.prototype.copy.call( this, source, recursive );
  8113. this.fov = source.fov;
  8114. this.zoom = source.zoom;
  8115. this.near = source.near;
  8116. this.far = source.far;
  8117. this.focus = source.focus;
  8118. this.aspect = source.aspect;
  8119. this.view = source.view === null ? null : Object.assign( {}, source.view );
  8120. this.filmGauge = source.filmGauge;
  8121. this.filmOffset = source.filmOffset;
  8122. return this;
  8123. },
  8124. /**
  8125. * Sets the FOV by focal length in respect to the current .filmGauge.
  8126. *
  8127. * The default film gauge is 35, so that the focal length can be specified for
  8128. * a 35mm (full frame) camera.
  8129. *
  8130. * Values for focal length and film gauge must have the same unit.
  8131. */
  8132. setFocalLength: function ( focalLength ) {
  8133. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  8134. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8135. this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
  8136. this.updateProjectionMatrix();
  8137. },
  8138. /**
  8139. * Calculates the focal length from the current .fov and .filmGauge.
  8140. */
  8141. getFocalLength: function () {
  8142. var vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
  8143. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8144. },
  8145. getEffectiveFOV: function () {
  8146. return MathUtils.RAD2DEG * 2 * Math.atan(
  8147. Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  8148. },
  8149. getFilmWidth: function () {
  8150. // film not completely covered in portrait format (aspect < 1)
  8151. return this.filmGauge * Math.min( this.aspect, 1 );
  8152. },
  8153. getFilmHeight: function () {
  8154. // film not completely covered in landscape format (aspect > 1)
  8155. return this.filmGauge / Math.max( this.aspect, 1 );
  8156. },
  8157. /**
  8158. * Sets an offset in a larger frustum. This is useful for multi-window or
  8159. * multi-monitor/multi-machine setups.
  8160. *
  8161. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8162. * the monitors are in grid like this
  8163. *
  8164. * +---+---+---+
  8165. * | A | B | C |
  8166. * +---+---+---+
  8167. * | D | E | F |
  8168. * +---+---+---+
  8169. *
  8170. * then for each monitor you would call it like this
  8171. *
  8172. * var w = 1920;
  8173. * var h = 1080;
  8174. * var fullWidth = w * 3;
  8175. * var fullHeight = h * 2;
  8176. *
  8177. * --A--
  8178. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8179. * --B--
  8180. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8181. * --C--
  8182. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8183. * --D--
  8184. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8185. * --E--
  8186. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8187. * --F--
  8188. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8189. *
  8190. * Note there is no reason monitors have to be the same size or in a grid.
  8191. */
  8192. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  8193. this.aspect = fullWidth / fullHeight;
  8194. if ( this.view === null ) {
  8195. this.view = {
  8196. enabled: true,
  8197. fullWidth: 1,
  8198. fullHeight: 1,
  8199. offsetX: 0,
  8200. offsetY: 0,
  8201. width: 1,
  8202. height: 1
  8203. };
  8204. }
  8205. this.view.enabled = true;
  8206. this.view.fullWidth = fullWidth;
  8207. this.view.fullHeight = fullHeight;
  8208. this.view.offsetX = x;
  8209. this.view.offsetY = y;
  8210. this.view.width = width;
  8211. this.view.height = height;
  8212. this.updateProjectionMatrix();
  8213. },
  8214. clearViewOffset: function () {
  8215. if ( this.view !== null ) {
  8216. this.view.enabled = false;
  8217. }
  8218. this.updateProjectionMatrix();
  8219. },
  8220. updateProjectionMatrix: function () {
  8221. var near = this.near,
  8222. top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8223. height = 2 * top,
  8224. width = this.aspect * height,
  8225. left = - 0.5 * width,
  8226. view = this.view;
  8227. if ( this.view !== null && this.view.enabled ) {
  8228. var fullWidth = view.fullWidth,
  8229. fullHeight = view.fullHeight;
  8230. left += view.offsetX * width / fullWidth;
  8231. top -= view.offsetY * height / fullHeight;
  8232. width *= view.width / fullWidth;
  8233. height *= view.height / fullHeight;
  8234. }
  8235. var skew = this.filmOffset;
  8236. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8237. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8238. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8239. },
  8240. toJSON: function ( meta ) {
  8241. var data = Object3D.prototype.toJSON.call( this, meta );
  8242. data.object.fov = this.fov;
  8243. data.object.zoom = this.zoom;
  8244. data.object.near = this.near;
  8245. data.object.far = this.far;
  8246. data.object.focus = this.focus;
  8247. data.object.aspect = this.aspect;
  8248. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8249. data.object.filmGauge = this.filmGauge;
  8250. data.object.filmOffset = this.filmOffset;
  8251. return data;
  8252. }
  8253. } );
  8254. /**
  8255. * Camera for rendering cube maps
  8256. * - renders scene into axis-aligned cube
  8257. *
  8258. * @author alteredq / http://alteredqualia.com/
  8259. */
  8260. var fov = 90, aspect = 1;
  8261. function CubeCamera( near, far, renderTarget ) {
  8262. Object3D.call( this );
  8263. this.type = 'CubeCamera';
  8264. if ( renderTarget.isWebGLCubeRenderTarget !== true ) {
  8265. console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' );
  8266. return;
  8267. }
  8268. this.renderTarget = renderTarget;
  8269. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8270. cameraPX.layers = this.layers;
  8271. cameraPX.up.set( 0, - 1, 0 );
  8272. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8273. this.add( cameraPX );
  8274. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8275. cameraNX.layers = this.layers;
  8276. cameraNX.up.set( 0, - 1, 0 );
  8277. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8278. this.add( cameraNX );
  8279. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8280. cameraPY.layers = this.layers;
  8281. cameraPY.up.set( 0, 0, 1 );
  8282. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8283. this.add( cameraPY );
  8284. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8285. cameraNY.layers = this.layers;
  8286. cameraNY.up.set( 0, 0, - 1 );
  8287. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8288. this.add( cameraNY );
  8289. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8290. cameraPZ.layers = this.layers;
  8291. cameraPZ.up.set( 0, - 1, 0 );
  8292. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8293. this.add( cameraPZ );
  8294. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8295. cameraNZ.layers = this.layers;
  8296. cameraNZ.up.set( 0, - 1, 0 );
  8297. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8298. this.add( cameraNZ );
  8299. this.update = function ( renderer, scene ) {
  8300. if ( this.parent === null ) this.updateMatrixWorld();
  8301. var currentXrEnabled = renderer.xr.enabled;
  8302. var currentRenderTarget = renderer.getRenderTarget();
  8303. renderer.xr.enabled = false;
  8304. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8305. renderTarget.texture.generateMipmaps = false;
  8306. renderer.setRenderTarget( renderTarget, 0 );
  8307. renderer.render( scene, cameraPX );
  8308. renderer.setRenderTarget( renderTarget, 1 );
  8309. renderer.render( scene, cameraNX );
  8310. renderer.setRenderTarget( renderTarget, 2 );
  8311. renderer.render( scene, cameraPY );
  8312. renderer.setRenderTarget( renderTarget, 3 );
  8313. renderer.render( scene, cameraNY );
  8314. renderer.setRenderTarget( renderTarget, 4 );
  8315. renderer.render( scene, cameraPZ );
  8316. renderTarget.texture.generateMipmaps = generateMipmaps;
  8317. renderer.setRenderTarget( renderTarget, 5 );
  8318. renderer.render( scene, cameraNZ );
  8319. renderer.setRenderTarget( currentRenderTarget );
  8320. renderer.xr.enabled = currentXrEnabled;
  8321. };
  8322. this.clear = function ( renderer, color, depth, stencil ) {
  8323. var currentRenderTarget = renderer.getRenderTarget();
  8324. for ( var i = 0; i < 6; i ++ ) {
  8325. renderer.setRenderTarget( renderTarget, i );
  8326. renderer.clear( color, depth, stencil );
  8327. }
  8328. renderer.setRenderTarget( currentRenderTarget );
  8329. };
  8330. }
  8331. CubeCamera.prototype = Object.create( Object3D.prototype );
  8332. CubeCamera.prototype.constructor = CubeCamera;
  8333. /**
  8334. * @author alteredq / http://alteredqualia.com
  8335. * @author WestLangley / http://github.com/WestLangley
  8336. */
  8337. function WebGLCubeRenderTarget( size, options, dummy ) {
  8338. if ( Number.isInteger( options ) ) {
  8339. console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
  8340. options = dummy;
  8341. }
  8342. WebGLRenderTarget.call( this, size, size, options );
  8343. }
  8344. WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype );
  8345. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  8346. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  8347. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8348. this.texture.type = texture.type;
  8349. this.texture.format = texture.format;
  8350. this.texture.encoding = texture.encoding;
  8351. var scene = new Scene();
  8352. var shader = {
  8353. uniforms: {
  8354. tEquirect: { value: null },
  8355. },
  8356. vertexShader: [
  8357. "varying vec3 vWorldDirection;",
  8358. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8359. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8360. "}",
  8361. "void main() {",
  8362. " vWorldDirection = transformDirection( position, modelMatrix );",
  8363. " #include <begin_vertex>",
  8364. " #include <project_vertex>",
  8365. "}"
  8366. ].join( '\n' ),
  8367. fragmentShader: [
  8368. "uniform sampler2D tEquirect;",
  8369. "varying vec3 vWorldDirection;",
  8370. "#include <common>",
  8371. "void main() {",
  8372. " vec3 direction = normalize( vWorldDirection );",
  8373. " vec2 sampleUV = equirectUv( direction );",
  8374. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8375. "}"
  8376. ].join( '\n' ),
  8377. };
  8378. var material = new ShaderMaterial( {
  8379. type: 'CubemapFromEquirect',
  8380. uniforms: cloneUniforms( shader.uniforms ),
  8381. vertexShader: shader.vertexShader,
  8382. fragmentShader: shader.fragmentShader,
  8383. side: BackSide,
  8384. blending: NoBlending
  8385. } );
  8386. material.uniforms.tEquirect.value = texture;
  8387. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8388. scene.add( mesh );
  8389. var camera = new CubeCamera( 1, 10, this );
  8390. camera.update( renderer, scene );
  8391. mesh.geometry.dispose();
  8392. mesh.material.dispose();
  8393. return this;
  8394. };
  8395. /**
  8396. * @author alteredq / http://alteredqualia.com/
  8397. */
  8398. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8399. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8400. this.image = { data: data || null, width: width || 1, height: height || 1 };
  8401. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8402. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8403. this.generateMipmaps = false;
  8404. this.flipY = false;
  8405. this.unpackAlignment = 1;
  8406. this.needsUpdate = true;
  8407. }
  8408. DataTexture.prototype = Object.create( Texture.prototype );
  8409. DataTexture.prototype.constructor = DataTexture;
  8410. DataTexture.prototype.isDataTexture = true;
  8411. /**
  8412. * @author mrdoob / http://mrdoob.com/
  8413. * @author alteredq / http://alteredqualia.com/
  8414. * @author bhouston / http://clara.io
  8415. */
  8416. var _sphere$1 = new Sphere();
  8417. var _vector$5 = new Vector3();
  8418. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8419. this.planes = [
  8420. ( p0 !== undefined ) ? p0 : new Plane(),
  8421. ( p1 !== undefined ) ? p1 : new Plane(),
  8422. ( p2 !== undefined ) ? p2 : new Plane(),
  8423. ( p3 !== undefined ) ? p3 : new Plane(),
  8424. ( p4 !== undefined ) ? p4 : new Plane(),
  8425. ( p5 !== undefined ) ? p5 : new Plane()
  8426. ];
  8427. }
  8428. Object.assign( Frustum.prototype, {
  8429. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8430. var planes = this.planes;
  8431. planes[ 0 ].copy( p0 );
  8432. planes[ 1 ].copy( p1 );
  8433. planes[ 2 ].copy( p2 );
  8434. planes[ 3 ].copy( p3 );
  8435. planes[ 4 ].copy( p4 );
  8436. planes[ 5 ].copy( p5 );
  8437. return this;
  8438. },
  8439. clone: function () {
  8440. return new this.constructor().copy( this );
  8441. },
  8442. copy: function ( frustum ) {
  8443. var planes = this.planes;
  8444. for ( var i = 0; i < 6; i ++ ) {
  8445. planes[ i ].copy( frustum.planes[ i ] );
  8446. }
  8447. return this;
  8448. },
  8449. setFromProjectionMatrix: function ( m ) {
  8450. var planes = this.planes;
  8451. var me = m.elements;
  8452. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8453. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8454. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8455. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8456. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8457. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8458. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8459. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8460. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8461. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8462. return this;
  8463. },
  8464. intersectsObject: function ( object ) {
  8465. var geometry = object.geometry;
  8466. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8467. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  8468. return this.intersectsSphere( _sphere$1 );
  8469. },
  8470. intersectsSprite: function ( sprite ) {
  8471. _sphere$1.center.set( 0, 0, 0 );
  8472. _sphere$1.radius = 0.7071067811865476;
  8473. _sphere$1.applyMatrix4( sprite.matrixWorld );
  8474. return this.intersectsSphere( _sphere$1 );
  8475. },
  8476. intersectsSphere: function ( sphere ) {
  8477. var planes = this.planes;
  8478. var center = sphere.center;
  8479. var negRadius = - sphere.radius;
  8480. for ( var i = 0; i < 6; i ++ ) {
  8481. var distance = planes[ i ].distanceToPoint( center );
  8482. if ( distance < negRadius ) {
  8483. return false;
  8484. }
  8485. }
  8486. return true;
  8487. },
  8488. intersectsBox: function ( box ) {
  8489. var planes = this.planes;
  8490. for ( var i = 0; i < 6; i ++ ) {
  8491. var plane = planes[ i ];
  8492. // corner at max distance
  8493. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8494. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8495. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8496. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  8497. return false;
  8498. }
  8499. }
  8500. return true;
  8501. },
  8502. containsPoint: function ( point ) {
  8503. var planes = this.planes;
  8504. for ( var i = 0; i < 6; i ++ ) {
  8505. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8506. return false;
  8507. }
  8508. }
  8509. return true;
  8510. }
  8511. } );
  8512. /**
  8513. * Uniforms library for shared webgl shaders
  8514. */
  8515. var UniformsLib = {
  8516. common: {
  8517. diffuse: { value: new Color( 0xeeeeee ) },
  8518. opacity: { value: 1.0 },
  8519. map: { value: null },
  8520. uvTransform: { value: new Matrix3() },
  8521. uv2Transform: { value: new Matrix3() },
  8522. alphaMap: { value: null },
  8523. },
  8524. specularmap: {
  8525. specularMap: { value: null },
  8526. },
  8527. envmap: {
  8528. envMap: { value: null },
  8529. flipEnvMap: { value: - 1 },
  8530. reflectivity: { value: 1.0 },
  8531. refractionRatio: { value: 0.98 },
  8532. maxMipLevel: { value: 0 }
  8533. },
  8534. aomap: {
  8535. aoMap: { value: null },
  8536. aoMapIntensity: { value: 1 }
  8537. },
  8538. lightmap: {
  8539. lightMap: { value: null },
  8540. lightMapIntensity: { value: 1 }
  8541. },
  8542. emissivemap: {
  8543. emissiveMap: { value: null }
  8544. },
  8545. bumpmap: {
  8546. bumpMap: { value: null },
  8547. bumpScale: { value: 1 }
  8548. },
  8549. normalmap: {
  8550. normalMap: { value: null },
  8551. normalScale: { value: new Vector2( 1, 1 ) }
  8552. },
  8553. displacementmap: {
  8554. displacementMap: { value: null },
  8555. displacementScale: { value: 1 },
  8556. displacementBias: { value: 0 }
  8557. },
  8558. roughnessmap: {
  8559. roughnessMap: { value: null }
  8560. },
  8561. metalnessmap: {
  8562. metalnessMap: { value: null }
  8563. },
  8564. gradientmap: {
  8565. gradientMap: { value: null }
  8566. },
  8567. fog: {
  8568. fogDensity: { value: 0.00025 },
  8569. fogNear: { value: 1 },
  8570. fogFar: { value: 2000 },
  8571. fogColor: { value: new Color( 0xffffff ) }
  8572. },
  8573. lights: {
  8574. ambientLightColor: { value: [] },
  8575. lightProbe: { value: [] },
  8576. directionalLights: { value: [], properties: {
  8577. direction: {},
  8578. color: {}
  8579. } },
  8580. directionalLightShadows: { value: [], properties: {
  8581. shadowBias: {},
  8582. shadowRadius: {},
  8583. shadowMapSize: {}
  8584. } },
  8585. directionalShadowMap: { value: [] },
  8586. directionalShadowMatrix: { value: [] },
  8587. spotLights: { value: [], properties: {
  8588. color: {},
  8589. position: {},
  8590. direction: {},
  8591. distance: {},
  8592. coneCos: {},
  8593. penumbraCos: {},
  8594. decay: {}
  8595. } },
  8596. spotLightShadows: { value: [], properties: {
  8597. shadowBias: {},
  8598. shadowRadius: {},
  8599. shadowMapSize: {}
  8600. } },
  8601. spotShadowMap: { value: [] },
  8602. spotShadowMatrix: { value: [] },
  8603. pointLights: { value: [], properties: {
  8604. color: {},
  8605. position: {},
  8606. decay: {},
  8607. distance: {}
  8608. } },
  8609. pointLightShadows: { value: [], properties: {
  8610. shadowBias: {},
  8611. shadowRadius: {},
  8612. shadowMapSize: {},
  8613. shadowCameraNear: {},
  8614. shadowCameraFar: {}
  8615. } },
  8616. pointShadowMap: { value: [] },
  8617. pointShadowMatrix: { value: [] },
  8618. hemisphereLights: { value: [], properties: {
  8619. direction: {},
  8620. skyColor: {},
  8621. groundColor: {}
  8622. } },
  8623. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8624. rectAreaLights: { value: [], properties: {
  8625. color: {},
  8626. position: {},
  8627. width: {},
  8628. height: {}
  8629. } }
  8630. },
  8631. points: {
  8632. diffuse: { value: new Color( 0xeeeeee ) },
  8633. opacity: { value: 1.0 },
  8634. size: { value: 1.0 },
  8635. scale: { value: 1.0 },
  8636. map: { value: null },
  8637. alphaMap: { value: null },
  8638. uvTransform: { value: new Matrix3() }
  8639. },
  8640. sprite: {
  8641. diffuse: { value: new Color( 0xeeeeee ) },
  8642. opacity: { value: 1.0 },
  8643. center: { value: new Vector2( 0.5, 0.5 ) },
  8644. rotation: { value: 0.0 },
  8645. map: { value: null },
  8646. alphaMap: { value: null },
  8647. uvTransform: { value: new Matrix3() }
  8648. }
  8649. };
  8650. /**
  8651. * @author mrdoob / http://mrdoob.com/
  8652. */
  8653. function WebGLAnimation() {
  8654. var context = null;
  8655. var isAnimating = false;
  8656. var animationLoop = null;
  8657. function onAnimationFrame( time, frame ) {
  8658. if ( isAnimating === false ) return;
  8659. animationLoop( time, frame );
  8660. context.requestAnimationFrame( onAnimationFrame );
  8661. }
  8662. return {
  8663. start: function () {
  8664. if ( isAnimating === true ) return;
  8665. if ( animationLoop === null ) return;
  8666. context.requestAnimationFrame( onAnimationFrame );
  8667. isAnimating = true;
  8668. },
  8669. stop: function () {
  8670. isAnimating = false;
  8671. },
  8672. setAnimationLoop: function ( callback ) {
  8673. animationLoop = callback;
  8674. },
  8675. setContext: function ( value ) {
  8676. context = value;
  8677. }
  8678. };
  8679. }
  8680. /**
  8681. * @author mrdoob / http://mrdoob.com/
  8682. */
  8683. function WebGLAttributes( gl, capabilities ) {
  8684. var isWebGL2 = capabilities.isWebGL2;
  8685. var buffers = new WeakMap();
  8686. function createBuffer( attribute, bufferType ) {
  8687. var array = attribute.array;
  8688. var usage = attribute.usage;
  8689. var buffer = gl.createBuffer();
  8690. gl.bindBuffer( bufferType, buffer );
  8691. gl.bufferData( bufferType, array, usage );
  8692. attribute.onUploadCallback();
  8693. var type = 5126;
  8694. if ( array instanceof Float32Array ) {
  8695. type = 5126;
  8696. } else if ( array instanceof Float64Array ) {
  8697. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  8698. } else if ( array instanceof Uint16Array ) {
  8699. type = 5123;
  8700. } else if ( array instanceof Int16Array ) {
  8701. type = 5122;
  8702. } else if ( array instanceof Uint32Array ) {
  8703. type = 5125;
  8704. } else if ( array instanceof Int32Array ) {
  8705. type = 5124;
  8706. } else if ( array instanceof Int8Array ) {
  8707. type = 5120;
  8708. } else if ( array instanceof Uint8Array ) {
  8709. type = 5121;
  8710. }
  8711. return {
  8712. buffer: buffer,
  8713. type: type,
  8714. bytesPerElement: array.BYTES_PER_ELEMENT,
  8715. version: attribute.version
  8716. };
  8717. }
  8718. function updateBuffer( buffer, attribute, bufferType ) {
  8719. var array = attribute.array;
  8720. var updateRange = attribute.updateRange;
  8721. gl.bindBuffer( bufferType, buffer );
  8722. if ( updateRange.count === - 1 ) {
  8723. // Not using update ranges
  8724. gl.bufferSubData( bufferType, 0, array );
  8725. } else {
  8726. if ( isWebGL2 ) {
  8727. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  8728. array, updateRange.offset, updateRange.count );
  8729. } else {
  8730. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  8731. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  8732. }
  8733. updateRange.count = - 1; // reset range
  8734. }
  8735. }
  8736. //
  8737. function get( attribute ) {
  8738. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  8739. return buffers.get( attribute );
  8740. }
  8741. function remove( attribute ) {
  8742. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  8743. var data = buffers.get( attribute );
  8744. if ( data ) {
  8745. gl.deleteBuffer( data.buffer );
  8746. buffers.delete( attribute );
  8747. }
  8748. }
  8749. function update( attribute, bufferType ) {
  8750. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  8751. var data = buffers.get( attribute );
  8752. if ( data === undefined ) {
  8753. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  8754. } else if ( data.version < attribute.version ) {
  8755. updateBuffer( data.buffer, attribute, bufferType );
  8756. data.version = attribute.version;
  8757. }
  8758. }
  8759. return {
  8760. get: get,
  8761. remove: remove,
  8762. update: update
  8763. };
  8764. }
  8765. /**
  8766. * @author mrdoob / http://mrdoob.com/
  8767. * @author Mugen87 / https://github.com/Mugen87
  8768. */
  8769. // PlaneGeometry
  8770. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  8771. Geometry.call( this );
  8772. this.type = 'PlaneGeometry';
  8773. this.parameters = {
  8774. width: width,
  8775. height: height,
  8776. widthSegments: widthSegments,
  8777. heightSegments: heightSegments
  8778. };
  8779. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  8780. this.mergeVertices();
  8781. }
  8782. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  8783. PlaneGeometry.prototype.constructor = PlaneGeometry;
  8784. // PlaneBufferGeometry
  8785. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  8786. BufferGeometry.call( this );
  8787. this.type = 'PlaneBufferGeometry';
  8788. this.parameters = {
  8789. width: width,
  8790. height: height,
  8791. widthSegments: widthSegments,
  8792. heightSegments: heightSegments
  8793. };
  8794. width = width || 1;
  8795. height = height || 1;
  8796. var width_half = width / 2;
  8797. var height_half = height / 2;
  8798. var gridX = Math.floor( widthSegments ) || 1;
  8799. var gridY = Math.floor( heightSegments ) || 1;
  8800. var gridX1 = gridX + 1;
  8801. var gridY1 = gridY + 1;
  8802. var segment_width = width / gridX;
  8803. var segment_height = height / gridY;
  8804. var ix, iy;
  8805. // buffers
  8806. var indices = [];
  8807. var vertices = [];
  8808. var normals = [];
  8809. var uvs = [];
  8810. // generate vertices, normals and uvs
  8811. for ( iy = 0; iy < gridY1; iy ++ ) {
  8812. var y = iy * segment_height - height_half;
  8813. for ( ix = 0; ix < gridX1; ix ++ ) {
  8814. var x = ix * segment_width - width_half;
  8815. vertices.push( x, - y, 0 );
  8816. normals.push( 0, 0, 1 );
  8817. uvs.push( ix / gridX );
  8818. uvs.push( 1 - ( iy / gridY ) );
  8819. }
  8820. }
  8821. // indices
  8822. for ( iy = 0; iy < gridY; iy ++ ) {
  8823. for ( ix = 0; ix < gridX; ix ++ ) {
  8824. var a = ix + gridX1 * iy;
  8825. var b = ix + gridX1 * ( iy + 1 );
  8826. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  8827. var d = ( ix + 1 ) + gridX1 * iy;
  8828. // faces
  8829. indices.push( a, b, d );
  8830. indices.push( b, c, d );
  8831. }
  8832. }
  8833. // build geometry
  8834. this.setIndex( indices );
  8835. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  8836. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  8837. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  8838. }
  8839. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  8840. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  8841. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8842. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8843. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8844. 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";
  8845. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8846. var begin_vertex = "vec3 transformed = vec3( position );";
  8847. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8848. 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";
  8849. 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";
  8850. 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";
  8851. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8852. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8853. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8854. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8855. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8856. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8857. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8858. var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\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}";
  8859. 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";
  8860. 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";
  8861. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8862. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8863. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8864. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8865. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8866. 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}";
  8867. 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#elif defined( ENVMAP_TYPE_SPHERE )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\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";
  8868. 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";
  8869. 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";
  8870. 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";
  8871. 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";
  8872. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8873. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8874. 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";
  8875. 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";
  8876. 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}";
  8877. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8878. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8879. 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";
  8880. 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\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\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\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\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\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\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\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\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\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";
  8881. 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#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, 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";
  8882. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8883. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\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\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\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)";
  8884. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8885. 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)";
  8886. 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";
  8887. 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}";
  8888. 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";
  8889. 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";
  8890. 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";
  8891. 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";
  8892. 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";
  8893. 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";
  8894. 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";
  8895. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8896. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8897. 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";
  8898. 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";
  8899. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8900. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8901. 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";
  8902. 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";
  8903. 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";
  8904. 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;";
  8905. 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";
  8906. 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";
  8907. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8908. 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";
  8909. 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";
  8910. 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}";
  8911. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8912. 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;";
  8913. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8914. 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";
  8915. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8916. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8917. 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#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#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#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";
  8918. 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#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#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#endif\n#endif";
  8919. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\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\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\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\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\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\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";
  8920. 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}";
  8921. 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";
  8922. 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";
  8923. 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";
  8924. 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";
  8925. 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";
  8926. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8927. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8928. var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\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}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\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 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
  8929. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8930. 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";
  8931. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8932. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8933. 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";
  8934. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8935. 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";
  8936. 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}";
  8937. 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}";
  8938. 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}";
  8939. 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}";
  8940. 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}";
  8941. 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}";
  8942. 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}";
  8943. 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}";
  8944. 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}";
  8945. 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}";
  8946. 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}";
  8947. 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}";
  8948. 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}";
  8949. 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}";
  8950. 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}";
  8951. 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}";
  8952. 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}";
  8953. 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}";
  8954. var meshtoon_frag = "#define TOON\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 <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 <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_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 + reflectedLight.directSpecular + reflectedLight.indirectSpecular + 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}";
  8955. 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}";
  8956. 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}";
  8957. 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}";
  8958. 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}";
  8959. 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}";
  8960. 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}";
  8961. 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}";
  8962. 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}";
  8963. 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}";
  8964. 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}";
  8965. var shadow_vert = "#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 <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8966. 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}";
  8967. 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}";
  8968. var ShaderChunk = {
  8969. alphamap_fragment: alphamap_fragment,
  8970. alphamap_pars_fragment: alphamap_pars_fragment,
  8971. alphatest_fragment: alphatest_fragment,
  8972. aomap_fragment: aomap_fragment,
  8973. aomap_pars_fragment: aomap_pars_fragment,
  8974. begin_vertex: begin_vertex,
  8975. beginnormal_vertex: beginnormal_vertex,
  8976. bsdfs: bsdfs,
  8977. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8978. clipping_planes_fragment: clipping_planes_fragment,
  8979. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8980. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8981. clipping_planes_vertex: clipping_planes_vertex,
  8982. color_fragment: color_fragment,
  8983. color_pars_fragment: color_pars_fragment,
  8984. color_pars_vertex: color_pars_vertex,
  8985. color_vertex: color_vertex,
  8986. common: common,
  8987. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8988. defaultnormal_vertex: defaultnormal_vertex,
  8989. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8990. displacementmap_vertex: displacementmap_vertex,
  8991. emissivemap_fragment: emissivemap_fragment,
  8992. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8993. encodings_fragment: encodings_fragment,
  8994. encodings_pars_fragment: encodings_pars_fragment,
  8995. envmap_fragment: envmap_fragment,
  8996. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8997. envmap_pars_fragment: envmap_pars_fragment,
  8998. envmap_pars_vertex: envmap_pars_vertex,
  8999. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  9000. envmap_vertex: envmap_vertex,
  9001. fog_vertex: fog_vertex,
  9002. fog_pars_vertex: fog_pars_vertex,
  9003. fog_fragment: fog_fragment,
  9004. fog_pars_fragment: fog_pars_fragment,
  9005. gradientmap_pars_fragment: gradientmap_pars_fragment,
  9006. lightmap_fragment: lightmap_fragment,
  9007. lightmap_pars_fragment: lightmap_pars_fragment,
  9008. lights_lambert_vertex: lights_lambert_vertex,
  9009. lights_pars_begin: lights_pars_begin,
  9010. lights_toon_fragment: lights_toon_fragment,
  9011. lights_toon_pars_fragment: lights_toon_pars_fragment,
  9012. lights_phong_fragment: lights_phong_fragment,
  9013. lights_phong_pars_fragment: lights_phong_pars_fragment,
  9014. lights_physical_fragment: lights_physical_fragment,
  9015. lights_physical_pars_fragment: lights_physical_pars_fragment,
  9016. lights_fragment_begin: lights_fragment_begin,
  9017. lights_fragment_maps: lights_fragment_maps,
  9018. lights_fragment_end: lights_fragment_end,
  9019. logdepthbuf_fragment: logdepthbuf_fragment,
  9020. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9021. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9022. logdepthbuf_vertex: logdepthbuf_vertex,
  9023. map_fragment: map_fragment,
  9024. map_pars_fragment: map_pars_fragment,
  9025. map_particle_fragment: map_particle_fragment,
  9026. map_particle_pars_fragment: map_particle_pars_fragment,
  9027. metalnessmap_fragment: metalnessmap_fragment,
  9028. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9029. morphnormal_vertex: morphnormal_vertex,
  9030. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9031. morphtarget_vertex: morphtarget_vertex,
  9032. normal_fragment_begin: normal_fragment_begin,
  9033. normal_fragment_maps: normal_fragment_maps,
  9034. normalmap_pars_fragment: normalmap_pars_fragment,
  9035. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9036. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9037. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9038. packing: packing,
  9039. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9040. project_vertex: project_vertex,
  9041. dithering_fragment: dithering_fragment,
  9042. dithering_pars_fragment: dithering_pars_fragment,
  9043. roughnessmap_fragment: roughnessmap_fragment,
  9044. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9045. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9046. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9047. shadowmap_vertex: shadowmap_vertex,
  9048. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9049. skinbase_vertex: skinbase_vertex,
  9050. skinning_pars_vertex: skinning_pars_vertex,
  9051. skinning_vertex: skinning_vertex,
  9052. skinnormal_vertex: skinnormal_vertex,
  9053. specularmap_fragment: specularmap_fragment,
  9054. specularmap_pars_fragment: specularmap_pars_fragment,
  9055. tonemapping_fragment: tonemapping_fragment,
  9056. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9057. uv_pars_fragment: uv_pars_fragment,
  9058. uv_pars_vertex: uv_pars_vertex,
  9059. uv_vertex: uv_vertex,
  9060. uv2_pars_fragment: uv2_pars_fragment,
  9061. uv2_pars_vertex: uv2_pars_vertex,
  9062. uv2_vertex: uv2_vertex,
  9063. worldpos_vertex: worldpos_vertex,
  9064. background_frag: background_frag,
  9065. background_vert: background_vert,
  9066. cube_frag: cube_frag,
  9067. cube_vert: cube_vert,
  9068. depth_frag: depth_frag,
  9069. depth_vert: depth_vert,
  9070. distanceRGBA_frag: distanceRGBA_frag,
  9071. distanceRGBA_vert: distanceRGBA_vert,
  9072. equirect_frag: equirect_frag,
  9073. equirect_vert: equirect_vert,
  9074. linedashed_frag: linedashed_frag,
  9075. linedashed_vert: linedashed_vert,
  9076. meshbasic_frag: meshbasic_frag,
  9077. meshbasic_vert: meshbasic_vert,
  9078. meshlambert_frag: meshlambert_frag,
  9079. meshlambert_vert: meshlambert_vert,
  9080. meshmatcap_frag: meshmatcap_frag,
  9081. meshmatcap_vert: meshmatcap_vert,
  9082. meshtoon_frag: meshtoon_frag,
  9083. meshtoon_vert: meshtoon_vert,
  9084. meshphong_frag: meshphong_frag,
  9085. meshphong_vert: meshphong_vert,
  9086. meshphysical_frag: meshphysical_frag,
  9087. meshphysical_vert: meshphysical_vert,
  9088. normal_frag: normal_frag,
  9089. normal_vert: normal_vert,
  9090. points_frag: points_frag,
  9091. points_vert: points_vert,
  9092. shadow_frag: shadow_frag,
  9093. shadow_vert: shadow_vert,
  9094. sprite_frag: sprite_frag,
  9095. sprite_vert: sprite_vert
  9096. };
  9097. /**
  9098. * @author alteredq / http://alteredqualia.com/
  9099. * @author mrdoob / http://mrdoob.com/
  9100. * @author mikael emtinger / http://gomo.se/
  9101. */
  9102. var ShaderLib = {
  9103. basic: {
  9104. uniforms: mergeUniforms( [
  9105. UniformsLib.common,
  9106. UniformsLib.specularmap,
  9107. UniformsLib.envmap,
  9108. UniformsLib.aomap,
  9109. UniformsLib.lightmap,
  9110. UniformsLib.fog
  9111. ] ),
  9112. vertexShader: ShaderChunk.meshbasic_vert,
  9113. fragmentShader: ShaderChunk.meshbasic_frag
  9114. },
  9115. lambert: {
  9116. uniforms: mergeUniforms( [
  9117. UniformsLib.common,
  9118. UniformsLib.specularmap,
  9119. UniformsLib.envmap,
  9120. UniformsLib.aomap,
  9121. UniformsLib.lightmap,
  9122. UniformsLib.emissivemap,
  9123. UniformsLib.fog,
  9124. UniformsLib.lights,
  9125. {
  9126. emissive: { value: new Color( 0x000000 ) }
  9127. }
  9128. ] ),
  9129. vertexShader: ShaderChunk.meshlambert_vert,
  9130. fragmentShader: ShaderChunk.meshlambert_frag
  9131. },
  9132. phong: {
  9133. uniforms: mergeUniforms( [
  9134. UniformsLib.common,
  9135. UniformsLib.specularmap,
  9136. UniformsLib.envmap,
  9137. UniformsLib.aomap,
  9138. UniformsLib.lightmap,
  9139. UniformsLib.emissivemap,
  9140. UniformsLib.bumpmap,
  9141. UniformsLib.normalmap,
  9142. UniformsLib.displacementmap,
  9143. UniformsLib.fog,
  9144. UniformsLib.lights,
  9145. {
  9146. emissive: { value: new Color( 0x000000 ) },
  9147. specular: { value: new Color( 0x111111 ) },
  9148. shininess: { value: 30 }
  9149. }
  9150. ] ),
  9151. vertexShader: ShaderChunk.meshphong_vert,
  9152. fragmentShader: ShaderChunk.meshphong_frag
  9153. },
  9154. standard: {
  9155. uniforms: mergeUniforms( [
  9156. UniformsLib.common,
  9157. UniformsLib.envmap,
  9158. UniformsLib.aomap,
  9159. UniformsLib.lightmap,
  9160. UniformsLib.emissivemap,
  9161. UniformsLib.bumpmap,
  9162. UniformsLib.normalmap,
  9163. UniformsLib.displacementmap,
  9164. UniformsLib.roughnessmap,
  9165. UniformsLib.metalnessmap,
  9166. UniformsLib.fog,
  9167. UniformsLib.lights,
  9168. {
  9169. emissive: { value: new Color( 0x000000 ) },
  9170. roughness: { value: 1.0 },
  9171. metalness: { value: 0.0 },
  9172. envMapIntensity: { value: 1 } // temporary
  9173. }
  9174. ] ),
  9175. vertexShader: ShaderChunk.meshphysical_vert,
  9176. fragmentShader: ShaderChunk.meshphysical_frag
  9177. },
  9178. toon: {
  9179. uniforms: mergeUniforms( [
  9180. UniformsLib.common,
  9181. UniformsLib.specularmap,
  9182. UniformsLib.aomap,
  9183. UniformsLib.lightmap,
  9184. UniformsLib.emissivemap,
  9185. UniformsLib.bumpmap,
  9186. UniformsLib.normalmap,
  9187. UniformsLib.displacementmap,
  9188. UniformsLib.gradientmap,
  9189. UniformsLib.fog,
  9190. UniformsLib.lights,
  9191. {
  9192. emissive: { value: new Color( 0x000000 ) },
  9193. specular: { value: new Color( 0x111111 ) },
  9194. shininess: { value: 30 }
  9195. }
  9196. ] ),
  9197. vertexShader: ShaderChunk.meshtoon_vert,
  9198. fragmentShader: ShaderChunk.meshtoon_frag
  9199. },
  9200. matcap: {
  9201. uniforms: mergeUniforms( [
  9202. UniformsLib.common,
  9203. UniformsLib.bumpmap,
  9204. UniformsLib.normalmap,
  9205. UniformsLib.displacementmap,
  9206. UniformsLib.fog,
  9207. {
  9208. matcap: { value: null }
  9209. }
  9210. ] ),
  9211. vertexShader: ShaderChunk.meshmatcap_vert,
  9212. fragmentShader: ShaderChunk.meshmatcap_frag
  9213. },
  9214. points: {
  9215. uniforms: mergeUniforms( [
  9216. UniformsLib.points,
  9217. UniformsLib.fog
  9218. ] ),
  9219. vertexShader: ShaderChunk.points_vert,
  9220. fragmentShader: ShaderChunk.points_frag
  9221. },
  9222. dashed: {
  9223. uniforms: mergeUniforms( [
  9224. UniformsLib.common,
  9225. UniformsLib.fog,
  9226. {
  9227. scale: { value: 1 },
  9228. dashSize: { value: 1 },
  9229. totalSize: { value: 2 }
  9230. }
  9231. ] ),
  9232. vertexShader: ShaderChunk.linedashed_vert,
  9233. fragmentShader: ShaderChunk.linedashed_frag
  9234. },
  9235. depth: {
  9236. uniforms: mergeUniforms( [
  9237. UniformsLib.common,
  9238. UniformsLib.displacementmap
  9239. ] ),
  9240. vertexShader: ShaderChunk.depth_vert,
  9241. fragmentShader: ShaderChunk.depth_frag
  9242. },
  9243. normal: {
  9244. uniforms: mergeUniforms( [
  9245. UniformsLib.common,
  9246. UniformsLib.bumpmap,
  9247. UniformsLib.normalmap,
  9248. UniformsLib.displacementmap,
  9249. {
  9250. opacity: { value: 1.0 }
  9251. }
  9252. ] ),
  9253. vertexShader: ShaderChunk.normal_vert,
  9254. fragmentShader: ShaderChunk.normal_frag
  9255. },
  9256. sprite: {
  9257. uniforms: mergeUniforms( [
  9258. UniformsLib.sprite,
  9259. UniformsLib.fog
  9260. ] ),
  9261. vertexShader: ShaderChunk.sprite_vert,
  9262. fragmentShader: ShaderChunk.sprite_frag
  9263. },
  9264. background: {
  9265. uniforms: {
  9266. uvTransform: { value: new Matrix3() },
  9267. t2D: { value: null },
  9268. },
  9269. vertexShader: ShaderChunk.background_vert,
  9270. fragmentShader: ShaderChunk.background_frag
  9271. },
  9272. /* -------------------------------------------------------------------------
  9273. // Cube map shader
  9274. ------------------------------------------------------------------------- */
  9275. cube: {
  9276. uniforms: mergeUniforms( [
  9277. UniformsLib.envmap,
  9278. {
  9279. opacity: { value: 1.0 }
  9280. }
  9281. ] ),
  9282. vertexShader: ShaderChunk.cube_vert,
  9283. fragmentShader: ShaderChunk.cube_frag
  9284. },
  9285. equirect: {
  9286. uniforms: {
  9287. tEquirect: { value: null },
  9288. },
  9289. vertexShader: ShaderChunk.equirect_vert,
  9290. fragmentShader: ShaderChunk.equirect_frag
  9291. },
  9292. distanceRGBA: {
  9293. uniforms: mergeUniforms( [
  9294. UniformsLib.common,
  9295. UniformsLib.displacementmap,
  9296. {
  9297. referencePosition: { value: new Vector3() },
  9298. nearDistance: { value: 1 },
  9299. farDistance: { value: 1000 }
  9300. }
  9301. ] ),
  9302. vertexShader: ShaderChunk.distanceRGBA_vert,
  9303. fragmentShader: ShaderChunk.distanceRGBA_frag
  9304. },
  9305. shadow: {
  9306. uniforms: mergeUniforms( [
  9307. UniformsLib.lights,
  9308. UniformsLib.fog,
  9309. {
  9310. color: { value: new Color( 0x00000 ) },
  9311. opacity: { value: 1.0 }
  9312. },
  9313. ] ),
  9314. vertexShader: ShaderChunk.shadow_vert,
  9315. fragmentShader: ShaderChunk.shadow_frag
  9316. }
  9317. };
  9318. ShaderLib.physical = {
  9319. uniforms: mergeUniforms( [
  9320. ShaderLib.standard.uniforms,
  9321. {
  9322. clearcoat: { value: 0 },
  9323. clearcoatMap: { value: null },
  9324. clearcoatRoughness: { value: 0 },
  9325. clearcoatRoughnessMap: { value: null },
  9326. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  9327. clearcoatNormalMap: { value: null },
  9328. sheen: { value: new Color( 0x000000 ) },
  9329. transparency: { value: 0 },
  9330. }
  9331. ] ),
  9332. vertexShader: ShaderChunk.meshphysical_vert,
  9333. fragmentShader: ShaderChunk.meshphysical_frag
  9334. };
  9335. /**
  9336. * @author mrdoob / http://mrdoob.com/
  9337. */
  9338. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9339. var clearColor = new Color( 0x000000 );
  9340. var clearAlpha = 0;
  9341. var planeMesh;
  9342. var boxMesh;
  9343. var currentBackground = null;
  9344. var currentBackgroundVersion = 0;
  9345. var currentTonemapping = null;
  9346. function render( renderList, scene, camera, forceClear ) {
  9347. var background = scene.background;
  9348. // Ignore background in AR
  9349. // TODO: Reconsider this.
  9350. var xr = renderer.xr;
  9351. var session = xr.getSession && xr.getSession();
  9352. if ( session && session.environmentBlendMode === 'additive' ) {
  9353. background = null;
  9354. }
  9355. if ( background === null ) {
  9356. setClear( clearColor, clearAlpha );
  9357. } else if ( background && background.isColor ) {
  9358. setClear( background, 1 );
  9359. forceClear = true;
  9360. }
  9361. if ( renderer.autoClear || forceClear ) {
  9362. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9363. }
  9364. if ( background && ( background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping ) ) {
  9365. if ( boxMesh === undefined ) {
  9366. boxMesh = new Mesh(
  9367. new BoxBufferGeometry( 1, 1, 1 ),
  9368. new ShaderMaterial( {
  9369. type: 'BackgroundCubeMaterial',
  9370. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9371. vertexShader: ShaderLib.cube.vertexShader,
  9372. fragmentShader: ShaderLib.cube.fragmentShader,
  9373. side: BackSide,
  9374. depthTest: false,
  9375. depthWrite: false,
  9376. fog: false
  9377. } )
  9378. );
  9379. boxMesh.geometry.deleteAttribute( 'normal' );
  9380. boxMesh.geometry.deleteAttribute( 'uv' );
  9381. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9382. this.matrixWorld.copyPosition( camera.matrixWorld );
  9383. };
  9384. // enable code injection for non-built-in material
  9385. Object.defineProperty( boxMesh.material, 'envMap', {
  9386. get: function () {
  9387. return this.uniforms.envMap.value;
  9388. }
  9389. } );
  9390. objects.update( boxMesh );
  9391. }
  9392. var texture = background.isWebGLCubeRenderTarget ? background.texture : background;
  9393. boxMesh.material.uniforms.envMap.value = texture;
  9394. boxMesh.material.uniforms.flipEnvMap.value = texture.isCubeTexture ? - 1 : 1;
  9395. if ( currentBackground !== background ||
  9396. currentBackgroundVersion !== texture.version ||
  9397. currentTonemapping !== renderer.toneMapping ) {
  9398. boxMesh.material.needsUpdate = true;
  9399. currentBackground = background;
  9400. currentBackgroundVersion = texture.version;
  9401. currentTonemapping = renderer.toneMapping;
  9402. }
  9403. // push to the pre-sorted opaque render list
  9404. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9405. } else if ( background && background.isTexture ) {
  9406. if ( planeMesh === undefined ) {
  9407. planeMesh = new Mesh(
  9408. new PlaneBufferGeometry( 2, 2 ),
  9409. new ShaderMaterial( {
  9410. type: 'BackgroundMaterial',
  9411. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9412. vertexShader: ShaderLib.background.vertexShader,
  9413. fragmentShader: ShaderLib.background.fragmentShader,
  9414. side: FrontSide,
  9415. depthTest: false,
  9416. depthWrite: false,
  9417. fog: false
  9418. } )
  9419. );
  9420. planeMesh.geometry.deleteAttribute( 'normal' );
  9421. // enable code injection for non-built-in material
  9422. Object.defineProperty( planeMesh.material, 'map', {
  9423. get: function () {
  9424. return this.uniforms.t2D.value;
  9425. }
  9426. } );
  9427. objects.update( planeMesh );
  9428. }
  9429. planeMesh.material.uniforms.t2D.value = background;
  9430. if ( background.matrixAutoUpdate === true ) {
  9431. background.updateMatrix();
  9432. }
  9433. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9434. if ( currentBackground !== background ||
  9435. currentBackgroundVersion !== background.version ||
  9436. currentTonemapping !== renderer.toneMapping ) {
  9437. planeMesh.material.needsUpdate = true;
  9438. currentBackground = background;
  9439. currentBackgroundVersion = background.version;
  9440. currentTonemapping = renderer.toneMapping;
  9441. }
  9442. // push to the pre-sorted opaque render list
  9443. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9444. }
  9445. }
  9446. function setClear( color, alpha ) {
  9447. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9448. }
  9449. return {
  9450. getClearColor: function () {
  9451. return clearColor;
  9452. },
  9453. setClearColor: function ( color, alpha ) {
  9454. clearColor.set( color );
  9455. clearAlpha = alpha !== undefined ? alpha : 1;
  9456. setClear( clearColor, clearAlpha );
  9457. },
  9458. getClearAlpha: function () {
  9459. return clearAlpha;
  9460. },
  9461. setClearAlpha: function ( alpha ) {
  9462. clearAlpha = alpha;
  9463. setClear( clearColor, clearAlpha );
  9464. },
  9465. render: render
  9466. };
  9467. }
  9468. /**
  9469. * @author mrdoob / http://mrdoob.com/
  9470. */
  9471. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9472. var isWebGL2 = capabilities.isWebGL2;
  9473. var mode;
  9474. function setMode( value ) {
  9475. mode = value;
  9476. }
  9477. function render( start, count ) {
  9478. gl.drawArrays( mode, start, count );
  9479. info.update( count, mode );
  9480. }
  9481. function renderInstances( geometry, start, count, primcount ) {
  9482. if ( primcount === 0 ) return;
  9483. var extension, methodName;
  9484. if ( isWebGL2 ) {
  9485. extension = gl;
  9486. methodName = 'drawArraysInstanced';
  9487. } else {
  9488. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9489. methodName = 'drawArraysInstancedANGLE';
  9490. if ( extension === null ) {
  9491. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9492. return;
  9493. }
  9494. }
  9495. extension[ methodName ]( mode, start, count, primcount );
  9496. info.update( count, mode, primcount );
  9497. }
  9498. //
  9499. this.setMode = setMode;
  9500. this.render = render;
  9501. this.renderInstances = renderInstances;
  9502. }
  9503. /**
  9504. * @author mrdoob / http://mrdoob.com/
  9505. */
  9506. function WebGLCapabilities( gl, extensions, parameters ) {
  9507. var maxAnisotropy;
  9508. function getMaxAnisotropy() {
  9509. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  9510. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9511. if ( extension !== null ) {
  9512. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9513. } else {
  9514. maxAnisotropy = 0;
  9515. }
  9516. return maxAnisotropy;
  9517. }
  9518. function getMaxPrecision( precision ) {
  9519. if ( precision === 'highp' ) {
  9520. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9521. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9522. return 'highp';
  9523. }
  9524. precision = 'mediump';
  9525. }
  9526. if ( precision === 'mediump' ) {
  9527. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9528. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9529. return 'mediump';
  9530. }
  9531. }
  9532. return 'lowp';
  9533. }
  9534. /* eslint-disable no-undef */
  9535. var isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  9536. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  9537. /* eslint-enable no-undef */
  9538. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9539. var maxPrecision = getMaxPrecision( precision );
  9540. if ( maxPrecision !== precision ) {
  9541. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9542. precision = maxPrecision;
  9543. }
  9544. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9545. var maxTextures = gl.getParameter( 34930 );
  9546. var maxVertexTextures = gl.getParameter( 35660 );
  9547. var maxTextureSize = gl.getParameter( 3379 );
  9548. var maxCubemapSize = gl.getParameter( 34076 );
  9549. var maxAttributes = gl.getParameter( 34921 );
  9550. var maxVertexUniforms = gl.getParameter( 36347 );
  9551. var maxVaryings = gl.getParameter( 36348 );
  9552. var maxFragmentUniforms = gl.getParameter( 36349 );
  9553. var vertexTextures = maxVertexTextures > 0;
  9554. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9555. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9556. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9557. return {
  9558. isWebGL2: isWebGL2,
  9559. getMaxAnisotropy: getMaxAnisotropy,
  9560. getMaxPrecision: getMaxPrecision,
  9561. precision: precision,
  9562. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9563. maxTextures: maxTextures,
  9564. maxVertexTextures: maxVertexTextures,
  9565. maxTextureSize: maxTextureSize,
  9566. maxCubemapSize: maxCubemapSize,
  9567. maxAttributes: maxAttributes,
  9568. maxVertexUniforms: maxVertexUniforms,
  9569. maxVaryings: maxVaryings,
  9570. maxFragmentUniforms: maxFragmentUniforms,
  9571. vertexTextures: vertexTextures,
  9572. floatFragmentTextures: floatFragmentTextures,
  9573. floatVertexTextures: floatVertexTextures,
  9574. maxSamples: maxSamples
  9575. };
  9576. }
  9577. /**
  9578. * @author tschw
  9579. */
  9580. function WebGLClipping() {
  9581. var scope = this,
  9582. globalState = null,
  9583. numGlobalPlanes = 0,
  9584. localClippingEnabled = false,
  9585. renderingShadows = false,
  9586. plane = new Plane(),
  9587. viewNormalMatrix = new Matrix3(),
  9588. uniform = { value: null, needsUpdate: false };
  9589. this.uniform = uniform;
  9590. this.numPlanes = 0;
  9591. this.numIntersection = 0;
  9592. this.init = function ( planes, enableLocalClipping, camera ) {
  9593. var enabled =
  9594. planes.length !== 0 ||
  9595. enableLocalClipping ||
  9596. // enable state of previous frame - the clipping code has to
  9597. // run another frame in order to reset the state:
  9598. numGlobalPlanes !== 0 ||
  9599. localClippingEnabled;
  9600. localClippingEnabled = enableLocalClipping;
  9601. globalState = projectPlanes( planes, camera, 0 );
  9602. numGlobalPlanes = planes.length;
  9603. return enabled;
  9604. };
  9605. this.beginShadows = function () {
  9606. renderingShadows = true;
  9607. projectPlanes( null );
  9608. };
  9609. this.endShadows = function () {
  9610. renderingShadows = false;
  9611. resetGlobalState();
  9612. };
  9613. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9614. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9615. // there's no local clipping
  9616. if ( renderingShadows ) {
  9617. // there's no global clipping
  9618. projectPlanes( null );
  9619. } else {
  9620. resetGlobalState();
  9621. }
  9622. } else {
  9623. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9624. lGlobal = nGlobal * 4,
  9625. dstArray = cache.clippingState || null;
  9626. uniform.value = dstArray; // ensure unique state
  9627. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9628. for ( var i = 0; i !== lGlobal; ++ i ) {
  9629. dstArray[ i ] = globalState[ i ];
  9630. }
  9631. cache.clippingState = dstArray;
  9632. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9633. this.numPlanes += nGlobal;
  9634. }
  9635. };
  9636. function resetGlobalState() {
  9637. if ( uniform.value !== globalState ) {
  9638. uniform.value = globalState;
  9639. uniform.needsUpdate = numGlobalPlanes > 0;
  9640. }
  9641. scope.numPlanes = numGlobalPlanes;
  9642. scope.numIntersection = 0;
  9643. }
  9644. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9645. var nPlanes = planes !== null ? planes.length : 0,
  9646. dstArray = null;
  9647. if ( nPlanes !== 0 ) {
  9648. dstArray = uniform.value;
  9649. if ( skipTransform !== true || dstArray === null ) {
  9650. var flatSize = dstOffset + nPlanes * 4,
  9651. viewMatrix = camera.matrixWorldInverse;
  9652. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9653. if ( dstArray === null || dstArray.length < flatSize ) {
  9654. dstArray = new Float32Array( flatSize );
  9655. }
  9656. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9657. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9658. plane.normal.toArray( dstArray, i4 );
  9659. dstArray[ i4 + 3 ] = plane.constant;
  9660. }
  9661. }
  9662. uniform.value = dstArray;
  9663. uniform.needsUpdate = true;
  9664. }
  9665. scope.numPlanes = nPlanes;
  9666. scope.numIntersection = 0;
  9667. return dstArray;
  9668. }
  9669. }
  9670. /**
  9671. * @author mrdoob / http://mrdoob.com/
  9672. */
  9673. function WebGLExtensions( gl ) {
  9674. var extensions = {};
  9675. return {
  9676. get: function ( name ) {
  9677. if ( extensions[ name ] !== undefined ) {
  9678. return extensions[ name ];
  9679. }
  9680. var extension;
  9681. switch ( name ) {
  9682. case 'WEBGL_depth_texture':
  9683. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9684. break;
  9685. case 'EXT_texture_filter_anisotropic':
  9686. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9687. break;
  9688. case 'WEBGL_compressed_texture_s3tc':
  9689. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9690. break;
  9691. case 'WEBGL_compressed_texture_pvrtc':
  9692. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9693. break;
  9694. default:
  9695. extension = gl.getExtension( name );
  9696. }
  9697. if ( extension === null ) {
  9698. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9699. }
  9700. extensions[ name ] = extension;
  9701. return extension;
  9702. }
  9703. };
  9704. }
  9705. /**
  9706. * @author mrdoob / http://mrdoob.com/
  9707. */
  9708. function WebGLGeometries( gl, attributes, info ) {
  9709. var geometries = new WeakMap();
  9710. var wireframeAttributes = new WeakMap();
  9711. function onGeometryDispose( event ) {
  9712. var geometry = event.target;
  9713. var buffergeometry = geometries.get( geometry );
  9714. if ( buffergeometry.index !== null ) {
  9715. attributes.remove( buffergeometry.index );
  9716. }
  9717. for ( var name in buffergeometry.attributes ) {
  9718. attributes.remove( buffergeometry.attributes[ name ] );
  9719. }
  9720. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9721. geometries.delete( geometry );
  9722. var attribute = wireframeAttributes.get( buffergeometry );
  9723. if ( attribute ) {
  9724. attributes.remove( attribute );
  9725. wireframeAttributes.delete( buffergeometry );
  9726. }
  9727. //
  9728. info.memory.geometries --;
  9729. }
  9730. function get( object, geometry ) {
  9731. var buffergeometry = geometries.get( geometry );
  9732. if ( buffergeometry ) return buffergeometry;
  9733. geometry.addEventListener( 'dispose', onGeometryDispose );
  9734. if ( geometry.isBufferGeometry ) {
  9735. buffergeometry = geometry;
  9736. } else if ( geometry.isGeometry ) {
  9737. if ( geometry._bufferGeometry === undefined ) {
  9738. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9739. }
  9740. buffergeometry = geometry._bufferGeometry;
  9741. }
  9742. geometries.set( geometry, buffergeometry );
  9743. info.memory.geometries ++;
  9744. return buffergeometry;
  9745. }
  9746. function update( geometry ) {
  9747. var index = geometry.index;
  9748. var geometryAttributes = geometry.attributes;
  9749. if ( index !== null ) {
  9750. attributes.update( index, 34963 );
  9751. }
  9752. for ( var name in geometryAttributes ) {
  9753. attributes.update( geometryAttributes[ name ], 34962 );
  9754. }
  9755. // morph targets
  9756. var morphAttributes = geometry.morphAttributes;
  9757. for ( var name in morphAttributes ) {
  9758. var array = morphAttributes[ name ];
  9759. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9760. attributes.update( array[ i ], 34962 );
  9761. }
  9762. }
  9763. }
  9764. function updateWireframeAttribute( geometry ) {
  9765. var indices = [];
  9766. var geometryIndex = geometry.index;
  9767. var geometryPosition = geometry.attributes.position;
  9768. var version = 0;
  9769. if ( geometryIndex !== null ) {
  9770. var array = geometryIndex.array;
  9771. version = geometryIndex.version;
  9772. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9773. var a = array[ i + 0 ];
  9774. var b = array[ i + 1 ];
  9775. var c = array[ i + 2 ];
  9776. indices.push( a, b, b, c, c, a );
  9777. }
  9778. } else {
  9779. var array = geometryPosition.array;
  9780. version = geometryPosition.version;
  9781. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9782. var a = i + 0;
  9783. var b = i + 1;
  9784. var c = i + 2;
  9785. indices.push( a, b, b, c, c, a );
  9786. }
  9787. }
  9788. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9789. attribute.version = version;
  9790. attributes.update( attribute, 34963 );
  9791. //
  9792. var previousAttribute = wireframeAttributes.get( geometry );
  9793. if ( previousAttribute ) attributes.remove( previousAttribute );
  9794. //
  9795. wireframeAttributes.set( geometry, attribute );
  9796. }
  9797. function getWireframeAttribute( geometry ) {
  9798. var currentAttribute = wireframeAttributes.get( geometry );
  9799. if ( currentAttribute ) {
  9800. var geometryIndex = geometry.index;
  9801. if ( geometryIndex !== null ) {
  9802. // if the attribute is obsolete, create a new one
  9803. if ( currentAttribute.version < geometryIndex.version ) {
  9804. updateWireframeAttribute( geometry );
  9805. }
  9806. }
  9807. } else {
  9808. updateWireframeAttribute( geometry );
  9809. }
  9810. return wireframeAttributes.get( geometry );
  9811. }
  9812. return {
  9813. get: get,
  9814. update: update,
  9815. getWireframeAttribute: getWireframeAttribute
  9816. };
  9817. }
  9818. /**
  9819. * @author mrdoob / http://mrdoob.com/
  9820. */
  9821. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9822. var isWebGL2 = capabilities.isWebGL2;
  9823. var mode;
  9824. function setMode( value ) {
  9825. mode = value;
  9826. }
  9827. var type, bytesPerElement;
  9828. function setIndex( value ) {
  9829. type = value.type;
  9830. bytesPerElement = value.bytesPerElement;
  9831. }
  9832. function render( start, count ) {
  9833. gl.drawElements( mode, count, type, start * bytesPerElement );
  9834. info.update( count, mode );
  9835. }
  9836. function renderInstances( geometry, start, count, primcount ) {
  9837. if ( primcount === 0 ) return;
  9838. var extension, methodName;
  9839. if ( isWebGL2 ) {
  9840. extension = gl;
  9841. methodName = 'drawElementsInstanced';
  9842. } else {
  9843. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9844. methodName = 'drawElementsInstancedANGLE';
  9845. if ( extension === null ) {
  9846. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9847. return;
  9848. }
  9849. }
  9850. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  9851. info.update( count, mode, primcount );
  9852. }
  9853. //
  9854. this.setMode = setMode;
  9855. this.setIndex = setIndex;
  9856. this.render = render;
  9857. this.renderInstances = renderInstances;
  9858. }
  9859. /**
  9860. * @author Mugen87 / https://github.com/Mugen87
  9861. */
  9862. function WebGLInfo( gl ) {
  9863. var memory = {
  9864. geometries: 0,
  9865. textures: 0
  9866. };
  9867. var render = {
  9868. frame: 0,
  9869. calls: 0,
  9870. triangles: 0,
  9871. points: 0,
  9872. lines: 0
  9873. };
  9874. function update( count, mode, instanceCount ) {
  9875. instanceCount = instanceCount || 1;
  9876. render.calls ++;
  9877. switch ( mode ) {
  9878. case 4:
  9879. render.triangles += instanceCount * ( count / 3 );
  9880. break;
  9881. case 1:
  9882. render.lines += instanceCount * ( count / 2 );
  9883. break;
  9884. case 3:
  9885. render.lines += instanceCount * ( count - 1 );
  9886. break;
  9887. case 2:
  9888. render.lines += instanceCount * count;
  9889. break;
  9890. case 0:
  9891. render.points += instanceCount * count;
  9892. break;
  9893. default:
  9894. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9895. break;
  9896. }
  9897. }
  9898. function reset() {
  9899. render.frame ++;
  9900. render.calls = 0;
  9901. render.triangles = 0;
  9902. render.points = 0;
  9903. render.lines = 0;
  9904. }
  9905. return {
  9906. memory: memory,
  9907. render: render,
  9908. programs: null,
  9909. autoReset: true,
  9910. reset: reset,
  9911. update: update
  9912. };
  9913. }
  9914. /**
  9915. * @author mrdoob / http://mrdoob.com/
  9916. */
  9917. function absNumericalSort( a, b ) {
  9918. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9919. }
  9920. function WebGLMorphtargets( gl ) {
  9921. var influencesList = {};
  9922. var morphInfluences = new Float32Array( 8 );
  9923. function update( object, geometry, material, program ) {
  9924. var objectInfluences = object.morphTargetInfluences;
  9925. // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9926. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9927. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9928. var influences = influencesList[ geometry.id ];
  9929. if ( influences === undefined ) {
  9930. // initialise list
  9931. influences = [];
  9932. for ( var i = 0; i < length; i ++ ) {
  9933. influences[ i ] = [ i, 0 ];
  9934. }
  9935. influencesList[ geometry.id ] = influences;
  9936. }
  9937. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9938. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9939. // Remove current morphAttributes
  9940. for ( var i = 0; i < length; i ++ ) {
  9941. var influence = influences[ i ];
  9942. if ( influence[ 1 ] !== 0 ) {
  9943. if ( morphTargets ) geometry.deleteAttribute( 'morphTarget' + i );
  9944. if ( morphNormals ) geometry.deleteAttribute( 'morphNormal' + i );
  9945. }
  9946. }
  9947. // Collect influences
  9948. for ( var i = 0; i < length; i ++ ) {
  9949. var influence = influences[ i ];
  9950. influence[ 0 ] = i;
  9951. influence[ 1 ] = objectInfluences[ i ];
  9952. }
  9953. influences.sort( absNumericalSort );
  9954. // Add morphAttributes
  9955. var morphInfluencesSum = 0;
  9956. for ( var i = 0; i < 8; i ++ ) {
  9957. var influence = influences[ i ];
  9958. if ( influence ) {
  9959. var index = influence[ 0 ];
  9960. var value = influence[ 1 ];
  9961. if ( value ) {
  9962. if ( morphTargets ) geometry.setAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9963. if ( morphNormals ) geometry.setAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9964. morphInfluences[ i ] = value;
  9965. morphInfluencesSum += value;
  9966. continue;
  9967. }
  9968. }
  9969. morphInfluences[ i ] = 0;
  9970. }
  9971. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9972. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9973. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9974. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9975. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  9976. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9977. }
  9978. return {
  9979. update: update
  9980. };
  9981. }
  9982. /**
  9983. * @author mrdoob / http://mrdoob.com/
  9984. */
  9985. function WebGLObjects( gl, geometries, attributes, info ) {
  9986. var updateMap = new WeakMap();
  9987. function update( object ) {
  9988. var frame = info.render.frame;
  9989. var geometry = object.geometry;
  9990. var buffergeometry = geometries.get( object, geometry );
  9991. // Update once per frame
  9992. if ( updateMap.get( buffergeometry ) !== frame ) {
  9993. if ( geometry.isGeometry ) {
  9994. buffergeometry.updateFromObject( object );
  9995. }
  9996. geometries.update( buffergeometry );
  9997. updateMap.set( buffergeometry, frame );
  9998. }
  9999. if ( object.isInstancedMesh ) {
  10000. attributes.update( object.instanceMatrix, 34962 );
  10001. }
  10002. return buffergeometry;
  10003. }
  10004. function dispose() {
  10005. updateMap = new WeakMap();
  10006. }
  10007. return {
  10008. update: update,
  10009. dispose: dispose
  10010. };
  10011. }
  10012. /**
  10013. * @author mrdoob / http://mrdoob.com/
  10014. */
  10015. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  10016. images = images !== undefined ? images : [];
  10017. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  10018. format = format !== undefined ? format : RGBFormat;
  10019. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  10020. this.flipY = false;
  10021. }
  10022. CubeTexture.prototype = Object.create( Texture.prototype );
  10023. CubeTexture.prototype.constructor = CubeTexture;
  10024. CubeTexture.prototype.isCubeTexture = true;
  10025. Object.defineProperty( CubeTexture.prototype, 'images', {
  10026. get: function () {
  10027. return this.image;
  10028. },
  10029. set: function ( value ) {
  10030. this.image = value;
  10031. }
  10032. } );
  10033. /**
  10034. * @author Takahiro https://github.com/takahirox
  10035. */
  10036. function DataTexture2DArray( data, width, height, depth ) {
  10037. Texture.call( this, null );
  10038. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  10039. this.magFilter = NearestFilter;
  10040. this.minFilter = NearestFilter;
  10041. this.wrapR = ClampToEdgeWrapping;
  10042. this.generateMipmaps = false;
  10043. this.flipY = false;
  10044. this.needsUpdate = true;
  10045. }
  10046. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  10047. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10048. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10049. /**
  10050. * @author Artur Trzesiok
  10051. */
  10052. function DataTexture3D( data, width, height, depth ) {
  10053. // We're going to add .setXXX() methods for setting properties later.
  10054. // Users can still set in DataTexture3D directly.
  10055. //
  10056. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  10057. // texture.anisotropy = 16;
  10058. //
  10059. // See #14839
  10060. Texture.call( this, null );
  10061. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  10062. this.magFilter = NearestFilter;
  10063. this.minFilter = NearestFilter;
  10064. this.wrapR = ClampToEdgeWrapping;
  10065. this.generateMipmaps = false;
  10066. this.flipY = false;
  10067. this.needsUpdate = true;
  10068. }
  10069. DataTexture3D.prototype = Object.create( Texture.prototype );
  10070. DataTexture3D.prototype.constructor = DataTexture3D;
  10071. DataTexture3D.prototype.isDataTexture3D = true;
  10072. /**
  10073. * @author tschw
  10074. * @author Mugen87 / https://github.com/Mugen87
  10075. * @author mrdoob / http://mrdoob.com/
  10076. *
  10077. * Uniforms of a program.
  10078. * Those form a tree structure with a special top-level container for the root,
  10079. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10080. *
  10081. *
  10082. * Properties of inner nodes including the top-level container:
  10083. *
  10084. * .seq - array of nested uniforms
  10085. * .map - nested uniforms by name
  10086. *
  10087. *
  10088. * Methods of all nodes except the top-level container:
  10089. *
  10090. * .setValue( gl, value, [textures] )
  10091. *
  10092. * uploads a uniform value(s)
  10093. * the 'textures' parameter is needed for sampler uniforms
  10094. *
  10095. *
  10096. * Static methods of the top-level container (textures factorizations):
  10097. *
  10098. * .upload( gl, seq, values, textures )
  10099. *
  10100. * sets uniforms in 'seq' to 'values[id].value'
  10101. *
  10102. * .seqWithValue( seq, values ) : filteredSeq
  10103. *
  10104. * filters 'seq' entries with corresponding entry in values
  10105. *
  10106. *
  10107. * Methods of the top-level container (textures factorizations):
  10108. *
  10109. * .setValue( gl, name, value, textures )
  10110. *
  10111. * sets uniform with name 'name' to 'value'
  10112. *
  10113. * .setOptional( gl, obj, prop )
  10114. *
  10115. * like .set for an optional property of the object
  10116. *
  10117. */
  10118. var emptyTexture = new Texture();
  10119. var emptyTexture2dArray = new DataTexture2DArray();
  10120. var emptyTexture3d = new DataTexture3D();
  10121. var emptyCubeTexture = new CubeTexture();
  10122. // --- Utilities ---
  10123. // Array Caches (provide typed arrays for temporary by size)
  10124. var arrayCacheF32 = [];
  10125. var arrayCacheI32 = [];
  10126. // Float32Array caches used for uploading Matrix uniforms
  10127. var mat4array = new Float32Array( 16 );
  10128. var mat3array = new Float32Array( 9 );
  10129. var mat2array = new Float32Array( 4 );
  10130. // Flattening for arrays of vectors and matrices
  10131. function flatten( array, nBlocks, blockSize ) {
  10132. var firstElem = array[ 0 ];
  10133. if ( firstElem <= 0 || firstElem > 0 ) return array;
  10134. // unoptimized: ! isNaN( firstElem )
  10135. // see http://jacksondunstan.com/articles/983
  10136. var n = nBlocks * blockSize,
  10137. r = arrayCacheF32[ n ];
  10138. if ( r === undefined ) {
  10139. r = new Float32Array( n );
  10140. arrayCacheF32[ n ] = r;
  10141. }
  10142. if ( nBlocks !== 0 ) {
  10143. firstElem.toArray( r, 0 );
  10144. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10145. offset += blockSize;
  10146. array[ i ].toArray( r, offset );
  10147. }
  10148. }
  10149. return r;
  10150. }
  10151. function arraysEqual( a, b ) {
  10152. if ( a.length !== b.length ) return false;
  10153. for ( var i = 0, l = a.length; i < l; i ++ ) {
  10154. if ( a[ i ] !== b[ i ] ) return false;
  10155. }
  10156. return true;
  10157. }
  10158. function copyArray( a, b ) {
  10159. for ( var i = 0, l = b.length; i < l; i ++ ) {
  10160. a[ i ] = b[ i ];
  10161. }
  10162. }
  10163. // Texture unit allocation
  10164. function allocTexUnits( textures, n ) {
  10165. var r = arrayCacheI32[ n ];
  10166. if ( r === undefined ) {
  10167. r = new Int32Array( n );
  10168. arrayCacheI32[ n ] = r;
  10169. }
  10170. for ( var i = 0; i !== n; ++ i )
  10171. r[ i ] = textures.allocateTextureUnit();
  10172. return r;
  10173. }
  10174. // --- Setters ---
  10175. // Note: Defining these methods externally, because they come in a bunch
  10176. // and this way their names minify.
  10177. // Single scalar
  10178. function setValueV1f( gl, v ) {
  10179. var cache = this.cache;
  10180. if ( cache[ 0 ] === v ) return;
  10181. gl.uniform1f( this.addr, v );
  10182. cache[ 0 ] = v;
  10183. }
  10184. // Single float vector (from flat array or THREE.VectorN)
  10185. function setValueV2f( gl, v ) {
  10186. var cache = this.cache;
  10187. if ( v.x !== undefined ) {
  10188. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10189. gl.uniform2f( this.addr, v.x, v.y );
  10190. cache[ 0 ] = v.x;
  10191. cache[ 1 ] = v.y;
  10192. }
  10193. } else {
  10194. if ( arraysEqual( cache, v ) ) return;
  10195. gl.uniform2fv( this.addr, v );
  10196. copyArray( cache, v );
  10197. }
  10198. }
  10199. function setValueV3f( gl, v ) {
  10200. var cache = this.cache;
  10201. if ( v.x !== undefined ) {
  10202. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10203. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10204. cache[ 0 ] = v.x;
  10205. cache[ 1 ] = v.y;
  10206. cache[ 2 ] = v.z;
  10207. }
  10208. } else if ( v.r !== undefined ) {
  10209. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10210. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10211. cache[ 0 ] = v.r;
  10212. cache[ 1 ] = v.g;
  10213. cache[ 2 ] = v.b;
  10214. }
  10215. } else {
  10216. if ( arraysEqual( cache, v ) ) return;
  10217. gl.uniform3fv( this.addr, v );
  10218. copyArray( cache, v );
  10219. }
  10220. }
  10221. function setValueV4f( gl, v ) {
  10222. var cache = this.cache;
  10223. if ( v.x !== undefined ) {
  10224. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10225. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10226. cache[ 0 ] = v.x;
  10227. cache[ 1 ] = v.y;
  10228. cache[ 2 ] = v.z;
  10229. cache[ 3 ] = v.w;
  10230. }
  10231. } else {
  10232. if ( arraysEqual( cache, v ) ) return;
  10233. gl.uniform4fv( this.addr, v );
  10234. copyArray( cache, v );
  10235. }
  10236. }
  10237. // Single matrix (from flat array or MatrixN)
  10238. function setValueM2( gl, v ) {
  10239. var cache = this.cache;
  10240. var elements = v.elements;
  10241. if ( elements === undefined ) {
  10242. if ( arraysEqual( cache, v ) ) return;
  10243. gl.uniformMatrix2fv( this.addr, false, v );
  10244. copyArray( cache, v );
  10245. } else {
  10246. if ( arraysEqual( cache, elements ) ) return;
  10247. mat2array.set( elements );
  10248. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10249. copyArray( cache, elements );
  10250. }
  10251. }
  10252. function setValueM3( gl, v ) {
  10253. var cache = this.cache;
  10254. var elements = v.elements;
  10255. if ( elements === undefined ) {
  10256. if ( arraysEqual( cache, v ) ) return;
  10257. gl.uniformMatrix3fv( this.addr, false, v );
  10258. copyArray( cache, v );
  10259. } else {
  10260. if ( arraysEqual( cache, elements ) ) return;
  10261. mat3array.set( elements );
  10262. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10263. copyArray( cache, elements );
  10264. }
  10265. }
  10266. function setValueM4( gl, v ) {
  10267. var cache = this.cache;
  10268. var elements = v.elements;
  10269. if ( elements === undefined ) {
  10270. if ( arraysEqual( cache, v ) ) return;
  10271. gl.uniformMatrix4fv( this.addr, false, v );
  10272. copyArray( cache, v );
  10273. } else {
  10274. if ( arraysEqual( cache, elements ) ) return;
  10275. mat4array.set( elements );
  10276. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10277. copyArray( cache, elements );
  10278. }
  10279. }
  10280. // Single texture (2D / Cube)
  10281. function setValueT1( gl, v, textures ) {
  10282. var cache = this.cache;
  10283. var unit = textures.allocateTextureUnit();
  10284. if ( cache[ 0 ] !== unit ) {
  10285. gl.uniform1i( this.addr, unit );
  10286. cache[ 0 ] = unit;
  10287. }
  10288. textures.safeSetTexture2D( v || emptyTexture, unit );
  10289. }
  10290. function setValueT2DArray1( gl, v, textures ) {
  10291. var cache = this.cache;
  10292. var unit = textures.allocateTextureUnit();
  10293. if ( cache[ 0 ] !== unit ) {
  10294. gl.uniform1i( this.addr, unit );
  10295. cache[ 0 ] = unit;
  10296. }
  10297. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10298. }
  10299. function setValueT3D1( gl, v, textures ) {
  10300. var cache = this.cache;
  10301. var unit = textures.allocateTextureUnit();
  10302. if ( cache[ 0 ] !== unit ) {
  10303. gl.uniform1i( this.addr, unit );
  10304. cache[ 0 ] = unit;
  10305. }
  10306. textures.setTexture3D( v || emptyTexture3d, unit );
  10307. }
  10308. function setValueT6( gl, v, textures ) {
  10309. var cache = this.cache;
  10310. var unit = textures.allocateTextureUnit();
  10311. if ( cache[ 0 ] !== unit ) {
  10312. gl.uniform1i( this.addr, unit );
  10313. cache[ 0 ] = unit;
  10314. }
  10315. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10316. }
  10317. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10318. function setValueV1i( gl, v ) {
  10319. var cache = this.cache;
  10320. if ( cache[ 0 ] === v ) return;
  10321. gl.uniform1i( this.addr, v );
  10322. cache[ 0 ] = v;
  10323. }
  10324. function setValueV2i( gl, v ) {
  10325. var cache = this.cache;
  10326. if ( arraysEqual( cache, v ) ) return;
  10327. gl.uniform2iv( this.addr, v );
  10328. copyArray( cache, v );
  10329. }
  10330. function setValueV3i( gl, v ) {
  10331. var cache = this.cache;
  10332. if ( arraysEqual( cache, v ) ) return;
  10333. gl.uniform3iv( this.addr, v );
  10334. copyArray( cache, v );
  10335. }
  10336. function setValueV4i( gl, v ) {
  10337. var cache = this.cache;
  10338. if ( arraysEqual( cache, v ) ) return;
  10339. gl.uniform4iv( this.addr, v );
  10340. copyArray( cache, v );
  10341. }
  10342. // uint
  10343. function setValueV1ui( gl, v ) {
  10344. var cache = this.cache;
  10345. if ( cache[ 0 ] === v ) return;
  10346. gl.uniform1ui( this.addr, v );
  10347. cache[ 0 ] = v;
  10348. }
  10349. // Helper to pick the right setter for the singular case
  10350. function getSingularSetter( type ) {
  10351. switch ( type ) {
  10352. case 0x1406: return setValueV1f; // FLOAT
  10353. case 0x8b50: return setValueV2f; // _VEC2
  10354. case 0x8b51: return setValueV3f; // _VEC3
  10355. case 0x8b52: return setValueV4f; // _VEC4
  10356. case 0x8b5a: return setValueM2; // _MAT2
  10357. case 0x8b5b: return setValueM3; // _MAT3
  10358. case 0x8b5c: return setValueM4; // _MAT4
  10359. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10360. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10361. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10362. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10363. case 0x1405: return setValueV1ui; // UINT
  10364. case 0x8b5e: // SAMPLER_2D
  10365. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10366. case 0x8dca: // INT_SAMPLER_2D
  10367. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10368. case 0x8b62: // SAMPLER_2D_SHADOW
  10369. return setValueT1;
  10370. case 0x8b5f: // SAMPLER_3D
  10371. case 0x8dcb: // INT_SAMPLER_3D
  10372. case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D
  10373. return setValueT3D1;
  10374. case 0x8b60: // SAMPLER_CUBE
  10375. case 0x8dcc: // INT_SAMPLER_CUBE
  10376. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10377. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10378. return setValueT6;
  10379. case 0x8dc1: // SAMPLER_2D_ARRAY
  10380. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10381. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10382. case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW
  10383. return setValueT2DArray1;
  10384. }
  10385. }
  10386. // Array of scalars
  10387. function setValueV1fArray( gl, v ) {
  10388. gl.uniform1fv( this.addr, v );
  10389. }
  10390. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10391. function setValueV1iArray( gl, v ) {
  10392. gl.uniform1iv( this.addr, v );
  10393. }
  10394. function setValueV2iArray( gl, v ) {
  10395. gl.uniform2iv( this.addr, v );
  10396. }
  10397. function setValueV3iArray( gl, v ) {
  10398. gl.uniform3iv( this.addr, v );
  10399. }
  10400. function setValueV4iArray( gl, v ) {
  10401. gl.uniform4iv( this.addr, v );
  10402. }
  10403. // Array of vectors (flat or from THREE classes)
  10404. function setValueV2fArray( gl, v ) {
  10405. var data = flatten( v, this.size, 2 );
  10406. gl.uniform2fv( this.addr, data );
  10407. }
  10408. function setValueV3fArray( gl, v ) {
  10409. var data = flatten( v, this.size, 3 );
  10410. gl.uniform3fv( this.addr, data );
  10411. }
  10412. function setValueV4fArray( gl, v ) {
  10413. var data = flatten( v, this.size, 4 );
  10414. gl.uniform4fv( this.addr, data );
  10415. }
  10416. // Array of matrices (flat or from THREE clases)
  10417. function setValueM2Array( gl, v ) {
  10418. var data = flatten( v, this.size, 4 );
  10419. gl.uniformMatrix2fv( this.addr, false, data );
  10420. }
  10421. function setValueM3Array( gl, v ) {
  10422. var data = flatten( v, this.size, 9 );
  10423. gl.uniformMatrix3fv( this.addr, false, data );
  10424. }
  10425. function setValueM4Array( gl, v ) {
  10426. var data = flatten( v, this.size, 16 );
  10427. gl.uniformMatrix4fv( this.addr, false, data );
  10428. }
  10429. // Array of textures (2D / Cube)
  10430. function setValueT1Array( gl, v, textures ) {
  10431. var n = v.length;
  10432. var units = allocTexUnits( textures, n );
  10433. gl.uniform1iv( this.addr, units );
  10434. for ( var i = 0; i !== n; ++ i ) {
  10435. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10436. }
  10437. }
  10438. function setValueT6Array( gl, v, textures ) {
  10439. var n = v.length;
  10440. var units = allocTexUnits( textures, n );
  10441. gl.uniform1iv( this.addr, units );
  10442. for ( var i = 0; i !== n; ++ i ) {
  10443. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10444. }
  10445. }
  10446. // Helper to pick the right setter for a pure (bottom-level) array
  10447. function getPureArraySetter( type ) {
  10448. switch ( type ) {
  10449. case 0x1406: return setValueV1fArray; // FLOAT
  10450. case 0x8b50: return setValueV2fArray; // _VEC2
  10451. case 0x8b51: return setValueV3fArray; // _VEC3
  10452. case 0x8b52: return setValueV4fArray; // _VEC4
  10453. case 0x8b5a: return setValueM2Array; // _MAT2
  10454. case 0x8b5b: return setValueM3Array; // _MAT3
  10455. case 0x8b5c: return setValueM4Array; // _MAT4
  10456. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10457. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10458. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10459. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10460. case 0x8b5e: // SAMPLER_2D
  10461. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10462. case 0x8dca: // INT_SAMPLER_2D
  10463. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10464. case 0x8b62: // SAMPLER_2D_SHADOW
  10465. return setValueT1Array;
  10466. case 0x8b60: // SAMPLER_CUBE
  10467. case 0x8dcc: // INT_SAMPLER_CUBE
  10468. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10469. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10470. return setValueT6Array;
  10471. }
  10472. }
  10473. // --- Uniform Classes ---
  10474. function SingleUniform( id, activeInfo, addr ) {
  10475. this.id = id;
  10476. this.addr = addr;
  10477. this.cache = [];
  10478. this.setValue = getSingularSetter( activeInfo.type );
  10479. // this.path = activeInfo.name; // DEBUG
  10480. }
  10481. function PureArrayUniform( id, activeInfo, addr ) {
  10482. this.id = id;
  10483. this.addr = addr;
  10484. this.cache = [];
  10485. this.size = activeInfo.size;
  10486. this.setValue = getPureArraySetter( activeInfo.type );
  10487. // this.path = activeInfo.name; // DEBUG
  10488. }
  10489. PureArrayUniform.prototype.updateCache = function ( data ) {
  10490. var cache = this.cache;
  10491. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10492. this.cache = new Float32Array( data.length );
  10493. }
  10494. copyArray( cache, data );
  10495. };
  10496. function StructuredUniform( id ) {
  10497. this.id = id;
  10498. this.seq = [];
  10499. this.map = {};
  10500. }
  10501. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10502. var seq = this.seq;
  10503. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10504. var u = seq[ i ];
  10505. u.setValue( gl, value[ u.id ], textures );
  10506. }
  10507. };
  10508. // --- Top-level ---
  10509. // Parser - builds up the property tree from the path strings
  10510. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10511. // extracts
  10512. // - the identifier (member name or array index)
  10513. // - followed by an optional right bracket (found when array index)
  10514. // - followed by an optional left bracket or dot (type of subscript)
  10515. //
  10516. // Note: These portions can be read in a non-overlapping fashion and
  10517. // allow straightforward parsing of the hierarchy that WebGL encodes
  10518. // in the uniform names.
  10519. function addUniform( container, uniformObject ) {
  10520. container.seq.push( uniformObject );
  10521. container.map[ uniformObject.id ] = uniformObject;
  10522. }
  10523. function parseUniform( activeInfo, addr, container ) {
  10524. var path = activeInfo.name,
  10525. pathLength = path.length;
  10526. // reset RegExp object, because of the early exit of a previous run
  10527. RePathPart.lastIndex = 0;
  10528. while ( true ) {
  10529. var match = RePathPart.exec( path ),
  10530. matchEnd = RePathPart.lastIndex,
  10531. id = match[ 1 ],
  10532. idIsIndex = match[ 2 ] === ']',
  10533. subscript = match[ 3 ];
  10534. if ( idIsIndex ) id = id | 0; // convert to integer
  10535. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10536. // bare name or "pure" bottom-level array "[0]" suffix
  10537. addUniform( container, subscript === undefined ?
  10538. new SingleUniform( id, activeInfo, addr ) :
  10539. new PureArrayUniform( id, activeInfo, addr ) );
  10540. break;
  10541. } else {
  10542. // step into inner node / create it in case it doesn't exist
  10543. var map = container.map, next = map[ id ];
  10544. if ( next === undefined ) {
  10545. next = new StructuredUniform( id );
  10546. addUniform( container, next );
  10547. }
  10548. container = next;
  10549. }
  10550. }
  10551. }
  10552. // Root Container
  10553. function WebGLUniforms( gl, program ) {
  10554. this.seq = [];
  10555. this.map = {};
  10556. var n = gl.getProgramParameter( program, 35718 );
  10557. for ( var i = 0; i < n; ++ i ) {
  10558. var info = gl.getActiveUniform( program, i ),
  10559. addr = gl.getUniformLocation( program, info.name );
  10560. parseUniform( info, addr, this );
  10561. }
  10562. }
  10563. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10564. var u = this.map[ name ];
  10565. if ( u !== undefined ) u.setValue( gl, value, textures );
  10566. };
  10567. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10568. var v = object[ name ];
  10569. if ( v !== undefined ) this.setValue( gl, name, v );
  10570. };
  10571. // Static interface
  10572. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10573. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10574. var u = seq[ i ],
  10575. v = values[ u.id ];
  10576. if ( v.needsUpdate !== false ) {
  10577. // note: always updating when .needsUpdate is undefined
  10578. u.setValue( gl, v.value, textures );
  10579. }
  10580. }
  10581. };
  10582. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10583. var r = [];
  10584. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10585. var u = seq[ i ];
  10586. if ( u.id in values ) r.push( u );
  10587. }
  10588. return r;
  10589. };
  10590. /**
  10591. * @author mrdoob / http://mrdoob.com/
  10592. */
  10593. function WebGLShader( gl, type, string ) {
  10594. var shader = gl.createShader( type );
  10595. gl.shaderSource( shader, string );
  10596. gl.compileShader( shader );
  10597. return shader;
  10598. }
  10599. /**
  10600. * @author mrdoob / http://mrdoob.com/
  10601. */
  10602. var programIdCount = 0;
  10603. function addLineNumbers( string ) {
  10604. var lines = string.split( '\n' );
  10605. for ( var i = 0; i < lines.length; i ++ ) {
  10606. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10607. }
  10608. return lines.join( '\n' );
  10609. }
  10610. function getEncodingComponents( encoding ) {
  10611. switch ( encoding ) {
  10612. case LinearEncoding:
  10613. return [ 'Linear', '( value )' ];
  10614. case sRGBEncoding:
  10615. return [ 'sRGB', '( value )' ];
  10616. case RGBEEncoding:
  10617. return [ 'RGBE', '( value )' ];
  10618. case RGBM7Encoding:
  10619. return [ 'RGBM', '( value, 7.0 )' ];
  10620. case RGBM16Encoding:
  10621. return [ 'RGBM', '( value, 16.0 )' ];
  10622. case RGBDEncoding:
  10623. return [ 'RGBD', '( value, 256.0 )' ];
  10624. case GammaEncoding:
  10625. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10626. case LogLuvEncoding:
  10627. return [ 'LogLuv', '( value )' ];
  10628. default:
  10629. throw new Error( 'unsupported encoding: ' + encoding );
  10630. }
  10631. }
  10632. function getShaderErrors( gl, shader, type ) {
  10633. var status = gl.getShaderParameter( shader, 35713 );
  10634. var log = gl.getShaderInfoLog( shader ).trim();
  10635. if ( status && log === '' ) return '';
  10636. // --enable-privileged-webgl-extension
  10637. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10638. var source = gl.getShaderSource( shader );
  10639. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10640. }
  10641. function getTexelDecodingFunction( functionName, encoding ) {
  10642. var components = getEncodingComponents( encoding );
  10643. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10644. }
  10645. function getTexelEncodingFunction( functionName, encoding ) {
  10646. var components = getEncodingComponents( encoding );
  10647. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10648. }
  10649. function getToneMappingFunction( functionName, toneMapping ) {
  10650. var toneMappingName;
  10651. switch ( toneMapping ) {
  10652. case LinearToneMapping:
  10653. toneMappingName = 'Linear';
  10654. break;
  10655. case ReinhardToneMapping:
  10656. toneMappingName = 'Reinhard';
  10657. break;
  10658. case Uncharted2ToneMapping:
  10659. toneMappingName = 'Uncharted2';
  10660. break;
  10661. case CineonToneMapping:
  10662. toneMappingName = 'OptimizedCineon';
  10663. break;
  10664. case ACESFilmicToneMapping:
  10665. toneMappingName = 'ACESFilmic';
  10666. break;
  10667. default:
  10668. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10669. }
  10670. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10671. }
  10672. function generateExtensions( parameters ) {
  10673. var chunks = [
  10674. ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10675. ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
  10676. ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10677. ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10678. ];
  10679. return chunks.filter( filterEmptyLine ).join( '\n' );
  10680. }
  10681. function generateDefines( defines ) {
  10682. var chunks = [];
  10683. for ( var name in defines ) {
  10684. var value = defines[ name ];
  10685. if ( value === false ) continue;
  10686. chunks.push( '#define ' + name + ' ' + value );
  10687. }
  10688. return chunks.join( '\n' );
  10689. }
  10690. function fetchAttributeLocations( gl, program ) {
  10691. var attributes = {};
  10692. var n = gl.getProgramParameter( program, 35721 );
  10693. for ( var i = 0; i < n; i ++ ) {
  10694. var info = gl.getActiveAttrib( program, i );
  10695. var name = info.name;
  10696. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10697. attributes[ name ] = gl.getAttribLocation( program, name );
  10698. }
  10699. return attributes;
  10700. }
  10701. function filterEmptyLine( string ) {
  10702. return string !== '';
  10703. }
  10704. function replaceLightNums( string, parameters ) {
  10705. return string
  10706. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10707. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10708. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10709. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10710. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  10711. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  10712. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  10713. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  10714. }
  10715. function replaceClippingPlaneNums( string, parameters ) {
  10716. return string
  10717. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10718. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10719. }
  10720. // Resolve Includes
  10721. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10722. function resolveIncludes( string ) {
  10723. return string.replace( includePattern, includeReplacer );
  10724. }
  10725. function includeReplacer( match, include ) {
  10726. var string = ShaderChunk[ include ];
  10727. if ( string === undefined ) {
  10728. throw new Error( 'Can not resolve #include <' + include + '>' );
  10729. }
  10730. return resolveIncludes( string );
  10731. }
  10732. // Unroll Loops
  10733. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10734. var unrollLoopPattern = /#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g;
  10735. function unrollLoops( string ) {
  10736. return string
  10737. .replace( unrollLoopPattern, loopReplacer )
  10738. .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer );
  10739. }
  10740. function deprecatedLoopReplacer( match, start, end, snippet ) {
  10741. console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' );
  10742. return loopReplacer( match, start, end, snippet );
  10743. }
  10744. function loopReplacer( match, start, end, snippet ) {
  10745. var string = '';
  10746. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10747. string += snippet
  10748. .replace( /\[ i \]/g, '[ ' + i + ' ]' )
  10749. .replace( /UNROLLED_LOOP_INDEX/g, i );
  10750. }
  10751. return string;
  10752. }
  10753. //
  10754. function generatePrecision( parameters ) {
  10755. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10756. if ( parameters.precision === "highp" ) {
  10757. precisionstring += "\n#define HIGH_PRECISION";
  10758. } else if ( parameters.precision === "mediump" ) {
  10759. precisionstring += "\n#define MEDIUM_PRECISION";
  10760. } else if ( parameters.precision === "lowp" ) {
  10761. precisionstring += "\n#define LOW_PRECISION";
  10762. }
  10763. return precisionstring;
  10764. }
  10765. function generateShadowMapTypeDefine( parameters ) {
  10766. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10767. if ( parameters.shadowMapType === PCFShadowMap ) {
  10768. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10769. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10770. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10771. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  10772. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10773. }
  10774. return shadowMapTypeDefine;
  10775. }
  10776. function generateEnvMapTypeDefine( parameters ) {
  10777. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10778. if ( parameters.envMap ) {
  10779. switch ( parameters.envMapMode ) {
  10780. case CubeReflectionMapping:
  10781. case CubeRefractionMapping:
  10782. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10783. break;
  10784. case CubeUVReflectionMapping:
  10785. case CubeUVRefractionMapping:
  10786. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10787. break;
  10788. case EquirectangularReflectionMapping:
  10789. case EquirectangularRefractionMapping:
  10790. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10791. break;
  10792. case SphericalReflectionMapping:
  10793. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10794. break;
  10795. }
  10796. }
  10797. return envMapTypeDefine;
  10798. }
  10799. function generateEnvMapModeDefine( parameters ) {
  10800. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10801. if ( parameters.envMap ) {
  10802. switch ( parameters.envMapMode ) {
  10803. case CubeRefractionMapping:
  10804. case EquirectangularRefractionMapping:
  10805. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10806. break;
  10807. }
  10808. }
  10809. return envMapModeDefine;
  10810. }
  10811. function generateEnvMapBlendingDefine( parameters ) {
  10812. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10813. if ( parameters.envMap ) {
  10814. switch ( parameters.combine ) {
  10815. case MultiplyOperation:
  10816. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10817. break;
  10818. case MixOperation:
  10819. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10820. break;
  10821. case AddOperation:
  10822. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10823. break;
  10824. }
  10825. }
  10826. return envMapBlendingDefine;
  10827. }
  10828. function WebGLProgram( renderer, cacheKey, parameters ) {
  10829. var gl = renderer.getContext();
  10830. var defines = parameters.defines;
  10831. var vertexShader = parameters.vertexShader;
  10832. var fragmentShader = parameters.fragmentShader;
  10833. var shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  10834. var envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  10835. var envMapModeDefine = generateEnvMapModeDefine( parameters );
  10836. var envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  10837. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10838. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
  10839. var customDefines = generateDefines( defines );
  10840. var program = gl.createProgram();
  10841. var prefixVertex, prefixFragment;
  10842. if ( parameters.isRawShaderMaterial ) {
  10843. prefixVertex = [
  10844. customDefines
  10845. ].filter( filterEmptyLine ).join( '\n' );
  10846. if ( prefixVertex.length > 0 ) {
  10847. prefixVertex += '\n';
  10848. }
  10849. prefixFragment = [
  10850. customExtensions,
  10851. customDefines
  10852. ].filter( filterEmptyLine ).join( '\n' );
  10853. if ( prefixFragment.length > 0 ) {
  10854. prefixFragment += '\n';
  10855. }
  10856. } else {
  10857. prefixVertex = [
  10858. generatePrecision( parameters ),
  10859. '#define SHADER_NAME ' + parameters.shaderName,
  10860. customDefines,
  10861. parameters.instancing ? '#define USE_INSTANCING' : '',
  10862. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10863. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10864. '#define MAX_BONES ' + parameters.maxBones,
  10865. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10866. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10867. parameters.map ? '#define USE_MAP' : '',
  10868. parameters.envMap ? '#define USE_ENVMAP' : '',
  10869. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10870. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10871. parameters.aoMap ? '#define USE_AOMAP' : '',
  10872. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10873. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10874. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10875. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10876. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10877. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10878. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10879. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10880. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10881. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10882. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10883. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10884. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10885. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10886. parameters.vertexColors ? '#define USE_COLOR' : '',
  10887. parameters.vertexUvs ? '#define USE_UV' : '',
  10888. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10889. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10890. parameters.skinning ? '#define USE_SKINNING' : '',
  10891. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10892. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10893. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10894. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10895. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10896. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10897. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10898. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10899. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10900. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10901. 'uniform mat4 modelMatrix;',
  10902. 'uniform mat4 modelViewMatrix;',
  10903. 'uniform mat4 projectionMatrix;',
  10904. 'uniform mat4 viewMatrix;',
  10905. 'uniform mat3 normalMatrix;',
  10906. 'uniform vec3 cameraPosition;',
  10907. 'uniform bool isOrthographic;',
  10908. '#ifdef USE_INSTANCING',
  10909. ' attribute mat4 instanceMatrix;',
  10910. '#endif',
  10911. 'attribute vec3 position;',
  10912. 'attribute vec3 normal;',
  10913. 'attribute vec2 uv;',
  10914. '#ifdef USE_TANGENT',
  10915. ' attribute vec4 tangent;',
  10916. '#endif',
  10917. '#ifdef USE_COLOR',
  10918. ' attribute vec3 color;',
  10919. '#endif',
  10920. '#ifdef USE_MORPHTARGETS',
  10921. ' attribute vec3 morphTarget0;',
  10922. ' attribute vec3 morphTarget1;',
  10923. ' attribute vec3 morphTarget2;',
  10924. ' attribute vec3 morphTarget3;',
  10925. ' #ifdef USE_MORPHNORMALS',
  10926. ' attribute vec3 morphNormal0;',
  10927. ' attribute vec3 morphNormal1;',
  10928. ' attribute vec3 morphNormal2;',
  10929. ' attribute vec3 morphNormal3;',
  10930. ' #else',
  10931. ' attribute vec3 morphTarget4;',
  10932. ' attribute vec3 morphTarget5;',
  10933. ' attribute vec3 morphTarget6;',
  10934. ' attribute vec3 morphTarget7;',
  10935. ' #endif',
  10936. '#endif',
  10937. '#ifdef USE_SKINNING',
  10938. ' attribute vec4 skinIndex;',
  10939. ' attribute vec4 skinWeight;',
  10940. '#endif',
  10941. '\n'
  10942. ].filter( filterEmptyLine ).join( '\n' );
  10943. prefixFragment = [
  10944. customExtensions,
  10945. generatePrecision( parameters ),
  10946. '#define SHADER_NAME ' + parameters.shaderName,
  10947. customDefines,
  10948. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10949. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10950. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10951. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10952. parameters.map ? '#define USE_MAP' : '',
  10953. parameters.matcap ? '#define USE_MATCAP' : '',
  10954. parameters.envMap ? '#define USE_ENVMAP' : '',
  10955. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10956. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10957. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10958. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10959. parameters.aoMap ? '#define USE_AOMAP' : '',
  10960. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10961. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10962. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10963. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10964. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10965. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10966. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10967. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10968. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10969. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10970. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10971. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10972. parameters.sheen ? '#define USE_SHEEN' : '',
  10973. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10974. parameters.vertexColors ? '#define USE_COLOR' : '',
  10975. parameters.vertexUvs ? '#define USE_UV' : '',
  10976. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10977. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10978. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10979. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10980. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10981. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10982. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10983. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10984. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10985. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10986. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10987. ( ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ) ? '#define TEXTURE_LOD_EXT' : '',
  10988. 'uniform mat4 viewMatrix;',
  10989. 'uniform vec3 cameraPosition;',
  10990. 'uniform bool isOrthographic;',
  10991. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10992. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10993. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10994. parameters.dithering ? '#define DITHERING' : '',
  10995. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding || parameters.lightMapEncoding ) ?
  10996. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10997. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10998. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10999. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  11000. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  11001. parameters.lightMapEncoding ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
  11002. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  11003. parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
  11004. '\n'
  11005. ].filter( filterEmptyLine ).join( '\n' );
  11006. }
  11007. vertexShader = resolveIncludes( vertexShader );
  11008. vertexShader = replaceLightNums( vertexShader, parameters );
  11009. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  11010. fragmentShader = resolveIncludes( fragmentShader );
  11011. fragmentShader = replaceLightNums( fragmentShader, parameters );
  11012. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  11013. vertexShader = unrollLoops( vertexShader );
  11014. fragmentShader = unrollLoops( fragmentShader );
  11015. if ( parameters.isWebGL2 && ! parameters.isRawShaderMaterial ) {
  11016. var isGLSL3ShaderMaterial = false;
  11017. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  11018. if ( parameters.isShaderMaterial &&
  11019. vertexShader.match( versionRegex ) !== null &&
  11020. fragmentShader.match( versionRegex ) !== null ) {
  11021. isGLSL3ShaderMaterial = true;
  11022. vertexShader = vertexShader.replace( versionRegex, '' );
  11023. fragmentShader = fragmentShader.replace( versionRegex, '' );
  11024. }
  11025. // GLSL 3.0 conversion
  11026. prefixVertex = [
  11027. '#version 300 es\n',
  11028. '#define attribute in',
  11029. '#define varying out',
  11030. '#define texture2D texture'
  11031. ].join( '\n' ) + '\n' + prefixVertex;
  11032. prefixFragment = [
  11033. '#version 300 es\n',
  11034. '#define varying in',
  11035. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  11036. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  11037. '#define gl_FragDepthEXT gl_FragDepth',
  11038. '#define texture2D texture',
  11039. '#define textureCube texture',
  11040. '#define texture2DProj textureProj',
  11041. '#define texture2DLodEXT textureLod',
  11042. '#define texture2DProjLodEXT textureProjLod',
  11043. '#define textureCubeLodEXT textureLod',
  11044. '#define texture2DGradEXT textureGrad',
  11045. '#define texture2DProjGradEXT textureProjGrad',
  11046. '#define textureCubeGradEXT textureGrad'
  11047. ].join( '\n' ) + '\n' + prefixFragment;
  11048. }
  11049. var vertexGlsl = prefixVertex + vertexShader;
  11050. var fragmentGlsl = prefixFragment + fragmentShader;
  11051. // console.log( '*VERTEX*', vertexGlsl );
  11052. // console.log( '*FRAGMENT*', fragmentGlsl );
  11053. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  11054. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  11055. gl.attachShader( program, glVertexShader );
  11056. gl.attachShader( program, glFragmentShader );
  11057. // Force a particular attribute to index 0.
  11058. if ( parameters.index0AttributeName !== undefined ) {
  11059. gl.bindAttribLocation( program, 0, parameters.index0AttributeName );
  11060. } else if ( parameters.morphTargets === true ) {
  11061. // programs with morphTargets displace position out of attribute 0
  11062. gl.bindAttribLocation( program, 0, 'position' );
  11063. }
  11064. gl.linkProgram( program );
  11065. // check for link errors
  11066. if ( renderer.debug.checkShaderErrors ) {
  11067. var programLog = gl.getProgramInfoLog( program ).trim();
  11068. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  11069. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  11070. var runnable = true;
  11071. var haveDiagnostics = true;
  11072. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  11073. runnable = false;
  11074. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  11075. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  11076. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  11077. } else if ( programLog !== '' ) {
  11078. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  11079. } else if ( vertexLog === '' || fragmentLog === '' ) {
  11080. haveDiagnostics = false;
  11081. }
  11082. if ( haveDiagnostics ) {
  11083. this.diagnostics = {
  11084. runnable: runnable,
  11085. programLog: programLog,
  11086. vertexShader: {
  11087. log: vertexLog,
  11088. prefix: prefixVertex
  11089. },
  11090. fragmentShader: {
  11091. log: fragmentLog,
  11092. prefix: prefixFragment
  11093. }
  11094. };
  11095. }
  11096. }
  11097. // Clean up
  11098. // Crashes in iOS9 and iOS10. #18402
  11099. // gl.detachShader( program, glVertexShader );
  11100. // gl.detachShader( program, glFragmentShader );
  11101. gl.deleteShader( glVertexShader );
  11102. gl.deleteShader( glFragmentShader );
  11103. // set up caching for uniform locations
  11104. var cachedUniforms;
  11105. this.getUniforms = function () {
  11106. if ( cachedUniforms === undefined ) {
  11107. cachedUniforms = new WebGLUniforms( gl, program );
  11108. }
  11109. return cachedUniforms;
  11110. };
  11111. // set up caching for attribute locations
  11112. var cachedAttributes;
  11113. this.getAttributes = function () {
  11114. if ( cachedAttributes === undefined ) {
  11115. cachedAttributes = fetchAttributeLocations( gl, program );
  11116. }
  11117. return cachedAttributes;
  11118. };
  11119. // free resource
  11120. this.destroy = function () {
  11121. gl.deleteProgram( program );
  11122. this.program = undefined;
  11123. };
  11124. //
  11125. this.name = parameters.shaderName;
  11126. this.id = programIdCount ++;
  11127. this.cacheKey = cacheKey;
  11128. this.usedTimes = 1;
  11129. this.program = program;
  11130. this.vertexShader = glVertexShader;
  11131. this.fragmentShader = glFragmentShader;
  11132. return this;
  11133. }
  11134. /**
  11135. * @author mrdoob / http://mrdoob.com/
  11136. */
  11137. function WebGLPrograms( renderer, extensions, capabilities ) {
  11138. var programs = [];
  11139. var isWebGL2 = capabilities.isWebGL2;
  11140. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11141. var floatVertexTextures = capabilities.floatVertexTextures;
  11142. var precision = capabilities.precision;
  11143. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11144. var vertexTextures = capabilities.vertexTextures;
  11145. var shaderIDs = {
  11146. MeshDepthMaterial: 'depth',
  11147. MeshDistanceMaterial: 'distanceRGBA',
  11148. MeshNormalMaterial: 'normal',
  11149. MeshBasicMaterial: 'basic',
  11150. MeshLambertMaterial: 'lambert',
  11151. MeshPhongMaterial: 'phong',
  11152. MeshToonMaterial: 'toon',
  11153. MeshStandardMaterial: 'physical',
  11154. MeshPhysicalMaterial: 'physical',
  11155. MeshMatcapMaterial: 'matcap',
  11156. LineBasicMaterial: 'basic',
  11157. LineDashedMaterial: 'dashed',
  11158. PointsMaterial: 'points',
  11159. ShadowMaterial: 'shadow',
  11160. SpriteMaterial: 'sprite'
  11161. };
  11162. var parameterNames = [
  11163. "precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing",
  11164. "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding", "envMapCubeUV",
  11165. "lightMap", "lightMapEncoding", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "tangentSpaceNormalMap", "clearcoatMap", "clearcoatRoughnessMap", "clearcoatNormalMap", "displacementMap", "specularMap",
  11166. "roughnessMap", "metalnessMap", "gradientMap",
  11167. "alphaMap", "combine", "vertexColors", "vertexTangents", "vertexUvs", "uvsVertexOnly", "fog", "useFog", "fogExp2",
  11168. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  11169. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  11170. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  11171. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  11172. "numDirLightShadows", "numPointLightShadows", "numSpotLightShadows",
  11173. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  11174. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering",
  11175. "sheen"
  11176. ];
  11177. function getShaderObject( material, shaderID ) {
  11178. var shaderobject;
  11179. if ( shaderID ) {
  11180. var shader = ShaderLib[ shaderID ];
  11181. shaderobject = {
  11182. name: material.type,
  11183. uniforms: UniformsUtils.clone( shader.uniforms ),
  11184. vertexShader: shader.vertexShader,
  11185. fragmentShader: shader.fragmentShader
  11186. };
  11187. } else {
  11188. shaderobject = {
  11189. name: material.type,
  11190. uniforms: material.uniforms,
  11191. vertexShader: material.vertexShader,
  11192. fragmentShader: material.fragmentShader
  11193. };
  11194. }
  11195. return shaderobject;
  11196. }
  11197. function allocateBones( object ) {
  11198. var skeleton = object.skeleton;
  11199. var bones = skeleton.bones;
  11200. if ( floatVertexTextures ) {
  11201. return 1024;
  11202. } else {
  11203. // default for when object is not specified
  11204. // ( for example when prebuilding shader to be used with multiple objects )
  11205. //
  11206. // - leave some extra space for other uniforms
  11207. // - limit here is ANGLE's 254 max uniform vectors
  11208. // (up to 54 should be safe)
  11209. var nVertexUniforms = maxVertexUniforms;
  11210. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  11211. var maxBones = Math.min( nVertexMatrices, bones.length );
  11212. if ( maxBones < bones.length ) {
  11213. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  11214. return 0;
  11215. }
  11216. return maxBones;
  11217. }
  11218. }
  11219. function getTextureEncodingFromMap( map ) {
  11220. var encoding;
  11221. if ( ! map ) {
  11222. encoding = LinearEncoding;
  11223. } else if ( map.isTexture ) {
  11224. encoding = map.encoding;
  11225. } else if ( map.isWebGLRenderTarget ) {
  11226. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  11227. encoding = map.texture.encoding;
  11228. }
  11229. return encoding;
  11230. }
  11231. this.getParameters = function ( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) {
  11232. var fog = scene.fog;
  11233. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11234. var envMap = material.envMap || environment;
  11235. var shaderID = shaderIDs[ material.type ];
  11236. // heuristics to create shader parameters according to lights in the scene
  11237. // (not to blow over maxLights budget)
  11238. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  11239. if ( material.precision !== null ) {
  11240. precision = capabilities.getMaxPrecision( material.precision );
  11241. if ( precision !== material.precision ) {
  11242. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11243. }
  11244. }
  11245. var shaderobject = getShaderObject( material, shaderID );
  11246. material.onBeforeCompile( shaderobject, renderer );
  11247. var currentRenderTarget = renderer.getRenderTarget();
  11248. var parameters = {
  11249. isWebGL2: isWebGL2,
  11250. shaderID: shaderID,
  11251. shaderName: shaderobject.name,
  11252. uniforms: shaderobject.uniforms,
  11253. vertexShader: shaderobject.vertexShader,
  11254. fragmentShader: shaderobject.fragmentShader,
  11255. defines: material.defines,
  11256. isRawShaderMaterial: material.isRawShaderMaterial,
  11257. isShaderMaterial: material.isShaderMaterial,
  11258. precision: precision,
  11259. instancing: object.isInstancedMesh === true,
  11260. supportsVertexTextures: vertexTextures,
  11261. outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
  11262. map: !! material.map,
  11263. mapEncoding: getTextureEncodingFromMap( material.map ),
  11264. matcap: !! material.matcap,
  11265. matcapEncoding: getTextureEncodingFromMap( material.matcap ),
  11266. envMap: !! envMap,
  11267. envMapMode: envMap && envMap.mapping,
  11268. envMapEncoding: getTextureEncodingFromMap( envMap ),
  11269. envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
  11270. lightMap: !! material.lightMap,
  11271. lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
  11272. aoMap: !! material.aoMap,
  11273. emissiveMap: !! material.emissiveMap,
  11274. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
  11275. bumpMap: !! material.bumpMap,
  11276. normalMap: !! material.normalMap,
  11277. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11278. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11279. clearcoatMap: !! material.clearcoatMap,
  11280. clearcoatRoughnessMap: !! material.clearcoatRoughnessMap,
  11281. clearcoatNormalMap: !! material.clearcoatNormalMap,
  11282. displacementMap: !! material.displacementMap,
  11283. roughnessMap: !! material.roughnessMap,
  11284. metalnessMap: !! material.metalnessMap,
  11285. specularMap: !! material.specularMap,
  11286. alphaMap: !! material.alphaMap,
  11287. gradientMap: !! material.gradientMap,
  11288. sheen: !! material.sheen,
  11289. combine: material.combine,
  11290. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11291. vertexColors: material.vertexColors,
  11292. 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,
  11293. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap ) && !! material.displacementMap,
  11294. fog: !! fog,
  11295. useFog: material.fog,
  11296. fogExp2: ( fog && fog.isFogExp2 ),
  11297. flatShading: material.flatShading,
  11298. sizeAttenuation: material.sizeAttenuation,
  11299. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11300. skinning: material.skinning && maxBones > 0,
  11301. maxBones: maxBones,
  11302. useVertexTexture: floatVertexTextures,
  11303. morphTargets: material.morphTargets,
  11304. morphNormals: material.morphNormals,
  11305. maxMorphTargets: renderer.maxMorphTargets,
  11306. maxMorphNormals: renderer.maxMorphNormals,
  11307. numDirLights: lights.directional.length,
  11308. numPointLights: lights.point.length,
  11309. numSpotLights: lights.spot.length,
  11310. numRectAreaLights: lights.rectArea.length,
  11311. numHemiLights: lights.hemi.length,
  11312. numDirLightShadows: lights.directionalShadowMap.length,
  11313. numPointLightShadows: lights.pointShadowMap.length,
  11314. numSpotLightShadows: lights.spotShadowMap.length,
  11315. numClippingPlanes: nClipPlanes,
  11316. numClipIntersection: nClipIntersection,
  11317. dithering: material.dithering,
  11318. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11319. shadowMapType: renderer.shadowMap.type,
  11320. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11321. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11322. premultipliedAlpha: material.premultipliedAlpha,
  11323. alphaTest: material.alphaTest,
  11324. doubleSided: material.side === DoubleSide,
  11325. flipSided: material.side === BackSide,
  11326. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
  11327. index0AttributeName: material.index0AttributeName,
  11328. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11329. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11330. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11331. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11332. rendererExtensionFragDepth: isWebGL2 || extensions.get( 'EXT_frag_depth' ) !== null,
  11333. rendererExtensionDrawBuffers: isWebGL2 || extensions.get( 'WEBGL_draw_buffers' ) !== null,
  11334. rendererExtensionShaderTextureLod: isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) !== null,
  11335. onBeforeCompile: material.onBeforeCompile
  11336. };
  11337. return parameters;
  11338. };
  11339. this.getProgramCacheKey = function ( parameters ) {
  11340. var array = [];
  11341. if ( parameters.shaderID ) {
  11342. array.push( parameters.shaderID );
  11343. } else {
  11344. array.push( parameters.fragmentShader );
  11345. array.push( parameters.vertexShader );
  11346. }
  11347. if ( parameters.defines !== undefined ) {
  11348. for ( var name in parameters.defines ) {
  11349. array.push( name );
  11350. array.push( parameters.defines[ name ] );
  11351. }
  11352. }
  11353. if ( parameters.isRawShaderMaterial === undefined ) {
  11354. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11355. array.push( parameters[ parameterNames[ i ] ] );
  11356. }
  11357. array.push( renderer.outputEncoding );
  11358. array.push( renderer.gammaFactor );
  11359. }
  11360. array.push( parameters.onBeforeCompile.toString() );
  11361. return array.join();
  11362. };
  11363. this.acquireProgram = function ( parameters, cacheKey ) {
  11364. var program;
  11365. // Check if code has been already compiled
  11366. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11367. var preexistingProgram = programs[ p ];
  11368. if ( preexistingProgram.cacheKey === cacheKey ) {
  11369. program = preexistingProgram;
  11370. ++ program.usedTimes;
  11371. break;
  11372. }
  11373. }
  11374. if ( program === undefined ) {
  11375. program = new WebGLProgram( renderer, cacheKey, parameters );
  11376. programs.push( program );
  11377. }
  11378. return program;
  11379. };
  11380. this.releaseProgram = function ( program ) {
  11381. if ( -- program.usedTimes === 0 ) {
  11382. // Remove from unordered set
  11383. var i = programs.indexOf( program );
  11384. programs[ i ] = programs[ programs.length - 1 ];
  11385. programs.pop();
  11386. // Free WebGL resources
  11387. program.destroy();
  11388. }
  11389. };
  11390. // Exposed for resource monitoring & error feedback via renderer.info:
  11391. this.programs = programs;
  11392. }
  11393. /**
  11394. * @author fordacious / fordacious.github.io
  11395. */
  11396. function WebGLProperties() {
  11397. var properties = new WeakMap();
  11398. function get( object ) {
  11399. var map = properties.get( object );
  11400. if ( map === undefined ) {
  11401. map = {};
  11402. properties.set( object, map );
  11403. }
  11404. return map;
  11405. }
  11406. function remove( object ) {
  11407. properties.delete( object );
  11408. }
  11409. function update( object, key, value ) {
  11410. properties.get( object )[ key ] = value;
  11411. }
  11412. function dispose() {
  11413. properties = new WeakMap();
  11414. }
  11415. return {
  11416. get: get,
  11417. remove: remove,
  11418. update: update,
  11419. dispose: dispose
  11420. };
  11421. }
  11422. /**
  11423. * @author mrdoob / http://mrdoob.com/
  11424. */
  11425. function painterSortStable( a, b ) {
  11426. if ( a.groupOrder !== b.groupOrder ) {
  11427. return a.groupOrder - b.groupOrder;
  11428. } else if ( a.renderOrder !== b.renderOrder ) {
  11429. return a.renderOrder - b.renderOrder;
  11430. } else if ( a.program !== b.program ) {
  11431. return a.program.id - b.program.id;
  11432. } else if ( a.material.id !== b.material.id ) {
  11433. return a.material.id - b.material.id;
  11434. } else if ( a.z !== b.z ) {
  11435. return a.z - b.z;
  11436. } else {
  11437. return a.id - b.id;
  11438. }
  11439. }
  11440. function reversePainterSortStable( a, b ) {
  11441. if ( a.groupOrder !== b.groupOrder ) {
  11442. return a.groupOrder - b.groupOrder;
  11443. } else if ( a.renderOrder !== b.renderOrder ) {
  11444. return a.renderOrder - b.renderOrder;
  11445. } else if ( a.z !== b.z ) {
  11446. return b.z - a.z;
  11447. } else {
  11448. return a.id - b.id;
  11449. }
  11450. }
  11451. function WebGLRenderList() {
  11452. var renderItems = [];
  11453. var renderItemsIndex = 0;
  11454. var opaque = [];
  11455. var transparent = [];
  11456. var defaultProgram = { id: - 1 };
  11457. function init() {
  11458. renderItemsIndex = 0;
  11459. opaque.length = 0;
  11460. transparent.length = 0;
  11461. }
  11462. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11463. var renderItem = renderItems[ renderItemsIndex ];
  11464. if ( renderItem === undefined ) {
  11465. renderItem = {
  11466. id: object.id,
  11467. object: object,
  11468. geometry: geometry,
  11469. material: material,
  11470. program: material.program || defaultProgram,
  11471. groupOrder: groupOrder,
  11472. renderOrder: object.renderOrder,
  11473. z: z,
  11474. group: group
  11475. };
  11476. renderItems[ renderItemsIndex ] = renderItem;
  11477. } else {
  11478. renderItem.id = object.id;
  11479. renderItem.object = object;
  11480. renderItem.geometry = geometry;
  11481. renderItem.material = material;
  11482. renderItem.program = material.program || defaultProgram;
  11483. renderItem.groupOrder = groupOrder;
  11484. renderItem.renderOrder = object.renderOrder;
  11485. renderItem.z = z;
  11486. renderItem.group = group;
  11487. }
  11488. renderItemsIndex ++;
  11489. return renderItem;
  11490. }
  11491. function push( object, geometry, material, groupOrder, z, group ) {
  11492. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11493. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11494. }
  11495. function unshift( object, geometry, material, groupOrder, z, group ) {
  11496. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11497. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11498. }
  11499. function sort( customOpaqueSort, customTransparentSort ) {
  11500. if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );
  11501. if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );
  11502. }
  11503. function finish() {
  11504. // Clear references from inactive renderItems in the list
  11505. for ( var i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
  11506. var renderItem = renderItems[ i ];
  11507. if ( renderItem.id === null ) break;
  11508. renderItem.id = null;
  11509. renderItem.object = null;
  11510. renderItem.geometry = null;
  11511. renderItem.material = null;
  11512. renderItem.program = null;
  11513. renderItem.group = null;
  11514. }
  11515. }
  11516. return {
  11517. opaque: opaque,
  11518. transparent: transparent,
  11519. init: init,
  11520. push: push,
  11521. unshift: unshift,
  11522. finish: finish,
  11523. sort: sort
  11524. };
  11525. }
  11526. function WebGLRenderLists() {
  11527. var lists = new WeakMap();
  11528. function onSceneDispose( event ) {
  11529. var scene = event.target;
  11530. scene.removeEventListener( 'dispose', onSceneDispose );
  11531. lists.delete( scene );
  11532. }
  11533. function get( scene, camera ) {
  11534. var cameras = lists.get( scene );
  11535. var list;
  11536. if ( cameras === undefined ) {
  11537. list = new WebGLRenderList();
  11538. lists.set( scene, new WeakMap() );
  11539. lists.get( scene ).set( camera, list );
  11540. scene.addEventListener( 'dispose', onSceneDispose );
  11541. } else {
  11542. list = cameras.get( camera );
  11543. if ( list === undefined ) {
  11544. list = new WebGLRenderList();
  11545. cameras.set( camera, list );
  11546. }
  11547. }
  11548. return list;
  11549. }
  11550. function dispose() {
  11551. lists = new WeakMap();
  11552. }
  11553. return {
  11554. get: get,
  11555. dispose: dispose
  11556. };
  11557. }
  11558. /**
  11559. * @author mrdoob / http://mrdoob.com/
  11560. */
  11561. function UniformsCache() {
  11562. var lights = {};
  11563. return {
  11564. get: function ( light ) {
  11565. if ( lights[ light.id ] !== undefined ) {
  11566. return lights[ light.id ];
  11567. }
  11568. var uniforms;
  11569. switch ( light.type ) {
  11570. case 'DirectionalLight':
  11571. uniforms = {
  11572. direction: new Vector3(),
  11573. color: new Color()
  11574. };
  11575. break;
  11576. case 'SpotLight':
  11577. uniforms = {
  11578. position: new Vector3(),
  11579. direction: new Vector3(),
  11580. color: new Color(),
  11581. distance: 0,
  11582. coneCos: 0,
  11583. penumbraCos: 0,
  11584. decay: 0
  11585. };
  11586. break;
  11587. case 'PointLight':
  11588. uniforms = {
  11589. position: new Vector3(),
  11590. color: new Color(),
  11591. distance: 0,
  11592. decay: 0
  11593. };
  11594. break;
  11595. case 'HemisphereLight':
  11596. uniforms = {
  11597. direction: new Vector3(),
  11598. skyColor: new Color(),
  11599. groundColor: new Color()
  11600. };
  11601. break;
  11602. case 'RectAreaLight':
  11603. uniforms = {
  11604. color: new Color(),
  11605. position: new Vector3(),
  11606. halfWidth: new Vector3(),
  11607. halfHeight: new Vector3()
  11608. };
  11609. break;
  11610. }
  11611. lights[ light.id ] = uniforms;
  11612. return uniforms;
  11613. }
  11614. };
  11615. }
  11616. function ShadowUniformsCache() {
  11617. var lights = {};
  11618. return {
  11619. get: function ( light ) {
  11620. if ( lights[ light.id ] !== undefined ) {
  11621. return lights[ light.id ];
  11622. }
  11623. var uniforms;
  11624. switch ( light.type ) {
  11625. case 'DirectionalLight':
  11626. uniforms = {
  11627. shadowBias: 0,
  11628. shadowRadius: 1,
  11629. shadowMapSize: new Vector2()
  11630. };
  11631. break;
  11632. case 'SpotLight':
  11633. uniforms = {
  11634. shadowBias: 0,
  11635. shadowRadius: 1,
  11636. shadowMapSize: new Vector2()
  11637. };
  11638. break;
  11639. case 'PointLight':
  11640. uniforms = {
  11641. shadowBias: 0,
  11642. shadowRadius: 1,
  11643. shadowMapSize: new Vector2(),
  11644. shadowCameraNear: 1,
  11645. shadowCameraFar: 1000
  11646. };
  11647. break;
  11648. // TODO (abelnation): set RectAreaLight shadow uniforms
  11649. }
  11650. lights[ light.id ] = uniforms;
  11651. return uniforms;
  11652. }
  11653. };
  11654. }
  11655. var nextVersion = 0;
  11656. function shadowCastingLightsFirst( lightA, lightB ) {
  11657. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  11658. }
  11659. function WebGLLights() {
  11660. var cache = new UniformsCache();
  11661. var shadowCache = ShadowUniformsCache();
  11662. var state = {
  11663. version: 0,
  11664. hash: {
  11665. directionalLength: - 1,
  11666. pointLength: - 1,
  11667. spotLength: - 1,
  11668. rectAreaLength: - 1,
  11669. hemiLength: - 1,
  11670. numDirectionalShadows: - 1,
  11671. numPointShadows: - 1,
  11672. numSpotShadows: - 1
  11673. },
  11674. ambient: [ 0, 0, 0 ],
  11675. probe: [],
  11676. directional: [],
  11677. directionalShadow: [],
  11678. directionalShadowMap: [],
  11679. directionalShadowMatrix: [],
  11680. spot: [],
  11681. spotShadow: [],
  11682. spotShadowMap: [],
  11683. spotShadowMatrix: [],
  11684. rectArea: [],
  11685. point: [],
  11686. pointShadow: [],
  11687. pointShadowMap: [],
  11688. pointShadowMatrix: [],
  11689. hemi: []
  11690. };
  11691. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11692. var vector3 = new Vector3();
  11693. var matrix4 = new Matrix4();
  11694. var matrix42 = new Matrix4();
  11695. function setup( lights, shadows, camera ) {
  11696. var r = 0, g = 0, b = 0;
  11697. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11698. var directionalLength = 0;
  11699. var pointLength = 0;
  11700. var spotLength = 0;
  11701. var rectAreaLength = 0;
  11702. var hemiLength = 0;
  11703. var numDirectionalShadows = 0;
  11704. var numPointShadows = 0;
  11705. var numSpotShadows = 0;
  11706. var viewMatrix = camera.matrixWorldInverse;
  11707. lights.sort( shadowCastingLightsFirst );
  11708. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  11709. var light = lights[ i ];
  11710. var color = light.color;
  11711. var intensity = light.intensity;
  11712. var distance = light.distance;
  11713. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11714. if ( light.isAmbientLight ) {
  11715. r += color.r * intensity;
  11716. g += color.g * intensity;
  11717. b += color.b * intensity;
  11718. } else if ( light.isLightProbe ) {
  11719. for ( var j = 0; j < 9; j ++ ) {
  11720. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11721. }
  11722. } else if ( light.isDirectionalLight ) {
  11723. var uniforms = cache.get( light );
  11724. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11725. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11726. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11727. uniforms.direction.sub( vector3 );
  11728. uniforms.direction.transformDirection( viewMatrix );
  11729. if ( light.castShadow ) {
  11730. var shadow = light.shadow;
  11731. var shadowUniforms = shadowCache.get( light );
  11732. shadowUniforms.shadowBias = shadow.bias;
  11733. shadowUniforms.shadowRadius = shadow.radius;
  11734. shadowUniforms.shadowMapSize = shadow.mapSize;
  11735. state.directionalShadow[ directionalLength ] = shadowUniforms;
  11736. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11737. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11738. numDirectionalShadows ++;
  11739. }
  11740. state.directional[ directionalLength ] = uniforms;
  11741. directionalLength ++;
  11742. } else if ( light.isSpotLight ) {
  11743. var uniforms = cache.get( light );
  11744. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11745. uniforms.position.applyMatrix4( viewMatrix );
  11746. uniforms.color.copy( color ).multiplyScalar( intensity );
  11747. uniforms.distance = distance;
  11748. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11749. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11750. uniforms.direction.sub( vector3 );
  11751. uniforms.direction.transformDirection( viewMatrix );
  11752. uniforms.coneCos = Math.cos( light.angle );
  11753. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11754. uniforms.decay = light.decay;
  11755. if ( light.castShadow ) {
  11756. var shadow = light.shadow;
  11757. var shadowUniforms = shadowCache.get( light );
  11758. shadowUniforms.shadowBias = shadow.bias;
  11759. shadowUniforms.shadowRadius = shadow.radius;
  11760. shadowUniforms.shadowMapSize = shadow.mapSize;
  11761. state.spotShadow[ spotLength ] = shadowUniforms;
  11762. state.spotShadowMap[ spotLength ] = shadowMap;
  11763. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11764. numSpotShadows ++;
  11765. }
  11766. state.spot[ spotLength ] = uniforms;
  11767. spotLength ++;
  11768. } else if ( light.isRectAreaLight ) {
  11769. var uniforms = cache.get( light );
  11770. // (a) intensity is the total visible light emitted
  11771. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11772. // (b) intensity is the brightness of the light
  11773. uniforms.color.copy( color ).multiplyScalar( intensity );
  11774. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11775. uniforms.position.applyMatrix4( viewMatrix );
  11776. // extract local rotation of light to derive width/height half vectors
  11777. matrix42.identity();
  11778. matrix4.copy( light.matrixWorld );
  11779. matrix4.premultiply( viewMatrix );
  11780. matrix42.extractRotation( matrix4 );
  11781. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11782. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11783. uniforms.halfWidth.applyMatrix4( matrix42 );
  11784. uniforms.halfHeight.applyMatrix4( matrix42 );
  11785. // TODO (abelnation): RectAreaLight distance?
  11786. // uniforms.distance = distance;
  11787. state.rectArea[ rectAreaLength ] = uniforms;
  11788. rectAreaLength ++;
  11789. } else if ( light.isPointLight ) {
  11790. var uniforms = cache.get( light );
  11791. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11792. uniforms.position.applyMatrix4( viewMatrix );
  11793. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11794. uniforms.distance = light.distance;
  11795. uniforms.decay = light.decay;
  11796. if ( light.castShadow ) {
  11797. var shadow = light.shadow;
  11798. var shadowUniforms = shadowCache.get( light );
  11799. shadowUniforms.shadowBias = shadow.bias;
  11800. shadowUniforms.shadowRadius = shadow.radius;
  11801. shadowUniforms.shadowMapSize = shadow.mapSize;
  11802. shadowUniforms.shadowCameraNear = shadow.camera.near;
  11803. shadowUniforms.shadowCameraFar = shadow.camera.far;
  11804. state.pointShadow[ pointLength ] = shadowUniforms;
  11805. state.pointShadowMap[ pointLength ] = shadowMap;
  11806. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11807. numPointShadows ++;
  11808. }
  11809. state.point[ pointLength ] = uniforms;
  11810. pointLength ++;
  11811. } else if ( light.isHemisphereLight ) {
  11812. var uniforms = cache.get( light );
  11813. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11814. uniforms.direction.transformDirection( viewMatrix );
  11815. uniforms.direction.normalize();
  11816. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11817. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11818. state.hemi[ hemiLength ] = uniforms;
  11819. hemiLength ++;
  11820. }
  11821. }
  11822. state.ambient[ 0 ] = r;
  11823. state.ambient[ 1 ] = g;
  11824. state.ambient[ 2 ] = b;
  11825. var hash = state.hash;
  11826. if ( hash.directionalLength !== directionalLength ||
  11827. hash.pointLength !== pointLength ||
  11828. hash.spotLength !== spotLength ||
  11829. hash.rectAreaLength !== rectAreaLength ||
  11830. hash.hemiLength !== hemiLength ||
  11831. hash.numDirectionalShadows !== numDirectionalShadows ||
  11832. hash.numPointShadows !== numPointShadows ||
  11833. hash.numSpotShadows !== numSpotShadows ) {
  11834. state.directional.length = directionalLength;
  11835. state.spot.length = spotLength;
  11836. state.rectArea.length = rectAreaLength;
  11837. state.point.length = pointLength;
  11838. state.hemi.length = hemiLength;
  11839. state.directionalShadow.length = numDirectionalShadows;
  11840. state.directionalShadowMap.length = numDirectionalShadows;
  11841. state.pointShadow.length = numPointShadows;
  11842. state.pointShadowMap.length = numPointShadows;
  11843. state.spotShadow.length = numSpotShadows;
  11844. state.spotShadowMap.length = numSpotShadows;
  11845. state.directionalShadowMatrix.length = numDirectionalShadows;
  11846. state.pointShadowMatrix.length = numPointShadows;
  11847. state.spotShadowMatrix.length = numSpotShadows;
  11848. hash.directionalLength = directionalLength;
  11849. hash.pointLength = pointLength;
  11850. hash.spotLength = spotLength;
  11851. hash.rectAreaLength = rectAreaLength;
  11852. hash.hemiLength = hemiLength;
  11853. hash.numDirectionalShadows = numDirectionalShadows;
  11854. hash.numPointShadows = numPointShadows;
  11855. hash.numSpotShadows = numSpotShadows;
  11856. state.version = nextVersion ++;
  11857. }
  11858. }
  11859. return {
  11860. setup: setup,
  11861. state: state
  11862. };
  11863. }
  11864. /**
  11865. * @author Mugen87 / https://github.com/Mugen87
  11866. */
  11867. function WebGLRenderState() {
  11868. var lights = new WebGLLights();
  11869. var lightsArray = [];
  11870. var shadowsArray = [];
  11871. function init() {
  11872. lightsArray.length = 0;
  11873. shadowsArray.length = 0;
  11874. }
  11875. function pushLight( light ) {
  11876. lightsArray.push( light );
  11877. }
  11878. function pushShadow( shadowLight ) {
  11879. shadowsArray.push( shadowLight );
  11880. }
  11881. function setupLights( camera ) {
  11882. lights.setup( lightsArray, shadowsArray, camera );
  11883. }
  11884. var state = {
  11885. lightsArray: lightsArray,
  11886. shadowsArray: shadowsArray,
  11887. lights: lights
  11888. };
  11889. return {
  11890. init: init,
  11891. state: state,
  11892. setupLights: setupLights,
  11893. pushLight: pushLight,
  11894. pushShadow: pushShadow
  11895. };
  11896. }
  11897. function WebGLRenderStates() {
  11898. var renderStates = new WeakMap();
  11899. function onSceneDispose( event ) {
  11900. var scene = event.target;
  11901. scene.removeEventListener( 'dispose', onSceneDispose );
  11902. renderStates.delete( scene );
  11903. }
  11904. function get( scene, camera ) {
  11905. var renderState;
  11906. if ( renderStates.has( scene ) === false ) {
  11907. renderState = new WebGLRenderState();
  11908. renderStates.set( scene, new WeakMap() );
  11909. renderStates.get( scene ).set( camera, renderState );
  11910. scene.addEventListener( 'dispose', onSceneDispose );
  11911. } else {
  11912. if ( renderStates.get( scene ).has( camera ) === false ) {
  11913. renderState = new WebGLRenderState();
  11914. renderStates.get( scene ).set( camera, renderState );
  11915. } else {
  11916. renderState = renderStates.get( scene ).get( camera );
  11917. }
  11918. }
  11919. return renderState;
  11920. }
  11921. function dispose() {
  11922. renderStates = new WeakMap();
  11923. }
  11924. return {
  11925. get: get,
  11926. dispose: dispose
  11927. };
  11928. }
  11929. /**
  11930. * @author mrdoob / http://mrdoob.com/
  11931. * @author alteredq / http://alteredqualia.com/
  11932. * @author bhouston / https://clara.io
  11933. * @author WestLangley / http://github.com/WestLangley
  11934. *
  11935. * parameters = {
  11936. *
  11937. * opacity: <float>,
  11938. *
  11939. * map: new THREE.Texture( <Image> ),
  11940. *
  11941. * alphaMap: new THREE.Texture( <Image> ),
  11942. *
  11943. * displacementMap: new THREE.Texture( <Image> ),
  11944. * displacementScale: <float>,
  11945. * displacementBias: <float>,
  11946. *
  11947. * wireframe: <boolean>,
  11948. * wireframeLinewidth: <float>
  11949. * }
  11950. */
  11951. function MeshDepthMaterial( parameters ) {
  11952. Material.call( this );
  11953. this.type = 'MeshDepthMaterial';
  11954. this.depthPacking = BasicDepthPacking;
  11955. this.skinning = false;
  11956. this.morphTargets = false;
  11957. this.map = null;
  11958. this.alphaMap = null;
  11959. this.displacementMap = null;
  11960. this.displacementScale = 1;
  11961. this.displacementBias = 0;
  11962. this.wireframe = false;
  11963. this.wireframeLinewidth = 1;
  11964. this.fog = false;
  11965. this.setValues( parameters );
  11966. }
  11967. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11968. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11969. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11970. MeshDepthMaterial.prototype.copy = function ( source ) {
  11971. Material.prototype.copy.call( this, source );
  11972. this.depthPacking = source.depthPacking;
  11973. this.skinning = source.skinning;
  11974. this.morphTargets = source.morphTargets;
  11975. this.map = source.map;
  11976. this.alphaMap = source.alphaMap;
  11977. this.displacementMap = source.displacementMap;
  11978. this.displacementScale = source.displacementScale;
  11979. this.displacementBias = source.displacementBias;
  11980. this.wireframe = source.wireframe;
  11981. this.wireframeLinewidth = source.wireframeLinewidth;
  11982. return this;
  11983. };
  11984. /**
  11985. * @author WestLangley / http://github.com/WestLangley
  11986. *
  11987. * parameters = {
  11988. *
  11989. * referencePosition: <float>,
  11990. * nearDistance: <float>,
  11991. * farDistance: <float>,
  11992. *
  11993. * skinning: <bool>,
  11994. * morphTargets: <bool>,
  11995. *
  11996. * map: new THREE.Texture( <Image> ),
  11997. *
  11998. * alphaMap: new THREE.Texture( <Image> ),
  11999. *
  12000. * displacementMap: new THREE.Texture( <Image> ),
  12001. * displacementScale: <float>,
  12002. * displacementBias: <float>
  12003. *
  12004. * }
  12005. */
  12006. function MeshDistanceMaterial( parameters ) {
  12007. Material.call( this );
  12008. this.type = 'MeshDistanceMaterial';
  12009. this.referencePosition = new Vector3();
  12010. this.nearDistance = 1;
  12011. this.farDistance = 1000;
  12012. this.skinning = false;
  12013. this.morphTargets = false;
  12014. this.map = null;
  12015. this.alphaMap = null;
  12016. this.displacementMap = null;
  12017. this.displacementScale = 1;
  12018. this.displacementBias = 0;
  12019. this.fog = false;
  12020. this.setValues( parameters );
  12021. }
  12022. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  12023. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12024. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12025. MeshDistanceMaterial.prototype.copy = function ( source ) {
  12026. Material.prototype.copy.call( this, source );
  12027. this.referencePosition.copy( source.referencePosition );
  12028. this.nearDistance = source.nearDistance;
  12029. this.farDistance = source.farDistance;
  12030. this.skinning = source.skinning;
  12031. this.morphTargets = source.morphTargets;
  12032. this.map = source.map;
  12033. this.alphaMap = source.alphaMap;
  12034. this.displacementMap = source.displacementMap;
  12035. this.displacementScale = source.displacementScale;
  12036. this.displacementBias = source.displacementBias;
  12037. return this;
  12038. };
  12039. 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}";
  12040. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12041. /**
  12042. * @author alteredq / http://alteredqualia.com/
  12043. * @author mrdoob / http://mrdoob.com/
  12044. */
  12045. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  12046. var _frustum = new Frustum(),
  12047. _shadowMapSize = new Vector2(),
  12048. _viewportSize = new Vector2(),
  12049. _viewport = new Vector4(),
  12050. _depthMaterials = [],
  12051. _distanceMaterials = [],
  12052. _materialCache = {};
  12053. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  12054. var shadowMaterialVertical = new ShaderMaterial( {
  12055. defines: {
  12056. SAMPLE_RATE: 2.0 / 8.0,
  12057. HALF_SAMPLE_RATE: 1.0 / 8.0
  12058. },
  12059. uniforms: {
  12060. shadow_pass: { value: null },
  12061. resolution: { value: new Vector2() },
  12062. radius: { value: 4.0 }
  12063. },
  12064. vertexShader: vsm_vert,
  12065. fragmentShader: vsm_frag
  12066. } );
  12067. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  12068. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  12069. var fullScreenTri = new BufferGeometry();
  12070. fullScreenTri.setAttribute(
  12071. "position",
  12072. new BufferAttribute(
  12073. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  12074. 3
  12075. )
  12076. );
  12077. var fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  12078. var scope = this;
  12079. this.enabled = false;
  12080. this.autoUpdate = true;
  12081. this.needsUpdate = false;
  12082. this.type = PCFShadowMap;
  12083. this.render = function ( lights, scene, camera ) {
  12084. if ( scope.enabled === false ) return;
  12085. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  12086. if ( lights.length === 0 ) return;
  12087. var currentRenderTarget = _renderer.getRenderTarget();
  12088. var activeCubeFace = _renderer.getActiveCubeFace();
  12089. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12090. var _state = _renderer.state;
  12091. // Set GL state for depth map.
  12092. _state.setBlending( NoBlending );
  12093. _state.buffers.color.setClear( 1, 1, 1, 1 );
  12094. _state.buffers.depth.setTest( true );
  12095. _state.setScissorTest( false );
  12096. // render depth map
  12097. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  12098. var light = lights[ i ];
  12099. var shadow = light.shadow;
  12100. if ( shadow === undefined ) {
  12101. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  12102. continue;
  12103. }
  12104. _shadowMapSize.copy( shadow.mapSize );
  12105. var shadowFrameExtents = shadow.getFrameExtents();
  12106. _shadowMapSize.multiply( shadowFrameExtents );
  12107. _viewportSize.copy( shadow.mapSize );
  12108. if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
  12109. if ( _shadowMapSize.x > maxTextureSize ) {
  12110. _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
  12111. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12112. shadow.mapSize.x = _viewportSize.x;
  12113. }
  12114. if ( _shadowMapSize.y > maxTextureSize ) {
  12115. _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
  12116. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12117. shadow.mapSize.y = _viewportSize.y;
  12118. }
  12119. }
  12120. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12121. var pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  12122. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12123. shadow.map.texture.name = light.name + ".shadowMap";
  12124. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12125. shadow.camera.updateProjectionMatrix();
  12126. }
  12127. if ( shadow.map === null ) {
  12128. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  12129. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12130. shadow.map.texture.name = light.name + ".shadowMap";
  12131. shadow.camera.updateProjectionMatrix();
  12132. }
  12133. _renderer.setRenderTarget( shadow.map );
  12134. _renderer.clear();
  12135. var viewportCount = shadow.getViewportCount();
  12136. for ( var vp = 0; vp < viewportCount; vp ++ ) {
  12137. var viewport = shadow.getViewport( vp );
  12138. _viewport.set(
  12139. _viewportSize.x * viewport.x,
  12140. _viewportSize.y * viewport.y,
  12141. _viewportSize.x * viewport.z,
  12142. _viewportSize.y * viewport.w
  12143. );
  12144. _state.viewport( _viewport );
  12145. shadow.updateMatrices( light, vp );
  12146. _frustum = shadow.getFrustum();
  12147. renderObject( scene, camera, shadow.camera, light, this.type );
  12148. }
  12149. // do blur pass for VSM
  12150. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12151. VSMPass( shadow, camera );
  12152. }
  12153. }
  12154. scope.needsUpdate = false;
  12155. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  12156. };
  12157. function VSMPass( shadow, camera ) {
  12158. var geometry = _objects.update( fullScreenMesh );
  12159. // vertical pass
  12160. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12161. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12162. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12163. _renderer.setRenderTarget( shadow.mapPass );
  12164. _renderer.clear();
  12165. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  12166. // horizonal pass
  12167. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12168. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  12169. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  12170. _renderer.setRenderTarget( shadow.map );
  12171. _renderer.clear();
  12172. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null );
  12173. }
  12174. function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  12175. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12176. var material = _depthMaterials[ index ];
  12177. if ( material === undefined ) {
  12178. material = new MeshDepthMaterial( {
  12179. depthPacking: RGBADepthPacking,
  12180. morphTargets: useMorphing,
  12181. skinning: useSkinning
  12182. } );
  12183. _depthMaterials[ index ] = material;
  12184. }
  12185. return material;
  12186. }
  12187. function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  12188. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12189. var material = _distanceMaterials[ index ];
  12190. if ( material === undefined ) {
  12191. material = new MeshDistanceMaterial( {
  12192. morphTargets: useMorphing,
  12193. skinning: useSkinning
  12194. } );
  12195. _distanceMaterials[ index ] = material;
  12196. }
  12197. return material;
  12198. }
  12199. function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
  12200. var result = null;
  12201. var getMaterialVariant = getDepthMaterialVariant;
  12202. var customMaterial = object.customDepthMaterial;
  12203. if ( light.isPointLight === true ) {
  12204. getMaterialVariant = getDistanceMaterialVariant;
  12205. customMaterial = object.customDistanceMaterial;
  12206. }
  12207. if ( customMaterial === undefined ) {
  12208. var useMorphing = false;
  12209. if ( material.morphTargets === true ) {
  12210. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12211. }
  12212. var useSkinning = false;
  12213. if ( object.isSkinnedMesh === true ) {
  12214. if ( material.skinning === true ) {
  12215. useSkinning = true;
  12216. } else {
  12217. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  12218. }
  12219. }
  12220. var useInstancing = object.isInstancedMesh === true;
  12221. result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
  12222. } else {
  12223. result = customMaterial;
  12224. }
  12225. if ( _renderer.localClippingEnabled &&
  12226. material.clipShadows === true &&
  12227. material.clippingPlanes.length !== 0 ) {
  12228. // in this case we need a unique material instance reflecting the
  12229. // appropriate state
  12230. var keyA = result.uuid, keyB = material.uuid;
  12231. var materialsForVariant = _materialCache[ keyA ];
  12232. if ( materialsForVariant === undefined ) {
  12233. materialsForVariant = {};
  12234. _materialCache[ keyA ] = materialsForVariant;
  12235. }
  12236. var cachedMaterial = materialsForVariant[ keyB ];
  12237. if ( cachedMaterial === undefined ) {
  12238. cachedMaterial = result.clone();
  12239. materialsForVariant[ keyB ] = cachedMaterial;
  12240. }
  12241. result = cachedMaterial;
  12242. }
  12243. result.visible = material.visible;
  12244. result.wireframe = material.wireframe;
  12245. if ( type === VSMShadowMap ) {
  12246. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  12247. } else {
  12248. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  12249. }
  12250. result.clipShadows = material.clipShadows;
  12251. result.clippingPlanes = material.clippingPlanes;
  12252. result.clipIntersection = material.clipIntersection;
  12253. result.wireframeLinewidth = material.wireframeLinewidth;
  12254. result.linewidth = material.linewidth;
  12255. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  12256. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  12257. result.nearDistance = shadowCameraNear;
  12258. result.farDistance = shadowCameraFar;
  12259. }
  12260. return result;
  12261. }
  12262. function renderObject( object, camera, shadowCamera, light, type ) {
  12263. if ( object.visible === false ) return;
  12264. var visible = object.layers.test( camera.layers );
  12265. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  12266. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  12267. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  12268. var geometry = _objects.update( object );
  12269. var material = object.material;
  12270. if ( Array.isArray( material ) ) {
  12271. var groups = geometry.groups;
  12272. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  12273. var group = groups[ k ];
  12274. var groupMaterial = material[ group.materialIndex ];
  12275. if ( groupMaterial && groupMaterial.visible ) {
  12276. var depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  12277. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  12278. }
  12279. }
  12280. } else if ( material.visible ) {
  12281. var depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
  12282. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  12283. }
  12284. }
  12285. }
  12286. var children = object.children;
  12287. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12288. renderObject( children[ i ], camera, shadowCamera, light, type );
  12289. }
  12290. }
  12291. }
  12292. /**
  12293. * @author mrdoob / http://mrdoob.com/
  12294. */
  12295. function WebGLState( gl, extensions, capabilities ) {
  12296. var isWebGL2 = capabilities.isWebGL2;
  12297. function ColorBuffer() {
  12298. var locked = false;
  12299. var color = new Vector4();
  12300. var currentColorMask = null;
  12301. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  12302. return {
  12303. setMask: function ( colorMask ) {
  12304. if ( currentColorMask !== colorMask && ! locked ) {
  12305. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  12306. currentColorMask = colorMask;
  12307. }
  12308. },
  12309. setLocked: function ( lock ) {
  12310. locked = lock;
  12311. },
  12312. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  12313. if ( premultipliedAlpha === true ) {
  12314. r *= a; g *= a; b *= a;
  12315. }
  12316. color.set( r, g, b, a );
  12317. if ( currentColorClear.equals( color ) === false ) {
  12318. gl.clearColor( r, g, b, a );
  12319. currentColorClear.copy( color );
  12320. }
  12321. },
  12322. reset: function () {
  12323. locked = false;
  12324. currentColorMask = null;
  12325. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  12326. }
  12327. };
  12328. }
  12329. function DepthBuffer() {
  12330. var locked = false;
  12331. var currentDepthMask = null;
  12332. var currentDepthFunc = null;
  12333. var currentDepthClear = null;
  12334. return {
  12335. setTest: function ( depthTest ) {
  12336. if ( depthTest ) {
  12337. enable( 2929 );
  12338. } else {
  12339. disable( 2929 );
  12340. }
  12341. },
  12342. setMask: function ( depthMask ) {
  12343. if ( currentDepthMask !== depthMask && ! locked ) {
  12344. gl.depthMask( depthMask );
  12345. currentDepthMask = depthMask;
  12346. }
  12347. },
  12348. setFunc: function ( depthFunc ) {
  12349. if ( currentDepthFunc !== depthFunc ) {
  12350. if ( depthFunc ) {
  12351. switch ( depthFunc ) {
  12352. case NeverDepth:
  12353. gl.depthFunc( 512 );
  12354. break;
  12355. case AlwaysDepth:
  12356. gl.depthFunc( 519 );
  12357. break;
  12358. case LessDepth:
  12359. gl.depthFunc( 513 );
  12360. break;
  12361. case LessEqualDepth:
  12362. gl.depthFunc( 515 );
  12363. break;
  12364. case EqualDepth:
  12365. gl.depthFunc( 514 );
  12366. break;
  12367. case GreaterEqualDepth:
  12368. gl.depthFunc( 518 );
  12369. break;
  12370. case GreaterDepth:
  12371. gl.depthFunc( 516 );
  12372. break;
  12373. case NotEqualDepth:
  12374. gl.depthFunc( 517 );
  12375. break;
  12376. default:
  12377. gl.depthFunc( 515 );
  12378. }
  12379. } else {
  12380. gl.depthFunc( 515 );
  12381. }
  12382. currentDepthFunc = depthFunc;
  12383. }
  12384. },
  12385. setLocked: function ( lock ) {
  12386. locked = lock;
  12387. },
  12388. setClear: function ( depth ) {
  12389. if ( currentDepthClear !== depth ) {
  12390. gl.clearDepth( depth );
  12391. currentDepthClear = depth;
  12392. }
  12393. },
  12394. reset: function () {
  12395. locked = false;
  12396. currentDepthMask = null;
  12397. currentDepthFunc = null;
  12398. currentDepthClear = null;
  12399. }
  12400. };
  12401. }
  12402. function StencilBuffer() {
  12403. var locked = false;
  12404. var currentStencilMask = null;
  12405. var currentStencilFunc = null;
  12406. var currentStencilRef = null;
  12407. var currentStencilFuncMask = null;
  12408. var currentStencilFail = null;
  12409. var currentStencilZFail = null;
  12410. var currentStencilZPass = null;
  12411. var currentStencilClear = null;
  12412. return {
  12413. setTest: function ( stencilTest ) {
  12414. if ( ! locked ) {
  12415. if ( stencilTest ) {
  12416. enable( 2960 );
  12417. } else {
  12418. disable( 2960 );
  12419. }
  12420. }
  12421. },
  12422. setMask: function ( stencilMask ) {
  12423. if ( currentStencilMask !== stencilMask && ! locked ) {
  12424. gl.stencilMask( stencilMask );
  12425. currentStencilMask = stencilMask;
  12426. }
  12427. },
  12428. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12429. if ( currentStencilFunc !== stencilFunc ||
  12430. currentStencilRef !== stencilRef ||
  12431. currentStencilFuncMask !== stencilMask ) {
  12432. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12433. currentStencilFunc = stencilFunc;
  12434. currentStencilRef = stencilRef;
  12435. currentStencilFuncMask = stencilMask;
  12436. }
  12437. },
  12438. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12439. if ( currentStencilFail !== stencilFail ||
  12440. currentStencilZFail !== stencilZFail ||
  12441. currentStencilZPass !== stencilZPass ) {
  12442. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12443. currentStencilFail = stencilFail;
  12444. currentStencilZFail = stencilZFail;
  12445. currentStencilZPass = stencilZPass;
  12446. }
  12447. },
  12448. setLocked: function ( lock ) {
  12449. locked = lock;
  12450. },
  12451. setClear: function ( stencil ) {
  12452. if ( currentStencilClear !== stencil ) {
  12453. gl.clearStencil( stencil );
  12454. currentStencilClear = stencil;
  12455. }
  12456. },
  12457. reset: function () {
  12458. locked = false;
  12459. currentStencilMask = null;
  12460. currentStencilFunc = null;
  12461. currentStencilRef = null;
  12462. currentStencilFuncMask = null;
  12463. currentStencilFail = null;
  12464. currentStencilZFail = null;
  12465. currentStencilZPass = null;
  12466. currentStencilClear = null;
  12467. }
  12468. };
  12469. }
  12470. //
  12471. var colorBuffer = new ColorBuffer();
  12472. var depthBuffer = new DepthBuffer();
  12473. var stencilBuffer = new StencilBuffer();
  12474. var maxVertexAttributes = gl.getParameter( 34921 );
  12475. var newAttributes = new Uint8Array( maxVertexAttributes );
  12476. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  12477. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  12478. var enabledCapabilities = {};
  12479. var currentProgram = null;
  12480. var currentBlendingEnabled = null;
  12481. var currentBlending = null;
  12482. var currentBlendEquation = null;
  12483. var currentBlendSrc = null;
  12484. var currentBlendDst = null;
  12485. var currentBlendEquationAlpha = null;
  12486. var currentBlendSrcAlpha = null;
  12487. var currentBlendDstAlpha = null;
  12488. var currentPremultipledAlpha = false;
  12489. var currentFlipSided = null;
  12490. var currentCullFace = null;
  12491. var currentLineWidth = null;
  12492. var currentPolygonOffsetFactor = null;
  12493. var currentPolygonOffsetUnits = null;
  12494. var maxTextures = gl.getParameter( 35661 );
  12495. var lineWidthAvailable = false;
  12496. var version = 0;
  12497. var glVersion = gl.getParameter( 7938 );
  12498. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12499. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12500. lineWidthAvailable = ( version >= 1.0 );
  12501. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12502. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12503. lineWidthAvailable = ( version >= 2.0 );
  12504. }
  12505. var currentTextureSlot = null;
  12506. var currentBoundTextures = {};
  12507. var currentScissor = new Vector4();
  12508. var currentViewport = new Vector4();
  12509. function createTexture( type, target, count ) {
  12510. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12511. var texture = gl.createTexture();
  12512. gl.bindTexture( type, texture );
  12513. gl.texParameteri( type, 10241, 9728 );
  12514. gl.texParameteri( type, 10240, 9728 );
  12515. for ( var i = 0; i < count; i ++ ) {
  12516. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12517. }
  12518. return texture;
  12519. }
  12520. var emptyTextures = {};
  12521. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12522. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12523. // init
  12524. colorBuffer.setClear( 0, 0, 0, 1 );
  12525. depthBuffer.setClear( 1 );
  12526. stencilBuffer.setClear( 0 );
  12527. enable( 2929 );
  12528. depthBuffer.setFunc( LessEqualDepth );
  12529. setFlipSided( false );
  12530. setCullFace( CullFaceBack );
  12531. enable( 2884 );
  12532. setBlending( NoBlending );
  12533. //
  12534. function initAttributes() {
  12535. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  12536. newAttributes[ i ] = 0;
  12537. }
  12538. }
  12539. function enableAttribute( attribute ) {
  12540. enableAttributeAndDivisor( attribute, 0 );
  12541. }
  12542. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  12543. newAttributes[ attribute ] = 1;
  12544. if ( enabledAttributes[ attribute ] === 0 ) {
  12545. gl.enableVertexAttribArray( attribute );
  12546. enabledAttributes[ attribute ] = 1;
  12547. }
  12548. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  12549. var extension = isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  12550. extension[ isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  12551. attributeDivisors[ attribute ] = meshPerAttribute;
  12552. }
  12553. }
  12554. function disableUnusedAttributes() {
  12555. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  12556. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  12557. gl.disableVertexAttribArray( i );
  12558. enabledAttributes[ i ] = 0;
  12559. }
  12560. }
  12561. }
  12562. function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
  12563. if ( isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
  12564. gl.vertexAttribIPointer( index, size, type, normalized, stride, offset );
  12565. } else {
  12566. gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
  12567. }
  12568. }
  12569. function enable( id ) {
  12570. if ( enabledCapabilities[ id ] !== true ) {
  12571. gl.enable( id );
  12572. enabledCapabilities[ id ] = true;
  12573. }
  12574. }
  12575. function disable( id ) {
  12576. if ( enabledCapabilities[ id ] !== false ) {
  12577. gl.disable( id );
  12578. enabledCapabilities[ id ] = false;
  12579. }
  12580. }
  12581. function useProgram( program ) {
  12582. if ( currentProgram !== program ) {
  12583. gl.useProgram( program );
  12584. currentProgram = program;
  12585. return true;
  12586. }
  12587. return false;
  12588. }
  12589. var equationToGL = {
  12590. [ AddEquation ]: 32774,
  12591. [ SubtractEquation ]: 32778,
  12592. [ ReverseSubtractEquation ]: 32779
  12593. };
  12594. if ( isWebGL2 ) {
  12595. equationToGL[ MinEquation ] = 32775;
  12596. equationToGL[ MaxEquation ] = 32776;
  12597. } else {
  12598. var extension = extensions.get( 'EXT_blend_minmax' );
  12599. if ( extension !== null ) {
  12600. equationToGL[ MinEquation ] = extension.MIN_EXT;
  12601. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  12602. }
  12603. }
  12604. var factorToGL = {
  12605. [ ZeroFactor ]: 0,
  12606. [ OneFactor ]: 1,
  12607. [ SrcColorFactor ]: 768,
  12608. [ SrcAlphaFactor ]: 770,
  12609. [ SrcAlphaSaturateFactor ]: 776,
  12610. [ DstColorFactor ]: 774,
  12611. [ DstAlphaFactor ]: 772,
  12612. [ OneMinusSrcColorFactor ]: 769,
  12613. [ OneMinusSrcAlphaFactor ]: 771,
  12614. [ OneMinusDstColorFactor ]: 775,
  12615. [ OneMinusDstAlphaFactor ]: 773
  12616. };
  12617. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12618. if ( blending === NoBlending ) {
  12619. if ( currentBlendingEnabled ) {
  12620. disable( 3042 );
  12621. currentBlendingEnabled = false;
  12622. }
  12623. return;
  12624. }
  12625. if ( ! currentBlendingEnabled ) {
  12626. enable( 3042 );
  12627. currentBlendingEnabled = true;
  12628. }
  12629. if ( blending !== CustomBlending ) {
  12630. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12631. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12632. gl.blendEquation( 32774 );
  12633. currentBlendEquation = AddEquation;
  12634. currentBlendEquationAlpha = AddEquation;
  12635. }
  12636. if ( premultipliedAlpha ) {
  12637. switch ( blending ) {
  12638. case NormalBlending:
  12639. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12640. break;
  12641. case AdditiveBlending:
  12642. gl.blendFunc( 1, 1 );
  12643. break;
  12644. case SubtractiveBlending:
  12645. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12646. break;
  12647. case MultiplyBlending:
  12648. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12649. break;
  12650. default:
  12651. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12652. break;
  12653. }
  12654. } else {
  12655. switch ( blending ) {
  12656. case NormalBlending:
  12657. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12658. break;
  12659. case AdditiveBlending:
  12660. gl.blendFunc( 770, 1 );
  12661. break;
  12662. case SubtractiveBlending:
  12663. gl.blendFunc( 0, 769 );
  12664. break;
  12665. case MultiplyBlending:
  12666. gl.blendFunc( 0, 768 );
  12667. break;
  12668. default:
  12669. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12670. break;
  12671. }
  12672. }
  12673. currentBlendSrc = null;
  12674. currentBlendDst = null;
  12675. currentBlendSrcAlpha = null;
  12676. currentBlendDstAlpha = null;
  12677. currentBlending = blending;
  12678. currentPremultipledAlpha = premultipliedAlpha;
  12679. }
  12680. return;
  12681. }
  12682. // custom blending
  12683. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12684. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12685. blendDstAlpha = blendDstAlpha || blendDst;
  12686. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12687. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  12688. currentBlendEquation = blendEquation;
  12689. currentBlendEquationAlpha = blendEquationAlpha;
  12690. }
  12691. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12692. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  12693. currentBlendSrc = blendSrc;
  12694. currentBlendDst = blendDst;
  12695. currentBlendSrcAlpha = blendSrcAlpha;
  12696. currentBlendDstAlpha = blendDstAlpha;
  12697. }
  12698. currentBlending = blending;
  12699. currentPremultipledAlpha = null;
  12700. }
  12701. function setMaterial( material, frontFaceCW ) {
  12702. material.side === DoubleSide
  12703. ? disable( 2884 )
  12704. : enable( 2884 );
  12705. var flipSided = ( material.side === BackSide );
  12706. if ( frontFaceCW ) flipSided = ! flipSided;
  12707. setFlipSided( flipSided );
  12708. ( material.blending === NormalBlending && material.transparent === false )
  12709. ? setBlending( NoBlending )
  12710. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12711. depthBuffer.setFunc( material.depthFunc );
  12712. depthBuffer.setTest( material.depthTest );
  12713. depthBuffer.setMask( material.depthWrite );
  12714. colorBuffer.setMask( material.colorWrite );
  12715. var stencilWrite = material.stencilWrite;
  12716. stencilBuffer.setTest( stencilWrite );
  12717. if ( stencilWrite ) {
  12718. stencilBuffer.setMask( material.stencilWriteMask );
  12719. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  12720. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12721. }
  12722. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12723. }
  12724. //
  12725. function setFlipSided( flipSided ) {
  12726. if ( currentFlipSided !== flipSided ) {
  12727. if ( flipSided ) {
  12728. gl.frontFace( 2304 );
  12729. } else {
  12730. gl.frontFace( 2305 );
  12731. }
  12732. currentFlipSided = flipSided;
  12733. }
  12734. }
  12735. function setCullFace( cullFace ) {
  12736. if ( cullFace !== CullFaceNone ) {
  12737. enable( 2884 );
  12738. if ( cullFace !== currentCullFace ) {
  12739. if ( cullFace === CullFaceBack ) {
  12740. gl.cullFace( 1029 );
  12741. } else if ( cullFace === CullFaceFront ) {
  12742. gl.cullFace( 1028 );
  12743. } else {
  12744. gl.cullFace( 1032 );
  12745. }
  12746. }
  12747. } else {
  12748. disable( 2884 );
  12749. }
  12750. currentCullFace = cullFace;
  12751. }
  12752. function setLineWidth( width ) {
  12753. if ( width !== currentLineWidth ) {
  12754. if ( lineWidthAvailable ) gl.lineWidth( width );
  12755. currentLineWidth = width;
  12756. }
  12757. }
  12758. function setPolygonOffset( polygonOffset, factor, units ) {
  12759. if ( polygonOffset ) {
  12760. enable( 32823 );
  12761. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12762. gl.polygonOffset( factor, units );
  12763. currentPolygonOffsetFactor = factor;
  12764. currentPolygonOffsetUnits = units;
  12765. }
  12766. } else {
  12767. disable( 32823 );
  12768. }
  12769. }
  12770. function setScissorTest( scissorTest ) {
  12771. if ( scissorTest ) {
  12772. enable( 3089 );
  12773. } else {
  12774. disable( 3089 );
  12775. }
  12776. }
  12777. // texture
  12778. function activeTexture( webglSlot ) {
  12779. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12780. if ( currentTextureSlot !== webglSlot ) {
  12781. gl.activeTexture( webglSlot );
  12782. currentTextureSlot = webglSlot;
  12783. }
  12784. }
  12785. function bindTexture( webglType, webglTexture ) {
  12786. if ( currentTextureSlot === null ) {
  12787. activeTexture();
  12788. }
  12789. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12790. if ( boundTexture === undefined ) {
  12791. boundTexture = { type: undefined, texture: undefined };
  12792. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12793. }
  12794. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12795. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12796. boundTexture.type = webglType;
  12797. boundTexture.texture = webglTexture;
  12798. }
  12799. }
  12800. function unbindTexture() {
  12801. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12802. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  12803. gl.bindTexture( boundTexture.type, null );
  12804. boundTexture.type = undefined;
  12805. boundTexture.texture = undefined;
  12806. }
  12807. }
  12808. function compressedTexImage2D() {
  12809. try {
  12810. gl.compressedTexImage2D.apply( gl, arguments );
  12811. } catch ( error ) {
  12812. console.error( 'THREE.WebGLState:', error );
  12813. }
  12814. }
  12815. function texImage2D() {
  12816. try {
  12817. gl.texImage2D.apply( gl, arguments );
  12818. } catch ( error ) {
  12819. console.error( 'THREE.WebGLState:', error );
  12820. }
  12821. }
  12822. function texImage3D() {
  12823. try {
  12824. gl.texImage3D.apply( gl, arguments );
  12825. } catch ( error ) {
  12826. console.error( 'THREE.WebGLState:', error );
  12827. }
  12828. }
  12829. //
  12830. function scissor( scissor ) {
  12831. if ( currentScissor.equals( scissor ) === false ) {
  12832. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12833. currentScissor.copy( scissor );
  12834. }
  12835. }
  12836. function viewport( viewport ) {
  12837. if ( currentViewport.equals( viewport ) === false ) {
  12838. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12839. currentViewport.copy( viewport );
  12840. }
  12841. }
  12842. //
  12843. function reset() {
  12844. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12845. if ( enabledAttributes[ i ] === 1 ) {
  12846. gl.disableVertexAttribArray( i );
  12847. enabledAttributes[ i ] = 0;
  12848. }
  12849. }
  12850. enabledCapabilities = {};
  12851. currentTextureSlot = null;
  12852. currentBoundTextures = {};
  12853. currentProgram = null;
  12854. currentBlending = null;
  12855. currentFlipSided = null;
  12856. currentCullFace = null;
  12857. colorBuffer.reset();
  12858. depthBuffer.reset();
  12859. stencilBuffer.reset();
  12860. }
  12861. return {
  12862. buffers: {
  12863. color: colorBuffer,
  12864. depth: depthBuffer,
  12865. stencil: stencilBuffer
  12866. },
  12867. initAttributes: initAttributes,
  12868. enableAttribute: enableAttribute,
  12869. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12870. disableUnusedAttributes: disableUnusedAttributes,
  12871. vertexAttribPointer: vertexAttribPointer,
  12872. enable: enable,
  12873. disable: disable,
  12874. useProgram: useProgram,
  12875. setBlending: setBlending,
  12876. setMaterial: setMaterial,
  12877. setFlipSided: setFlipSided,
  12878. setCullFace: setCullFace,
  12879. setLineWidth: setLineWidth,
  12880. setPolygonOffset: setPolygonOffset,
  12881. setScissorTest: setScissorTest,
  12882. activeTexture: activeTexture,
  12883. bindTexture: bindTexture,
  12884. unbindTexture: unbindTexture,
  12885. compressedTexImage2D: compressedTexImage2D,
  12886. texImage2D: texImage2D,
  12887. texImage3D: texImage3D,
  12888. scissor: scissor,
  12889. viewport: viewport,
  12890. reset: reset
  12891. };
  12892. }
  12893. /**
  12894. * @author mrdoob / http://mrdoob.com/
  12895. */
  12896. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12897. var isWebGL2 = capabilities.isWebGL2;
  12898. var maxTextures = capabilities.maxTextures;
  12899. var maxCubemapSize = capabilities.maxCubemapSize;
  12900. var maxTextureSize = capabilities.maxTextureSize;
  12901. var maxSamples = capabilities.maxSamples;
  12902. var _videoTextures = new WeakMap();
  12903. var _canvas;
  12904. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12905. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12906. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12907. var useOffscreenCanvas = false;
  12908. try {
  12909. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  12910. && ( new OffscreenCanvas( 1, 1 ).getContext( "2d" ) ) !== null;
  12911. } catch ( err ) {
  12912. // Ignore any errors
  12913. }
  12914. function createCanvas( width, height ) {
  12915. // Use OffscreenCanvas when available. Specially needed in web workers
  12916. return useOffscreenCanvas ?
  12917. new OffscreenCanvas( width, height ) :
  12918. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12919. }
  12920. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12921. var scale = 1;
  12922. // handle case if texture exceeds max size
  12923. if ( image.width > maxSize || image.height > maxSize ) {
  12924. scale = maxSize / Math.max( image.width, image.height );
  12925. }
  12926. // only perform resize if necessary
  12927. if ( scale < 1 || needsPowerOfTwo === true ) {
  12928. // only perform resize for certain image types
  12929. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12930. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12931. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12932. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12933. var width = floor( scale * image.width );
  12934. var height = floor( scale * image.height );
  12935. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12936. // cube textures can't reuse the same canvas
  12937. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12938. canvas.width = width;
  12939. canvas.height = height;
  12940. var context = canvas.getContext( '2d' );
  12941. context.drawImage( image, 0, 0, width, height );
  12942. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12943. return canvas;
  12944. } else {
  12945. if ( 'data' in image ) {
  12946. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12947. }
  12948. return image;
  12949. }
  12950. }
  12951. return image;
  12952. }
  12953. function isPowerOfTwo( image ) {
  12954. return MathUtils.isPowerOfTwo( image.width ) && MathUtils.isPowerOfTwo( image.height );
  12955. }
  12956. function textureNeedsPowerOfTwo( texture ) {
  12957. if ( isWebGL2 ) return false;
  12958. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12959. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12960. }
  12961. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12962. return texture.generateMipmaps && supportsMips &&
  12963. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12964. }
  12965. function generateMipmap( target, texture, width, height ) {
  12966. _gl.generateMipmap( target );
  12967. var textureProperties = properties.get( texture );
  12968. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12969. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12970. }
  12971. function getInternalFormat( internalFormatName, glFormat, glType ) {
  12972. if ( isWebGL2 === false ) return glFormat;
  12973. if ( internalFormatName !== null ) {
  12974. if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
  12975. console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
  12976. }
  12977. var internalFormat = glFormat;
  12978. if ( glFormat === 6403 ) {
  12979. if ( glType === 5126 ) internalFormat = 33326;
  12980. if ( glType === 5131 ) internalFormat = 33325;
  12981. if ( glType === 5121 ) internalFormat = 33321;
  12982. }
  12983. if ( glFormat === 6407 ) {
  12984. if ( glType === 5126 ) internalFormat = 34837;
  12985. if ( glType === 5131 ) internalFormat = 34843;
  12986. if ( glType === 5121 ) internalFormat = 32849;
  12987. }
  12988. if ( glFormat === 6408 ) {
  12989. if ( glType === 5126 ) internalFormat = 34836;
  12990. if ( glType === 5131 ) internalFormat = 34842;
  12991. if ( glType === 5121 ) internalFormat = 32856;
  12992. }
  12993. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12994. internalFormat === 34842 || internalFormat === 34836 ) {
  12995. extensions.get( 'EXT_color_buffer_float' );
  12996. }
  12997. return internalFormat;
  12998. }
  12999. // Fallback filters for non-power-of-2 textures
  13000. function filterFallback( f ) {
  13001. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  13002. return 9728;
  13003. }
  13004. return 9729;
  13005. }
  13006. //
  13007. function onTextureDispose( event ) {
  13008. var texture = event.target;
  13009. texture.removeEventListener( 'dispose', onTextureDispose );
  13010. deallocateTexture( texture );
  13011. if ( texture.isVideoTexture ) {
  13012. _videoTextures.delete( texture );
  13013. }
  13014. info.memory.textures --;
  13015. }
  13016. function onRenderTargetDispose( event ) {
  13017. var renderTarget = event.target;
  13018. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13019. deallocateRenderTarget( renderTarget );
  13020. info.memory.textures --;
  13021. }
  13022. //
  13023. function deallocateTexture( texture ) {
  13024. var textureProperties = properties.get( texture );
  13025. if ( textureProperties.__webglInit === undefined ) return;
  13026. _gl.deleteTexture( textureProperties.__webglTexture );
  13027. properties.remove( texture );
  13028. }
  13029. function deallocateRenderTarget( renderTarget ) {
  13030. var renderTargetProperties = properties.get( renderTarget );
  13031. var textureProperties = properties.get( renderTarget.texture );
  13032. if ( ! renderTarget ) return;
  13033. if ( textureProperties.__webglTexture !== undefined ) {
  13034. _gl.deleteTexture( textureProperties.__webglTexture );
  13035. }
  13036. if ( renderTarget.depthTexture ) {
  13037. renderTarget.depthTexture.dispose();
  13038. }
  13039. if ( renderTarget.isWebGLCubeRenderTarget ) {
  13040. for ( var i = 0; i < 6; i ++ ) {
  13041. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13042. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  13043. }
  13044. } else {
  13045. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13046. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  13047. if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer );
  13048. if ( renderTargetProperties.__webglColorRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer );
  13049. if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer );
  13050. }
  13051. properties.remove( renderTarget.texture );
  13052. properties.remove( renderTarget );
  13053. }
  13054. //
  13055. var textureUnits = 0;
  13056. function resetTextureUnits() {
  13057. textureUnits = 0;
  13058. }
  13059. function allocateTextureUnit() {
  13060. var textureUnit = textureUnits;
  13061. if ( textureUnit >= maxTextures ) {
  13062. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  13063. }
  13064. textureUnits += 1;
  13065. return textureUnit;
  13066. }
  13067. //
  13068. function setTexture2D( texture, slot ) {
  13069. var textureProperties = properties.get( texture );
  13070. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  13071. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13072. var image = texture.image;
  13073. if ( image === undefined ) {
  13074. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  13075. } else if ( image.complete === false ) {
  13076. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  13077. } else {
  13078. uploadTexture( textureProperties, texture, slot );
  13079. return;
  13080. }
  13081. }
  13082. state.activeTexture( 33984 + slot );
  13083. state.bindTexture( 3553, textureProperties.__webglTexture );
  13084. }
  13085. function setTexture2DArray( texture, slot ) {
  13086. var textureProperties = properties.get( texture );
  13087. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13088. uploadTexture( textureProperties, texture, slot );
  13089. return;
  13090. }
  13091. state.activeTexture( 33984 + slot );
  13092. state.bindTexture( 35866, textureProperties.__webglTexture );
  13093. }
  13094. function setTexture3D( texture, slot ) {
  13095. var textureProperties = properties.get( texture );
  13096. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13097. uploadTexture( textureProperties, texture, slot );
  13098. return;
  13099. }
  13100. state.activeTexture( 33984 + slot );
  13101. state.bindTexture( 32879, textureProperties.__webglTexture );
  13102. }
  13103. function setTextureCube( texture, slot ) {
  13104. if ( texture.image.length !== 6 ) return;
  13105. var textureProperties = properties.get( texture );
  13106. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13107. initTexture( textureProperties, texture );
  13108. state.activeTexture( 33984 + slot );
  13109. state.bindTexture( 34067, textureProperties.__webglTexture );
  13110. _gl.pixelStorei( 37440, texture.flipY );
  13111. var isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
  13112. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  13113. var cubeImage = [];
  13114. for ( var i = 0; i < 6; i ++ ) {
  13115. if ( ! isCompressed && ! isDataTexture ) {
  13116. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  13117. } else {
  13118. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13119. }
  13120. }
  13121. var image = cubeImage[ 0 ],
  13122. supportsMips = isPowerOfTwo( image ) || isWebGL2,
  13123. glFormat = utils.convert( texture.format ),
  13124. glType = utils.convert( texture.type ),
  13125. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13126. setTextureParameters( 34067, texture, supportsMips );
  13127. var mipmaps;
  13128. if ( isCompressed ) {
  13129. for ( var i = 0; i < 6; i ++ ) {
  13130. mipmaps = cubeImage[ i ].mipmaps;
  13131. for ( var j = 0; j < mipmaps.length; j ++ ) {
  13132. var mipmap = mipmaps[ j ];
  13133. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13134. if ( glFormat !== null ) {
  13135. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13136. } else {
  13137. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  13138. }
  13139. } else {
  13140. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13141. }
  13142. }
  13143. }
  13144. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13145. } else {
  13146. mipmaps = texture.mipmaps;
  13147. for ( var i = 0; i < 6; i ++ ) {
  13148. if ( isDataTexture ) {
  13149. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13150. for ( var j = 0; j < mipmaps.length; j ++ ) {
  13151. var mipmap = mipmaps[ j ];
  13152. var mipmapImage = mipmap.image[ i ].image;
  13153. state.texImage2D( 34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  13154. }
  13155. } else {
  13156. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  13157. for ( var j = 0; j < mipmaps.length; j ++ ) {
  13158. var mipmap = mipmaps[ j ];
  13159. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  13160. }
  13161. }
  13162. }
  13163. textureProperties.__maxMipLevel = mipmaps.length;
  13164. }
  13165. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13166. // We assume images for cube map have the same size.
  13167. generateMipmap( 34067, texture, image.width, image.height );
  13168. }
  13169. textureProperties.__version = texture.version;
  13170. if ( texture.onUpdate ) texture.onUpdate( texture );
  13171. } else {
  13172. state.activeTexture( 33984 + slot );
  13173. state.bindTexture( 34067, textureProperties.__webglTexture );
  13174. }
  13175. }
  13176. function setTextureCubeDynamic( texture, slot ) {
  13177. state.activeTexture( 33984 + slot );
  13178. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  13179. }
  13180. var wrappingToGL = {
  13181. [ RepeatWrapping ]: 10497,
  13182. [ ClampToEdgeWrapping ]: 33071,
  13183. [ MirroredRepeatWrapping ]: 33648
  13184. };
  13185. var filterToGL = {
  13186. [ NearestFilter ]: 9728,
  13187. [ NearestMipmapNearestFilter ]: 9984,
  13188. [ NearestMipmapLinearFilter ]: 9986,
  13189. [ LinearFilter ]: 9729,
  13190. [ LinearMipmapNearestFilter ]: 9985,
  13191. [ LinearMipmapLinearFilter ]: 9987
  13192. };
  13193. function setTextureParameters( textureType, texture, supportsMips ) {
  13194. if ( supportsMips ) {
  13195. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  13196. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  13197. if ( textureType === 32879 || textureType === 35866 ) {
  13198. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  13199. }
  13200. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  13201. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  13202. } else {
  13203. _gl.texParameteri( textureType, 10242, 33071 );
  13204. _gl.texParameteri( textureType, 10243, 33071 );
  13205. if ( textureType === 32879 || textureType === 35866 ) {
  13206. _gl.texParameteri( textureType, 32882, 33071 );
  13207. }
  13208. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  13209. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  13210. }
  13211. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  13212. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  13213. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  13214. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  13215. }
  13216. }
  13217. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13218. if ( extension ) {
  13219. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  13220. if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  13221. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13222. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  13223. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13224. }
  13225. }
  13226. }
  13227. function initTexture( textureProperties, texture ) {
  13228. if ( textureProperties.__webglInit === undefined ) {
  13229. textureProperties.__webglInit = true;
  13230. texture.addEventListener( 'dispose', onTextureDispose );
  13231. textureProperties.__webglTexture = _gl.createTexture();
  13232. info.memory.textures ++;
  13233. }
  13234. }
  13235. function uploadTexture( textureProperties, texture, slot ) {
  13236. var textureType = 3553;
  13237. if ( texture.isDataTexture2DArray ) textureType = 35866;
  13238. if ( texture.isDataTexture3D ) textureType = 32879;
  13239. initTexture( textureProperties, texture );
  13240. state.activeTexture( 33984 + slot );
  13241. state.bindTexture( textureType, textureProperties.__webglTexture );
  13242. _gl.pixelStorei( 37440, texture.flipY );
  13243. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  13244. _gl.pixelStorei( 3317, texture.unpackAlignment );
  13245. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  13246. var image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  13247. var supportsMips = isPowerOfTwo( image ) || isWebGL2,
  13248. glFormat = utils.convert( texture.format ),
  13249. glType = utils.convert( texture.type ),
  13250. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13251. setTextureParameters( textureType, texture, supportsMips );
  13252. var mipmap, mipmaps = texture.mipmaps;
  13253. if ( texture.isDepthTexture ) {
  13254. // populate depth texture with dummy data
  13255. glInternalFormat = 6402;
  13256. if ( isWebGL2 ) {
  13257. if ( texture.type === FloatType ) {
  13258. glInternalFormat = 36012;
  13259. } else if ( texture.type === UnsignedIntType ) {
  13260. glInternalFormat = 33190;
  13261. } else if ( texture.type === UnsignedInt248Type ) {
  13262. glInternalFormat = 35056;
  13263. } else {
  13264. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13265. }
  13266. } else {
  13267. if ( texture.type === FloatType ) {
  13268. console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
  13269. }
  13270. }
  13271. // validation checks for WebGL 1
  13272. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  13273. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13274. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13275. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13276. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  13277. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  13278. texture.type = UnsignedShortType;
  13279. glType = utils.convert( texture.type );
  13280. }
  13281. }
  13282. if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) {
  13283. // Depth stencil textures need the DEPTH_STENCIL internal format
  13284. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13285. glInternalFormat = 34041;
  13286. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13287. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13288. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13289. if ( texture.type !== UnsignedInt248Type ) {
  13290. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  13291. texture.type = UnsignedInt248Type;
  13292. glType = utils.convert( texture.type );
  13293. }
  13294. }
  13295. //
  13296. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  13297. } else if ( texture.isDataTexture ) {
  13298. // use manually created mipmaps if available
  13299. // if there are no manual mipmaps
  13300. // set 0 level mipmap and then use GL to generate other mipmap levels
  13301. if ( mipmaps.length > 0 && supportsMips ) {
  13302. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13303. mipmap = mipmaps[ i ];
  13304. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13305. }
  13306. texture.generateMipmaps = false;
  13307. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13308. } else {
  13309. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13310. textureProperties.__maxMipLevel = 0;
  13311. }
  13312. } else if ( texture.isCompressedTexture ) {
  13313. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13314. mipmap = mipmaps[ i ];
  13315. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13316. if ( glFormat !== null ) {
  13317. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13318. } else {
  13319. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  13320. }
  13321. } else {
  13322. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13323. }
  13324. }
  13325. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13326. } else if ( texture.isDataTexture2DArray ) {
  13327. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13328. textureProperties.__maxMipLevel = 0;
  13329. } else if ( texture.isDataTexture3D ) {
  13330. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13331. textureProperties.__maxMipLevel = 0;
  13332. } else {
  13333. // regular Texture (image, video, canvas)
  13334. // use manually created mipmaps if available
  13335. // if there are no manual mipmaps
  13336. // set 0 level mipmap and then use GL to generate other mipmap levels
  13337. if ( mipmaps.length > 0 && supportsMips ) {
  13338. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13339. mipmap = mipmaps[ i ];
  13340. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  13341. }
  13342. texture.generateMipmaps = false;
  13343. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13344. } else {
  13345. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  13346. textureProperties.__maxMipLevel = 0;
  13347. }
  13348. }
  13349. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13350. generateMipmap( textureType, texture, image.width, image.height );
  13351. }
  13352. textureProperties.__version = texture.version;
  13353. if ( texture.onUpdate ) texture.onUpdate( texture );
  13354. }
  13355. // Render targets
  13356. // Setup storage for target texture and bind it to correct framebuffer
  13357. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  13358. var glFormat = utils.convert( renderTarget.texture.format );
  13359. var glType = utils.convert( renderTarget.texture.type );
  13360. var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13361. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13362. _gl.bindFramebuffer( 36160, framebuffer );
  13363. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  13364. _gl.bindFramebuffer( 36160, null );
  13365. }
  13366. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13367. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  13368. _gl.bindRenderbuffer( 36161, renderbuffer );
  13369. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13370. var glInternalFormat = 33189;
  13371. if ( isMultisample ) {
  13372. var depthTexture = renderTarget.depthTexture;
  13373. if ( depthTexture && depthTexture.isDepthTexture ) {
  13374. if ( depthTexture.type === FloatType ) {
  13375. glInternalFormat = 36012;
  13376. } else if ( depthTexture.type === UnsignedIntType ) {
  13377. glInternalFormat = 33190;
  13378. }
  13379. }
  13380. var samples = getRenderTargetSamples( renderTarget );
  13381. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13382. } else {
  13383. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13384. }
  13385. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  13386. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13387. if ( isMultisample ) {
  13388. var samples = getRenderTargetSamples( renderTarget );
  13389. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  13390. } else {
  13391. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  13392. }
  13393. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  13394. } else {
  13395. var glFormat = utils.convert( renderTarget.texture.format );
  13396. var glType = utils.convert( renderTarget.texture.type );
  13397. var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13398. if ( isMultisample ) {
  13399. var samples = getRenderTargetSamples( renderTarget );
  13400. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13401. } else {
  13402. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13403. }
  13404. }
  13405. _gl.bindRenderbuffer( 36161, null );
  13406. }
  13407. // Setup resources for a Depth Texture for a FBO (needs an extension)
  13408. function setupDepthTexture( framebuffer, renderTarget ) {
  13409. var isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
  13410. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  13411. _gl.bindFramebuffer( 36160, framebuffer );
  13412. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  13413. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  13414. }
  13415. // upload an empty depth texture with framebuffer size
  13416. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  13417. renderTarget.depthTexture.image.width !== renderTarget.width ||
  13418. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13419. renderTarget.depthTexture.image.width = renderTarget.width;
  13420. renderTarget.depthTexture.image.height = renderTarget.height;
  13421. renderTarget.depthTexture.needsUpdate = true;
  13422. }
  13423. setTexture2D( renderTarget.depthTexture, 0 );
  13424. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13425. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13426. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13427. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13428. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13429. } else {
  13430. throw new Error( 'Unknown depthTexture format' );
  13431. }
  13432. }
  13433. // Setup GL resources for a non-texture depth buffer
  13434. function setupDepthRenderbuffer( renderTarget ) {
  13435. var renderTargetProperties = properties.get( renderTarget );
  13436. var isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13437. if ( renderTarget.depthTexture ) {
  13438. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13439. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13440. } else {
  13441. if ( isCube ) {
  13442. renderTargetProperties.__webglDepthbuffer = [];
  13443. for ( var i = 0; i < 6; i ++ ) {
  13444. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13445. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13446. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );
  13447. }
  13448. } else {
  13449. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13450. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13451. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );
  13452. }
  13453. }
  13454. _gl.bindFramebuffer( 36160, null );
  13455. }
  13456. // Set up GL resources for the render target
  13457. function setupRenderTarget( renderTarget ) {
  13458. var renderTargetProperties = properties.get( renderTarget );
  13459. var textureProperties = properties.get( renderTarget.texture );
  13460. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13461. textureProperties.__webglTexture = _gl.createTexture();
  13462. info.memory.textures ++;
  13463. var isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13464. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13465. var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13466. // Handles WebGL2 RGBFormat fallback - #18858
  13467. if ( isWebGL2 && renderTarget.texture.format === RGBFormat && ( renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType ) ) {
  13468. renderTarget.texture.format = RGBAFormat;
  13469. console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
  13470. }
  13471. // Setup framebuffer
  13472. if ( isCube ) {
  13473. renderTargetProperties.__webglFramebuffer = [];
  13474. for ( var i = 0; i < 6; i ++ ) {
  13475. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13476. }
  13477. } else {
  13478. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13479. if ( isMultisample ) {
  13480. if ( isWebGL2 ) {
  13481. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13482. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13483. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13484. var glFormat = utils.convert( renderTarget.texture.format );
  13485. var glType = utils.convert( renderTarget.texture.type );
  13486. var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13487. var samples = getRenderTargetSamples( renderTarget );
  13488. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13489. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13490. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13491. _gl.bindRenderbuffer( 36161, null );
  13492. if ( renderTarget.depthBuffer ) {
  13493. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13494. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13495. }
  13496. _gl.bindFramebuffer( 36160, null );
  13497. } else {
  13498. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13499. }
  13500. }
  13501. }
  13502. // Setup color buffer
  13503. if ( isCube ) {
  13504. state.bindTexture( 34067, textureProperties.__webglTexture );
  13505. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13506. for ( var i = 0; i < 6; i ++ ) {
  13507. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13508. }
  13509. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13510. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13511. }
  13512. state.bindTexture( 34067, null );
  13513. } else {
  13514. state.bindTexture( 3553, textureProperties.__webglTexture );
  13515. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13516. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13517. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13518. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13519. }
  13520. state.bindTexture( 3553, null );
  13521. }
  13522. // Setup depth and stencil buffers
  13523. if ( renderTarget.depthBuffer ) {
  13524. setupDepthRenderbuffer( renderTarget );
  13525. }
  13526. }
  13527. function updateRenderTargetMipmap( renderTarget ) {
  13528. var texture = renderTarget.texture;
  13529. var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13530. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13531. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13532. var webglTexture = properties.get( texture ).__webglTexture;
  13533. state.bindTexture( target, webglTexture );
  13534. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13535. state.bindTexture( target, null );
  13536. }
  13537. }
  13538. function updateMultisampleRenderTarget( renderTarget ) {
  13539. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13540. if ( isWebGL2 ) {
  13541. var renderTargetProperties = properties.get( renderTarget );
  13542. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13543. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13544. var width = renderTarget.width;
  13545. var height = renderTarget.height;
  13546. var mask = 16384;
  13547. if ( renderTarget.depthBuffer ) mask |= 256;
  13548. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13549. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13550. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); // see #18905
  13551. } else {
  13552. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13553. }
  13554. }
  13555. }
  13556. function getRenderTargetSamples( renderTarget ) {
  13557. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13558. Math.min( maxSamples, renderTarget.samples ) : 0;
  13559. }
  13560. function updateVideoTexture( texture ) {
  13561. var frame = info.render.frame;
  13562. // Check the last frame we updated the VideoTexture
  13563. if ( _videoTextures.get( texture ) !== frame ) {
  13564. _videoTextures.set( texture, frame );
  13565. texture.update();
  13566. }
  13567. }
  13568. // backwards compatibility
  13569. var warnedTexture2D = false;
  13570. var warnedTextureCube = false;
  13571. function safeSetTexture2D( texture, slot ) {
  13572. if ( texture && texture.isWebGLRenderTarget ) {
  13573. if ( warnedTexture2D === false ) {
  13574. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13575. warnedTexture2D = true;
  13576. }
  13577. texture = texture.texture;
  13578. }
  13579. setTexture2D( texture, slot );
  13580. }
  13581. function safeSetTextureCube( texture, slot ) {
  13582. if ( texture && texture.isWebGLCubeRenderTarget ) {
  13583. if ( warnedTextureCube === false ) {
  13584. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13585. warnedTextureCube = true;
  13586. }
  13587. texture = texture.texture;
  13588. }
  13589. // currently relying on the fact that WebGLCubeRenderTarget.texture is a Texture and NOT a CubeTexture
  13590. // TODO: unify these code paths
  13591. if ( ( texture && texture.isCubeTexture ) ||
  13592. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13593. // CompressedTexture can have Array in image :/
  13594. // this function alone should take care of cube textures
  13595. setTextureCube( texture, slot );
  13596. } else {
  13597. // assumed: texture property of THREE.WebGLCubeRenderTarget
  13598. setTextureCubeDynamic( texture, slot );
  13599. }
  13600. }
  13601. //
  13602. this.allocateTextureUnit = allocateTextureUnit;
  13603. this.resetTextureUnits = resetTextureUnits;
  13604. this.setTexture2D = setTexture2D;
  13605. this.setTexture2DArray = setTexture2DArray;
  13606. this.setTexture3D = setTexture3D;
  13607. this.setTextureCube = setTextureCube;
  13608. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13609. this.setupRenderTarget = setupRenderTarget;
  13610. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13611. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13612. this.safeSetTexture2D = safeSetTexture2D;
  13613. this.safeSetTextureCube = safeSetTextureCube;
  13614. }
  13615. /**
  13616. * @author thespite / http://www.twitter.com/thespite
  13617. */
  13618. function WebGLUtils( gl, extensions, capabilities ) {
  13619. var isWebGL2 = capabilities.isWebGL2;
  13620. function convert( p ) {
  13621. var extension;
  13622. if ( p === UnsignedByteType ) return 5121;
  13623. if ( p === UnsignedShort4444Type ) return 32819;
  13624. if ( p === UnsignedShort5551Type ) return 32820;
  13625. if ( p === UnsignedShort565Type ) return 33635;
  13626. if ( p === ByteType ) return 5120;
  13627. if ( p === ShortType ) return 5122;
  13628. if ( p === UnsignedShortType ) return 5123;
  13629. if ( p === IntType ) return 5124;
  13630. if ( p === UnsignedIntType ) return 5125;
  13631. if ( p === FloatType ) return 5126;
  13632. if ( p === HalfFloatType ) {
  13633. if ( isWebGL2 ) return 5131;
  13634. extension = extensions.get( 'OES_texture_half_float' );
  13635. if ( extension !== null ) {
  13636. return extension.HALF_FLOAT_OES;
  13637. } else {
  13638. return null;
  13639. }
  13640. }
  13641. if ( p === AlphaFormat ) return 6406;
  13642. if ( p === RGBFormat ) return 6407;
  13643. if ( p === RGBAFormat ) return 6408;
  13644. if ( p === LuminanceFormat ) return 6409;
  13645. if ( p === LuminanceAlphaFormat ) return 6410;
  13646. if ( p === DepthFormat ) return 6402;
  13647. if ( p === DepthStencilFormat ) return 34041;
  13648. if ( p === RedFormat ) return 6403;
  13649. // WebGL2 formats.
  13650. if ( p === RedIntegerFormat ) return 36244;
  13651. if ( p === RGFormat ) return 33319;
  13652. if ( p === RGIntegerFormat ) return 33320;
  13653. if ( p === RGBIntegerFormat ) return 36248;
  13654. if ( p === RGBAIntegerFormat ) return 36249;
  13655. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13656. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13657. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13658. if ( extension !== null ) {
  13659. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13660. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13661. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13662. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13663. } else {
  13664. return null;
  13665. }
  13666. }
  13667. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13668. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13669. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13670. if ( extension !== null ) {
  13671. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13672. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13673. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13674. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13675. } else {
  13676. return null;
  13677. }
  13678. }
  13679. if ( p === RGB_ETC1_Format ) {
  13680. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13681. if ( extension !== null ) {
  13682. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13683. } else {
  13684. return null;
  13685. }
  13686. }
  13687. if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
  13688. extension = extensions.get( 'WEBGL_compressed_texture_etc' );
  13689. if ( extension !== null ) {
  13690. if ( p === RGB_ETC2_Format ) return extension.COMPRESSED_RGB8_ETC2;
  13691. if ( p === RGBA_ETC2_EAC_Format ) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13692. }
  13693. }
  13694. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13695. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13696. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13697. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13698. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ||
  13699. p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format ||
  13700. p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format ||
  13701. p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format ||
  13702. p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format ||
  13703. p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format ) {
  13704. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13705. if ( extension !== null ) {
  13706. // TODO Complete?
  13707. return p;
  13708. } else {
  13709. return null;
  13710. }
  13711. }
  13712. if ( p === RGBA_BPTC_Format ) {
  13713. extension = extensions.get( 'EXT_texture_compression_bptc' );
  13714. if ( extension !== null ) {
  13715. // TODO Complete?
  13716. return p;
  13717. } else {
  13718. return null;
  13719. }
  13720. }
  13721. if ( p === UnsignedInt248Type ) {
  13722. if ( isWebGL2 ) return 34042;
  13723. extension = extensions.get( 'WEBGL_depth_texture' );
  13724. if ( extension !== null ) {
  13725. return extension.UNSIGNED_INT_24_8_WEBGL;
  13726. } else {
  13727. return null;
  13728. }
  13729. }
  13730. }
  13731. return { convert: convert };
  13732. }
  13733. /**
  13734. * @author mrdoob / http://mrdoob.com/
  13735. */
  13736. function ArrayCamera( array ) {
  13737. PerspectiveCamera.call( this );
  13738. this.cameras = array || [];
  13739. }
  13740. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13741. constructor: ArrayCamera,
  13742. isArrayCamera: true
  13743. } );
  13744. /**
  13745. * @author mrdoob / http://mrdoob.com/
  13746. */
  13747. function Group() {
  13748. Object3D.call( this );
  13749. this.type = 'Group';
  13750. }
  13751. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13752. constructor: Group,
  13753. isGroup: true
  13754. } );
  13755. /**
  13756. * @author Mugen87 / https://github.com/Mugen87
  13757. */
  13758. function WebXRController() {
  13759. this._targetRay = null;
  13760. this._grip = null;
  13761. }
  13762. Object.assign( WebXRController.prototype, {
  13763. constructor: WebXRController,
  13764. getTargetRaySpace: function () {
  13765. if ( this._targetRay === null ) {
  13766. this._targetRay = new Group();
  13767. this._targetRay.matrixAutoUpdate = false;
  13768. this._targetRay.visible = false;
  13769. }
  13770. return this._targetRay;
  13771. },
  13772. getGripSpace: function () {
  13773. if ( this._grip === null ) {
  13774. this._grip = new Group();
  13775. this._grip.matrixAutoUpdate = false;
  13776. this._grip.visible = false;
  13777. }
  13778. return this._grip;
  13779. },
  13780. dispatchEvent: function ( event ) {
  13781. if ( this._targetRay !== null ) {
  13782. this._targetRay.dispatchEvent( event );
  13783. }
  13784. if ( this._grip !== null ) {
  13785. this._grip.dispatchEvent( event );
  13786. }
  13787. return this;
  13788. },
  13789. disconnect: function ( inputSource ) {
  13790. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  13791. if ( this._targetRay !== null ) {
  13792. this._targetRay.visible = false;
  13793. }
  13794. if ( this._grip !== null ) {
  13795. this._grip.visible = false;
  13796. }
  13797. return this;
  13798. },
  13799. update: function ( inputSource, frame, referenceSpace ) {
  13800. var inputPose = null;
  13801. var gripPose = null;
  13802. var targetRay = this._targetRay;
  13803. var grip = this._grip;
  13804. if ( inputSource ) {
  13805. if ( targetRay !== null ) {
  13806. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13807. if ( inputPose !== null ) {
  13808. targetRay.matrix.fromArray( inputPose.transform.matrix );
  13809. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  13810. }
  13811. }
  13812. if ( grip !== null && inputSource.gripSpace ) {
  13813. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  13814. if ( gripPose !== null ) {
  13815. grip.matrix.fromArray( gripPose.transform.matrix );
  13816. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  13817. }
  13818. }
  13819. }
  13820. if ( targetRay !== null ) {
  13821. targetRay.visible = ( inputPose !== null );
  13822. }
  13823. if ( grip !== null ) {
  13824. grip.visible = ( gripPose !== null );
  13825. }
  13826. return this;
  13827. }
  13828. } );
  13829. /**
  13830. * @author mrdoob / http://mrdoob.com/
  13831. */
  13832. function WebXRManager( renderer, gl ) {
  13833. var scope = this;
  13834. var session = null;
  13835. var framebufferScaleFactor = 1.0;
  13836. var referenceSpace = null;
  13837. var referenceSpaceType = 'local-floor';
  13838. var pose = null;
  13839. var controllers = [];
  13840. var inputSourcesMap = new Map();
  13841. //
  13842. var cameraL = new PerspectiveCamera();
  13843. cameraL.layers.enable( 1 );
  13844. cameraL.viewport = new Vector4();
  13845. var cameraR = new PerspectiveCamera();
  13846. cameraR.layers.enable( 2 );
  13847. cameraR.viewport = new Vector4();
  13848. var cameras = [ cameraL, cameraR ];
  13849. var cameraVR = new ArrayCamera();
  13850. cameraVR.layers.enable( 1 );
  13851. cameraVR.layers.enable( 2 );
  13852. var _currentDepthNear = null;
  13853. var _currentDepthFar = null;
  13854. //
  13855. this.enabled = false;
  13856. this.isPresenting = false;
  13857. this.getController = function ( index ) {
  13858. var controller = controllers[ index ];
  13859. if ( controller === undefined ) {
  13860. controller = new WebXRController();
  13861. controllers[ index ] = controller;
  13862. }
  13863. return controller.getTargetRaySpace();
  13864. };
  13865. this.getControllerGrip = function ( index ) {
  13866. var controller = controllers[ index ];
  13867. if ( controller === undefined ) {
  13868. controller = new WebXRController();
  13869. controllers[ index ] = controller;
  13870. }
  13871. return controller.getGripSpace();
  13872. };
  13873. //
  13874. function onSessionEvent( event ) {
  13875. var controller = inputSourcesMap.get( event.inputSource );
  13876. if ( controller ) {
  13877. controller.dispatchEvent( { type: event.type } );
  13878. }
  13879. }
  13880. function onSessionEnd() {
  13881. inputSourcesMap.forEach( function ( controller, inputSource ) {
  13882. controller.disconnect( inputSource );
  13883. } );
  13884. inputSourcesMap.clear();
  13885. //
  13886. renderer.setFramebuffer( null );
  13887. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13888. animation.stop();
  13889. scope.isPresenting = false;
  13890. scope.dispatchEvent( { type: 'sessionend' } );
  13891. }
  13892. function onRequestReferenceSpace( value ) {
  13893. referenceSpace = value;
  13894. animation.setContext( session );
  13895. animation.start();
  13896. scope.isPresenting = true;
  13897. scope.dispatchEvent( { type: 'sessionstart' } );
  13898. }
  13899. this.setFramebufferScaleFactor = function ( value ) {
  13900. framebufferScaleFactor = value;
  13901. if ( scope.isPresenting === true ) {
  13902. console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' );
  13903. }
  13904. };
  13905. this.setReferenceSpaceType = function ( value ) {
  13906. referenceSpaceType = value;
  13907. if ( scope.isPresenting === true ) {
  13908. console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' );
  13909. }
  13910. };
  13911. this.getReferenceSpace = function () {
  13912. return referenceSpace;
  13913. };
  13914. this.getSession = function () {
  13915. return session;
  13916. };
  13917. this.setSession = function ( value ) {
  13918. session = value;
  13919. if ( session !== null ) {
  13920. session.addEventListener( 'select', onSessionEvent );
  13921. session.addEventListener( 'selectstart', onSessionEvent );
  13922. session.addEventListener( 'selectend', onSessionEvent );
  13923. session.addEventListener( 'squeeze', onSessionEvent );
  13924. session.addEventListener( 'squeezestart', onSessionEvent );
  13925. session.addEventListener( 'squeezeend', onSessionEvent );
  13926. session.addEventListener( 'end', onSessionEnd );
  13927. var attributes = gl.getContextAttributes();
  13928. if ( attributes.xrCompatible !== true ) {
  13929. gl.makeXRCompatible();
  13930. }
  13931. var layerInit = {
  13932. antialias: attributes.antialias,
  13933. alpha: attributes.alpha,
  13934. depth: attributes.depth,
  13935. stencil: attributes.stencil,
  13936. framebufferScaleFactor: framebufferScaleFactor
  13937. };
  13938. // eslint-disable-next-line no-undef
  13939. var baseLayer = new XRWebGLLayer( session, gl, layerInit );
  13940. session.updateRenderState( { baseLayer: baseLayer } );
  13941. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13942. //
  13943. session.addEventListener( 'inputsourceschange', updateInputSources );
  13944. }
  13945. };
  13946. function updateInputSources( event ) {
  13947. var inputSources = session.inputSources;
  13948. // Assign inputSources to available controllers
  13949. for ( var i = 0; i < controllers.length; i ++ ) {
  13950. inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
  13951. }
  13952. // Notify disconnected
  13953. for ( var i = 0; i < event.removed.length; i ++ ) {
  13954. var inputSource = event.removed[ i ];
  13955. var controller = inputSourcesMap.get( inputSource );
  13956. if ( controller ) {
  13957. controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
  13958. inputSourcesMap.delete( inputSource );
  13959. }
  13960. }
  13961. // Notify connected
  13962. for ( var i = 0; i < event.added.length; i ++ ) {
  13963. var inputSource = event.added[ i ];
  13964. var controller = inputSourcesMap.get( inputSource );
  13965. if ( controller ) {
  13966. controller.dispatchEvent( { type: 'connected', data: inputSource } );
  13967. }
  13968. }
  13969. }
  13970. //
  13971. var cameraLPos = new Vector3();
  13972. var cameraRPos = new Vector3();
  13973. /**
  13974. * @author jsantell / https://www.jsantell.com/
  13975. *
  13976. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13977. * the cameras' projection and world matrices have already been set.
  13978. * And that near and far planes are identical for both cameras.
  13979. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13980. */
  13981. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13982. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13983. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13984. var ipd = cameraLPos.distanceTo( cameraRPos );
  13985. var projL = cameraL.projectionMatrix.elements;
  13986. var projR = cameraR.projectionMatrix.elements;
  13987. // VR systems will have identical far and near planes, and
  13988. // most likely identical top and bottom frustum extents.
  13989. // Use the left camera for these values.
  13990. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13991. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13992. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13993. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13994. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13995. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13996. var left = near * leftFov;
  13997. var right = near * rightFov;
  13998. // Calculate the new camera's position offset from the
  13999. // left camera. xOffset should be roughly half `ipd`.
  14000. var zOffset = ipd / ( - leftFov + rightFov );
  14001. var xOffset = zOffset * - leftFov;
  14002. // TODO: Better way to apply this offset?
  14003. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  14004. camera.translateX( xOffset );
  14005. camera.translateZ( zOffset );
  14006. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  14007. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14008. // Find the union of the frustum values of the cameras and scale
  14009. // the values so that the near plane's position does not change in world space,
  14010. // although must now be relative to the new union camera.
  14011. var near2 = near + zOffset;
  14012. var far2 = far + zOffset;
  14013. var left2 = left - xOffset;
  14014. var right2 = right + ( ipd - xOffset );
  14015. var top2 = topFov * far / far2 * near2;
  14016. var bottom2 = bottomFov * far / far2 * near2;
  14017. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  14018. }
  14019. function updateCamera( camera, parent ) {
  14020. if ( parent === null ) {
  14021. camera.matrixWorld.copy( camera.matrix );
  14022. } else {
  14023. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  14024. }
  14025. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14026. }
  14027. this.getCamera = function ( camera ) {
  14028. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14029. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14030. if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {
  14031. // Note that the new renderState won't apply until the next frame. See #18320
  14032. session.updateRenderState( {
  14033. depthNear: cameraVR.near,
  14034. depthFar: cameraVR.far
  14035. } );
  14036. _currentDepthNear = cameraVR.near;
  14037. _currentDepthFar = cameraVR.far;
  14038. }
  14039. var parent = camera.parent;
  14040. var cameras = cameraVR.cameras;
  14041. updateCamera( cameraVR, parent );
  14042. for ( var i = 0; i < cameras.length; i ++ ) {
  14043. updateCamera( cameras[ i ], parent );
  14044. }
  14045. // update camera and its children
  14046. camera.matrixWorld.copy( cameraVR.matrixWorld );
  14047. var children = camera.children;
  14048. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14049. children[ i ].updateMatrixWorld( true );
  14050. }
  14051. // update projection matrix for proper view frustum culling
  14052. if ( cameras.length === 2 ) {
  14053. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  14054. } else {
  14055. // assume single camera setup (AR)
  14056. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  14057. }
  14058. return cameraVR;
  14059. };
  14060. // Animation Loop
  14061. var onAnimationFrameCallback = null;
  14062. function onAnimationFrame( time, frame ) {
  14063. pose = frame.getViewerPose( referenceSpace );
  14064. if ( pose !== null ) {
  14065. var views = pose.views;
  14066. var baseLayer = session.renderState.baseLayer;
  14067. renderer.setFramebuffer( baseLayer.framebuffer );
  14068. var cameraVRNeedsUpdate = false;
  14069. // check if it's necessary to rebuild cameraVR's camera list
  14070. if ( views.length !== cameraVR.cameras.length ) {
  14071. cameraVR.cameras.length = 0;
  14072. cameraVRNeedsUpdate = true;
  14073. }
  14074. for ( var i = 0; i < views.length; i ++ ) {
  14075. var view = views[ i ];
  14076. var viewport = baseLayer.getViewport( view );
  14077. var camera = cameras[ i ];
  14078. camera.matrix.fromArray( view.transform.matrix );
  14079. camera.projectionMatrix.fromArray( view.projectionMatrix );
  14080. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  14081. if ( i === 0 ) {
  14082. cameraVR.matrix.copy( camera.matrix );
  14083. }
  14084. if ( cameraVRNeedsUpdate === true ) {
  14085. cameraVR.cameras.push( camera );
  14086. }
  14087. }
  14088. }
  14089. //
  14090. var inputSources = session.inputSources;
  14091. for ( var i = 0; i < controllers.length; i ++ ) {
  14092. var controller = controllers[ i ];
  14093. var inputSource = inputSources[ i ];
  14094. controller.update( inputSource, frame, referenceSpace );
  14095. }
  14096. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
  14097. }
  14098. var animation = new WebGLAnimation();
  14099. animation.setAnimationLoop( onAnimationFrame );
  14100. this.setAnimationLoop = function ( callback ) {
  14101. onAnimationFrameCallback = callback;
  14102. };
  14103. this.dispose = function () {};
  14104. }
  14105. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  14106. /**
  14107. * @author mrdoob / http://mrdoob.com/
  14108. */
  14109. function WebGLMaterials( properties ) {
  14110. function refreshFogUniforms( uniforms, fog ) {
  14111. uniforms.fogColor.value.copy( fog.color );
  14112. if ( fog.isFog ) {
  14113. uniforms.fogNear.value = fog.near;
  14114. uniforms.fogFar.value = fog.far;
  14115. } else if ( fog.isFogExp2 ) {
  14116. uniforms.fogDensity.value = fog.density;
  14117. }
  14118. }
  14119. function refreshMaterialUniforms( uniforms, material, environment, pixelRatio, height ) {
  14120. if ( material.isMeshBasicMaterial ) {
  14121. refreshUniformsCommon( uniforms, material );
  14122. } else if ( material.isMeshLambertMaterial ) {
  14123. refreshUniformsCommon( uniforms, material );
  14124. refreshUniformsLambert( uniforms, material );
  14125. } else if ( material.isMeshToonMaterial ) {
  14126. refreshUniformsCommon( uniforms, material );
  14127. refreshUniformsToon( uniforms, material );
  14128. } else if ( material.isMeshPhongMaterial ) {
  14129. refreshUniformsCommon( uniforms, material );
  14130. refreshUniformsPhong( uniforms, material );
  14131. } else if ( material.isMeshStandardMaterial ) {
  14132. refreshUniformsCommon( uniforms, material, environment );
  14133. if ( material.isMeshPhysicalMaterial ) {
  14134. refreshUniformsPhysical( uniforms, material, environment );
  14135. } else {
  14136. refreshUniformsStandard( uniforms, material, environment );
  14137. }
  14138. } else if ( material.isMeshMatcapMaterial ) {
  14139. refreshUniformsCommon( uniforms, material );
  14140. refreshUniformsMatcap( uniforms, material );
  14141. } else if ( material.isMeshDepthMaterial ) {
  14142. refreshUniformsCommon( uniforms, material );
  14143. refreshUniformsDepth( uniforms, material );
  14144. } else if ( material.isMeshDistanceMaterial ) {
  14145. refreshUniformsCommon( uniforms, material );
  14146. refreshUniformsDistance( uniforms, material );
  14147. } else if ( material.isMeshNormalMaterial ) {
  14148. refreshUniformsCommon( uniforms, material );
  14149. refreshUniformsNormal( uniforms, material );
  14150. } else if ( material.isLineBasicMaterial ) {
  14151. refreshUniformsLine( uniforms, material );
  14152. if ( material.isLineDashedMaterial ) {
  14153. refreshUniformsDash( uniforms, material );
  14154. }
  14155. } else if ( material.isPointsMaterial ) {
  14156. refreshUniformsPoints( uniforms, material, pixelRatio, height );
  14157. } else if ( material.isSpriteMaterial ) {
  14158. refreshUniformsSprites( uniforms, material );
  14159. } else if ( material.isShadowMaterial ) {
  14160. uniforms.color.value.copy( material.color );
  14161. uniforms.opacity.value = material.opacity;
  14162. } else if ( material.isShaderMaterial ) {
  14163. material.uniformsNeedUpdate = false; // #15581
  14164. }
  14165. }
  14166. function refreshUniformsCommon( uniforms, material, environment ) {
  14167. uniforms.opacity.value = material.opacity;
  14168. if ( material.color ) {
  14169. uniforms.diffuse.value.copy( material.color );
  14170. }
  14171. if ( material.emissive ) {
  14172. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14173. }
  14174. if ( material.map ) {
  14175. uniforms.map.value = material.map;
  14176. }
  14177. if ( material.alphaMap ) {
  14178. uniforms.alphaMap.value = material.alphaMap;
  14179. }
  14180. if ( material.specularMap ) {
  14181. uniforms.specularMap.value = material.specularMap;
  14182. }
  14183. var envMap = material.envMap || environment;
  14184. if ( envMap ) {
  14185. uniforms.envMap.value = envMap;
  14186. uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1;
  14187. uniforms.reflectivity.value = material.reflectivity;
  14188. uniforms.refractionRatio.value = material.refractionRatio;
  14189. uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel;
  14190. }
  14191. if ( material.lightMap ) {
  14192. uniforms.lightMap.value = material.lightMap;
  14193. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14194. }
  14195. if ( material.aoMap ) {
  14196. uniforms.aoMap.value = material.aoMap;
  14197. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14198. }
  14199. // uv repeat and offset setting priorities
  14200. // 1. color map
  14201. // 2. specular map
  14202. // 3. normal map
  14203. // 4. bump map
  14204. // 5. alpha map
  14205. // 6. emissive map
  14206. var uvScaleMap;
  14207. if ( material.map ) {
  14208. uvScaleMap = material.map;
  14209. } else if ( material.specularMap ) {
  14210. uvScaleMap = material.specularMap;
  14211. } else if ( material.displacementMap ) {
  14212. uvScaleMap = material.displacementMap;
  14213. } else if ( material.normalMap ) {
  14214. uvScaleMap = material.normalMap;
  14215. } else if ( material.bumpMap ) {
  14216. uvScaleMap = material.bumpMap;
  14217. } else if ( material.roughnessMap ) {
  14218. uvScaleMap = material.roughnessMap;
  14219. } else if ( material.metalnessMap ) {
  14220. uvScaleMap = material.metalnessMap;
  14221. } else if ( material.alphaMap ) {
  14222. uvScaleMap = material.alphaMap;
  14223. } else if ( material.emissiveMap ) {
  14224. uvScaleMap = material.emissiveMap;
  14225. }
  14226. if ( uvScaleMap !== undefined ) {
  14227. // backwards compatibility
  14228. if ( uvScaleMap.isWebGLRenderTarget ) {
  14229. uvScaleMap = uvScaleMap.texture;
  14230. }
  14231. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14232. uvScaleMap.updateMatrix();
  14233. }
  14234. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14235. }
  14236. // uv repeat and offset setting priorities for uv2
  14237. // 1. ao map
  14238. // 2. light map
  14239. var uv2ScaleMap;
  14240. if ( material.aoMap ) {
  14241. uv2ScaleMap = material.aoMap;
  14242. } else if ( material.lightMap ) {
  14243. uv2ScaleMap = material.lightMap;
  14244. }
  14245. if ( uv2ScaleMap !== undefined ) {
  14246. // backwards compatibility
  14247. if ( uv2ScaleMap.isWebGLRenderTarget ) {
  14248. uv2ScaleMap = uv2ScaleMap.texture;
  14249. }
  14250. if ( uv2ScaleMap.matrixAutoUpdate === true ) {
  14251. uv2ScaleMap.updateMatrix();
  14252. }
  14253. uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );
  14254. }
  14255. }
  14256. function refreshUniformsLine( uniforms, material ) {
  14257. uniforms.diffuse.value.copy( material.color );
  14258. uniforms.opacity.value = material.opacity;
  14259. }
  14260. function refreshUniformsDash( uniforms, material ) {
  14261. uniforms.dashSize.value = material.dashSize;
  14262. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14263. uniforms.scale.value = material.scale;
  14264. }
  14265. function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {
  14266. uniforms.diffuse.value.copy( material.color );
  14267. uniforms.opacity.value = material.opacity;
  14268. uniforms.size.value = material.size * pixelRatio;
  14269. uniforms.scale.value = height * 0.5;
  14270. if ( material.map ) {
  14271. uniforms.map.value = material.map;
  14272. }
  14273. if ( material.alphaMap ) {
  14274. uniforms.alphaMap.value = material.alphaMap;
  14275. }
  14276. // uv repeat and offset setting priorities
  14277. // 1. color map
  14278. // 2. alpha map
  14279. var uvScaleMap;
  14280. if ( material.map ) {
  14281. uvScaleMap = material.map;
  14282. } else if ( material.alphaMap ) {
  14283. uvScaleMap = material.alphaMap;
  14284. }
  14285. if ( uvScaleMap !== undefined ) {
  14286. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14287. uvScaleMap.updateMatrix();
  14288. }
  14289. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14290. }
  14291. }
  14292. function refreshUniformsSprites( uniforms, material ) {
  14293. uniforms.diffuse.value.copy( material.color );
  14294. uniforms.opacity.value = material.opacity;
  14295. uniforms.rotation.value = material.rotation;
  14296. if ( material.map ) {
  14297. uniforms.map.value = material.map;
  14298. }
  14299. if ( material.alphaMap ) {
  14300. uniforms.alphaMap.value = material.alphaMap;
  14301. }
  14302. // uv repeat and offset setting priorities
  14303. // 1. color map
  14304. // 2. alpha map
  14305. var uvScaleMap;
  14306. if ( material.map ) {
  14307. uvScaleMap = material.map;
  14308. } else if ( material.alphaMap ) {
  14309. uvScaleMap = material.alphaMap;
  14310. }
  14311. if ( uvScaleMap !== undefined ) {
  14312. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14313. uvScaleMap.updateMatrix();
  14314. }
  14315. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14316. }
  14317. }
  14318. function refreshUniformsLambert( uniforms, material ) {
  14319. if ( material.emissiveMap ) {
  14320. uniforms.emissiveMap.value = material.emissiveMap;
  14321. }
  14322. }
  14323. function refreshUniformsPhong( uniforms, material ) {
  14324. uniforms.specular.value.copy( material.specular );
  14325. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14326. if ( material.emissiveMap ) {
  14327. uniforms.emissiveMap.value = material.emissiveMap;
  14328. }
  14329. if ( material.bumpMap ) {
  14330. uniforms.bumpMap.value = material.bumpMap;
  14331. uniforms.bumpScale.value = material.bumpScale;
  14332. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14333. }
  14334. if ( material.normalMap ) {
  14335. uniforms.normalMap.value = material.normalMap;
  14336. uniforms.normalScale.value.copy( material.normalScale );
  14337. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14338. }
  14339. if ( material.displacementMap ) {
  14340. uniforms.displacementMap.value = material.displacementMap;
  14341. uniforms.displacementScale.value = material.displacementScale;
  14342. uniforms.displacementBias.value = material.displacementBias;
  14343. }
  14344. }
  14345. function refreshUniformsToon( uniforms, material ) {
  14346. uniforms.specular.value.copy( material.specular );
  14347. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14348. if ( material.gradientMap ) {
  14349. uniforms.gradientMap.value = material.gradientMap;
  14350. }
  14351. if ( material.emissiveMap ) {
  14352. uniforms.emissiveMap.value = material.emissiveMap;
  14353. }
  14354. if ( material.bumpMap ) {
  14355. uniforms.bumpMap.value = material.bumpMap;
  14356. uniforms.bumpScale.value = material.bumpScale;
  14357. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14358. }
  14359. if ( material.normalMap ) {
  14360. uniforms.normalMap.value = material.normalMap;
  14361. uniforms.normalScale.value.copy( material.normalScale );
  14362. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14363. }
  14364. if ( material.displacementMap ) {
  14365. uniforms.displacementMap.value = material.displacementMap;
  14366. uniforms.displacementScale.value = material.displacementScale;
  14367. uniforms.displacementBias.value = material.displacementBias;
  14368. }
  14369. }
  14370. function refreshUniformsStandard( uniforms, material, environment ) {
  14371. uniforms.roughness.value = material.roughness;
  14372. uniforms.metalness.value = material.metalness;
  14373. if ( material.roughnessMap ) {
  14374. uniforms.roughnessMap.value = material.roughnessMap;
  14375. }
  14376. if ( material.metalnessMap ) {
  14377. uniforms.metalnessMap.value = material.metalnessMap;
  14378. }
  14379. if ( material.emissiveMap ) {
  14380. uniforms.emissiveMap.value = material.emissiveMap;
  14381. }
  14382. if ( material.bumpMap ) {
  14383. uniforms.bumpMap.value = material.bumpMap;
  14384. uniforms.bumpScale.value = material.bumpScale;
  14385. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14386. }
  14387. if ( material.normalMap ) {
  14388. uniforms.normalMap.value = material.normalMap;
  14389. uniforms.normalScale.value.copy( material.normalScale );
  14390. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14391. }
  14392. if ( material.displacementMap ) {
  14393. uniforms.displacementMap.value = material.displacementMap;
  14394. uniforms.displacementScale.value = material.displacementScale;
  14395. uniforms.displacementBias.value = material.displacementBias;
  14396. }
  14397. if ( material.envMap || environment ) {
  14398. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14399. uniforms.envMapIntensity.value = material.envMapIntensity;
  14400. }
  14401. }
  14402. function refreshUniformsPhysical( uniforms, material, environment ) {
  14403. refreshUniformsStandard( uniforms, material, environment );
  14404. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14405. uniforms.clearcoat.value = material.clearcoat;
  14406. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14407. if ( material.sheen ) uniforms.sheen.value.copy( material.sheen );
  14408. if ( material.clearcoatMap ) {
  14409. uniforms.clearcoatMap.value = material.clearcoatMap;
  14410. }
  14411. if ( material.clearcoatRoughnessMap ) {
  14412. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14413. }
  14414. if ( material.clearcoatNormalMap ) {
  14415. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  14416. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14417. if ( material.side === BackSide ) {
  14418. uniforms.clearcoatNormalScale.value.negate();
  14419. }
  14420. }
  14421. uniforms.transparency.value = material.transparency;
  14422. }
  14423. function refreshUniformsMatcap( uniforms, material ) {
  14424. if ( material.matcap ) {
  14425. uniforms.matcap.value = material.matcap;
  14426. }
  14427. if ( material.bumpMap ) {
  14428. uniforms.bumpMap.value = material.bumpMap;
  14429. uniforms.bumpScale.value = material.bumpScale;
  14430. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14431. }
  14432. if ( material.normalMap ) {
  14433. uniforms.normalMap.value = material.normalMap;
  14434. uniforms.normalScale.value.copy( material.normalScale );
  14435. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14436. }
  14437. if ( material.displacementMap ) {
  14438. uniforms.displacementMap.value = material.displacementMap;
  14439. uniforms.displacementScale.value = material.displacementScale;
  14440. uniforms.displacementBias.value = material.displacementBias;
  14441. }
  14442. }
  14443. function refreshUniformsDepth( uniforms, material ) {
  14444. if ( material.displacementMap ) {
  14445. uniforms.displacementMap.value = material.displacementMap;
  14446. uniforms.displacementScale.value = material.displacementScale;
  14447. uniforms.displacementBias.value = material.displacementBias;
  14448. }
  14449. }
  14450. function refreshUniformsDistance( uniforms, material ) {
  14451. if ( material.displacementMap ) {
  14452. uniforms.displacementMap.value = material.displacementMap;
  14453. uniforms.displacementScale.value = material.displacementScale;
  14454. uniforms.displacementBias.value = material.displacementBias;
  14455. }
  14456. uniforms.referencePosition.value.copy( material.referencePosition );
  14457. uniforms.nearDistance.value = material.nearDistance;
  14458. uniforms.farDistance.value = material.farDistance;
  14459. }
  14460. function refreshUniformsNormal( uniforms, material ) {
  14461. if ( material.bumpMap ) {
  14462. uniforms.bumpMap.value = material.bumpMap;
  14463. uniforms.bumpScale.value = material.bumpScale;
  14464. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14465. }
  14466. if ( material.normalMap ) {
  14467. uniforms.normalMap.value = material.normalMap;
  14468. uniforms.normalScale.value.copy( material.normalScale );
  14469. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14470. }
  14471. if ( material.displacementMap ) {
  14472. uniforms.displacementMap.value = material.displacementMap;
  14473. uniforms.displacementScale.value = material.displacementScale;
  14474. uniforms.displacementBias.value = material.displacementBias;
  14475. }
  14476. }
  14477. return {
  14478. refreshFogUniforms: refreshFogUniforms,
  14479. refreshMaterialUniforms: refreshMaterialUniforms
  14480. };
  14481. }
  14482. /**
  14483. * @author supereggbert / http://www.paulbrunt.co.uk/
  14484. * @author mrdoob / http://mrdoob.com/
  14485. * @author alteredq / http://alteredqualia.com/
  14486. * @author szimek / https://github.com/szimek/
  14487. * @author tschw
  14488. */
  14489. function WebGLRenderer( parameters ) {
  14490. parameters = parameters || {};
  14491. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14492. _context = parameters.context !== undefined ? parameters.context : null,
  14493. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14494. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14495. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14496. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14497. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14498. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14499. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14500. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14501. var currentRenderList = null;
  14502. var currentRenderState = null;
  14503. // public properties
  14504. this.domElement = _canvas;
  14505. // Debug configuration container
  14506. this.debug = {
  14507. /**
  14508. * Enables error checking and reporting when shader programs are being compiled
  14509. * @type {boolean}
  14510. */
  14511. checkShaderErrors: true
  14512. };
  14513. // clearing
  14514. this.autoClear = true;
  14515. this.autoClearColor = true;
  14516. this.autoClearDepth = true;
  14517. this.autoClearStencil = true;
  14518. // scene graph
  14519. this.sortObjects = true;
  14520. // user-defined clipping
  14521. this.clippingPlanes = [];
  14522. this.localClippingEnabled = false;
  14523. // physically based shading
  14524. this.gammaFactor = 2.0; // for backwards compatibility
  14525. this.outputEncoding = LinearEncoding;
  14526. // physical lights
  14527. this.physicallyCorrectLights = false;
  14528. // tone mapping
  14529. this.toneMapping = NoToneMapping;
  14530. this.toneMappingExposure = 1.0;
  14531. this.toneMappingWhitePoint = 1.0;
  14532. // morphs
  14533. this.maxMorphTargets = 8;
  14534. this.maxMorphNormals = 4;
  14535. // internal properties
  14536. var _this = this,
  14537. _isContextLost = false,
  14538. // internal state cache
  14539. _framebuffer = null,
  14540. _currentActiveCubeFace = 0,
  14541. _currentActiveMipmapLevel = 0,
  14542. _currentRenderTarget = null,
  14543. _currentFramebuffer = null,
  14544. _currentMaterialId = - 1,
  14545. // geometry and program caching
  14546. _currentGeometryProgram = {
  14547. geometry: null,
  14548. program: null,
  14549. wireframe: false
  14550. },
  14551. _currentCamera = null,
  14552. _currentArrayCamera = null,
  14553. _currentViewport = new Vector4(),
  14554. _currentScissor = new Vector4(),
  14555. _currentScissorTest = null,
  14556. //
  14557. _width = _canvas.width,
  14558. _height = _canvas.height,
  14559. _pixelRatio = 1,
  14560. _opaqueSort = null,
  14561. _transparentSort = null,
  14562. _viewport = new Vector4( 0, 0, _width, _height ),
  14563. _scissor = new Vector4( 0, 0, _width, _height ),
  14564. _scissorTest = false,
  14565. // frustum
  14566. _frustum = new Frustum(),
  14567. // clipping
  14568. _clipping = new WebGLClipping(),
  14569. _clippingEnabled = false,
  14570. _localClippingEnabled = false,
  14571. // camera matrices cache
  14572. _projScreenMatrix = new Matrix4(),
  14573. _vector3 = new Vector3();
  14574. function getTargetPixelRatio() {
  14575. return _currentRenderTarget === null ? _pixelRatio : 1;
  14576. }
  14577. // initialize
  14578. var _gl;
  14579. try {
  14580. var contextAttributes = {
  14581. alpha: _alpha,
  14582. depth: _depth,
  14583. stencil: _stencil,
  14584. antialias: _antialias,
  14585. premultipliedAlpha: _premultipliedAlpha,
  14586. preserveDrawingBuffer: _preserveDrawingBuffer,
  14587. powerPreference: _powerPreference,
  14588. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14589. };
  14590. // event listeners must be registered before WebGL context is created, see #12753
  14591. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14592. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  14593. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  14594. if ( _gl === null ) {
  14595. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14596. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  14597. } else {
  14598. throw new Error( 'Error creating WebGL context.' );
  14599. }
  14600. }
  14601. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14602. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14603. _gl.getShaderPrecisionFormat = function () {
  14604. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14605. };
  14606. }
  14607. } catch ( error ) {
  14608. console.error( 'THREE.WebGLRenderer: ' + error.message );
  14609. throw error;
  14610. }
  14611. var extensions, capabilities, state, info;
  14612. var properties, textures, attributes, geometries, objects;
  14613. var programCache, materials, renderLists, renderStates;
  14614. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14615. var utils;
  14616. function initGLContext() {
  14617. extensions = new WebGLExtensions( _gl );
  14618. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  14619. if ( capabilities.isWebGL2 === false ) {
  14620. extensions.get( 'WEBGL_depth_texture' );
  14621. extensions.get( 'OES_texture_float' );
  14622. extensions.get( 'OES_texture_half_float' );
  14623. extensions.get( 'OES_texture_half_float_linear' );
  14624. extensions.get( 'OES_standard_derivatives' );
  14625. extensions.get( 'OES_element_index_uint' );
  14626. extensions.get( 'ANGLE_instanced_arrays' );
  14627. }
  14628. extensions.get( 'OES_texture_float_linear' );
  14629. utils = new WebGLUtils( _gl, extensions, capabilities );
  14630. state = new WebGLState( _gl, extensions, capabilities );
  14631. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14632. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14633. info = new WebGLInfo( _gl );
  14634. properties = new WebGLProperties();
  14635. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  14636. attributes = new WebGLAttributes( _gl, capabilities );
  14637. geometries = new WebGLGeometries( _gl, attributes, info );
  14638. objects = new WebGLObjects( _gl, geometries, attributes, info );
  14639. morphtargets = new WebGLMorphtargets( _gl );
  14640. programCache = new WebGLPrograms( _this, extensions, capabilities );
  14641. materials = new WebGLMaterials( properties );
  14642. renderLists = new WebGLRenderLists();
  14643. renderStates = new WebGLRenderStates();
  14644. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  14645. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  14646. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  14647. info.programs = programCache.programs;
  14648. _this.capabilities = capabilities;
  14649. _this.extensions = extensions;
  14650. _this.properties = properties;
  14651. _this.renderLists = renderLists;
  14652. _this.state = state;
  14653. _this.info = info;
  14654. }
  14655. initGLContext();
  14656. // xr
  14657. var xr = new WebXRManager( _this, _gl );
  14658. this.xr = xr;
  14659. // shadow map
  14660. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  14661. this.shadowMap = shadowMap;
  14662. // API
  14663. this.getContext = function () {
  14664. return _gl;
  14665. };
  14666. this.getContextAttributes = function () {
  14667. return _gl.getContextAttributes();
  14668. };
  14669. this.forceContextLoss = function () {
  14670. var extension = extensions.get( 'WEBGL_lose_context' );
  14671. if ( extension ) extension.loseContext();
  14672. };
  14673. this.forceContextRestore = function () {
  14674. var extension = extensions.get( 'WEBGL_lose_context' );
  14675. if ( extension ) extension.restoreContext();
  14676. };
  14677. this.getPixelRatio = function () {
  14678. return _pixelRatio;
  14679. };
  14680. this.setPixelRatio = function ( value ) {
  14681. if ( value === undefined ) return;
  14682. _pixelRatio = value;
  14683. this.setSize( _width, _height, false );
  14684. };
  14685. this.getSize = function ( target ) {
  14686. if ( target === undefined ) {
  14687. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  14688. target = new Vector2();
  14689. }
  14690. return target.set( _width, _height );
  14691. };
  14692. this.setSize = function ( width, height, updateStyle ) {
  14693. if ( xr.isPresenting ) {
  14694. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  14695. return;
  14696. }
  14697. _width = width;
  14698. _height = height;
  14699. _canvas.width = Math.floor( width * _pixelRatio );
  14700. _canvas.height = Math.floor( height * _pixelRatio );
  14701. if ( updateStyle !== false ) {
  14702. _canvas.style.width = width + 'px';
  14703. _canvas.style.height = height + 'px';
  14704. }
  14705. this.setViewport( 0, 0, width, height );
  14706. };
  14707. this.getDrawingBufferSize = function ( target ) {
  14708. if ( target === undefined ) {
  14709. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  14710. target = new Vector2();
  14711. }
  14712. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  14713. };
  14714. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14715. _width = width;
  14716. _height = height;
  14717. _pixelRatio = pixelRatio;
  14718. _canvas.width = Math.floor( width * pixelRatio );
  14719. _canvas.height = Math.floor( height * pixelRatio );
  14720. this.setViewport( 0, 0, width, height );
  14721. };
  14722. this.getCurrentViewport = function ( target ) {
  14723. if ( target === undefined ) {
  14724. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14725. target = new Vector4();
  14726. }
  14727. return target.copy( _currentViewport );
  14728. };
  14729. this.getViewport = function ( target ) {
  14730. return target.copy( _viewport );
  14731. };
  14732. this.setViewport = function ( x, y, width, height ) {
  14733. if ( x.isVector4 ) {
  14734. _viewport.set( x.x, x.y, x.z, x.w );
  14735. } else {
  14736. _viewport.set( x, y, width, height );
  14737. }
  14738. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14739. };
  14740. this.getScissor = function ( target ) {
  14741. return target.copy( _scissor );
  14742. };
  14743. this.setScissor = function ( x, y, width, height ) {
  14744. if ( x.isVector4 ) {
  14745. _scissor.set( x.x, x.y, x.z, x.w );
  14746. } else {
  14747. _scissor.set( x, y, width, height );
  14748. }
  14749. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14750. };
  14751. this.getScissorTest = function () {
  14752. return _scissorTest;
  14753. };
  14754. this.setScissorTest = function ( boolean ) {
  14755. state.setScissorTest( _scissorTest = boolean );
  14756. };
  14757. this.setOpaqueSort = function ( method ) {
  14758. _opaqueSort = method;
  14759. };
  14760. this.setTransparentSort = function ( method ) {
  14761. _transparentSort = method;
  14762. };
  14763. // Clearing
  14764. this.getClearColor = function () {
  14765. return background.getClearColor();
  14766. };
  14767. this.setClearColor = function () {
  14768. background.setClearColor.apply( background, arguments );
  14769. };
  14770. this.getClearAlpha = function () {
  14771. return background.getClearAlpha();
  14772. };
  14773. this.setClearAlpha = function () {
  14774. background.setClearAlpha.apply( background, arguments );
  14775. };
  14776. this.clear = function ( color, depth, stencil ) {
  14777. var bits = 0;
  14778. if ( color === undefined || color ) bits |= 16384;
  14779. if ( depth === undefined || depth ) bits |= 256;
  14780. if ( stencil === undefined || stencil ) bits |= 1024;
  14781. _gl.clear( bits );
  14782. };
  14783. this.clearColor = function () {
  14784. this.clear( true, false, false );
  14785. };
  14786. this.clearDepth = function () {
  14787. this.clear( false, true, false );
  14788. };
  14789. this.clearStencil = function () {
  14790. this.clear( false, false, true );
  14791. };
  14792. //
  14793. this.dispose = function () {
  14794. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14795. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14796. renderLists.dispose();
  14797. renderStates.dispose();
  14798. properties.dispose();
  14799. objects.dispose();
  14800. xr.dispose();
  14801. animation.stop();
  14802. };
  14803. // Events
  14804. function onContextLost( event ) {
  14805. event.preventDefault();
  14806. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14807. _isContextLost = true;
  14808. }
  14809. function onContextRestore( /* event */ ) {
  14810. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14811. _isContextLost = false;
  14812. initGLContext();
  14813. }
  14814. function onMaterialDispose( event ) {
  14815. var material = event.target;
  14816. material.removeEventListener( 'dispose', onMaterialDispose );
  14817. deallocateMaterial( material );
  14818. }
  14819. // Buffer deallocation
  14820. function deallocateMaterial( material ) {
  14821. releaseMaterialProgramReference( material );
  14822. properties.remove( material );
  14823. }
  14824. function releaseMaterialProgramReference( material ) {
  14825. var programInfo = properties.get( material ).program;
  14826. material.program = undefined;
  14827. if ( programInfo !== undefined ) {
  14828. programCache.releaseProgram( programInfo );
  14829. }
  14830. }
  14831. // Buffer rendering
  14832. function renderObjectImmediate( object, program ) {
  14833. object.render( function ( object ) {
  14834. _this.renderBufferImmediate( object, program );
  14835. } );
  14836. }
  14837. this.renderBufferImmediate = function ( object, program ) {
  14838. state.initAttributes();
  14839. var buffers = properties.get( object );
  14840. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14841. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14842. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14843. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14844. var programAttributes = program.getAttributes();
  14845. if ( object.hasPositions ) {
  14846. _gl.bindBuffer( 34962, buffers.position );
  14847. _gl.bufferData( 34962, object.positionArray, 35048 );
  14848. state.enableAttribute( programAttributes.position );
  14849. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14850. }
  14851. if ( object.hasNormals ) {
  14852. _gl.bindBuffer( 34962, buffers.normal );
  14853. _gl.bufferData( 34962, object.normalArray, 35048 );
  14854. state.enableAttribute( programAttributes.normal );
  14855. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14856. }
  14857. if ( object.hasUvs ) {
  14858. _gl.bindBuffer( 34962, buffers.uv );
  14859. _gl.bufferData( 34962, object.uvArray, 35048 );
  14860. state.enableAttribute( programAttributes.uv );
  14861. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14862. }
  14863. if ( object.hasColors ) {
  14864. _gl.bindBuffer( 34962, buffers.color );
  14865. _gl.bufferData( 34962, object.colorArray, 35048 );
  14866. state.enableAttribute( programAttributes.color );
  14867. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14868. }
  14869. state.disableUnusedAttributes();
  14870. _gl.drawArrays( 4, 0, object.count );
  14871. object.count = 0;
  14872. };
  14873. var tempScene = new Scene();
  14874. this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
  14875. if ( scene === null ) scene = tempScene; // renderBufferDirect second parameter used to be fog (could be null)
  14876. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14877. var program = setProgram( camera, scene, material, object );
  14878. state.setMaterial( material, frontFaceCW );
  14879. var updateBuffers = false;
  14880. if ( _currentGeometryProgram.geometry !== geometry.id ||
  14881. _currentGeometryProgram.program !== program.id ||
  14882. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  14883. _currentGeometryProgram.geometry = geometry.id;
  14884. _currentGeometryProgram.program = program.id;
  14885. _currentGeometryProgram.wireframe = material.wireframe === true;
  14886. updateBuffers = true;
  14887. }
  14888. if ( material.morphTargets || material.morphNormals ) {
  14889. morphtargets.update( object, geometry, material, program );
  14890. updateBuffers = true;
  14891. }
  14892. if ( object.isInstancedMesh === true ) {
  14893. updateBuffers = true;
  14894. }
  14895. //
  14896. var index = geometry.index;
  14897. var position = geometry.attributes.position;
  14898. //
  14899. if ( index === null ) {
  14900. if ( position === undefined || position.count === 0 ) return;
  14901. } else if ( index.count === 0 ) {
  14902. return;
  14903. }
  14904. //
  14905. var rangeFactor = 1;
  14906. if ( material.wireframe === true ) {
  14907. index = geometries.getWireframeAttribute( geometry );
  14908. rangeFactor = 2;
  14909. }
  14910. var attribute;
  14911. var renderer = bufferRenderer;
  14912. if ( index !== null ) {
  14913. attribute = attributes.get( index );
  14914. renderer = indexedBufferRenderer;
  14915. renderer.setIndex( attribute );
  14916. }
  14917. if ( updateBuffers ) {
  14918. setupVertexAttributes( object, geometry, material, program );
  14919. if ( index !== null ) {
  14920. _gl.bindBuffer( 34963, attribute.buffer );
  14921. }
  14922. }
  14923. //
  14924. var dataCount = ( index !== null ) ? index.count : position.count;
  14925. var rangeStart = geometry.drawRange.start * rangeFactor;
  14926. var rangeCount = geometry.drawRange.count * rangeFactor;
  14927. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14928. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14929. var drawStart = Math.max( rangeStart, groupStart );
  14930. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14931. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14932. if ( drawCount === 0 ) return;
  14933. //
  14934. if ( object.isMesh ) {
  14935. if ( material.wireframe === true ) {
  14936. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14937. renderer.setMode( 1 );
  14938. } else {
  14939. renderer.setMode( 4 );
  14940. }
  14941. } else if ( object.isLine ) {
  14942. var lineWidth = material.linewidth;
  14943. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14944. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14945. if ( object.isLineSegments ) {
  14946. renderer.setMode( 1 );
  14947. } else if ( object.isLineLoop ) {
  14948. renderer.setMode( 2 );
  14949. } else {
  14950. renderer.setMode( 3 );
  14951. }
  14952. } else if ( object.isPoints ) {
  14953. renderer.setMode( 0 );
  14954. } else if ( object.isSprite ) {
  14955. renderer.setMode( 4 );
  14956. }
  14957. if ( object.isInstancedMesh ) {
  14958. renderer.renderInstances( geometry, drawStart, drawCount, object.count );
  14959. } else if ( geometry.isInstancedBufferGeometry ) {
  14960. var instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
  14961. renderer.renderInstances( geometry, drawStart, drawCount, instanceCount );
  14962. } else {
  14963. renderer.render( drawStart, drawCount );
  14964. }
  14965. };
  14966. function setupVertexAttributes( object, geometry, material, program ) {
  14967. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  14968. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
  14969. }
  14970. state.initAttributes();
  14971. var geometryAttributes = geometry.attributes;
  14972. var programAttributes = program.getAttributes();
  14973. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14974. for ( var name in programAttributes ) {
  14975. var programAttribute = programAttributes[ name ];
  14976. if ( programAttribute >= 0 ) {
  14977. var geometryAttribute = geometryAttributes[ name ];
  14978. if ( geometryAttribute !== undefined ) {
  14979. var normalized = geometryAttribute.normalized;
  14980. var size = geometryAttribute.itemSize;
  14981. var attribute = attributes.get( geometryAttribute );
  14982. // TODO Attribute may not be available on context restore
  14983. if ( attribute === undefined ) continue;
  14984. var buffer = attribute.buffer;
  14985. var type = attribute.type;
  14986. var bytesPerElement = attribute.bytesPerElement;
  14987. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14988. var data = geometryAttribute.data;
  14989. var stride = data.stride;
  14990. var offset = geometryAttribute.offset;
  14991. if ( data && data.isInstancedInterleavedBuffer ) {
  14992. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14993. if ( geometry._maxInstanceCount === undefined ) {
  14994. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  14995. }
  14996. } else {
  14997. state.enableAttribute( programAttribute );
  14998. }
  14999. _gl.bindBuffer( 34962, buffer );
  15000. state.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  15001. } else {
  15002. if ( geometryAttribute.isInstancedBufferAttribute ) {
  15003. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  15004. if ( geometry._maxInstanceCount === undefined ) {
  15005. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15006. }
  15007. } else {
  15008. state.enableAttribute( programAttribute );
  15009. }
  15010. _gl.bindBuffer( 34962, buffer );
  15011. state.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  15012. }
  15013. } else if ( name === 'instanceMatrix' ) {
  15014. var attribute = attributes.get( object.instanceMatrix );
  15015. // TODO Attribute may not be available on context restore
  15016. if ( attribute === undefined ) continue;
  15017. var buffer = attribute.buffer;
  15018. var type = attribute.type;
  15019. state.enableAttributeAndDivisor( programAttribute + 0, 1 );
  15020. state.enableAttributeAndDivisor( programAttribute + 1, 1 );
  15021. state.enableAttributeAndDivisor( programAttribute + 2, 1 );
  15022. state.enableAttributeAndDivisor( programAttribute + 3, 1 );
  15023. _gl.bindBuffer( 34962, buffer );
  15024. _gl.vertexAttribPointer( programAttribute + 0, 4, type, false, 64, 0 );
  15025. _gl.vertexAttribPointer( programAttribute + 1, 4, type, false, 64, 16 );
  15026. _gl.vertexAttribPointer( programAttribute + 2, 4, type, false, 64, 32 );
  15027. _gl.vertexAttribPointer( programAttribute + 3, 4, type, false, 64, 48 );
  15028. } else if ( materialDefaultAttributeValues !== undefined ) {
  15029. var value = materialDefaultAttributeValues[ name ];
  15030. if ( value !== undefined ) {
  15031. switch ( value.length ) {
  15032. case 2:
  15033. _gl.vertexAttrib2fv( programAttribute, value );
  15034. break;
  15035. case 3:
  15036. _gl.vertexAttrib3fv( programAttribute, value );
  15037. break;
  15038. case 4:
  15039. _gl.vertexAttrib4fv( programAttribute, value );
  15040. break;
  15041. default:
  15042. _gl.vertexAttrib1fv( programAttribute, value );
  15043. }
  15044. }
  15045. }
  15046. }
  15047. }
  15048. state.disableUnusedAttributes();
  15049. }
  15050. // Compile
  15051. this.compile = function ( scene, camera ) {
  15052. currentRenderState = renderStates.get( scene, camera );
  15053. currentRenderState.init();
  15054. scene.traverse( function ( object ) {
  15055. if ( object.isLight ) {
  15056. currentRenderState.pushLight( object );
  15057. if ( object.castShadow ) {
  15058. currentRenderState.pushShadow( object );
  15059. }
  15060. }
  15061. } );
  15062. currentRenderState.setupLights( camera );
  15063. const compiled = {};
  15064. scene.traverse( function ( object ) {
  15065. let material = object.material;
  15066. if ( material ) {
  15067. if ( Array.isArray( material ) ) {
  15068. for ( let i = 0; i < material.length; i ++ ) {
  15069. let material2 = material[ i ];
  15070. if ( material2.uuid in compiled === false ) {
  15071. initMaterial( material2, scene, object );
  15072. compiled[ material2.uuid ] = true;
  15073. }
  15074. }
  15075. } else if ( material.uuid in compiled === false ) {
  15076. initMaterial( material, scene, object );
  15077. compiled[ material.uuid ] = true;
  15078. }
  15079. }
  15080. } );
  15081. };
  15082. // Animation Loop
  15083. var onAnimationFrameCallback = null;
  15084. function onAnimationFrame( time ) {
  15085. if ( xr.isPresenting ) return;
  15086. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  15087. }
  15088. var animation = new WebGLAnimation();
  15089. animation.setAnimationLoop( onAnimationFrame );
  15090. if ( typeof window !== 'undefined' ) animation.setContext( window );
  15091. this.setAnimationLoop = function ( callback ) {
  15092. onAnimationFrameCallback = callback;
  15093. xr.setAnimationLoop( callback );
  15094. animation.start();
  15095. };
  15096. // Rendering
  15097. this.render = function ( scene, camera ) {
  15098. var renderTarget, forceClear;
  15099. if ( arguments[ 2 ] !== undefined ) {
  15100. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  15101. renderTarget = arguments[ 2 ];
  15102. }
  15103. if ( arguments[ 3 ] !== undefined ) {
  15104. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  15105. forceClear = arguments[ 3 ];
  15106. }
  15107. if ( ! ( camera && camera.isCamera ) ) {
  15108. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15109. return;
  15110. }
  15111. if ( _isContextLost ) return;
  15112. // reset caching for this frame
  15113. _currentGeometryProgram.geometry = null;
  15114. _currentGeometryProgram.program = null;
  15115. _currentGeometryProgram.wireframe = false;
  15116. _currentMaterialId = - 1;
  15117. _currentCamera = null;
  15118. // update scene graph
  15119. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15120. // update camera matrices and frustum
  15121. if ( camera.parent === null ) camera.updateMatrixWorld();
  15122. if ( xr.enabled && xr.isPresenting ) {
  15123. camera = xr.getCamera( camera );
  15124. }
  15125. //
  15126. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  15127. currentRenderState = renderStates.get( scene, camera );
  15128. currentRenderState.init();
  15129. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15130. _frustum.setFromProjectionMatrix( _projScreenMatrix );
  15131. _localClippingEnabled = this.localClippingEnabled;
  15132. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15133. currentRenderList = renderLists.get( scene, camera );
  15134. currentRenderList.init();
  15135. projectObject( scene, camera, 0, _this.sortObjects );
  15136. currentRenderList.finish();
  15137. if ( _this.sortObjects === true ) {
  15138. currentRenderList.sort( _opaqueSort, _transparentSort );
  15139. }
  15140. //
  15141. if ( _clippingEnabled ) _clipping.beginShadows();
  15142. var shadowsArray = currentRenderState.state.shadowsArray;
  15143. shadowMap.render( shadowsArray, scene, camera );
  15144. currentRenderState.setupLights( camera );
  15145. if ( _clippingEnabled ) _clipping.endShadows();
  15146. //
  15147. if ( this.info.autoReset ) this.info.reset();
  15148. if ( renderTarget !== undefined ) {
  15149. this.setRenderTarget( renderTarget );
  15150. }
  15151. //
  15152. background.render( currentRenderList, scene, camera, forceClear );
  15153. // render scene
  15154. var opaqueObjects = currentRenderList.opaque;
  15155. var transparentObjects = currentRenderList.transparent;
  15156. if ( scene.overrideMaterial ) {
  15157. var overrideMaterial = scene.overrideMaterial;
  15158. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  15159. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  15160. } else {
  15161. // opaque pass (front-to-back order)
  15162. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  15163. // transparent pass (back-to-front order)
  15164. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  15165. }
  15166. //
  15167. scene.onAfterRender( _this, scene, camera );
  15168. //
  15169. if ( _currentRenderTarget !== null ) {
  15170. // Generate mipmap if we're using any kind of mipmap filtering
  15171. textures.updateRenderTargetMipmap( _currentRenderTarget );
  15172. // resolve multisample renderbuffers to a single-sample texture if necessary
  15173. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  15174. }
  15175. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15176. state.buffers.depth.setTest( true );
  15177. state.buffers.depth.setMask( true );
  15178. state.buffers.color.setMask( true );
  15179. state.setPolygonOffset( false );
  15180. // _gl.finish();
  15181. currentRenderList = null;
  15182. currentRenderState = null;
  15183. };
  15184. function projectObject( object, camera, groupOrder, sortObjects ) {
  15185. if ( object.visible === false ) return;
  15186. var visible = object.layers.test( camera.layers );
  15187. if ( visible ) {
  15188. if ( object.isGroup ) {
  15189. groupOrder = object.renderOrder;
  15190. } else if ( object.isLOD ) {
  15191. if ( object.autoUpdate === true ) object.update( camera );
  15192. } else if ( object.isLight ) {
  15193. currentRenderState.pushLight( object );
  15194. if ( object.castShadow ) {
  15195. currentRenderState.pushShadow( object );
  15196. }
  15197. } else if ( object.isSprite ) {
  15198. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  15199. if ( sortObjects ) {
  15200. _vector3.setFromMatrixPosition( object.matrixWorld )
  15201. .applyMatrix4( _projScreenMatrix );
  15202. }
  15203. var geometry = objects.update( object );
  15204. var material = object.material;
  15205. if ( material.visible ) {
  15206. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15207. }
  15208. }
  15209. } else if ( object.isImmediateRenderObject ) {
  15210. if ( sortObjects ) {
  15211. _vector3.setFromMatrixPosition( object.matrixWorld )
  15212. .applyMatrix4( _projScreenMatrix );
  15213. }
  15214. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  15215. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  15216. if ( object.isSkinnedMesh ) {
  15217. // update skeleton only once in a frame
  15218. if ( object.skeleton.frame !== info.render.frame ) {
  15219. object.skeleton.update();
  15220. object.skeleton.frame = info.render.frame;
  15221. }
  15222. }
  15223. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  15224. if ( sortObjects ) {
  15225. _vector3.setFromMatrixPosition( object.matrixWorld )
  15226. .applyMatrix4( _projScreenMatrix );
  15227. }
  15228. var geometry = objects.update( object );
  15229. var material = object.material;
  15230. if ( Array.isArray( material ) ) {
  15231. var groups = geometry.groups;
  15232. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15233. var group = groups[ i ];
  15234. var groupMaterial = material[ group.materialIndex ];
  15235. if ( groupMaterial && groupMaterial.visible ) {
  15236. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  15237. }
  15238. }
  15239. } else if ( material.visible ) {
  15240. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15241. }
  15242. }
  15243. }
  15244. }
  15245. var children = object.children;
  15246. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15247. projectObject( children[ i ], camera, groupOrder, sortObjects );
  15248. }
  15249. }
  15250. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  15251. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15252. var renderItem = renderList[ i ];
  15253. var object = renderItem.object;
  15254. var geometry = renderItem.geometry;
  15255. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15256. var group = renderItem.group;
  15257. if ( camera.isArrayCamera ) {
  15258. _currentArrayCamera = camera;
  15259. var cameras = camera.cameras;
  15260. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  15261. var camera2 = cameras[ j ];
  15262. if ( object.layers.test( camera2.layers ) ) {
  15263. state.viewport( _currentViewport.copy( camera2.viewport ) );
  15264. currentRenderState.setupLights( camera2 );
  15265. renderObject( object, scene, camera2, geometry, material, group );
  15266. }
  15267. }
  15268. } else {
  15269. _currentArrayCamera = null;
  15270. renderObject( object, scene, camera, geometry, material, group );
  15271. }
  15272. }
  15273. }
  15274. function renderObject( object, scene, camera, geometry, material, group ) {
  15275. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  15276. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15277. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15278. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15279. if ( object.isImmediateRenderObject ) {
  15280. var program = setProgram( camera, scene, material, object );
  15281. state.setMaterial( material );
  15282. _currentGeometryProgram.geometry = null;
  15283. _currentGeometryProgram.program = null;
  15284. _currentGeometryProgram.wireframe = false;
  15285. renderObjectImmediate( object, program );
  15286. } else {
  15287. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  15288. }
  15289. object.onAfterRender( _this, scene, camera, geometry, material, group );
  15290. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15291. }
  15292. function initMaterial( material, scene, object ) {
  15293. var materialProperties = properties.get( material );
  15294. var lights = currentRenderState.state.lights;
  15295. var shadowsArray = currentRenderState.state.shadowsArray;
  15296. var lightsStateVersion = lights.state.version;
  15297. var parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object );
  15298. var programCacheKey = programCache.getProgramCacheKey( parameters );
  15299. var program = materialProperties.program;
  15300. var programChange = true;
  15301. if ( program === undefined ) {
  15302. // new material
  15303. material.addEventListener( 'dispose', onMaterialDispose );
  15304. } else if ( program.cacheKey !== programCacheKey ) {
  15305. // changed glsl or parameters
  15306. releaseMaterialProgramReference( material );
  15307. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  15308. materialProperties.lightsStateVersion = lightsStateVersion;
  15309. programChange = false;
  15310. } else if ( parameters.shaderID !== undefined ) {
  15311. // same glsl and uniform list
  15312. return;
  15313. } else {
  15314. // only rebuild uniform list
  15315. programChange = false;
  15316. }
  15317. if ( programChange ) {
  15318. program = programCache.acquireProgram( parameters, programCacheKey );
  15319. materialProperties.program = program;
  15320. materialProperties.uniforms = parameters.uniforms;
  15321. materialProperties.outputEncoding = parameters.outputEncoding;
  15322. material.program = program;
  15323. }
  15324. var programAttributes = program.getAttributes();
  15325. if ( material.morphTargets ) {
  15326. material.numSupportedMorphTargets = 0;
  15327. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15328. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  15329. material.numSupportedMorphTargets ++;
  15330. }
  15331. }
  15332. }
  15333. if ( material.morphNormals ) {
  15334. material.numSupportedMorphNormals = 0;
  15335. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15336. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  15337. material.numSupportedMorphNormals ++;
  15338. }
  15339. }
  15340. }
  15341. var uniforms = materialProperties.uniforms;
  15342. if ( ! material.isShaderMaterial &&
  15343. ! material.isRawShaderMaterial ||
  15344. material.clipping === true ) {
  15345. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15346. materialProperties.numIntersection = _clipping.numIntersection;
  15347. uniforms.clippingPlanes = _clipping.uniform;
  15348. }
  15349. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15350. materialProperties.fog = scene.fog;
  15351. // store the light setup it was created for
  15352. materialProperties.needsLights = materialNeedsLights( material );
  15353. materialProperties.lightsStateVersion = lightsStateVersion;
  15354. if ( materialProperties.needsLights ) {
  15355. // wire up the material to this renderer's lighting state
  15356. uniforms.ambientLightColor.value = lights.state.ambient;
  15357. uniforms.lightProbe.value = lights.state.probe;
  15358. uniforms.directionalLights.value = lights.state.directional;
  15359. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15360. uniforms.spotLights.value = lights.state.spot;
  15361. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15362. uniforms.rectAreaLights.value = lights.state.rectArea;
  15363. uniforms.pointLights.value = lights.state.point;
  15364. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15365. uniforms.hemisphereLights.value = lights.state.hemi;
  15366. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15367. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15368. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15369. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15370. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15371. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  15372. // TODO (abelnation): add area lights shadow info to uniforms
  15373. }
  15374. var progUniforms = materialProperties.program.getUniforms(),
  15375. uniformsList =
  15376. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15377. materialProperties.uniformsList = uniformsList;
  15378. }
  15379. function setProgram( camera, scene, material, object ) {
  15380. textures.resetTextureUnits();
  15381. var fog = scene.fog;
  15382. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15383. var encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15384. var materialProperties = properties.get( material );
  15385. var lights = currentRenderState.state.lights;
  15386. if ( _clippingEnabled ) {
  15387. if ( _localClippingEnabled || camera !== _currentCamera ) {
  15388. var useCache =
  15389. camera === _currentCamera &&
  15390. material.id === _currentMaterialId;
  15391. // we might want to call this function with some ClippingGroup
  15392. // object instead of the material, once it becomes feasible
  15393. // (#8465, #8379)
  15394. _clipping.setState(
  15395. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  15396. camera, materialProperties, useCache );
  15397. }
  15398. }
  15399. if ( material.version === materialProperties.__version ) {
  15400. if ( materialProperties.program === undefined ) {
  15401. initMaterial( material, scene, object );
  15402. } else if ( material.fog && materialProperties.fog !== fog ) {
  15403. initMaterial( material, scene, object );
  15404. } else if ( materialProperties.environment !== environment ) {
  15405. initMaterial( material, scene, object );
  15406. } else if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  15407. initMaterial( material, scene, object );
  15408. } else if ( materialProperties.numClippingPlanes !== undefined &&
  15409. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  15410. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  15411. initMaterial( material, scene, object );
  15412. } else if ( materialProperties.outputEncoding !== encoding ) {
  15413. initMaterial( material, scene, object );
  15414. }
  15415. } else {
  15416. initMaterial( material, scene, object );
  15417. materialProperties.__version = material.version;
  15418. }
  15419. var refreshProgram = false;
  15420. var refreshMaterial = false;
  15421. var refreshLights = false;
  15422. var program = materialProperties.program,
  15423. p_uniforms = program.getUniforms(),
  15424. m_uniforms = materialProperties.uniforms;
  15425. if ( state.useProgram( program.program ) ) {
  15426. refreshProgram = true;
  15427. refreshMaterial = true;
  15428. refreshLights = true;
  15429. }
  15430. if ( material.id !== _currentMaterialId ) {
  15431. _currentMaterialId = material.id;
  15432. refreshMaterial = true;
  15433. }
  15434. if ( refreshProgram || _currentCamera !== camera ) {
  15435. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  15436. if ( capabilities.logarithmicDepthBuffer ) {
  15437. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15438. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15439. }
  15440. if ( _currentCamera !== camera ) {
  15441. _currentCamera = camera;
  15442. // lighting uniforms depend on the camera so enforce an update
  15443. // now, in case this material supports lights - or later, when
  15444. // the next material that does gets activated:
  15445. refreshMaterial = true; // set to true on material change
  15446. refreshLights = true; // remains set until update done
  15447. }
  15448. // load material specific uniforms
  15449. // (shader material also gets them for the sake of genericity)
  15450. if ( material.isShaderMaterial ||
  15451. material.isMeshPhongMaterial ||
  15452. material.isMeshToonMaterial ||
  15453. material.isMeshStandardMaterial ||
  15454. material.envMap ) {
  15455. var uCamPos = p_uniforms.map.cameraPosition;
  15456. if ( uCamPos !== undefined ) {
  15457. uCamPos.setValue( _gl,
  15458. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15459. }
  15460. }
  15461. if ( material.isMeshPhongMaterial ||
  15462. material.isMeshToonMaterial ||
  15463. material.isMeshLambertMaterial ||
  15464. material.isMeshBasicMaterial ||
  15465. material.isMeshStandardMaterial ||
  15466. material.isShaderMaterial ) {
  15467. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  15468. }
  15469. if ( material.isMeshPhongMaterial ||
  15470. material.isMeshToonMaterial ||
  15471. material.isMeshLambertMaterial ||
  15472. material.isMeshBasicMaterial ||
  15473. material.isMeshStandardMaterial ||
  15474. material.isShaderMaterial ||
  15475. material.skinning ) {
  15476. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15477. }
  15478. }
  15479. // skinning uniforms must be set even if material didn't change
  15480. // auto-setting of texture unit for bone texture must go before other textures
  15481. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15482. if ( material.skinning ) {
  15483. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15484. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15485. var skeleton = object.skeleton;
  15486. if ( skeleton ) {
  15487. var bones = skeleton.bones;
  15488. if ( capabilities.floatVertexTextures ) {
  15489. if ( skeleton.boneTexture === undefined ) {
  15490. // layout (1 matrix = 4 pixels)
  15491. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15492. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15493. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15494. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15495. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15496. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  15497. size = MathUtils.ceilPowerOfTwo( size );
  15498. size = Math.max( size, 4 );
  15499. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  15500. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  15501. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  15502. skeleton.boneMatrices = boneMatrices;
  15503. skeleton.boneTexture = boneTexture;
  15504. skeleton.boneTextureSize = size;
  15505. }
  15506. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  15507. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  15508. } else {
  15509. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15510. }
  15511. }
  15512. }
  15513. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  15514. materialProperties.receiveShadow = object.receiveShadow;
  15515. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  15516. }
  15517. if ( refreshMaterial ) {
  15518. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  15519. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  15520. if ( materialProperties.needsLights ) {
  15521. // the current material requires lighting info
  15522. // note: all lighting uniforms are always set correctly
  15523. // they simply reference the renderer's state for their
  15524. // values
  15525. //
  15526. // use the current material's .needsUpdate flags to set
  15527. // the GL state when required
  15528. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15529. }
  15530. // refresh uniforms common to several materials
  15531. if ( fog && material.fog ) {
  15532. materials.refreshFogUniforms( m_uniforms, fog );
  15533. }
  15534. materials.refreshMaterialUniforms( m_uniforms, material, environment, _pixelRatio, _height );
  15535. // RectAreaLight Texture
  15536. // TODO (mrdoob): Find a nicer implementation
  15537. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  15538. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  15539. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15540. }
  15541. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  15542. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15543. material.uniformsNeedUpdate = false;
  15544. }
  15545. if ( material.isSpriteMaterial ) {
  15546. p_uniforms.setValue( _gl, 'center', object.center );
  15547. }
  15548. // common matrices
  15549. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  15550. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  15551. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15552. return program;
  15553. }
  15554. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15555. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15556. uniforms.ambientLightColor.needsUpdate = value;
  15557. uniforms.lightProbe.needsUpdate = value;
  15558. uniforms.directionalLights.needsUpdate = value;
  15559. uniforms.directionalLightShadows.needsUpdate = value;
  15560. uniforms.pointLights.needsUpdate = value;
  15561. uniforms.pointLightShadows.needsUpdate = value;
  15562. uniforms.spotLights.needsUpdate = value;
  15563. uniforms.spotLightShadows.needsUpdate = value;
  15564. uniforms.rectAreaLights.needsUpdate = value;
  15565. uniforms.hemisphereLights.needsUpdate = value;
  15566. }
  15567. function materialNeedsLights( material ) {
  15568. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
  15569. material.isMeshStandardMaterial || material.isShadowMaterial ||
  15570. ( material.isShaderMaterial && material.lights === true );
  15571. }
  15572. //
  15573. this.setFramebuffer = function ( value ) {
  15574. if ( _framebuffer !== value && _currentRenderTarget === null ) _gl.bindFramebuffer( 36160, value );
  15575. _framebuffer = value;
  15576. };
  15577. this.getActiveCubeFace = function () {
  15578. return _currentActiveCubeFace;
  15579. };
  15580. this.getActiveMipmapLevel = function () {
  15581. return _currentActiveMipmapLevel;
  15582. };
  15583. this.getRenderTarget = function () {
  15584. return _currentRenderTarget;
  15585. };
  15586. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15587. _currentRenderTarget = renderTarget;
  15588. _currentActiveCubeFace = activeCubeFace;
  15589. _currentActiveMipmapLevel = activeMipmapLevel;
  15590. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15591. textures.setupRenderTarget( renderTarget );
  15592. }
  15593. var framebuffer = _framebuffer;
  15594. var isCube = false;
  15595. if ( renderTarget ) {
  15596. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15597. if ( renderTarget.isWebGLCubeRenderTarget ) {
  15598. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15599. isCube = true;
  15600. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15601. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15602. } else {
  15603. framebuffer = __webglFramebuffer;
  15604. }
  15605. _currentViewport.copy( renderTarget.viewport );
  15606. _currentScissor.copy( renderTarget.scissor );
  15607. _currentScissorTest = renderTarget.scissorTest;
  15608. } else {
  15609. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15610. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15611. _currentScissorTest = _scissorTest;
  15612. }
  15613. if ( _currentFramebuffer !== framebuffer ) {
  15614. _gl.bindFramebuffer( 36160, framebuffer );
  15615. _currentFramebuffer = framebuffer;
  15616. }
  15617. state.viewport( _currentViewport );
  15618. state.scissor( _currentScissor );
  15619. state.setScissorTest( _currentScissorTest );
  15620. if ( isCube ) {
  15621. var textureProperties = properties.get( renderTarget.texture );
  15622. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15623. }
  15624. };
  15625. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15626. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15627. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15628. return;
  15629. }
  15630. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15631. if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
  15632. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15633. }
  15634. if ( framebuffer ) {
  15635. var restore = false;
  15636. if ( framebuffer !== _currentFramebuffer ) {
  15637. _gl.bindFramebuffer( 36160, framebuffer );
  15638. restore = true;
  15639. }
  15640. try {
  15641. var texture = renderTarget.texture;
  15642. var textureFormat = texture.format;
  15643. var textureType = texture.type;
  15644. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15645. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15646. return;
  15647. }
  15648. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15649. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15650. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15651. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15652. return;
  15653. }
  15654. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15655. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15656. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15657. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15658. }
  15659. } else {
  15660. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15661. }
  15662. } finally {
  15663. if ( restore ) {
  15664. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15665. }
  15666. }
  15667. }
  15668. };
  15669. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15670. if ( level === undefined ) level = 0;
  15671. var levelScale = Math.pow( 2, - level );
  15672. var width = Math.floor( texture.image.width * levelScale );
  15673. var height = Math.floor( texture.image.height * levelScale );
  15674. var glFormat = utils.convert( texture.format );
  15675. textures.setTexture2D( texture, 0 );
  15676. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  15677. state.unbindTexture();
  15678. };
  15679. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15680. if ( level === undefined ) level = 0;
  15681. var width = srcTexture.image.width;
  15682. var height = srcTexture.image.height;
  15683. var glFormat = utils.convert( dstTexture.format );
  15684. var glType = utils.convert( dstTexture.type );
  15685. textures.setTexture2D( dstTexture, 0 );
  15686. if ( srcTexture.isDataTexture ) {
  15687. _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15688. } else {
  15689. if ( srcTexture.isCompressedTexture ) {
  15690. _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
  15691. } else {
  15692. _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image );
  15693. }
  15694. }
  15695. // Generate mipmaps only when copying level 0
  15696. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( 3553 );
  15697. state.unbindTexture();
  15698. };
  15699. this.initTexture = function ( texture ) {
  15700. textures.setTexture2D( texture, 0 );
  15701. state.unbindTexture();
  15702. };
  15703. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15704. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15705. }
  15706. }
  15707. /**
  15708. * @author mrdoob / http://mrdoob.com/
  15709. * @author alteredq / http://alteredqualia.com/
  15710. */
  15711. function FogExp2( color, density ) {
  15712. this.name = '';
  15713. this.color = new Color( color );
  15714. this.density = ( density !== undefined ) ? density : 0.00025;
  15715. }
  15716. Object.assign( FogExp2.prototype, {
  15717. isFogExp2: true,
  15718. clone: function () {
  15719. return new FogExp2( this.color, this.density );
  15720. },
  15721. toJSON: function ( /* meta */ ) {
  15722. return {
  15723. type: 'FogExp2',
  15724. color: this.color.getHex(),
  15725. density: this.density
  15726. };
  15727. }
  15728. } );
  15729. /**
  15730. * @author mrdoob / http://mrdoob.com/
  15731. * @author alteredq / http://alteredqualia.com/
  15732. */
  15733. function Fog( color, near, far ) {
  15734. this.name = '';
  15735. this.color = new Color( color );
  15736. this.near = ( near !== undefined ) ? near : 1;
  15737. this.far = ( far !== undefined ) ? far : 1000;
  15738. }
  15739. Object.assign( Fog.prototype, {
  15740. isFog: true,
  15741. clone: function () {
  15742. return new Fog( this.color, this.near, this.far );
  15743. },
  15744. toJSON: function ( /* meta */ ) {
  15745. return {
  15746. type: 'Fog',
  15747. color: this.color.getHex(),
  15748. near: this.near,
  15749. far: this.far
  15750. };
  15751. }
  15752. } );
  15753. /**
  15754. * @author benaadams / https://twitter.com/ben_a_adams
  15755. */
  15756. function InterleavedBuffer( array, stride ) {
  15757. this.array = array;
  15758. this.stride = stride;
  15759. this.count = array !== undefined ? array.length / stride : 0;
  15760. this.usage = StaticDrawUsage;
  15761. this.updateRange = { offset: 0, count: - 1 };
  15762. this.version = 0;
  15763. }
  15764. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15765. set: function ( value ) {
  15766. if ( value === true ) this.version ++;
  15767. }
  15768. } );
  15769. Object.assign( InterleavedBuffer.prototype, {
  15770. isInterleavedBuffer: true,
  15771. onUploadCallback: function () {},
  15772. setUsage: function ( value ) {
  15773. this.usage = value;
  15774. return this;
  15775. },
  15776. copy: function ( source ) {
  15777. this.array = new source.array.constructor( source.array );
  15778. this.count = source.count;
  15779. this.stride = source.stride;
  15780. this.usage = source.usage;
  15781. return this;
  15782. },
  15783. copyAt: function ( index1, attribute, index2 ) {
  15784. index1 *= this.stride;
  15785. index2 *= attribute.stride;
  15786. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15787. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15788. }
  15789. return this;
  15790. },
  15791. set: function ( value, offset ) {
  15792. if ( offset === undefined ) offset = 0;
  15793. this.array.set( value, offset );
  15794. return this;
  15795. },
  15796. clone: function () {
  15797. return new this.constructor().copy( this );
  15798. },
  15799. onUpload: function ( callback ) {
  15800. this.onUploadCallback = callback;
  15801. return this;
  15802. }
  15803. } );
  15804. /**
  15805. * @author benaadams / https://twitter.com/ben_a_adams
  15806. */
  15807. var _vector$6 = new Vector3();
  15808. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15809. this.name = '';
  15810. this.data = interleavedBuffer;
  15811. this.itemSize = itemSize;
  15812. this.offset = offset;
  15813. this.normalized = normalized === true;
  15814. }
  15815. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15816. count: {
  15817. get: function () {
  15818. return this.data.count;
  15819. }
  15820. },
  15821. array: {
  15822. get: function () {
  15823. return this.data.array;
  15824. }
  15825. }
  15826. } );
  15827. Object.assign( InterleavedBufferAttribute.prototype, {
  15828. isInterleavedBufferAttribute: true,
  15829. applyMatrix4: function ( m ) {
  15830. for ( var i = 0, l = this.data.count; i < l; i ++ ) {
  15831. _vector$6.x = this.getX( i );
  15832. _vector$6.y = this.getY( i );
  15833. _vector$6.z = this.getZ( i );
  15834. _vector$6.applyMatrix4( m );
  15835. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  15836. }
  15837. return this;
  15838. },
  15839. setX: function ( index, x ) {
  15840. this.data.array[ index * this.data.stride + this.offset ] = x;
  15841. return this;
  15842. },
  15843. setY: function ( index, y ) {
  15844. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15845. return this;
  15846. },
  15847. setZ: function ( index, z ) {
  15848. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15849. return this;
  15850. },
  15851. setW: function ( index, w ) {
  15852. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15853. return this;
  15854. },
  15855. getX: function ( index ) {
  15856. return this.data.array[ index * this.data.stride + this.offset ];
  15857. },
  15858. getY: function ( index ) {
  15859. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15860. },
  15861. getZ: function ( index ) {
  15862. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15863. },
  15864. getW: function ( index ) {
  15865. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15866. },
  15867. setXY: function ( index, x, y ) {
  15868. index = index * this.data.stride + this.offset;
  15869. this.data.array[ index + 0 ] = x;
  15870. this.data.array[ index + 1 ] = y;
  15871. return this;
  15872. },
  15873. setXYZ: function ( index, x, y, z ) {
  15874. index = index * this.data.stride + this.offset;
  15875. this.data.array[ index + 0 ] = x;
  15876. this.data.array[ index + 1 ] = y;
  15877. this.data.array[ index + 2 ] = z;
  15878. return this;
  15879. },
  15880. setXYZW: function ( index, x, y, z, w ) {
  15881. index = index * this.data.stride + this.offset;
  15882. this.data.array[ index + 0 ] = x;
  15883. this.data.array[ index + 1 ] = y;
  15884. this.data.array[ index + 2 ] = z;
  15885. this.data.array[ index + 3 ] = w;
  15886. return this;
  15887. },
  15888. clone: function () {
  15889. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
  15890. var array = [];
  15891. for ( var i = 0; i < this.count; i ++ ) {
  15892. var index = i * this.data.stride + this.offset;
  15893. for ( var j = 0; j < this.itemSize; j ++ ) {
  15894. array.push( this.data.array[ index + j ] );
  15895. }
  15896. }
  15897. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  15898. },
  15899. toJSON: function () {
  15900. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
  15901. var array = [];
  15902. for ( var i = 0; i < this.count; i ++ ) {
  15903. var index = i * this.data.stride + this.offset;
  15904. for ( var j = 0; j < this.itemSize; j ++ ) {
  15905. array.push( this.data.array[ index + j ] );
  15906. }
  15907. }
  15908. // deinterleave data and save it as an ordinary buffer attribute for now
  15909. return {
  15910. itemSize: this.itemSize,
  15911. type: this.array.constructor.name,
  15912. array: array,
  15913. normalized: this.normalized
  15914. };
  15915. }
  15916. } );
  15917. /**
  15918. * @author alteredq / http://alteredqualia.com/
  15919. *
  15920. * parameters = {
  15921. * color: <hex>,
  15922. * map: new THREE.Texture( <Image> ),
  15923. * alphaMap: new THREE.Texture( <Image> ),
  15924. * rotation: <float>,
  15925. * sizeAttenuation: <bool>
  15926. * }
  15927. */
  15928. function SpriteMaterial( parameters ) {
  15929. Material.call( this );
  15930. this.type = 'SpriteMaterial';
  15931. this.color = new Color( 0xffffff );
  15932. this.map = null;
  15933. this.alphaMap = null;
  15934. this.rotation = 0;
  15935. this.sizeAttenuation = true;
  15936. this.transparent = true;
  15937. this.setValues( parameters );
  15938. }
  15939. SpriteMaterial.prototype = Object.create( Material.prototype );
  15940. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15941. SpriteMaterial.prototype.isSpriteMaterial = true;
  15942. SpriteMaterial.prototype.copy = function ( source ) {
  15943. Material.prototype.copy.call( this, source );
  15944. this.color.copy( source.color );
  15945. this.map = source.map;
  15946. this.alphaMap = source.alphaMap;
  15947. this.rotation = source.rotation;
  15948. this.sizeAttenuation = source.sizeAttenuation;
  15949. return this;
  15950. };
  15951. /**
  15952. * @author mikael emtinger / http://gomo.se/
  15953. * @author alteredq / http://alteredqualia.com/
  15954. */
  15955. var _geometry;
  15956. var _intersectPoint = new Vector3();
  15957. var _worldScale = new Vector3();
  15958. var _mvPosition = new Vector3();
  15959. var _alignedPosition = new Vector2();
  15960. var _rotatedPosition = new Vector2();
  15961. var _viewWorldMatrix = new Matrix4();
  15962. var _vA$1 = new Vector3();
  15963. var _vB$1 = new Vector3();
  15964. var _vC$1 = new Vector3();
  15965. var _uvA$1 = new Vector2();
  15966. var _uvB$1 = new Vector2();
  15967. var _uvC$1 = new Vector2();
  15968. function Sprite( material ) {
  15969. Object3D.call( this );
  15970. this.type = 'Sprite';
  15971. if ( _geometry === undefined ) {
  15972. _geometry = new BufferGeometry();
  15973. var float32Array = new Float32Array( [
  15974. - 0.5, - 0.5, 0, 0, 0,
  15975. 0.5, - 0.5, 0, 1, 0,
  15976. 0.5, 0.5, 0, 1, 1,
  15977. - 0.5, 0.5, 0, 0, 1
  15978. ] );
  15979. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15980. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15981. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15982. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15983. }
  15984. this.geometry = _geometry;
  15985. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15986. this.center = new Vector2( 0.5, 0.5 );
  15987. }
  15988. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15989. constructor: Sprite,
  15990. isSprite: true,
  15991. raycast: function ( raycaster, intersects ) {
  15992. if ( raycaster.camera === null ) {
  15993. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  15994. }
  15995. _worldScale.setFromMatrixScale( this.matrixWorld );
  15996. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  15997. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  15998. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15999. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  16000. _worldScale.multiplyScalar( - _mvPosition.z );
  16001. }
  16002. var rotation = this.material.rotation;
  16003. var sin, cos;
  16004. if ( rotation !== 0 ) {
  16005. cos = Math.cos( rotation );
  16006. sin = Math.sin( rotation );
  16007. }
  16008. var center = this.center;
  16009. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16010. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16011. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16012. _uvA$1.set( 0, 0 );
  16013. _uvB$1.set( 1, 0 );
  16014. _uvC$1.set( 1, 1 );
  16015. // check first triangle
  16016. var intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  16017. if ( intersect === null ) {
  16018. // check second triangle
  16019. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16020. _uvB$1.set( 0, 1 );
  16021. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  16022. if ( intersect === null ) {
  16023. return;
  16024. }
  16025. }
  16026. var distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  16027. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16028. intersects.push( {
  16029. distance: distance,
  16030. point: _intersectPoint.clone(),
  16031. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  16032. face: null,
  16033. object: this
  16034. } );
  16035. },
  16036. clone: function () {
  16037. return new this.constructor( this.material ).copy( this );
  16038. },
  16039. copy: function ( source ) {
  16040. Object3D.prototype.copy.call( this, source );
  16041. if ( source.center !== undefined ) this.center.copy( source.center );
  16042. return this;
  16043. }
  16044. } );
  16045. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  16046. // compute position in camera space
  16047. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  16048. // to check if rotation is not zero
  16049. if ( sin !== undefined ) {
  16050. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  16051. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  16052. } else {
  16053. _rotatedPosition.copy( _alignedPosition );
  16054. }
  16055. vertexPosition.copy( mvPosition );
  16056. vertexPosition.x += _rotatedPosition.x;
  16057. vertexPosition.y += _rotatedPosition.y;
  16058. // transform to world space
  16059. vertexPosition.applyMatrix4( _viewWorldMatrix );
  16060. }
  16061. /**
  16062. * @author mikael emtinger / http://gomo.se/
  16063. * @author alteredq / http://alteredqualia.com/
  16064. * @author mrdoob / http://mrdoob.com/
  16065. */
  16066. var _v1$4 = new Vector3();
  16067. var _v2$2 = new Vector3();
  16068. function LOD() {
  16069. Object3D.call( this );
  16070. this._currentLevel = 0;
  16071. this.type = 'LOD';
  16072. Object.defineProperties( this, {
  16073. levels: {
  16074. enumerable: true,
  16075. value: []
  16076. }
  16077. } );
  16078. this.autoUpdate = true;
  16079. }
  16080. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16081. constructor: LOD,
  16082. isLOD: true,
  16083. copy: function ( source ) {
  16084. Object3D.prototype.copy.call( this, source, false );
  16085. var levels = source.levels;
  16086. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  16087. var level = levels[ i ];
  16088. this.addLevel( level.object.clone(), level.distance );
  16089. }
  16090. this.autoUpdate = source.autoUpdate;
  16091. return this;
  16092. },
  16093. addLevel: function ( object, distance ) {
  16094. if ( distance === undefined ) distance = 0;
  16095. distance = Math.abs( distance );
  16096. var levels = this.levels;
  16097. for ( var l = 0; l < levels.length; l ++ ) {
  16098. if ( distance < levels[ l ].distance ) {
  16099. break;
  16100. }
  16101. }
  16102. levels.splice( l, 0, { distance: distance, object: object } );
  16103. this.add( object );
  16104. return this;
  16105. },
  16106. getCurrentLevel: function () {
  16107. return this._currentLevel;
  16108. },
  16109. getObjectForDistance: function ( distance ) {
  16110. var levels = this.levels;
  16111. if ( levels.length > 0 ) {
  16112. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  16113. if ( distance < levels[ i ].distance ) {
  16114. break;
  16115. }
  16116. }
  16117. return levels[ i - 1 ].object;
  16118. }
  16119. return null;
  16120. },
  16121. raycast: function ( raycaster, intersects ) {
  16122. var levels = this.levels;
  16123. if ( levels.length > 0 ) {
  16124. _v1$4.setFromMatrixPosition( this.matrixWorld );
  16125. var distance = raycaster.ray.origin.distanceTo( _v1$4 );
  16126. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  16127. }
  16128. },
  16129. update: function ( camera ) {
  16130. var levels = this.levels;
  16131. if ( levels.length > 1 ) {
  16132. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  16133. _v2$2.setFromMatrixPosition( this.matrixWorld );
  16134. var distance = _v1$4.distanceTo( _v2$2 ) / camera.zoom;
  16135. levels[ 0 ].object.visible = true;
  16136. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  16137. if ( distance >= levels[ i ].distance ) {
  16138. levels[ i - 1 ].object.visible = false;
  16139. levels[ i ].object.visible = true;
  16140. } else {
  16141. break;
  16142. }
  16143. }
  16144. this._currentLevel = i - 1;
  16145. for ( ; i < l; i ++ ) {
  16146. levels[ i ].object.visible = false;
  16147. }
  16148. }
  16149. },
  16150. toJSON: function ( meta ) {
  16151. var data = Object3D.prototype.toJSON.call( this, meta );
  16152. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  16153. data.object.levels = [];
  16154. var levels = this.levels;
  16155. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  16156. var level = levels[ i ];
  16157. data.object.levels.push( {
  16158. object: level.object.uuid,
  16159. distance: level.distance
  16160. } );
  16161. }
  16162. return data;
  16163. }
  16164. } );
  16165. /**
  16166. * @author mikael emtinger / http://gomo.se/
  16167. * @author alteredq / http://alteredqualia.com/
  16168. * @author ikerr / http://verold.com
  16169. */
  16170. function SkinnedMesh( geometry, material ) {
  16171. if ( geometry && geometry.isGeometry ) {
  16172. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16173. }
  16174. Mesh.call( this, geometry, material );
  16175. this.type = 'SkinnedMesh';
  16176. this.bindMode = 'attached';
  16177. this.bindMatrix = new Matrix4();
  16178. this.bindMatrixInverse = new Matrix4();
  16179. }
  16180. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16181. constructor: SkinnedMesh,
  16182. isSkinnedMesh: true,
  16183. bind: function ( skeleton, bindMatrix ) {
  16184. this.skeleton = skeleton;
  16185. if ( bindMatrix === undefined ) {
  16186. this.updateMatrixWorld( true );
  16187. this.skeleton.calculateInverses();
  16188. bindMatrix = this.matrixWorld;
  16189. }
  16190. this.bindMatrix.copy( bindMatrix );
  16191. this.bindMatrixInverse.getInverse( bindMatrix );
  16192. },
  16193. pose: function () {
  16194. this.skeleton.pose();
  16195. },
  16196. normalizeSkinWeights: function () {
  16197. var vector = new Vector4();
  16198. var skinWeight = this.geometry.attributes.skinWeight;
  16199. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  16200. vector.x = skinWeight.getX( i );
  16201. vector.y = skinWeight.getY( i );
  16202. vector.z = skinWeight.getZ( i );
  16203. vector.w = skinWeight.getW( i );
  16204. var scale = 1.0 / vector.manhattanLength();
  16205. if ( scale !== Infinity ) {
  16206. vector.multiplyScalar( scale );
  16207. } else {
  16208. vector.set( 1, 0, 0, 0 ); // do something reasonable
  16209. }
  16210. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  16211. }
  16212. },
  16213. updateMatrixWorld: function ( force ) {
  16214. Mesh.prototype.updateMatrixWorld.call( this, force );
  16215. if ( this.bindMode === 'attached' ) {
  16216. this.bindMatrixInverse.getInverse( this.matrixWorld );
  16217. } else if ( this.bindMode === 'detached' ) {
  16218. this.bindMatrixInverse.getInverse( this.bindMatrix );
  16219. } else {
  16220. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  16221. }
  16222. },
  16223. clone: function () {
  16224. return new this.constructor( this.geometry, this.material ).copy( this );
  16225. },
  16226. boneTransform: ( function () {
  16227. var basePosition = new Vector3();
  16228. var skinIndex = new Vector4();
  16229. var skinWeight = new Vector4();
  16230. var vector = new Vector3();
  16231. var matrix = new Matrix4();
  16232. return function ( index, target ) {
  16233. var skeleton = this.skeleton;
  16234. var geometry = this.geometry;
  16235. skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  16236. skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  16237. basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
  16238. target.set( 0, 0, 0 );
  16239. for ( var i = 0; i < 4; i ++ ) {
  16240. var weight = skinWeight.getComponent( i );
  16241. if ( weight !== 0 ) {
  16242. var boneIndex = skinIndex.getComponent( i );
  16243. matrix.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  16244. target.addScaledVector( vector.copy( basePosition ).applyMatrix4( matrix ), weight );
  16245. }
  16246. }
  16247. return target.applyMatrix4( this.bindMatrixInverse );
  16248. };
  16249. }() )
  16250. } );
  16251. /**
  16252. * @author mikael emtinger / http://gomo.se/
  16253. * @author alteredq / http://alteredqualia.com/
  16254. * @author michael guerrero / http://realitymeltdown.com
  16255. * @author ikerr / http://verold.com
  16256. */
  16257. var _offsetMatrix = new Matrix4();
  16258. var _identityMatrix = new Matrix4();
  16259. function Skeleton( bones, boneInverses ) {
  16260. // copy the bone array
  16261. bones = bones || [];
  16262. this.bones = bones.slice( 0 );
  16263. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  16264. this.frame = - 1;
  16265. // use the supplied bone inverses or calculate the inverses
  16266. if ( boneInverses === undefined ) {
  16267. this.calculateInverses();
  16268. } else {
  16269. if ( this.bones.length === boneInverses.length ) {
  16270. this.boneInverses = boneInverses.slice( 0 );
  16271. } else {
  16272. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  16273. this.boneInverses = [];
  16274. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16275. this.boneInverses.push( new Matrix4() );
  16276. }
  16277. }
  16278. }
  16279. }
  16280. Object.assign( Skeleton.prototype, {
  16281. calculateInverses: function () {
  16282. this.boneInverses = [];
  16283. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16284. var inverse = new Matrix4();
  16285. if ( this.bones[ i ] ) {
  16286. inverse.getInverse( this.bones[ i ].matrixWorld );
  16287. }
  16288. this.boneInverses.push( inverse );
  16289. }
  16290. },
  16291. pose: function () {
  16292. var bone, i, il;
  16293. // recover the bind-time world matrices
  16294. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  16295. bone = this.bones[ i ];
  16296. if ( bone ) {
  16297. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  16298. }
  16299. }
  16300. // compute the local matrices, positions, rotations and scales
  16301. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  16302. bone = this.bones[ i ];
  16303. if ( bone ) {
  16304. if ( bone.parent && bone.parent.isBone ) {
  16305. bone.matrix.getInverse( bone.parent.matrixWorld );
  16306. bone.matrix.multiply( bone.matrixWorld );
  16307. } else {
  16308. bone.matrix.copy( bone.matrixWorld );
  16309. }
  16310. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  16311. }
  16312. }
  16313. },
  16314. update: function () {
  16315. var bones = this.bones;
  16316. var boneInverses = this.boneInverses;
  16317. var boneMatrices = this.boneMatrices;
  16318. var boneTexture = this.boneTexture;
  16319. // flatten bone matrices to array
  16320. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  16321. // compute the offset between the current and the original transform
  16322. var matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  16323. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  16324. _offsetMatrix.toArray( boneMatrices, i * 16 );
  16325. }
  16326. if ( boneTexture !== undefined ) {
  16327. boneTexture.needsUpdate = true;
  16328. }
  16329. },
  16330. clone: function () {
  16331. return new Skeleton( this.bones, this.boneInverses );
  16332. },
  16333. getBoneByName: function ( name ) {
  16334. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16335. var bone = this.bones[ i ];
  16336. if ( bone.name === name ) {
  16337. return bone;
  16338. }
  16339. }
  16340. return undefined;
  16341. },
  16342. dispose: function ( ) {
  16343. if ( this.boneTexture ) {
  16344. this.boneTexture.dispose();
  16345. this.boneTexture = undefined;
  16346. }
  16347. }
  16348. } );
  16349. /**
  16350. * @author mikael emtinger / http://gomo.se/
  16351. * @author alteredq / http://alteredqualia.com/
  16352. * @author ikerr / http://verold.com
  16353. */
  16354. function Bone() {
  16355. Object3D.call( this );
  16356. this.type = 'Bone';
  16357. }
  16358. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16359. constructor: Bone,
  16360. isBone: true
  16361. } );
  16362. /**
  16363. * @author mrdoob / http://mrdoob.com/
  16364. */
  16365. var _instanceLocalMatrix = new Matrix4();
  16366. var _instanceWorldMatrix = new Matrix4();
  16367. var _instanceIntersects = [];
  16368. var _mesh = new Mesh();
  16369. function InstancedMesh( geometry, material, count ) {
  16370. Mesh.call( this, geometry, material );
  16371. this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
  16372. this.count = count;
  16373. this.frustumCulled = false;
  16374. }
  16375. InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16376. constructor: InstancedMesh,
  16377. isInstancedMesh: true,
  16378. getMatrixAt: function ( index, matrix ) {
  16379. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  16380. },
  16381. raycast: function ( raycaster, intersects ) {
  16382. var matrixWorld = this.matrixWorld;
  16383. var raycastTimes = this.count;
  16384. _mesh.geometry = this.geometry;
  16385. _mesh.material = this.material;
  16386. if ( _mesh.material === undefined ) return;
  16387. for ( var instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  16388. // calculate the world matrix for each instance
  16389. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  16390. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  16391. // the mesh represents this single instance
  16392. _mesh.matrixWorld = _instanceWorldMatrix;
  16393. _mesh.raycast( raycaster, _instanceIntersects );
  16394. // process the result of raycast
  16395. for ( var i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  16396. var intersect = _instanceIntersects[ i ];
  16397. intersect.instanceId = instanceId;
  16398. intersect.object = this;
  16399. intersects.push( intersect );
  16400. }
  16401. _instanceIntersects.length = 0;
  16402. }
  16403. },
  16404. setMatrixAt: function ( index, matrix ) {
  16405. matrix.toArray( this.instanceMatrix.array, index * 16 );
  16406. },
  16407. updateMorphTargets: function () {
  16408. }
  16409. } );
  16410. /**
  16411. * @author mrdoob / http://mrdoob.com/
  16412. * @author alteredq / http://alteredqualia.com/
  16413. *
  16414. * parameters = {
  16415. * color: <hex>,
  16416. * opacity: <float>,
  16417. *
  16418. * linewidth: <float>,
  16419. * linecap: "round",
  16420. * linejoin: "round"
  16421. * }
  16422. */
  16423. function LineBasicMaterial( parameters ) {
  16424. Material.call( this );
  16425. this.type = 'LineBasicMaterial';
  16426. this.color = new Color( 0xffffff );
  16427. this.linewidth = 1;
  16428. this.linecap = 'round';
  16429. this.linejoin = 'round';
  16430. this.morphTargets = false;
  16431. this.setValues( parameters );
  16432. }
  16433. LineBasicMaterial.prototype = Object.create( Material.prototype );
  16434. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16435. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16436. LineBasicMaterial.prototype.copy = function ( source ) {
  16437. Material.prototype.copy.call( this, source );
  16438. this.color.copy( source.color );
  16439. this.linewidth = source.linewidth;
  16440. this.linecap = source.linecap;
  16441. this.linejoin = source.linejoin;
  16442. this.morphTargets = source.morphTargets;
  16443. return this;
  16444. };
  16445. /**
  16446. * @author mrdoob / http://mrdoob.com/
  16447. */
  16448. var _start = new Vector3();
  16449. var _end = new Vector3();
  16450. var _inverseMatrix$1 = new Matrix4();
  16451. var _ray$1 = new Ray();
  16452. var _sphere$2 = new Sphere();
  16453. function Line( geometry, material, mode ) {
  16454. if ( mode === 1 ) {
  16455. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  16456. }
  16457. Object3D.call( this );
  16458. this.type = 'Line';
  16459. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16460. this.material = material !== undefined ? material : new LineBasicMaterial();
  16461. this.updateMorphTargets();
  16462. }
  16463. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16464. constructor: Line,
  16465. isLine: true,
  16466. computeLineDistances: function () {
  16467. var geometry = this.geometry;
  16468. if ( geometry.isBufferGeometry ) {
  16469. // we assume non-indexed geometry
  16470. if ( geometry.index === null ) {
  16471. var positionAttribute = geometry.attributes.position;
  16472. var lineDistances = [ 0 ];
  16473. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  16474. _start.fromBufferAttribute( positionAttribute, i - 1 );
  16475. _end.fromBufferAttribute( positionAttribute, i );
  16476. lineDistances[ i ] = lineDistances[ i - 1 ];
  16477. lineDistances[ i ] += _start.distanceTo( _end );
  16478. }
  16479. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16480. } else {
  16481. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16482. }
  16483. } else if ( geometry.isGeometry ) {
  16484. var vertices = geometry.vertices;
  16485. var lineDistances = geometry.lineDistances;
  16486. lineDistances[ 0 ] = 0;
  16487. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  16488. lineDistances[ i ] = lineDistances[ i - 1 ];
  16489. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  16490. }
  16491. }
  16492. return this;
  16493. },
  16494. raycast: function ( raycaster, intersects ) {
  16495. var geometry = this.geometry;
  16496. var matrixWorld = this.matrixWorld;
  16497. var threshold = raycaster.params.Line.threshold;
  16498. // Checking boundingSphere distance to ray
  16499. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16500. _sphere$2.copy( geometry.boundingSphere );
  16501. _sphere$2.applyMatrix4( matrixWorld );
  16502. _sphere$2.radius += threshold;
  16503. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
  16504. //
  16505. _inverseMatrix$1.getInverse( matrixWorld );
  16506. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  16507. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16508. var localThresholdSq = localThreshold * localThreshold;
  16509. var vStart = new Vector3();
  16510. var vEnd = new Vector3();
  16511. var interSegment = new Vector3();
  16512. var interRay = new Vector3();
  16513. var step = ( this && this.isLineSegments ) ? 2 : 1;
  16514. if ( geometry.isBufferGeometry ) {
  16515. var index = geometry.index;
  16516. var attributes = geometry.attributes;
  16517. var positions = attributes.position.array;
  16518. if ( index !== null ) {
  16519. var indices = index.array;
  16520. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  16521. var a = indices[ i ];
  16522. var b = indices[ i + 1 ];
  16523. vStart.fromArray( positions, a * 3 );
  16524. vEnd.fromArray( positions, b * 3 );
  16525. var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16526. if ( distSq > localThresholdSq ) continue;
  16527. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16528. var distance = raycaster.ray.origin.distanceTo( interRay );
  16529. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16530. intersects.push( {
  16531. distance: distance,
  16532. // What do we want? intersection point on the ray or on the segment??
  16533. // point: raycaster.ray.at( distance ),
  16534. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16535. index: i,
  16536. face: null,
  16537. faceIndex: null,
  16538. object: this
  16539. } );
  16540. }
  16541. } else {
  16542. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  16543. vStart.fromArray( positions, 3 * i );
  16544. vEnd.fromArray( positions, 3 * i + 3 );
  16545. var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16546. if ( distSq > localThresholdSq ) continue;
  16547. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16548. var distance = raycaster.ray.origin.distanceTo( interRay );
  16549. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16550. intersects.push( {
  16551. distance: distance,
  16552. // What do we want? intersection point on the ray or on the segment??
  16553. // point: raycaster.ray.at( distance ),
  16554. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16555. index: i,
  16556. face: null,
  16557. faceIndex: null,
  16558. object: this
  16559. } );
  16560. }
  16561. }
  16562. } else if ( geometry.isGeometry ) {
  16563. var vertices = geometry.vertices;
  16564. var nbVertices = vertices.length;
  16565. for ( var i = 0; i < nbVertices - 1; i += step ) {
  16566. var distSq = _ray$1.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  16567. if ( distSq > localThresholdSq ) continue;
  16568. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16569. var distance = raycaster.ray.origin.distanceTo( interRay );
  16570. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16571. intersects.push( {
  16572. distance: distance,
  16573. // What do we want? intersection point on the ray or on the segment??
  16574. // point: raycaster.ray.at( distance ),
  16575. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16576. index: i,
  16577. face: null,
  16578. faceIndex: null,
  16579. object: this
  16580. } );
  16581. }
  16582. }
  16583. },
  16584. updateMorphTargets: function () {
  16585. var geometry = this.geometry;
  16586. var m, ml, name;
  16587. if ( geometry.isBufferGeometry ) {
  16588. var morphAttributes = geometry.morphAttributes;
  16589. var keys = Object.keys( morphAttributes );
  16590. if ( keys.length > 0 ) {
  16591. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16592. if ( morphAttribute !== undefined ) {
  16593. this.morphTargetInfluences = [];
  16594. this.morphTargetDictionary = {};
  16595. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16596. name = morphAttribute[ m ].name || String( m );
  16597. this.morphTargetInfluences.push( 0 );
  16598. this.morphTargetDictionary[ name ] = m;
  16599. }
  16600. }
  16601. }
  16602. } else {
  16603. var morphTargets = geometry.morphTargets;
  16604. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16605. console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16606. }
  16607. }
  16608. },
  16609. clone: function () {
  16610. return new this.constructor( this.geometry, this.material ).copy( this );
  16611. }
  16612. } );
  16613. /**
  16614. * @author mrdoob / http://mrdoob.com/
  16615. */
  16616. var _start$1 = new Vector3();
  16617. var _end$1 = new Vector3();
  16618. function LineSegments( geometry, material ) {
  16619. Line.call( this, geometry, material );
  16620. this.type = 'LineSegments';
  16621. }
  16622. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16623. constructor: LineSegments,
  16624. isLineSegments: true,
  16625. computeLineDistances: function () {
  16626. var geometry = this.geometry;
  16627. if ( geometry.isBufferGeometry ) {
  16628. // we assume non-indexed geometry
  16629. if ( geometry.index === null ) {
  16630. var positionAttribute = geometry.attributes.position;
  16631. var lineDistances = [];
  16632. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16633. _start$1.fromBufferAttribute( positionAttribute, i );
  16634. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  16635. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16636. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16637. }
  16638. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16639. } else {
  16640. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16641. }
  16642. } else if ( geometry.isGeometry ) {
  16643. var vertices = geometry.vertices;
  16644. var lineDistances = geometry.lineDistances;
  16645. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  16646. _start$1.copy( vertices[ i ] );
  16647. _end$1.copy( vertices[ i + 1 ] );
  16648. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16649. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16650. }
  16651. }
  16652. return this;
  16653. }
  16654. } );
  16655. /**
  16656. * @author mgreter / http://github.com/mgreter
  16657. */
  16658. function LineLoop( geometry, material ) {
  16659. Line.call( this, geometry, material );
  16660. this.type = 'LineLoop';
  16661. }
  16662. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16663. constructor: LineLoop,
  16664. isLineLoop: true,
  16665. } );
  16666. /**
  16667. * @author mrdoob / http://mrdoob.com/
  16668. * @author alteredq / http://alteredqualia.com/
  16669. *
  16670. * parameters = {
  16671. * color: <hex>,
  16672. * opacity: <float>,
  16673. * map: new THREE.Texture( <Image> ),
  16674. * alphaMap: new THREE.Texture( <Image> ),
  16675. *
  16676. * size: <float>,
  16677. * sizeAttenuation: <bool>
  16678. *
  16679. * morphTargets: <bool>
  16680. * }
  16681. */
  16682. function PointsMaterial( parameters ) {
  16683. Material.call( this );
  16684. this.type = 'PointsMaterial';
  16685. this.color = new Color( 0xffffff );
  16686. this.map = null;
  16687. this.alphaMap = null;
  16688. this.size = 1;
  16689. this.sizeAttenuation = true;
  16690. this.morphTargets = false;
  16691. this.setValues( parameters );
  16692. }
  16693. PointsMaterial.prototype = Object.create( Material.prototype );
  16694. PointsMaterial.prototype.constructor = PointsMaterial;
  16695. PointsMaterial.prototype.isPointsMaterial = true;
  16696. PointsMaterial.prototype.copy = function ( source ) {
  16697. Material.prototype.copy.call( this, source );
  16698. this.color.copy( source.color );
  16699. this.map = source.map;
  16700. this.alphaMap = source.alphaMap;
  16701. this.size = source.size;
  16702. this.sizeAttenuation = source.sizeAttenuation;
  16703. this.morphTargets = source.morphTargets;
  16704. return this;
  16705. };
  16706. /**
  16707. * @author alteredq / http://alteredqualia.com/
  16708. */
  16709. var _inverseMatrix$2 = new Matrix4();
  16710. var _ray$2 = new Ray();
  16711. var _sphere$3 = new Sphere();
  16712. var _position$1 = new Vector3();
  16713. function Points( geometry, material ) {
  16714. Object3D.call( this );
  16715. this.type = 'Points';
  16716. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16717. this.material = material !== undefined ? material : new PointsMaterial();
  16718. this.updateMorphTargets();
  16719. }
  16720. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16721. constructor: Points,
  16722. isPoints: true,
  16723. raycast: function ( raycaster, intersects ) {
  16724. var geometry = this.geometry;
  16725. var matrixWorld = this.matrixWorld;
  16726. var threshold = raycaster.params.Points.threshold;
  16727. // Checking boundingSphere distance to ray
  16728. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16729. _sphere$3.copy( geometry.boundingSphere );
  16730. _sphere$3.applyMatrix4( matrixWorld );
  16731. _sphere$3.radius += threshold;
  16732. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  16733. //
  16734. _inverseMatrix$2.getInverse( matrixWorld );
  16735. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  16736. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16737. var localThresholdSq = localThreshold * localThreshold;
  16738. if ( geometry.isBufferGeometry ) {
  16739. var index = geometry.index;
  16740. var attributes = geometry.attributes;
  16741. var positions = attributes.position.array;
  16742. if ( index !== null ) {
  16743. var indices = index.array;
  16744. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  16745. var a = indices[ i ];
  16746. _position$1.fromArray( positions, a * 3 );
  16747. testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16748. }
  16749. } else {
  16750. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  16751. _position$1.fromArray( positions, i * 3 );
  16752. testPoint( _position$1, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16753. }
  16754. }
  16755. } else {
  16756. var vertices = geometry.vertices;
  16757. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  16758. testPoint( vertices[ i ], i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16759. }
  16760. }
  16761. },
  16762. updateMorphTargets: function () {
  16763. var geometry = this.geometry;
  16764. var m, ml, name;
  16765. if ( geometry.isBufferGeometry ) {
  16766. var morphAttributes = geometry.morphAttributes;
  16767. var keys = Object.keys( morphAttributes );
  16768. if ( keys.length > 0 ) {
  16769. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16770. if ( morphAttribute !== undefined ) {
  16771. this.morphTargetInfluences = [];
  16772. this.morphTargetDictionary = {};
  16773. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16774. name = morphAttribute[ m ].name || String( m );
  16775. this.morphTargetInfluences.push( 0 );
  16776. this.morphTargetDictionary[ name ] = m;
  16777. }
  16778. }
  16779. }
  16780. } else {
  16781. var morphTargets = geometry.morphTargets;
  16782. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16783. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16784. }
  16785. }
  16786. },
  16787. clone: function () {
  16788. return new this.constructor( this.geometry, this.material ).copy( this );
  16789. }
  16790. } );
  16791. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  16792. var rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  16793. if ( rayPointDistanceSq < localThresholdSq ) {
  16794. var intersectPoint = new Vector3();
  16795. _ray$2.closestPointToPoint( point, intersectPoint );
  16796. intersectPoint.applyMatrix4( matrixWorld );
  16797. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16798. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16799. intersects.push( {
  16800. distance: distance,
  16801. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16802. point: intersectPoint,
  16803. index: index,
  16804. face: null,
  16805. object: object
  16806. } );
  16807. }
  16808. }
  16809. /**
  16810. * @author mrdoob / http://mrdoob.com/
  16811. */
  16812. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16813. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16814. this.format = format !== undefined ? format : RGBFormat;
  16815. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16816. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16817. this.generateMipmaps = false;
  16818. }
  16819. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16820. constructor: VideoTexture,
  16821. isVideoTexture: true,
  16822. update: function () {
  16823. var video = this.image;
  16824. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  16825. this.needsUpdate = true;
  16826. }
  16827. }
  16828. } );
  16829. /**
  16830. * @author alteredq / http://alteredqualia.com/
  16831. */
  16832. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16833. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16834. this.image = { width: width, height: height };
  16835. this.mipmaps = mipmaps;
  16836. // no flipping for cube textures
  16837. // (also flipping doesn't work for compressed textures )
  16838. this.flipY = false;
  16839. // can't generate mipmaps for compressed textures
  16840. // mips must be embedded in DDS files
  16841. this.generateMipmaps = false;
  16842. }
  16843. CompressedTexture.prototype = Object.create( Texture.prototype );
  16844. CompressedTexture.prototype.constructor = CompressedTexture;
  16845. CompressedTexture.prototype.isCompressedTexture = true;
  16846. /**
  16847. * @author mrdoob / http://mrdoob.com/
  16848. */
  16849. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16850. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16851. this.needsUpdate = true;
  16852. }
  16853. CanvasTexture.prototype = Object.create( Texture.prototype );
  16854. CanvasTexture.prototype.constructor = CanvasTexture;
  16855. CanvasTexture.prototype.isCanvasTexture = true;
  16856. /**
  16857. * @author Matt DesLauriers / @mattdesl
  16858. * @author atix / arthursilber.de
  16859. */
  16860. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16861. format = format !== undefined ? format : DepthFormat;
  16862. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16863. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16864. }
  16865. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16866. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16867. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16868. this.image = { width: width, height: height };
  16869. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16870. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16871. this.flipY = false;
  16872. this.generateMipmaps = false;
  16873. }
  16874. DepthTexture.prototype = Object.create( Texture.prototype );
  16875. DepthTexture.prototype.constructor = DepthTexture;
  16876. DepthTexture.prototype.isDepthTexture = true;
  16877. /**
  16878. * @author mrdoob / http://mrdoob.com/
  16879. * @author Mugen87 / https://github.com/Mugen87
  16880. */
  16881. function WireframeGeometry( geometry ) {
  16882. BufferGeometry.call( this );
  16883. this.type = 'WireframeGeometry';
  16884. // buffer
  16885. var vertices = [];
  16886. // helper variables
  16887. var i, j, l, o, ol;
  16888. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16889. var key, keys = [ 'a', 'b', 'c' ];
  16890. var vertex;
  16891. // different logic for Geometry and BufferGeometry
  16892. if ( geometry && geometry.isGeometry ) {
  16893. // create a data structure that contains all edges without duplicates
  16894. var faces = geometry.faces;
  16895. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16896. var face = faces[ i ];
  16897. for ( j = 0; j < 3; j ++ ) {
  16898. edge1 = face[ keys[ j ] ];
  16899. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16900. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16901. edge[ 1 ] = Math.max( edge1, edge2 );
  16902. key = edge[ 0 ] + ',' + edge[ 1 ];
  16903. if ( edges[ key ] === undefined ) {
  16904. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16905. }
  16906. }
  16907. }
  16908. // generate vertices
  16909. for ( key in edges ) {
  16910. e = edges[ key ];
  16911. vertex = geometry.vertices[ e.index1 ];
  16912. vertices.push( vertex.x, vertex.y, vertex.z );
  16913. vertex = geometry.vertices[ e.index2 ];
  16914. vertices.push( vertex.x, vertex.y, vertex.z );
  16915. }
  16916. } else if ( geometry && geometry.isBufferGeometry ) {
  16917. var position, indices, groups;
  16918. var group, start, count;
  16919. var index1, index2;
  16920. vertex = new Vector3();
  16921. if ( geometry.index !== null ) {
  16922. // indexed BufferGeometry
  16923. position = geometry.attributes.position;
  16924. indices = geometry.index;
  16925. groups = geometry.groups;
  16926. if ( groups.length === 0 ) {
  16927. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16928. }
  16929. // create a data structure that contains all eges without duplicates
  16930. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16931. group = groups[ o ];
  16932. start = group.start;
  16933. count = group.count;
  16934. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16935. for ( j = 0; j < 3; j ++ ) {
  16936. edge1 = indices.getX( i + j );
  16937. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16938. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16939. edge[ 1 ] = Math.max( edge1, edge2 );
  16940. key = edge[ 0 ] + ',' + edge[ 1 ];
  16941. if ( edges[ key ] === undefined ) {
  16942. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16943. }
  16944. }
  16945. }
  16946. }
  16947. // generate vertices
  16948. for ( key in edges ) {
  16949. e = edges[ key ];
  16950. vertex.fromBufferAttribute( position, e.index1 );
  16951. vertices.push( vertex.x, vertex.y, vertex.z );
  16952. vertex.fromBufferAttribute( position, e.index2 );
  16953. vertices.push( vertex.x, vertex.y, vertex.z );
  16954. }
  16955. } else {
  16956. // non-indexed BufferGeometry
  16957. position = geometry.attributes.position;
  16958. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16959. for ( j = 0; j < 3; j ++ ) {
  16960. // three edges per triangle, an edge is represented as (index1, index2)
  16961. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16962. index1 = 3 * i + j;
  16963. vertex.fromBufferAttribute( position, index1 );
  16964. vertices.push( vertex.x, vertex.y, vertex.z );
  16965. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16966. vertex.fromBufferAttribute( position, index2 );
  16967. vertices.push( vertex.x, vertex.y, vertex.z );
  16968. }
  16969. }
  16970. }
  16971. }
  16972. // build geometry
  16973. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16974. }
  16975. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16976. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16977. /**
  16978. * @author zz85 / https://github.com/zz85
  16979. * @author Mugen87 / https://github.com/Mugen87
  16980. *
  16981. * Parametric Surfaces Geometry
  16982. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  16983. */
  16984. // ParametricGeometry
  16985. function ParametricGeometry( func, slices, stacks ) {
  16986. Geometry.call( this );
  16987. this.type = 'ParametricGeometry';
  16988. this.parameters = {
  16989. func: func,
  16990. slices: slices,
  16991. stacks: stacks
  16992. };
  16993. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16994. this.mergeVertices();
  16995. }
  16996. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16997. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16998. // ParametricBufferGeometry
  16999. function ParametricBufferGeometry( func, slices, stacks ) {
  17000. BufferGeometry.call( this );
  17001. this.type = 'ParametricBufferGeometry';
  17002. this.parameters = {
  17003. func: func,
  17004. slices: slices,
  17005. stacks: stacks
  17006. };
  17007. // buffers
  17008. var indices = [];
  17009. var vertices = [];
  17010. var normals = [];
  17011. var uvs = [];
  17012. var EPS = 0.00001;
  17013. var normal = new Vector3();
  17014. var p0 = new Vector3(), p1 = new Vector3();
  17015. var pu = new Vector3(), pv = new Vector3();
  17016. var i, j;
  17017. if ( func.length < 3 ) {
  17018. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  17019. }
  17020. // generate vertices, normals and uvs
  17021. var sliceCount = slices + 1;
  17022. for ( i = 0; i <= stacks; i ++ ) {
  17023. var v = i / stacks;
  17024. for ( j = 0; j <= slices; j ++ ) {
  17025. var u = j / slices;
  17026. // vertex
  17027. func( u, v, p0 );
  17028. vertices.push( p0.x, p0.y, p0.z );
  17029. // normal
  17030. // approximate tangent vectors via finite differences
  17031. if ( u - EPS >= 0 ) {
  17032. func( u - EPS, v, p1 );
  17033. pu.subVectors( p0, p1 );
  17034. } else {
  17035. func( u + EPS, v, p1 );
  17036. pu.subVectors( p1, p0 );
  17037. }
  17038. if ( v - EPS >= 0 ) {
  17039. func( u, v - EPS, p1 );
  17040. pv.subVectors( p0, p1 );
  17041. } else {
  17042. func( u, v + EPS, p1 );
  17043. pv.subVectors( p1, p0 );
  17044. }
  17045. // cross product of tangent vectors returns surface normal
  17046. normal.crossVectors( pu, pv ).normalize();
  17047. normals.push( normal.x, normal.y, normal.z );
  17048. // uv
  17049. uvs.push( u, v );
  17050. }
  17051. }
  17052. // generate indices
  17053. for ( i = 0; i < stacks; i ++ ) {
  17054. for ( j = 0; j < slices; j ++ ) {
  17055. var a = i * sliceCount + j;
  17056. var b = i * sliceCount + j + 1;
  17057. var c = ( i + 1 ) * sliceCount + j + 1;
  17058. var d = ( i + 1 ) * sliceCount + j;
  17059. // faces one and two
  17060. indices.push( a, b, d );
  17061. indices.push( b, c, d );
  17062. }
  17063. }
  17064. // build geometry
  17065. this.setIndex( indices );
  17066. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17067. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17068. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17069. }
  17070. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17071. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  17072. /**
  17073. * @author clockworkgeek / https://github.com/clockworkgeek
  17074. * @author timothypratley / https://github.com/timothypratley
  17075. * @author WestLangley / http://github.com/WestLangley
  17076. * @author Mugen87 / https://github.com/Mugen87
  17077. */
  17078. // PolyhedronGeometry
  17079. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  17080. Geometry.call( this );
  17081. this.type = 'PolyhedronGeometry';
  17082. this.parameters = {
  17083. vertices: vertices,
  17084. indices: indices,
  17085. radius: radius,
  17086. detail: detail
  17087. };
  17088. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  17089. this.mergeVertices();
  17090. }
  17091. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  17092. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  17093. // PolyhedronBufferGeometry
  17094. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  17095. BufferGeometry.call( this );
  17096. this.type = 'PolyhedronBufferGeometry';
  17097. this.parameters = {
  17098. vertices: vertices,
  17099. indices: indices,
  17100. radius: radius,
  17101. detail: detail
  17102. };
  17103. radius = radius || 1;
  17104. detail = detail || 0;
  17105. // default buffer data
  17106. var vertexBuffer = [];
  17107. var uvBuffer = [];
  17108. // the subdivision creates the vertex buffer data
  17109. subdivide( detail );
  17110. // all vertices should lie on a conceptual sphere with a given radius
  17111. applyRadius( radius );
  17112. // finally, create the uv data
  17113. generateUVs();
  17114. // build non-indexed geometry
  17115. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  17116. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  17117. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  17118. if ( detail === 0 ) {
  17119. this.computeVertexNormals(); // flat normals
  17120. } else {
  17121. this.normalizeNormals(); // smooth normals
  17122. }
  17123. // helper functions
  17124. function subdivide( detail ) {
  17125. var a = new Vector3();
  17126. var b = new Vector3();
  17127. var c = new Vector3();
  17128. // iterate over all faces and apply a subdivison with the given detail value
  17129. for ( var i = 0; i < indices.length; i += 3 ) {
  17130. // get the vertices of the face
  17131. getVertexByIndex( indices[ i + 0 ], a );
  17132. getVertexByIndex( indices[ i + 1 ], b );
  17133. getVertexByIndex( indices[ i + 2 ], c );
  17134. // perform subdivision
  17135. subdivideFace( a, b, c, detail );
  17136. }
  17137. }
  17138. function subdivideFace( a, b, c, detail ) {
  17139. var cols = Math.pow( 2, detail );
  17140. // we use this multidimensional array as a data structure for creating the subdivision
  17141. var v = [];
  17142. var i, j;
  17143. // construct all of the vertices for this subdivision
  17144. for ( i = 0; i <= cols; i ++ ) {
  17145. v[ i ] = [];
  17146. var aj = a.clone().lerp( c, i / cols );
  17147. var bj = b.clone().lerp( c, i / cols );
  17148. var rows = cols - i;
  17149. for ( j = 0; j <= rows; j ++ ) {
  17150. if ( j === 0 && i === cols ) {
  17151. v[ i ][ j ] = aj;
  17152. } else {
  17153. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  17154. }
  17155. }
  17156. }
  17157. // construct all of the faces
  17158. for ( i = 0; i < cols; i ++ ) {
  17159. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  17160. var k = Math.floor( j / 2 );
  17161. if ( j % 2 === 0 ) {
  17162. pushVertex( v[ i ][ k + 1 ] );
  17163. pushVertex( v[ i + 1 ][ k ] );
  17164. pushVertex( v[ i ][ k ] );
  17165. } else {
  17166. pushVertex( v[ i ][ k + 1 ] );
  17167. pushVertex( v[ i + 1 ][ k + 1 ] );
  17168. pushVertex( v[ i + 1 ][ k ] );
  17169. }
  17170. }
  17171. }
  17172. }
  17173. function applyRadius( radius ) {
  17174. var vertex = new Vector3();
  17175. // iterate over the entire buffer and apply the radius to each vertex
  17176. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  17177. vertex.x = vertexBuffer[ i + 0 ];
  17178. vertex.y = vertexBuffer[ i + 1 ];
  17179. vertex.z = vertexBuffer[ i + 2 ];
  17180. vertex.normalize().multiplyScalar( radius );
  17181. vertexBuffer[ i + 0 ] = vertex.x;
  17182. vertexBuffer[ i + 1 ] = vertex.y;
  17183. vertexBuffer[ i + 2 ] = vertex.z;
  17184. }
  17185. }
  17186. function generateUVs() {
  17187. var vertex = new Vector3();
  17188. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  17189. vertex.x = vertexBuffer[ i + 0 ];
  17190. vertex.y = vertexBuffer[ i + 1 ];
  17191. vertex.z = vertexBuffer[ i + 2 ];
  17192. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  17193. var v = inclination( vertex ) / Math.PI + 0.5;
  17194. uvBuffer.push( u, 1 - v );
  17195. }
  17196. correctUVs();
  17197. correctSeam();
  17198. }
  17199. function correctSeam() {
  17200. // handle case when face straddles the seam, see #3269
  17201. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  17202. // uv data of a single face
  17203. var x0 = uvBuffer[ i + 0 ];
  17204. var x1 = uvBuffer[ i + 2 ];
  17205. var x2 = uvBuffer[ i + 4 ];
  17206. var max = Math.max( x0, x1, x2 );
  17207. var min = Math.min( x0, x1, x2 );
  17208. // 0.9 is somewhat arbitrary
  17209. if ( max > 0.9 && min < 0.1 ) {
  17210. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  17211. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  17212. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  17213. }
  17214. }
  17215. }
  17216. function pushVertex( vertex ) {
  17217. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  17218. }
  17219. function getVertexByIndex( index, vertex ) {
  17220. var stride = index * 3;
  17221. vertex.x = vertices[ stride + 0 ];
  17222. vertex.y = vertices[ stride + 1 ];
  17223. vertex.z = vertices[ stride + 2 ];
  17224. }
  17225. function correctUVs() {
  17226. var a = new Vector3();
  17227. var b = new Vector3();
  17228. var c = new Vector3();
  17229. var centroid = new Vector3();
  17230. var uvA = new Vector2();
  17231. var uvB = new Vector2();
  17232. var uvC = new Vector2();
  17233. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  17234. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  17235. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  17236. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  17237. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  17238. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  17239. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  17240. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  17241. var azi = azimuth( centroid );
  17242. correctUV( uvA, j + 0, a, azi );
  17243. correctUV( uvB, j + 2, b, azi );
  17244. correctUV( uvC, j + 4, c, azi );
  17245. }
  17246. }
  17247. function correctUV( uv, stride, vector, azimuth ) {
  17248. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  17249. uvBuffer[ stride ] = uv.x - 1;
  17250. }
  17251. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  17252. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  17253. }
  17254. }
  17255. // Angle around the Y axis, counter-clockwise when looking from above.
  17256. function azimuth( vector ) {
  17257. return Math.atan2( vector.z, - vector.x );
  17258. }
  17259. // Angle above the XZ plane.
  17260. function inclination( vector ) {
  17261. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  17262. }
  17263. }
  17264. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17265. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  17266. /**
  17267. * @author timothypratley / https://github.com/timothypratley
  17268. * @author Mugen87 / https://github.com/Mugen87
  17269. */
  17270. // TetrahedronGeometry
  17271. function TetrahedronGeometry( radius, detail ) {
  17272. Geometry.call( this );
  17273. this.type = 'TetrahedronGeometry';
  17274. this.parameters = {
  17275. radius: radius,
  17276. detail: detail
  17277. };
  17278. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  17279. this.mergeVertices();
  17280. }
  17281. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  17282. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  17283. // TetrahedronBufferGeometry
  17284. function TetrahedronBufferGeometry( radius, detail ) {
  17285. var vertices = [
  17286. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  17287. ];
  17288. var indices = [
  17289. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  17290. ];
  17291. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17292. this.type = 'TetrahedronBufferGeometry';
  17293. this.parameters = {
  17294. radius: radius,
  17295. detail: detail
  17296. };
  17297. }
  17298. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17299. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  17300. /**
  17301. * @author timothypratley / https://github.com/timothypratley
  17302. * @author Mugen87 / https://github.com/Mugen87
  17303. */
  17304. // OctahedronGeometry
  17305. function OctahedronGeometry( radius, detail ) {
  17306. Geometry.call( this );
  17307. this.type = 'OctahedronGeometry';
  17308. this.parameters = {
  17309. radius: radius,
  17310. detail: detail
  17311. };
  17312. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  17313. this.mergeVertices();
  17314. }
  17315. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  17316. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  17317. // OctahedronBufferGeometry
  17318. function OctahedronBufferGeometry( radius, detail ) {
  17319. var vertices = [
  17320. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  17321. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  17322. ];
  17323. var indices = [
  17324. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  17325. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  17326. 1, 3, 4, 1, 4, 2
  17327. ];
  17328. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17329. this.type = 'OctahedronBufferGeometry';
  17330. this.parameters = {
  17331. radius: radius,
  17332. detail: detail
  17333. };
  17334. }
  17335. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17336. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  17337. /**
  17338. * @author timothypratley / https://github.com/timothypratley
  17339. * @author Mugen87 / https://github.com/Mugen87
  17340. */
  17341. // IcosahedronGeometry
  17342. function IcosahedronGeometry( radius, detail ) {
  17343. Geometry.call( this );
  17344. this.type = 'IcosahedronGeometry';
  17345. this.parameters = {
  17346. radius: radius,
  17347. detail: detail
  17348. };
  17349. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  17350. this.mergeVertices();
  17351. }
  17352. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  17353. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  17354. // IcosahedronBufferGeometry
  17355. function IcosahedronBufferGeometry( radius, detail ) {
  17356. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17357. var vertices = [
  17358. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  17359. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  17360. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  17361. ];
  17362. var indices = [
  17363. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  17364. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17365. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  17366. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  17367. ];
  17368. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17369. this.type = 'IcosahedronBufferGeometry';
  17370. this.parameters = {
  17371. radius: radius,
  17372. detail: detail
  17373. };
  17374. }
  17375. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17376. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  17377. /**
  17378. * @author Abe Pazos / https://hamoid.com
  17379. * @author Mugen87 / https://github.com/Mugen87
  17380. */
  17381. // DodecahedronGeometry
  17382. function DodecahedronGeometry( radius, detail ) {
  17383. Geometry.call( this );
  17384. this.type = 'DodecahedronGeometry';
  17385. this.parameters = {
  17386. radius: radius,
  17387. detail: detail
  17388. };
  17389. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  17390. this.mergeVertices();
  17391. }
  17392. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  17393. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  17394. // DodecahedronBufferGeometry
  17395. function DodecahedronBufferGeometry( radius, detail ) {
  17396. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17397. var r = 1 / t;
  17398. var vertices = [
  17399. // (±1, ±1, ±1)
  17400. - 1, - 1, - 1, - 1, - 1, 1,
  17401. - 1, 1, - 1, - 1, 1, 1,
  17402. 1, - 1, - 1, 1, - 1, 1,
  17403. 1, 1, - 1, 1, 1, 1,
  17404. // (0, ±1/φ, ±φ)
  17405. 0, - r, - t, 0, - r, t,
  17406. 0, r, - t, 0, r, t,
  17407. // (±1/φ, ±φ, 0)
  17408. - r, - t, 0, - r, t, 0,
  17409. r, - t, 0, r, t, 0,
  17410. // (±φ, 0, ±1/φ)
  17411. - t, 0, - r, t, 0, - r,
  17412. - t, 0, r, t, 0, r
  17413. ];
  17414. var indices = [
  17415. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  17416. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  17417. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  17418. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  17419. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  17420. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  17421. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  17422. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  17423. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  17424. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  17425. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  17426. 1, 12, 14, 1, 14, 5, 1, 5, 9
  17427. ];
  17428. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17429. this.type = 'DodecahedronBufferGeometry';
  17430. this.parameters = {
  17431. radius: radius,
  17432. detail: detail
  17433. };
  17434. }
  17435. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17436. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  17437. /**
  17438. * @author oosmoxiecode / https://github.com/oosmoxiecode
  17439. * @author WestLangley / https://github.com/WestLangley
  17440. * @author zz85 / https://github.com/zz85
  17441. * @author miningold / https://github.com/miningold
  17442. * @author jonobr1 / https://github.com/jonobr1
  17443. * @author Mugen87 / https://github.com/Mugen87
  17444. *
  17445. */
  17446. // TubeGeometry
  17447. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  17448. Geometry.call( this );
  17449. this.type = 'TubeGeometry';
  17450. this.parameters = {
  17451. path: path,
  17452. tubularSegments: tubularSegments,
  17453. radius: radius,
  17454. radialSegments: radialSegments,
  17455. closed: closed
  17456. };
  17457. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  17458. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  17459. // expose internals
  17460. this.tangents = bufferGeometry.tangents;
  17461. this.normals = bufferGeometry.normals;
  17462. this.binormals = bufferGeometry.binormals;
  17463. // create geometry
  17464. this.fromBufferGeometry( bufferGeometry );
  17465. this.mergeVertices();
  17466. }
  17467. TubeGeometry.prototype = Object.create( Geometry.prototype );
  17468. TubeGeometry.prototype.constructor = TubeGeometry;
  17469. // TubeBufferGeometry
  17470. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  17471. BufferGeometry.call( this );
  17472. this.type = 'TubeBufferGeometry';
  17473. this.parameters = {
  17474. path: path,
  17475. tubularSegments: tubularSegments,
  17476. radius: radius,
  17477. radialSegments: radialSegments,
  17478. closed: closed
  17479. };
  17480. tubularSegments = tubularSegments || 64;
  17481. radius = radius || 1;
  17482. radialSegments = radialSegments || 8;
  17483. closed = closed || false;
  17484. var frames = path.computeFrenetFrames( tubularSegments, closed );
  17485. // expose internals
  17486. this.tangents = frames.tangents;
  17487. this.normals = frames.normals;
  17488. this.binormals = frames.binormals;
  17489. // helper variables
  17490. var vertex = new Vector3();
  17491. var normal = new Vector3();
  17492. var uv = new Vector2();
  17493. var P = new Vector3();
  17494. var i, j;
  17495. // buffer
  17496. var vertices = [];
  17497. var normals = [];
  17498. var uvs = [];
  17499. var indices = [];
  17500. // create buffer data
  17501. generateBufferData();
  17502. // build geometry
  17503. this.setIndex( indices );
  17504. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17505. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17506. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17507. // functions
  17508. function generateBufferData() {
  17509. for ( i = 0; i < tubularSegments; i ++ ) {
  17510. generateSegment( i );
  17511. }
  17512. // if the geometry is not closed, generate the last row of vertices and normals
  17513. // at the regular position on the given path
  17514. //
  17515. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  17516. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  17517. // uvs are generated in a separate function.
  17518. // this makes it easy compute correct values for closed geometries
  17519. generateUVs();
  17520. // finally create faces
  17521. generateIndices();
  17522. }
  17523. function generateSegment( i ) {
  17524. // we use getPointAt to sample evenly distributed points from the given path
  17525. P = path.getPointAt( i / tubularSegments, P );
  17526. // retrieve corresponding normal and binormal
  17527. var N = frames.normals[ i ];
  17528. var B = frames.binormals[ i ];
  17529. // generate normals and vertices for the current segment
  17530. for ( j = 0; j <= radialSegments; j ++ ) {
  17531. var v = j / radialSegments * Math.PI * 2;
  17532. var sin = Math.sin( v );
  17533. var cos = - Math.cos( v );
  17534. // normal
  17535. normal.x = ( cos * N.x + sin * B.x );
  17536. normal.y = ( cos * N.y + sin * B.y );
  17537. normal.z = ( cos * N.z + sin * B.z );
  17538. normal.normalize();
  17539. normals.push( normal.x, normal.y, normal.z );
  17540. // vertex
  17541. vertex.x = P.x + radius * normal.x;
  17542. vertex.y = P.y + radius * normal.y;
  17543. vertex.z = P.z + radius * normal.z;
  17544. vertices.push( vertex.x, vertex.y, vertex.z );
  17545. }
  17546. }
  17547. function generateIndices() {
  17548. for ( j = 1; j <= tubularSegments; j ++ ) {
  17549. for ( i = 1; i <= radialSegments; i ++ ) {
  17550. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17551. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17552. var c = ( radialSegments + 1 ) * j + i;
  17553. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17554. // faces
  17555. indices.push( a, b, d );
  17556. indices.push( b, c, d );
  17557. }
  17558. }
  17559. }
  17560. function generateUVs() {
  17561. for ( i = 0; i <= tubularSegments; i ++ ) {
  17562. for ( j = 0; j <= radialSegments; j ++ ) {
  17563. uv.x = i / tubularSegments;
  17564. uv.y = j / radialSegments;
  17565. uvs.push( uv.x, uv.y );
  17566. }
  17567. }
  17568. }
  17569. }
  17570. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17571. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  17572. TubeBufferGeometry.prototype.toJSON = function () {
  17573. var data = BufferGeometry.prototype.toJSON.call( this );
  17574. data.path = this.parameters.path.toJSON();
  17575. return data;
  17576. };
  17577. /**
  17578. * @author oosmoxiecode
  17579. * @author Mugen87 / https://github.com/Mugen87
  17580. *
  17581. * based on http://www.blackpawn.com/texts/pqtorus/
  17582. */
  17583. // TorusKnotGeometry
  17584. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  17585. Geometry.call( this );
  17586. this.type = 'TorusKnotGeometry';
  17587. this.parameters = {
  17588. radius: radius,
  17589. tube: tube,
  17590. tubularSegments: tubularSegments,
  17591. radialSegments: radialSegments,
  17592. p: p,
  17593. q: q
  17594. };
  17595. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  17596. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  17597. this.mergeVertices();
  17598. }
  17599. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  17600. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  17601. // TorusKnotBufferGeometry
  17602. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  17603. BufferGeometry.call( this );
  17604. this.type = 'TorusKnotBufferGeometry';
  17605. this.parameters = {
  17606. radius: radius,
  17607. tube: tube,
  17608. tubularSegments: tubularSegments,
  17609. radialSegments: radialSegments,
  17610. p: p,
  17611. q: q
  17612. };
  17613. radius = radius || 1;
  17614. tube = tube || 0.4;
  17615. tubularSegments = Math.floor( tubularSegments ) || 64;
  17616. radialSegments = Math.floor( radialSegments ) || 8;
  17617. p = p || 2;
  17618. q = q || 3;
  17619. // buffers
  17620. var indices = [];
  17621. var vertices = [];
  17622. var normals = [];
  17623. var uvs = [];
  17624. // helper variables
  17625. var i, j;
  17626. var vertex = new Vector3();
  17627. var normal = new Vector3();
  17628. var P1 = new Vector3();
  17629. var P2 = new Vector3();
  17630. var B = new Vector3();
  17631. var T = new Vector3();
  17632. var N = new Vector3();
  17633. // generate vertices, normals and uvs
  17634. for ( i = 0; i <= tubularSegments; ++ i ) {
  17635. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17636. var u = i / tubularSegments * p * Math.PI * 2;
  17637. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17638. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17639. calculatePositionOnCurve( u, p, q, radius, P1 );
  17640. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17641. // calculate orthonormal basis
  17642. T.subVectors( P2, P1 );
  17643. N.addVectors( P2, P1 );
  17644. B.crossVectors( T, N );
  17645. N.crossVectors( B, T );
  17646. // normalize B, N. T can be ignored, we don't use it
  17647. B.normalize();
  17648. N.normalize();
  17649. for ( j = 0; j <= radialSegments; ++ j ) {
  17650. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17651. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17652. var v = j / radialSegments * Math.PI * 2;
  17653. var cx = - tube * Math.cos( v );
  17654. var cy = tube * Math.sin( v );
  17655. // now calculate the final vertex position.
  17656. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17657. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17658. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17659. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17660. vertices.push( vertex.x, vertex.y, vertex.z );
  17661. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17662. normal.subVectors( vertex, P1 ).normalize();
  17663. normals.push( normal.x, normal.y, normal.z );
  17664. // uv
  17665. uvs.push( i / tubularSegments );
  17666. uvs.push( j / radialSegments );
  17667. }
  17668. }
  17669. // generate indices
  17670. for ( j = 1; j <= tubularSegments; j ++ ) {
  17671. for ( i = 1; i <= radialSegments; i ++ ) {
  17672. // indices
  17673. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17674. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17675. var c = ( radialSegments + 1 ) * j + i;
  17676. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17677. // faces
  17678. indices.push( a, b, d );
  17679. indices.push( b, c, d );
  17680. }
  17681. }
  17682. // build geometry
  17683. this.setIndex( indices );
  17684. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17685. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17686. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17687. // this function calculates the current position on the torus curve
  17688. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17689. var cu = Math.cos( u );
  17690. var su = Math.sin( u );
  17691. var quOverP = q / p * u;
  17692. var cs = Math.cos( quOverP );
  17693. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17694. position.y = radius * ( 2 + cs ) * su * 0.5;
  17695. position.z = radius * Math.sin( quOverP ) * 0.5;
  17696. }
  17697. }
  17698. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17699. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17700. /**
  17701. * @author oosmoxiecode
  17702. * @author mrdoob / http://mrdoob.com/
  17703. * @author Mugen87 / https://github.com/Mugen87
  17704. */
  17705. // TorusGeometry
  17706. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17707. Geometry.call( this );
  17708. this.type = 'TorusGeometry';
  17709. this.parameters = {
  17710. radius: radius,
  17711. tube: tube,
  17712. radialSegments: radialSegments,
  17713. tubularSegments: tubularSegments,
  17714. arc: arc
  17715. };
  17716. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17717. this.mergeVertices();
  17718. }
  17719. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17720. TorusGeometry.prototype.constructor = TorusGeometry;
  17721. // TorusBufferGeometry
  17722. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17723. BufferGeometry.call( this );
  17724. this.type = 'TorusBufferGeometry';
  17725. this.parameters = {
  17726. radius: radius,
  17727. tube: tube,
  17728. radialSegments: radialSegments,
  17729. tubularSegments: tubularSegments,
  17730. arc: arc
  17731. };
  17732. radius = radius || 1;
  17733. tube = tube || 0.4;
  17734. radialSegments = Math.floor( radialSegments ) || 8;
  17735. tubularSegments = Math.floor( tubularSegments ) || 6;
  17736. arc = arc || Math.PI * 2;
  17737. // buffers
  17738. var indices = [];
  17739. var vertices = [];
  17740. var normals = [];
  17741. var uvs = [];
  17742. // helper variables
  17743. var center = new Vector3();
  17744. var vertex = new Vector3();
  17745. var normal = new Vector3();
  17746. var j, i;
  17747. // generate vertices, normals and uvs
  17748. for ( j = 0; j <= radialSegments; j ++ ) {
  17749. for ( i = 0; i <= tubularSegments; i ++ ) {
  17750. var u = i / tubularSegments * arc;
  17751. var v = j / radialSegments * Math.PI * 2;
  17752. // vertex
  17753. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  17754. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  17755. vertex.z = tube * Math.sin( v );
  17756. vertices.push( vertex.x, vertex.y, vertex.z );
  17757. // normal
  17758. center.x = radius * Math.cos( u );
  17759. center.y = radius * Math.sin( u );
  17760. normal.subVectors( vertex, center ).normalize();
  17761. normals.push( normal.x, normal.y, normal.z );
  17762. // uv
  17763. uvs.push( i / tubularSegments );
  17764. uvs.push( j / radialSegments );
  17765. }
  17766. }
  17767. // generate indices
  17768. for ( j = 1; j <= radialSegments; j ++ ) {
  17769. for ( i = 1; i <= tubularSegments; i ++ ) {
  17770. // indices
  17771. var a = ( tubularSegments + 1 ) * j + i - 1;
  17772. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  17773. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  17774. var d = ( tubularSegments + 1 ) * j + i;
  17775. // faces
  17776. indices.push( a, b, d );
  17777. indices.push( b, c, d );
  17778. }
  17779. }
  17780. // build geometry
  17781. this.setIndex( indices );
  17782. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17783. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17784. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17785. }
  17786. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17787. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  17788. /**
  17789. * @author Mugen87 / https://github.com/Mugen87
  17790. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17791. */
  17792. var Earcut = {
  17793. triangulate: function ( data, holeIndices, dim ) {
  17794. dim = dim || 2;
  17795. var hasHoles = holeIndices && holeIndices.length,
  17796. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  17797. outerNode = linkedList( data, 0, outerLen, dim, true ),
  17798. triangles = [];
  17799. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  17800. var minX, minY, maxX, maxY, x, y, invSize;
  17801. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  17802. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17803. if ( data.length > 80 * dim ) {
  17804. minX = maxX = data[ 0 ];
  17805. minY = maxY = data[ 1 ];
  17806. for ( var i = dim; i < outerLen; i += dim ) {
  17807. x = data[ i ];
  17808. y = data[ i + 1 ];
  17809. if ( x < minX ) minX = x;
  17810. if ( y < minY ) minY = y;
  17811. if ( x > maxX ) maxX = x;
  17812. if ( y > maxY ) maxY = y;
  17813. }
  17814. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17815. invSize = Math.max( maxX - minX, maxY - minY );
  17816. invSize = invSize !== 0 ? 1 / invSize : 0;
  17817. }
  17818. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  17819. return triangles;
  17820. }
  17821. };
  17822. // create a circular doubly linked list from polygon points in the specified winding order
  17823. function linkedList( data, start, end, dim, clockwise ) {
  17824. var i, last;
  17825. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  17826. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17827. } else {
  17828. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17829. }
  17830. if ( last && equals( last, last.next ) ) {
  17831. removeNode( last );
  17832. last = last.next;
  17833. }
  17834. return last;
  17835. }
  17836. // eliminate colinear or duplicate points
  17837. function filterPoints( start, end ) {
  17838. if ( ! start ) return start;
  17839. if ( ! end ) end = start;
  17840. var p = start,
  17841. again;
  17842. do {
  17843. again = false;
  17844. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17845. removeNode( p );
  17846. p = end = p.prev;
  17847. if ( p === p.next ) break;
  17848. again = true;
  17849. } else {
  17850. p = p.next;
  17851. }
  17852. } while ( again || p !== end );
  17853. return end;
  17854. }
  17855. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17856. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17857. if ( ! ear ) return;
  17858. // interlink polygon nodes in z-order
  17859. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17860. var stop = ear,
  17861. prev, next;
  17862. // iterate through ears, slicing them one by one
  17863. while ( ear.prev !== ear.next ) {
  17864. prev = ear.prev;
  17865. next = ear.next;
  17866. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17867. // cut off the triangle
  17868. triangles.push( prev.i / dim );
  17869. triangles.push( ear.i / dim );
  17870. triangles.push( next.i / dim );
  17871. removeNode( ear );
  17872. // skipping the next vertex leads to less sliver triangles
  17873. ear = next.next;
  17874. stop = next.next;
  17875. continue;
  17876. }
  17877. ear = next;
  17878. // if we looped through the whole remaining polygon and can't find any more ears
  17879. if ( ear === stop ) {
  17880. // try filtering points and slicing again
  17881. if ( ! pass ) {
  17882. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17883. // if this didn't work, try curing all small self-intersections locally
  17884. } else if ( pass === 1 ) {
  17885. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  17886. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17887. // as a last resort, try splitting the remaining polygon into two
  17888. } else if ( pass === 2 ) {
  17889. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17890. }
  17891. break;
  17892. }
  17893. }
  17894. }
  17895. // check whether a polygon node forms a valid ear with adjacent nodes
  17896. function isEar( ear ) {
  17897. var a = ear.prev,
  17898. b = ear,
  17899. c = ear.next;
  17900. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17901. // now make sure we don't have other points inside the potential ear
  17902. var p = ear.next.next;
  17903. while ( p !== ear.prev ) {
  17904. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17905. area( p.prev, p, p.next ) >= 0 ) return false;
  17906. p = p.next;
  17907. }
  17908. return true;
  17909. }
  17910. function isEarHashed( ear, minX, minY, invSize ) {
  17911. var a = ear.prev,
  17912. b = ear,
  17913. c = ear.next;
  17914. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17915. // triangle bbox; min & max are calculated like this for speed
  17916. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17917. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17918. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17919. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17920. // z-order range for the current triangle bbox;
  17921. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17922. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17923. var p = ear.prevZ,
  17924. n = ear.nextZ;
  17925. // look for points inside the triangle in both directions
  17926. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  17927. if ( p !== ear.prev && p !== ear.next &&
  17928. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17929. area( p.prev, p, p.next ) >= 0 ) return false;
  17930. p = p.prevZ;
  17931. if ( n !== ear.prev && n !== ear.next &&
  17932. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17933. area( n.prev, n, n.next ) >= 0 ) return false;
  17934. n = n.nextZ;
  17935. }
  17936. // look for remaining points in decreasing z-order
  17937. while ( p && p.z >= minZ ) {
  17938. if ( p !== ear.prev && p !== ear.next &&
  17939. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17940. area( p.prev, p, p.next ) >= 0 ) return false;
  17941. p = p.prevZ;
  17942. }
  17943. // look for remaining points in increasing z-order
  17944. while ( n && n.z <= maxZ ) {
  17945. if ( n !== ear.prev && n !== ear.next &&
  17946. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17947. area( n.prev, n, n.next ) >= 0 ) return false;
  17948. n = n.nextZ;
  17949. }
  17950. return true;
  17951. }
  17952. // go through all polygon nodes and cure small local self-intersections
  17953. function cureLocalIntersections( start, triangles, dim ) {
  17954. var p = start;
  17955. do {
  17956. var a = p.prev,
  17957. b = p.next.next;
  17958. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17959. triangles.push( a.i / dim );
  17960. triangles.push( p.i / dim );
  17961. triangles.push( b.i / dim );
  17962. // remove two nodes involved
  17963. removeNode( p );
  17964. removeNode( p.next );
  17965. p = start = b;
  17966. }
  17967. p = p.next;
  17968. } while ( p !== start );
  17969. return filterPoints( p );
  17970. }
  17971. // try splitting polygon into two and triangulate them independently
  17972. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17973. // look for a valid diagonal that divides the polygon into two
  17974. var a = start;
  17975. do {
  17976. var b = a.next.next;
  17977. while ( b !== a.prev ) {
  17978. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17979. // split the polygon in two by the diagonal
  17980. var c = splitPolygon( a, b );
  17981. // filter colinear points around the cuts
  17982. a = filterPoints( a, a.next );
  17983. c = filterPoints( c, c.next );
  17984. // run earcut on each half
  17985. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17986. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17987. return;
  17988. }
  17989. b = b.next;
  17990. }
  17991. a = a.next;
  17992. } while ( a !== start );
  17993. }
  17994. // link every hole into the outer loop, producing a single-ring polygon without holes
  17995. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17996. var queue = [],
  17997. i, len, start, end, list;
  17998. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17999. start = holeIndices[ i ] * dim;
  18000. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  18001. list = linkedList( data, start, end, dim, false );
  18002. if ( list === list.next ) list.steiner = true;
  18003. queue.push( getLeftmost( list ) );
  18004. }
  18005. queue.sort( compareX );
  18006. // process holes from left to right
  18007. for ( i = 0; i < queue.length; i ++ ) {
  18008. eliminateHole( queue[ i ], outerNode );
  18009. outerNode = filterPoints( outerNode, outerNode.next );
  18010. }
  18011. return outerNode;
  18012. }
  18013. function compareX( a, b ) {
  18014. return a.x - b.x;
  18015. }
  18016. // find a bridge between vertices that connects hole with an outer ring and and link it
  18017. function eliminateHole( hole, outerNode ) {
  18018. outerNode = findHoleBridge( hole, outerNode );
  18019. if ( outerNode ) {
  18020. var b = splitPolygon( outerNode, hole );
  18021. // filter collinear points around the cuts
  18022. filterPoints( outerNode, outerNode.next );
  18023. filterPoints( b, b.next );
  18024. }
  18025. }
  18026. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18027. function findHoleBridge( hole, outerNode ) {
  18028. var p = outerNode,
  18029. hx = hole.x,
  18030. hy = hole.y,
  18031. qx = - Infinity,
  18032. m;
  18033. // find a segment intersected by a ray from the hole's leftmost point to the left;
  18034. // segment's endpoint with lesser x will be potential connection point
  18035. do {
  18036. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  18037. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  18038. if ( x <= hx && x > qx ) {
  18039. qx = x;
  18040. if ( x === hx ) {
  18041. if ( hy === p.y ) return p;
  18042. if ( hy === p.next.y ) return p.next;
  18043. }
  18044. m = p.x < p.next.x ? p : p.next;
  18045. }
  18046. }
  18047. p = p.next;
  18048. } while ( p !== outerNode );
  18049. if ( ! m ) return null;
  18050. if ( hx === qx ) return m; // hole touches outer segment; pick leftmost endpoint
  18051. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18052. // if there are no points found, we have a valid connection;
  18053. // otherwise choose the point of the minimum angle with the ray as connection point
  18054. var stop = m,
  18055. mx = m.x,
  18056. my = m.y,
  18057. tanMin = Infinity,
  18058. tan;
  18059. p = m;
  18060. do {
  18061. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  18062. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  18063. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  18064. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  18065. m = p;
  18066. tanMin = tan;
  18067. }
  18068. }
  18069. p = p.next;
  18070. } while ( p !== stop );
  18071. return m;
  18072. }
  18073. // whether sector in vertex m contains sector in vertex p in the same coordinates
  18074. function sectorContainsSector( m, p ) {
  18075. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  18076. }
  18077. // interlink polygon nodes in z-order
  18078. function indexCurve( start, minX, minY, invSize ) {
  18079. var p = start;
  18080. do {
  18081. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  18082. p.prevZ = p.prev;
  18083. p.nextZ = p.next;
  18084. p = p.next;
  18085. } while ( p !== start );
  18086. p.prevZ.nextZ = null;
  18087. p.prevZ = null;
  18088. sortLinked( p );
  18089. }
  18090. // Simon Tatham's linked list merge sort algorithm
  18091. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18092. function sortLinked( list ) {
  18093. var i, p, q, e, tail, numMerges, pSize, qSize,
  18094. inSize = 1;
  18095. do {
  18096. p = list;
  18097. list = null;
  18098. tail = null;
  18099. numMerges = 0;
  18100. while ( p ) {
  18101. numMerges ++;
  18102. q = p;
  18103. pSize = 0;
  18104. for ( i = 0; i < inSize; i ++ ) {
  18105. pSize ++;
  18106. q = q.nextZ;
  18107. if ( ! q ) break;
  18108. }
  18109. qSize = inSize;
  18110. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  18111. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  18112. e = p;
  18113. p = p.nextZ;
  18114. pSize --;
  18115. } else {
  18116. e = q;
  18117. q = q.nextZ;
  18118. qSize --;
  18119. }
  18120. if ( tail ) tail.nextZ = e;
  18121. else list = e;
  18122. e.prevZ = tail;
  18123. tail = e;
  18124. }
  18125. p = q;
  18126. }
  18127. tail.nextZ = null;
  18128. inSize *= 2;
  18129. } while ( numMerges > 1 );
  18130. return list;
  18131. }
  18132. // z-order of a point given coords and inverse of the longer side of data bbox
  18133. function zOrder( x, y, minX, minY, invSize ) {
  18134. // coords are transformed into non-negative 15-bit integer range
  18135. x = 32767 * ( x - minX ) * invSize;
  18136. y = 32767 * ( y - minY ) * invSize;
  18137. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  18138. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  18139. x = ( x | ( x << 2 ) ) & 0x33333333;
  18140. x = ( x | ( x << 1 ) ) & 0x55555555;
  18141. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  18142. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  18143. y = ( y | ( y << 2 ) ) & 0x33333333;
  18144. y = ( y | ( y << 1 ) ) & 0x55555555;
  18145. return x | ( y << 1 );
  18146. }
  18147. // find the leftmost node of a polygon ring
  18148. function getLeftmost( start ) {
  18149. var p = start,
  18150. leftmost = start;
  18151. do {
  18152. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  18153. p = p.next;
  18154. } while ( p !== start );
  18155. return leftmost;
  18156. }
  18157. // check if a point lies within a convex triangle
  18158. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  18159. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  18160. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  18161. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  18162. }
  18163. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18164. function isValidDiagonal( a, b ) {
  18165. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  18166. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  18167. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  18168. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  18169. }
  18170. // signed area of a triangle
  18171. function area( p, q, r ) {
  18172. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  18173. }
  18174. // check if two points are equal
  18175. function equals( p1, p2 ) {
  18176. return p1.x === p2.x && p1.y === p2.y;
  18177. }
  18178. // check if two segments intersect
  18179. function intersects( p1, q1, p2, q2 ) {
  18180. var o1 = sign( area( p1, q1, p2 ) );
  18181. var o2 = sign( area( p1, q1, q2 ) );
  18182. var o3 = sign( area( p2, q2, p1 ) );
  18183. var o4 = sign( area( p2, q2, q1 ) );
  18184. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  18185. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18186. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18187. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18188. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18189. return false;
  18190. }
  18191. // for collinear points p, q, r, check if point q lies on segment pr
  18192. function onSegment( p, q, r ) {
  18193. 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 );
  18194. }
  18195. function sign( num ) {
  18196. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  18197. }
  18198. // check if a polygon diagonal intersects any polygon segments
  18199. function intersectsPolygon( a, b ) {
  18200. var p = a;
  18201. do {
  18202. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  18203. intersects( p, p.next, a, b ) ) return true;
  18204. p = p.next;
  18205. } while ( p !== a );
  18206. return false;
  18207. }
  18208. // check if a polygon diagonal is locally inside the polygon
  18209. function locallyInside( a, b ) {
  18210. return area( a.prev, a, a.next ) < 0 ?
  18211. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  18212. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  18213. }
  18214. // check if the middle point of a polygon diagonal is inside the polygon
  18215. function middleInside( a, b ) {
  18216. var p = a,
  18217. inside = false,
  18218. px = ( a.x + b.x ) / 2,
  18219. py = ( a.y + b.y ) / 2;
  18220. do {
  18221. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  18222. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  18223. inside = ! inside;
  18224. p = p.next;
  18225. } while ( p !== a );
  18226. return inside;
  18227. }
  18228. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18229. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18230. function splitPolygon( a, b ) {
  18231. var a2 = new Node( a.i, a.x, a.y ),
  18232. b2 = new Node( b.i, b.x, b.y ),
  18233. an = a.next,
  18234. bp = b.prev;
  18235. a.next = b;
  18236. b.prev = a;
  18237. a2.next = an;
  18238. an.prev = a2;
  18239. b2.next = a2;
  18240. a2.prev = b2;
  18241. bp.next = b2;
  18242. b2.prev = bp;
  18243. return b2;
  18244. }
  18245. // create a node and optionally link it with previous one (in a circular doubly linked list)
  18246. function insertNode( i, x, y, last ) {
  18247. var p = new Node( i, x, y );
  18248. if ( ! last ) {
  18249. p.prev = p;
  18250. p.next = p;
  18251. } else {
  18252. p.next = last.next;
  18253. p.prev = last;
  18254. last.next.prev = p;
  18255. last.next = p;
  18256. }
  18257. return p;
  18258. }
  18259. function removeNode( p ) {
  18260. p.next.prev = p.prev;
  18261. p.prev.next = p.next;
  18262. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  18263. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  18264. }
  18265. function Node( i, x, y ) {
  18266. // vertex index in coordinates array
  18267. this.i = i;
  18268. // vertex coordinates
  18269. this.x = x;
  18270. this.y = y;
  18271. // previous and next vertex nodes in a polygon ring
  18272. this.prev = null;
  18273. this.next = null;
  18274. // z-order curve value
  18275. this.z = null;
  18276. // previous and next nodes in z-order
  18277. this.prevZ = null;
  18278. this.nextZ = null;
  18279. // indicates whether this is a steiner point
  18280. this.steiner = false;
  18281. }
  18282. function signedArea( data, start, end, dim ) {
  18283. var sum = 0;
  18284. for ( var i = start, j = end - dim; i < end; i += dim ) {
  18285. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  18286. j = i;
  18287. }
  18288. return sum;
  18289. }
  18290. /**
  18291. * @author zz85 / http://www.lab4games.net/zz85/blog
  18292. */
  18293. var ShapeUtils = {
  18294. // calculate area of the contour polygon
  18295. area: function ( contour ) {
  18296. var n = contour.length;
  18297. var a = 0.0;
  18298. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  18299. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  18300. }
  18301. return a * 0.5;
  18302. },
  18303. isClockWise: function ( pts ) {
  18304. return ShapeUtils.area( pts ) < 0;
  18305. },
  18306. triangulateShape: function ( contour, holes ) {
  18307. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18308. var holeIndices = []; // array of hole indices
  18309. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18310. removeDupEndPts( contour );
  18311. addContour( vertices, contour );
  18312. //
  18313. var holeIndex = contour.length;
  18314. holes.forEach( removeDupEndPts );
  18315. for ( var i = 0; i < holes.length; i ++ ) {
  18316. holeIndices.push( holeIndex );
  18317. holeIndex += holes[ i ].length;
  18318. addContour( vertices, holes[ i ] );
  18319. }
  18320. //
  18321. var triangles = Earcut.triangulate( vertices, holeIndices );
  18322. //
  18323. for ( var i = 0; i < triangles.length; i += 3 ) {
  18324. faces.push( triangles.slice( i, i + 3 ) );
  18325. }
  18326. return faces;
  18327. }
  18328. };
  18329. function removeDupEndPts( points ) {
  18330. var l = points.length;
  18331. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  18332. points.pop();
  18333. }
  18334. }
  18335. function addContour( vertices, contour ) {
  18336. for ( var i = 0; i < contour.length; i ++ ) {
  18337. vertices.push( contour[ i ].x );
  18338. vertices.push( contour[ i ].y );
  18339. }
  18340. }
  18341. /**
  18342. * @author zz85 / http://www.lab4games.net/zz85/blog
  18343. *
  18344. * Creates extruded geometry from a path shape.
  18345. *
  18346. * parameters = {
  18347. *
  18348. * curveSegments: <int>, // number of points on the curves
  18349. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18350. * depth: <float>, // Depth to extrude the shape
  18351. *
  18352. * bevelEnabled: <bool>, // turn on bevel
  18353. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18354. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  18355. * bevelOffset: <float>, // how far from shape outline does bevel start
  18356. * bevelSegments: <int>, // number of bevel layers
  18357. *
  18358. * extrudePath: <THREE.Curve> // curve to extrude shape along
  18359. *
  18360. * UVGenerator: <Object> // object that provides UV generator functions
  18361. *
  18362. * }
  18363. */
  18364. // ExtrudeGeometry
  18365. function ExtrudeGeometry( shapes, options ) {
  18366. Geometry.call( this );
  18367. this.type = 'ExtrudeGeometry';
  18368. this.parameters = {
  18369. shapes: shapes,
  18370. options: options
  18371. };
  18372. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  18373. this.mergeVertices();
  18374. }
  18375. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  18376. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  18377. ExtrudeGeometry.prototype.toJSON = function () {
  18378. var data = Geometry.prototype.toJSON.call( this );
  18379. var shapes = this.parameters.shapes;
  18380. var options = this.parameters.options;
  18381. return toJSON( shapes, options, data );
  18382. };
  18383. // ExtrudeBufferGeometry
  18384. function ExtrudeBufferGeometry( shapes, options ) {
  18385. BufferGeometry.call( this );
  18386. this.type = 'ExtrudeBufferGeometry';
  18387. this.parameters = {
  18388. shapes: shapes,
  18389. options: options
  18390. };
  18391. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18392. var scope = this;
  18393. var verticesArray = [];
  18394. var uvArray = [];
  18395. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18396. var shape = shapes[ i ];
  18397. addShape( shape );
  18398. }
  18399. // build geometry
  18400. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  18401. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  18402. this.computeVertexNormals();
  18403. // functions
  18404. function addShape( shape ) {
  18405. var placeholder = [];
  18406. // options
  18407. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18408. var steps = options.steps !== undefined ? options.steps : 1;
  18409. var depth = options.depth !== undefined ? options.depth : 100;
  18410. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18411. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18412. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18413. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18414. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18415. var extrudePath = options.extrudePath;
  18416. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  18417. // deprecated options
  18418. if ( options.amount !== undefined ) {
  18419. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  18420. depth = options.amount;
  18421. }
  18422. //
  18423. var extrudePts, extrudeByPath = false;
  18424. var splineTube, binormal, normal, position2;
  18425. if ( extrudePath ) {
  18426. extrudePts = extrudePath.getSpacedPoints( steps );
  18427. extrudeByPath = true;
  18428. bevelEnabled = false; // bevels not supported for path extrusion
  18429. // SETUP TNB variables
  18430. // TODO1 - have a .isClosed in spline?
  18431. splineTube = extrudePath.computeFrenetFrames( steps, false );
  18432. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18433. binormal = new Vector3();
  18434. normal = new Vector3();
  18435. position2 = new Vector3();
  18436. }
  18437. // Safeguards if bevels are not enabled
  18438. if ( ! bevelEnabled ) {
  18439. bevelSegments = 0;
  18440. bevelThickness = 0;
  18441. bevelSize = 0;
  18442. bevelOffset = 0;
  18443. }
  18444. // Variables initialization
  18445. var ahole, h, hl; // looping of holes
  18446. var shapePoints = shape.extractPoints( curveSegments );
  18447. var vertices = shapePoints.shape;
  18448. var holes = shapePoints.holes;
  18449. var reverse = ! ShapeUtils.isClockWise( vertices );
  18450. if ( reverse ) {
  18451. vertices = vertices.reverse();
  18452. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18453. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18454. ahole = holes[ h ];
  18455. if ( ShapeUtils.isClockWise( ahole ) ) {
  18456. holes[ h ] = ahole.reverse();
  18457. }
  18458. }
  18459. }
  18460. var faces = ShapeUtils.triangulateShape( vertices, holes );
  18461. /* Vertices */
  18462. var contour = vertices; // vertices has all points but contour has only points of circumference
  18463. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18464. ahole = holes[ h ];
  18465. vertices = vertices.concat( ahole );
  18466. }
  18467. function scalePt2( pt, vec, size ) {
  18468. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18469. return vec.clone().multiplyScalar( size ).add( pt );
  18470. }
  18471. var b, bs, t, z,
  18472. vert, vlen = vertices.length,
  18473. face, flen = faces.length;
  18474. // Find directions for point movement
  18475. function getBevelVec( inPt, inPrev, inNext ) {
  18476. // computes for inPt the corresponding point inPt' on a new contour
  18477. // shifted by 1 unit (length of normalized vector) to the left
  18478. // if we walk along contour clockwise, this new contour is outside the old one
  18479. //
  18480. // inPt' is the intersection of the two lines parallel to the two
  18481. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18482. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18483. // good reading for geometry algorithms (here: line-line intersection)
  18484. // http://geomalgorithms.com/a05-_intersect-1.html
  18485. var v_prev_x = inPt.x - inPrev.x,
  18486. v_prev_y = inPt.y - inPrev.y;
  18487. var v_next_x = inNext.x - inPt.x,
  18488. v_next_y = inNext.y - inPt.y;
  18489. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18490. // check for collinear edges
  18491. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18492. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  18493. // not collinear
  18494. // length of vectors for normalizing
  18495. var v_prev_len = Math.sqrt( v_prev_lensq );
  18496. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18497. // shift adjacent points by unit vectors to the left
  18498. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18499. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18500. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18501. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18502. // scaling factor for v_prev to intersection point
  18503. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18504. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18505. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18506. // vector from inPt to intersection point
  18507. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18508. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18509. // Don't normalize!, otherwise sharp corners become ugly
  18510. // but prevent crazy spikes
  18511. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18512. if ( v_trans_lensq <= 2 ) {
  18513. return new Vector2( v_trans_x, v_trans_y );
  18514. } else {
  18515. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18516. }
  18517. } else {
  18518. // handle special case of collinear edges
  18519. var direction_eq = false; // assumes: opposite
  18520. if ( v_prev_x > Number.EPSILON ) {
  18521. if ( v_next_x > Number.EPSILON ) {
  18522. direction_eq = true;
  18523. }
  18524. } else {
  18525. if ( v_prev_x < - Number.EPSILON ) {
  18526. if ( v_next_x < - Number.EPSILON ) {
  18527. direction_eq = true;
  18528. }
  18529. } else {
  18530. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18531. direction_eq = true;
  18532. }
  18533. }
  18534. }
  18535. if ( direction_eq ) {
  18536. // console.log("Warning: lines are a straight sequence");
  18537. v_trans_x = - v_prev_y;
  18538. v_trans_y = v_prev_x;
  18539. shrink_by = Math.sqrt( v_prev_lensq );
  18540. } else {
  18541. // console.log("Warning: lines are a straight spike");
  18542. v_trans_x = v_prev_x;
  18543. v_trans_y = v_prev_y;
  18544. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18545. }
  18546. }
  18547. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18548. }
  18549. var contourMovements = [];
  18550. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18551. if ( j === il ) j = 0;
  18552. if ( k === il ) k = 0;
  18553. // (j)---(i)---(k)
  18554. // console.log('i,j,k', i, j , k)
  18555. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18556. }
  18557. var holesMovements = [],
  18558. oneHoleMovements, verticesMovements = contourMovements.concat();
  18559. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18560. ahole = holes[ h ];
  18561. oneHoleMovements = [];
  18562. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18563. if ( j === il ) j = 0;
  18564. if ( k === il ) k = 0;
  18565. // (j)---(i)---(k)
  18566. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18567. }
  18568. holesMovements.push( oneHoleMovements );
  18569. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18570. }
  18571. // Loop bevelSegments, 1 for the front, 1 for the back
  18572. for ( b = 0; b < bevelSegments; b ++ ) {
  18573. //for ( b = bevelSegments; b > 0; b -- ) {
  18574. t = b / bevelSegments;
  18575. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18576. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18577. // contract shape
  18578. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18579. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18580. v( vert.x, vert.y, - z );
  18581. }
  18582. // expand holes
  18583. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18584. ahole = holes[ h ];
  18585. oneHoleMovements = holesMovements[ h ];
  18586. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18587. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18588. v( vert.x, vert.y, - z );
  18589. }
  18590. }
  18591. }
  18592. bs = bevelSize + bevelOffset;
  18593. // Back facing vertices
  18594. for ( i = 0; i < vlen; i ++ ) {
  18595. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18596. if ( ! extrudeByPath ) {
  18597. v( vert.x, vert.y, 0 );
  18598. } else {
  18599. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18600. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  18601. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  18602. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18603. v( position2.x, position2.y, position2.z );
  18604. }
  18605. }
  18606. // Add stepped vertices...
  18607. // Including front facing vertices
  18608. var s;
  18609. for ( s = 1; s <= steps; s ++ ) {
  18610. for ( i = 0; i < vlen; i ++ ) {
  18611. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18612. if ( ! extrudeByPath ) {
  18613. v( vert.x, vert.y, depth / steps * s );
  18614. } else {
  18615. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18616. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  18617. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  18618. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18619. v( position2.x, position2.y, position2.z );
  18620. }
  18621. }
  18622. }
  18623. // Add bevel segments planes
  18624. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18625. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18626. t = b / bevelSegments;
  18627. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18628. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18629. // contract shape
  18630. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18631. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18632. v( vert.x, vert.y, depth + z );
  18633. }
  18634. // expand holes
  18635. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18636. ahole = holes[ h ];
  18637. oneHoleMovements = holesMovements[ h ];
  18638. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18639. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18640. if ( ! extrudeByPath ) {
  18641. v( vert.x, vert.y, depth + z );
  18642. } else {
  18643. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18644. }
  18645. }
  18646. }
  18647. }
  18648. /* Faces */
  18649. // Top and bottom faces
  18650. buildLidFaces();
  18651. // Sides faces
  18652. buildSideFaces();
  18653. ///// Internal functions
  18654. function buildLidFaces() {
  18655. var start = verticesArray.length / 3;
  18656. if ( bevelEnabled ) {
  18657. var layer = 0; // steps + 1
  18658. var offset = vlen * layer;
  18659. // Bottom faces
  18660. for ( i = 0; i < flen; i ++ ) {
  18661. face = faces[ i ];
  18662. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18663. }
  18664. layer = steps + bevelSegments * 2;
  18665. offset = vlen * layer;
  18666. // Top faces
  18667. for ( i = 0; i < flen; i ++ ) {
  18668. face = faces[ i ];
  18669. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18670. }
  18671. } else {
  18672. // Bottom faces
  18673. for ( i = 0; i < flen; i ++ ) {
  18674. face = faces[ i ];
  18675. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18676. }
  18677. // Top faces
  18678. for ( i = 0; i < flen; i ++ ) {
  18679. face = faces[ i ];
  18680. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18681. }
  18682. }
  18683. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18684. }
  18685. // Create faces for the z-sides of the shape
  18686. function buildSideFaces() {
  18687. var start = verticesArray.length / 3;
  18688. var layeroffset = 0;
  18689. sidewalls( contour, layeroffset );
  18690. layeroffset += contour.length;
  18691. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18692. ahole = holes[ h ];
  18693. sidewalls( ahole, layeroffset );
  18694. //, true
  18695. layeroffset += ahole.length;
  18696. }
  18697. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18698. }
  18699. function sidewalls( contour, layeroffset ) {
  18700. var j, k;
  18701. i = contour.length;
  18702. while ( -- i >= 0 ) {
  18703. j = i;
  18704. k = i - 1;
  18705. if ( k < 0 ) k = contour.length - 1;
  18706. //console.log('b', i,j, i-1, k,vertices.length);
  18707. var s = 0,
  18708. sl = steps + bevelSegments * 2;
  18709. for ( s = 0; s < sl; s ++ ) {
  18710. var slen1 = vlen * s;
  18711. var slen2 = vlen * ( s + 1 );
  18712. var a = layeroffset + j + slen1,
  18713. b = layeroffset + k + slen1,
  18714. c = layeroffset + k + slen2,
  18715. d = layeroffset + j + slen2;
  18716. f4( a, b, c, d );
  18717. }
  18718. }
  18719. }
  18720. function v( x, y, z ) {
  18721. placeholder.push( x );
  18722. placeholder.push( y );
  18723. placeholder.push( z );
  18724. }
  18725. function f3( a, b, c ) {
  18726. addVertex( a );
  18727. addVertex( b );
  18728. addVertex( c );
  18729. var nextIndex = verticesArray.length / 3;
  18730. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18731. addUV( uvs[ 0 ] );
  18732. addUV( uvs[ 1 ] );
  18733. addUV( uvs[ 2 ] );
  18734. }
  18735. function f4( a, b, c, d ) {
  18736. addVertex( a );
  18737. addVertex( b );
  18738. addVertex( d );
  18739. addVertex( b );
  18740. addVertex( c );
  18741. addVertex( d );
  18742. var nextIndex = verticesArray.length / 3;
  18743. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18744. addUV( uvs[ 0 ] );
  18745. addUV( uvs[ 1 ] );
  18746. addUV( uvs[ 3 ] );
  18747. addUV( uvs[ 1 ] );
  18748. addUV( uvs[ 2 ] );
  18749. addUV( uvs[ 3 ] );
  18750. }
  18751. function addVertex( index ) {
  18752. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18753. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18754. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18755. }
  18756. function addUV( vector2 ) {
  18757. uvArray.push( vector2.x );
  18758. uvArray.push( vector2.y );
  18759. }
  18760. }
  18761. }
  18762. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18763. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  18764. ExtrudeBufferGeometry.prototype.toJSON = function () {
  18765. var data = BufferGeometry.prototype.toJSON.call( this );
  18766. var shapes = this.parameters.shapes;
  18767. var options = this.parameters.options;
  18768. return toJSON( shapes, options, data );
  18769. };
  18770. //
  18771. var WorldUVGenerator = {
  18772. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18773. var a_x = vertices[ indexA * 3 ];
  18774. var a_y = vertices[ indexA * 3 + 1 ];
  18775. var b_x = vertices[ indexB * 3 ];
  18776. var b_y = vertices[ indexB * 3 + 1 ];
  18777. var c_x = vertices[ indexC * 3 ];
  18778. var c_y = vertices[ indexC * 3 + 1 ];
  18779. return [
  18780. new Vector2( a_x, a_y ),
  18781. new Vector2( b_x, b_y ),
  18782. new Vector2( c_x, c_y )
  18783. ];
  18784. },
  18785. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  18786. var a_x = vertices[ indexA * 3 ];
  18787. var a_y = vertices[ indexA * 3 + 1 ];
  18788. var a_z = vertices[ indexA * 3 + 2 ];
  18789. var b_x = vertices[ indexB * 3 ];
  18790. var b_y = vertices[ indexB * 3 + 1 ];
  18791. var b_z = vertices[ indexB * 3 + 2 ];
  18792. var c_x = vertices[ indexC * 3 ];
  18793. var c_y = vertices[ indexC * 3 + 1 ];
  18794. var c_z = vertices[ indexC * 3 + 2 ];
  18795. var d_x = vertices[ indexD * 3 ];
  18796. var d_y = vertices[ indexD * 3 + 1 ];
  18797. var d_z = vertices[ indexD * 3 + 2 ];
  18798. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  18799. return [
  18800. new Vector2( a_x, 1 - a_z ),
  18801. new Vector2( b_x, 1 - b_z ),
  18802. new Vector2( c_x, 1 - c_z ),
  18803. new Vector2( d_x, 1 - d_z )
  18804. ];
  18805. } else {
  18806. return [
  18807. new Vector2( a_y, 1 - a_z ),
  18808. new Vector2( b_y, 1 - b_z ),
  18809. new Vector2( c_y, 1 - c_z ),
  18810. new Vector2( d_y, 1 - d_z )
  18811. ];
  18812. }
  18813. }
  18814. };
  18815. function toJSON( shapes, options, data ) {
  18816. //
  18817. data.shapes = [];
  18818. if ( Array.isArray( shapes ) ) {
  18819. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18820. var shape = shapes[ i ];
  18821. data.shapes.push( shape.uuid );
  18822. }
  18823. } else {
  18824. data.shapes.push( shapes.uuid );
  18825. }
  18826. //
  18827. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18828. return data;
  18829. }
  18830. /**
  18831. * @author zz85 / http://www.lab4games.net/zz85/blog
  18832. * @author alteredq / http://alteredqualia.com/
  18833. *
  18834. * Text = 3D Text
  18835. *
  18836. * parameters = {
  18837. * font: <THREE.Font>, // font
  18838. *
  18839. * size: <float>, // size of the text
  18840. * height: <float>, // thickness to extrude text
  18841. * curveSegments: <int>, // number of points on the curves
  18842. *
  18843. * bevelEnabled: <bool>, // turn on bevel
  18844. * bevelThickness: <float>, // how deep into text bevel goes
  18845. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18846. * bevelOffset: <float> // how far from text outline does bevel start
  18847. * }
  18848. */
  18849. // TextGeometry
  18850. function TextGeometry( text, parameters ) {
  18851. Geometry.call( this );
  18852. this.type = 'TextGeometry';
  18853. this.parameters = {
  18854. text: text,
  18855. parameters: parameters
  18856. };
  18857. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  18858. this.mergeVertices();
  18859. }
  18860. TextGeometry.prototype = Object.create( Geometry.prototype );
  18861. TextGeometry.prototype.constructor = TextGeometry;
  18862. // TextBufferGeometry
  18863. function TextBufferGeometry( text, parameters ) {
  18864. parameters = parameters || {};
  18865. var font = parameters.font;
  18866. if ( ! ( font && font.isFont ) ) {
  18867. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18868. return new Geometry();
  18869. }
  18870. var shapes = font.generateShapes( text, parameters.size );
  18871. // translate parameters to ExtrudeGeometry API
  18872. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18873. // defaults
  18874. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18875. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18876. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18877. ExtrudeBufferGeometry.call( this, shapes, parameters );
  18878. this.type = 'TextBufferGeometry';
  18879. }
  18880. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  18881. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  18882. /**
  18883. * @author mrdoob / http://mrdoob.com/
  18884. * @author benaadams / https://twitter.com/ben_a_adams
  18885. * @author Mugen87 / https://github.com/Mugen87
  18886. */
  18887. // SphereGeometry
  18888. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18889. Geometry.call( this );
  18890. this.type = 'SphereGeometry';
  18891. this.parameters = {
  18892. radius: radius,
  18893. widthSegments: widthSegments,
  18894. heightSegments: heightSegments,
  18895. phiStart: phiStart,
  18896. phiLength: phiLength,
  18897. thetaStart: thetaStart,
  18898. thetaLength: thetaLength
  18899. };
  18900. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  18901. this.mergeVertices();
  18902. }
  18903. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18904. SphereGeometry.prototype.constructor = SphereGeometry;
  18905. // SphereBufferGeometry
  18906. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18907. BufferGeometry.call( this );
  18908. this.type = 'SphereBufferGeometry';
  18909. this.parameters = {
  18910. radius: radius,
  18911. widthSegments: widthSegments,
  18912. heightSegments: heightSegments,
  18913. phiStart: phiStart,
  18914. phiLength: phiLength,
  18915. thetaStart: thetaStart,
  18916. thetaLength: thetaLength
  18917. };
  18918. radius = radius || 1;
  18919. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18920. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18921. phiStart = phiStart !== undefined ? phiStart : 0;
  18922. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18923. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18924. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18925. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18926. var ix, iy;
  18927. var index = 0;
  18928. var grid = [];
  18929. var vertex = new Vector3();
  18930. var normal = new Vector3();
  18931. // buffers
  18932. var indices = [];
  18933. var vertices = [];
  18934. var normals = [];
  18935. var uvs = [];
  18936. // generate vertices, normals and uvs
  18937. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18938. var verticesRow = [];
  18939. var v = iy / heightSegments;
  18940. // special case for the poles
  18941. var uOffset = 0;
  18942. if ( iy == 0 && thetaStart == 0 ) {
  18943. uOffset = 0.5 / widthSegments;
  18944. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18945. uOffset = - 0.5 / widthSegments;
  18946. }
  18947. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18948. var u = ix / widthSegments;
  18949. // vertex
  18950. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18951. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18952. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18953. vertices.push( vertex.x, vertex.y, vertex.z );
  18954. // normal
  18955. normal.copy( vertex ).normalize();
  18956. normals.push( normal.x, normal.y, normal.z );
  18957. // uv
  18958. uvs.push( u + uOffset, 1 - v );
  18959. verticesRow.push( index ++ );
  18960. }
  18961. grid.push( verticesRow );
  18962. }
  18963. // indices
  18964. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18965. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18966. var a = grid[ iy ][ ix + 1 ];
  18967. var b = grid[ iy ][ ix ];
  18968. var c = grid[ iy + 1 ][ ix ];
  18969. var d = grid[ iy + 1 ][ ix + 1 ];
  18970. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18971. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18972. }
  18973. }
  18974. // build geometry
  18975. this.setIndex( indices );
  18976. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18977. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18978. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18979. }
  18980. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18981. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18982. /**
  18983. * @author Kaleb Murphy
  18984. * @author Mugen87 / https://github.com/Mugen87
  18985. */
  18986. // RingGeometry
  18987. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18988. Geometry.call( this );
  18989. this.type = 'RingGeometry';
  18990. this.parameters = {
  18991. innerRadius: innerRadius,
  18992. outerRadius: outerRadius,
  18993. thetaSegments: thetaSegments,
  18994. phiSegments: phiSegments,
  18995. thetaStart: thetaStart,
  18996. thetaLength: thetaLength
  18997. };
  18998. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18999. this.mergeVertices();
  19000. }
  19001. RingGeometry.prototype = Object.create( Geometry.prototype );
  19002. RingGeometry.prototype.constructor = RingGeometry;
  19003. // RingBufferGeometry
  19004. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19005. BufferGeometry.call( this );
  19006. this.type = 'RingBufferGeometry';
  19007. this.parameters = {
  19008. innerRadius: innerRadius,
  19009. outerRadius: outerRadius,
  19010. thetaSegments: thetaSegments,
  19011. phiSegments: phiSegments,
  19012. thetaStart: thetaStart,
  19013. thetaLength: thetaLength
  19014. };
  19015. innerRadius = innerRadius || 0.5;
  19016. outerRadius = outerRadius || 1;
  19017. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19018. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19019. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19020. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  19021. // buffers
  19022. var indices = [];
  19023. var vertices = [];
  19024. var normals = [];
  19025. var uvs = [];
  19026. // some helper variables
  19027. var segment;
  19028. var radius = innerRadius;
  19029. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19030. var vertex = new Vector3();
  19031. var uv = new Vector2();
  19032. var j, i;
  19033. // generate vertices, normals and uvs
  19034. for ( j = 0; j <= phiSegments; j ++ ) {
  19035. for ( i = 0; i <= thetaSegments; i ++ ) {
  19036. // values are generate from the inside of the ring to the outside
  19037. segment = thetaStart + i / thetaSegments * thetaLength;
  19038. // vertex
  19039. vertex.x = radius * Math.cos( segment );
  19040. vertex.y = radius * Math.sin( segment );
  19041. vertices.push( vertex.x, vertex.y, vertex.z );
  19042. // normal
  19043. normals.push( 0, 0, 1 );
  19044. // uv
  19045. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  19046. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  19047. uvs.push( uv.x, uv.y );
  19048. }
  19049. // increase the radius for next row of vertices
  19050. radius += radiusStep;
  19051. }
  19052. // indices
  19053. for ( j = 0; j < phiSegments; j ++ ) {
  19054. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  19055. for ( i = 0; i < thetaSegments; i ++ ) {
  19056. segment = i + thetaSegmentLevel;
  19057. var a = segment;
  19058. var b = segment + thetaSegments + 1;
  19059. var c = segment + thetaSegments + 2;
  19060. var d = segment + 1;
  19061. // faces
  19062. indices.push( a, b, d );
  19063. indices.push( b, c, d );
  19064. }
  19065. }
  19066. // build geometry
  19067. this.setIndex( indices );
  19068. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19069. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19070. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19071. }
  19072. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19073. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  19074. /**
  19075. * @author zz85 / https://github.com/zz85
  19076. * @author bhouston / http://clara.io
  19077. * @author Mugen87 / https://github.com/Mugen87
  19078. */
  19079. // LatheGeometry
  19080. function LatheGeometry( points, segments, phiStart, phiLength ) {
  19081. Geometry.call( this );
  19082. this.type = 'LatheGeometry';
  19083. this.parameters = {
  19084. points: points,
  19085. segments: segments,
  19086. phiStart: phiStart,
  19087. phiLength: phiLength
  19088. };
  19089. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  19090. this.mergeVertices();
  19091. }
  19092. LatheGeometry.prototype = Object.create( Geometry.prototype );
  19093. LatheGeometry.prototype.constructor = LatheGeometry;
  19094. // LatheBufferGeometry
  19095. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  19096. BufferGeometry.call( this );
  19097. this.type = 'LatheBufferGeometry';
  19098. this.parameters = {
  19099. points: points,
  19100. segments: segments,
  19101. phiStart: phiStart,
  19102. phiLength: phiLength
  19103. };
  19104. segments = Math.floor( segments ) || 12;
  19105. phiStart = phiStart || 0;
  19106. phiLength = phiLength || Math.PI * 2;
  19107. // clamp phiLength so it's in range of [ 0, 2PI ]
  19108. phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 );
  19109. // buffers
  19110. var indices = [];
  19111. var vertices = [];
  19112. var uvs = [];
  19113. // helper variables
  19114. var base;
  19115. var inverseSegments = 1.0 / segments;
  19116. var vertex = new Vector3();
  19117. var uv = new Vector2();
  19118. var i, j;
  19119. // generate vertices and uvs
  19120. for ( i = 0; i <= segments; i ++ ) {
  19121. var phi = phiStart + i * inverseSegments * phiLength;
  19122. var sin = Math.sin( phi );
  19123. var cos = Math.cos( phi );
  19124. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  19125. // vertex
  19126. vertex.x = points[ j ].x * sin;
  19127. vertex.y = points[ j ].y;
  19128. vertex.z = points[ j ].x * cos;
  19129. vertices.push( vertex.x, vertex.y, vertex.z );
  19130. // uv
  19131. uv.x = i / segments;
  19132. uv.y = j / ( points.length - 1 );
  19133. uvs.push( uv.x, uv.y );
  19134. }
  19135. }
  19136. // indices
  19137. for ( i = 0; i < segments; i ++ ) {
  19138. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  19139. base = j + i * points.length;
  19140. var a = base;
  19141. var b = base + points.length;
  19142. var c = base + points.length + 1;
  19143. var d = base + 1;
  19144. // faces
  19145. indices.push( a, b, d );
  19146. indices.push( b, c, d );
  19147. }
  19148. }
  19149. // build geometry
  19150. this.setIndex( indices );
  19151. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19152. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19153. // generate normals
  19154. this.computeVertexNormals();
  19155. // if the geometry is closed, we need to average the normals along the seam.
  19156. // because the corresponding vertices are identical (but still have different UVs).
  19157. if ( phiLength === Math.PI * 2 ) {
  19158. var normals = this.attributes.normal.array;
  19159. var n1 = new Vector3();
  19160. var n2 = new Vector3();
  19161. var n = new Vector3();
  19162. // this is the buffer offset for the last line of vertices
  19163. base = segments * points.length * 3;
  19164. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  19165. // select the normal of the vertex in the first line
  19166. n1.x = normals[ j + 0 ];
  19167. n1.y = normals[ j + 1 ];
  19168. n1.z = normals[ j + 2 ];
  19169. // select the normal of the vertex in the last line
  19170. n2.x = normals[ base + j + 0 ];
  19171. n2.y = normals[ base + j + 1 ];
  19172. n2.z = normals[ base + j + 2 ];
  19173. // average normals
  19174. n.addVectors( n1, n2 ).normalize();
  19175. // assign the new values to both normals
  19176. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  19177. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  19178. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  19179. }
  19180. }
  19181. }
  19182. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19183. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  19184. /**
  19185. * @author jonobr1 / http://jonobr1.com
  19186. * @author Mugen87 / https://github.com/Mugen87
  19187. */
  19188. // ShapeGeometry
  19189. function ShapeGeometry( shapes, curveSegments ) {
  19190. Geometry.call( this );
  19191. this.type = 'ShapeGeometry';
  19192. if ( typeof curveSegments === 'object' ) {
  19193. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  19194. curveSegments = curveSegments.curveSegments;
  19195. }
  19196. this.parameters = {
  19197. shapes: shapes,
  19198. curveSegments: curveSegments
  19199. };
  19200. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  19201. this.mergeVertices();
  19202. }
  19203. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  19204. ShapeGeometry.prototype.constructor = ShapeGeometry;
  19205. ShapeGeometry.prototype.toJSON = function () {
  19206. var data = Geometry.prototype.toJSON.call( this );
  19207. var shapes = this.parameters.shapes;
  19208. return toJSON$1( shapes, data );
  19209. };
  19210. // ShapeBufferGeometry
  19211. function ShapeBufferGeometry( shapes, curveSegments ) {
  19212. BufferGeometry.call( this );
  19213. this.type = 'ShapeBufferGeometry';
  19214. this.parameters = {
  19215. shapes: shapes,
  19216. curveSegments: curveSegments
  19217. };
  19218. curveSegments = curveSegments || 12;
  19219. // buffers
  19220. var indices = [];
  19221. var vertices = [];
  19222. var normals = [];
  19223. var uvs = [];
  19224. // helper variables
  19225. var groupStart = 0;
  19226. var groupCount = 0;
  19227. // allow single and array values for "shapes" parameter
  19228. if ( Array.isArray( shapes ) === false ) {
  19229. addShape( shapes );
  19230. } else {
  19231. for ( var i = 0; i < shapes.length; i ++ ) {
  19232. addShape( shapes[ i ] );
  19233. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  19234. groupStart += groupCount;
  19235. groupCount = 0;
  19236. }
  19237. }
  19238. // build geometry
  19239. this.setIndex( indices );
  19240. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19241. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19242. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19243. // helper functions
  19244. function addShape( shape ) {
  19245. var i, l, shapeHole;
  19246. var indexOffset = vertices.length / 3;
  19247. var points = shape.extractPoints( curveSegments );
  19248. var shapeVertices = points.shape;
  19249. var shapeHoles = points.holes;
  19250. // check direction of vertices
  19251. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  19252. shapeVertices = shapeVertices.reverse();
  19253. }
  19254. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19255. shapeHole = shapeHoles[ i ];
  19256. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  19257. shapeHoles[ i ] = shapeHole.reverse();
  19258. }
  19259. }
  19260. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  19261. // join vertices of inner and outer paths to a single array
  19262. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19263. shapeHole = shapeHoles[ i ];
  19264. shapeVertices = shapeVertices.concat( shapeHole );
  19265. }
  19266. // vertices, normals, uvs
  19267. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  19268. var vertex = shapeVertices[ i ];
  19269. vertices.push( vertex.x, vertex.y, 0 );
  19270. normals.push( 0, 0, 1 );
  19271. uvs.push( vertex.x, vertex.y ); // world uvs
  19272. }
  19273. // incides
  19274. for ( i = 0, l = faces.length; i < l; i ++ ) {
  19275. var face = faces[ i ];
  19276. var a = face[ 0 ] + indexOffset;
  19277. var b = face[ 1 ] + indexOffset;
  19278. var c = face[ 2 ] + indexOffset;
  19279. indices.push( a, b, c );
  19280. groupCount += 3;
  19281. }
  19282. }
  19283. }
  19284. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19285. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  19286. ShapeBufferGeometry.prototype.toJSON = function () {
  19287. var data = BufferGeometry.prototype.toJSON.call( this );
  19288. var shapes = this.parameters.shapes;
  19289. return toJSON$1( shapes, data );
  19290. };
  19291. //
  19292. function toJSON$1( shapes, data ) {
  19293. data.shapes = [];
  19294. if ( Array.isArray( shapes ) ) {
  19295. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19296. var shape = shapes[ i ];
  19297. data.shapes.push( shape.uuid );
  19298. }
  19299. } else {
  19300. data.shapes.push( shapes.uuid );
  19301. }
  19302. return data;
  19303. }
  19304. /**
  19305. * @author WestLangley / http://github.com/WestLangley
  19306. * @author Mugen87 / https://github.com/Mugen87
  19307. */
  19308. function EdgesGeometry( geometry, thresholdAngle ) {
  19309. BufferGeometry.call( this );
  19310. this.type = 'EdgesGeometry';
  19311. this.parameters = {
  19312. thresholdAngle: thresholdAngle
  19313. };
  19314. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19315. // buffer
  19316. var vertices = [];
  19317. // helper variables
  19318. var thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle );
  19319. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  19320. var key, keys = [ 'a', 'b', 'c' ];
  19321. // prepare source geometry
  19322. var geometry2;
  19323. if ( geometry.isBufferGeometry ) {
  19324. geometry2 = new Geometry();
  19325. geometry2.fromBufferGeometry( geometry );
  19326. } else {
  19327. geometry2 = geometry.clone();
  19328. }
  19329. geometry2.mergeVertices();
  19330. geometry2.computeFaceNormals();
  19331. var sourceVertices = geometry2.vertices;
  19332. var faces = geometry2.faces;
  19333. // now create a data structure where each entry represents an edge with its adjoining faces
  19334. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19335. var face = faces[ i ];
  19336. for ( var j = 0; j < 3; j ++ ) {
  19337. edge1 = face[ keys[ j ] ];
  19338. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  19339. edge[ 0 ] = Math.min( edge1, edge2 );
  19340. edge[ 1 ] = Math.max( edge1, edge2 );
  19341. key = edge[ 0 ] + ',' + edge[ 1 ];
  19342. if ( edges[ key ] === undefined ) {
  19343. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  19344. } else {
  19345. edges[ key ].face2 = i;
  19346. }
  19347. }
  19348. }
  19349. // generate vertices
  19350. for ( key in edges ) {
  19351. var e = edges[ key ];
  19352. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  19353. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  19354. var vertex = sourceVertices[ e.index1 ];
  19355. vertices.push( vertex.x, vertex.y, vertex.z );
  19356. vertex = sourceVertices[ e.index2 ];
  19357. vertices.push( vertex.x, vertex.y, vertex.z );
  19358. }
  19359. }
  19360. // build geometry
  19361. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19362. }
  19363. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  19364. EdgesGeometry.prototype.constructor = EdgesGeometry;
  19365. /**
  19366. * @author mrdoob / http://mrdoob.com/
  19367. * @author Mugen87 / https://github.com/Mugen87
  19368. */
  19369. // CylinderGeometry
  19370. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19371. Geometry.call( this );
  19372. this.type = 'CylinderGeometry';
  19373. this.parameters = {
  19374. radiusTop: radiusTop,
  19375. radiusBottom: radiusBottom,
  19376. height: height,
  19377. radialSegments: radialSegments,
  19378. heightSegments: heightSegments,
  19379. openEnded: openEnded,
  19380. thetaStart: thetaStart,
  19381. thetaLength: thetaLength
  19382. };
  19383. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  19384. this.mergeVertices();
  19385. }
  19386. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  19387. CylinderGeometry.prototype.constructor = CylinderGeometry;
  19388. // CylinderBufferGeometry
  19389. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19390. BufferGeometry.call( this );
  19391. this.type = 'CylinderBufferGeometry';
  19392. this.parameters = {
  19393. radiusTop: radiusTop,
  19394. radiusBottom: radiusBottom,
  19395. height: height,
  19396. radialSegments: radialSegments,
  19397. heightSegments: heightSegments,
  19398. openEnded: openEnded,
  19399. thetaStart: thetaStart,
  19400. thetaLength: thetaLength
  19401. };
  19402. var scope = this;
  19403. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  19404. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  19405. height = height || 1;
  19406. radialSegments = Math.floor( radialSegments ) || 8;
  19407. heightSegments = Math.floor( heightSegments ) || 1;
  19408. openEnded = openEnded !== undefined ? openEnded : false;
  19409. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  19410. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19411. // buffers
  19412. var indices = [];
  19413. var vertices = [];
  19414. var normals = [];
  19415. var uvs = [];
  19416. // helper variables
  19417. var index = 0;
  19418. var indexArray = [];
  19419. var halfHeight = height / 2;
  19420. var groupStart = 0;
  19421. // generate geometry
  19422. generateTorso();
  19423. if ( openEnded === false ) {
  19424. if ( radiusTop > 0 ) generateCap( true );
  19425. if ( radiusBottom > 0 ) generateCap( false );
  19426. }
  19427. // build geometry
  19428. this.setIndex( indices );
  19429. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19430. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19431. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19432. function generateTorso() {
  19433. var x, y;
  19434. var normal = new Vector3();
  19435. var vertex = new Vector3();
  19436. var groupCount = 0;
  19437. // this will be used to calculate the normal
  19438. var slope = ( radiusBottom - radiusTop ) / height;
  19439. // generate vertices, normals and uvs
  19440. for ( y = 0; y <= heightSegments; y ++ ) {
  19441. var indexRow = [];
  19442. var v = y / heightSegments;
  19443. // calculate the radius of the current row
  19444. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19445. for ( x = 0; x <= radialSegments; x ++ ) {
  19446. var u = x / radialSegments;
  19447. var theta = u * thetaLength + thetaStart;
  19448. var sinTheta = Math.sin( theta );
  19449. var cosTheta = Math.cos( theta );
  19450. // vertex
  19451. vertex.x = radius * sinTheta;
  19452. vertex.y = - v * height + halfHeight;
  19453. vertex.z = radius * cosTheta;
  19454. vertices.push( vertex.x, vertex.y, vertex.z );
  19455. // normal
  19456. normal.set( sinTheta, slope, cosTheta ).normalize();
  19457. normals.push( normal.x, normal.y, normal.z );
  19458. // uv
  19459. uvs.push( u, 1 - v );
  19460. // save index of vertex in respective row
  19461. indexRow.push( index ++ );
  19462. }
  19463. // now save vertices of the row in our index array
  19464. indexArray.push( indexRow );
  19465. }
  19466. // generate indices
  19467. for ( x = 0; x < radialSegments; x ++ ) {
  19468. for ( y = 0; y < heightSegments; y ++ ) {
  19469. // we use the index array to access the correct indices
  19470. var a = indexArray[ y ][ x ];
  19471. var b = indexArray[ y + 1 ][ x ];
  19472. var c = indexArray[ y + 1 ][ x + 1 ];
  19473. var d = indexArray[ y ][ x + 1 ];
  19474. // faces
  19475. indices.push( a, b, d );
  19476. indices.push( b, c, d );
  19477. // update group counter
  19478. groupCount += 6;
  19479. }
  19480. }
  19481. // add a group to the geometry. this will ensure multi material support
  19482. scope.addGroup( groupStart, groupCount, 0 );
  19483. // calculate new start value for groups
  19484. groupStart += groupCount;
  19485. }
  19486. function generateCap( top ) {
  19487. var x, centerIndexStart, centerIndexEnd;
  19488. var uv = new Vector2();
  19489. var vertex = new Vector3();
  19490. var groupCount = 0;
  19491. var radius = ( top === true ) ? radiusTop : radiusBottom;
  19492. var sign = ( top === true ) ? 1 : - 1;
  19493. // save the index of the first center vertex
  19494. centerIndexStart = index;
  19495. // first we generate the center vertex data of the cap.
  19496. // because the geometry needs one set of uvs per face,
  19497. // we must generate a center vertex per face/segment
  19498. for ( x = 1; x <= radialSegments; x ++ ) {
  19499. // vertex
  19500. vertices.push( 0, halfHeight * sign, 0 );
  19501. // normal
  19502. normals.push( 0, sign, 0 );
  19503. // uv
  19504. uvs.push( 0.5, 0.5 );
  19505. // increase index
  19506. index ++;
  19507. }
  19508. // save the index of the last center vertex
  19509. centerIndexEnd = index;
  19510. // now we generate the surrounding vertices, normals and uvs
  19511. for ( x = 0; x <= radialSegments; x ++ ) {
  19512. var u = x / radialSegments;
  19513. var theta = u * thetaLength + thetaStart;
  19514. var cosTheta = Math.cos( theta );
  19515. var sinTheta = Math.sin( theta );
  19516. // vertex
  19517. vertex.x = radius * sinTheta;
  19518. vertex.y = halfHeight * sign;
  19519. vertex.z = radius * cosTheta;
  19520. vertices.push( vertex.x, vertex.y, vertex.z );
  19521. // normal
  19522. normals.push( 0, sign, 0 );
  19523. // uv
  19524. uv.x = ( cosTheta * 0.5 ) + 0.5;
  19525. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  19526. uvs.push( uv.x, uv.y );
  19527. // increase index
  19528. index ++;
  19529. }
  19530. // generate indices
  19531. for ( x = 0; x < radialSegments; x ++ ) {
  19532. var c = centerIndexStart + x;
  19533. var i = centerIndexEnd + x;
  19534. if ( top === true ) {
  19535. // face top
  19536. indices.push( i, i + 1, c );
  19537. } else {
  19538. // face bottom
  19539. indices.push( i + 1, i, c );
  19540. }
  19541. groupCount += 3;
  19542. }
  19543. // add a group to the geometry. this will ensure multi material support
  19544. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  19545. // calculate new start value for groups
  19546. groupStart += groupCount;
  19547. }
  19548. }
  19549. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19550. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  19551. /**
  19552. * @author abelnation / http://github.com/abelnation
  19553. */
  19554. // ConeGeometry
  19555. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19556. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19557. this.type = 'ConeGeometry';
  19558. this.parameters = {
  19559. radius: radius,
  19560. height: height,
  19561. radialSegments: radialSegments,
  19562. heightSegments: heightSegments,
  19563. openEnded: openEnded,
  19564. thetaStart: thetaStart,
  19565. thetaLength: thetaLength
  19566. };
  19567. }
  19568. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  19569. ConeGeometry.prototype.constructor = ConeGeometry;
  19570. // ConeBufferGeometry
  19571. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19572. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19573. this.type = 'ConeBufferGeometry';
  19574. this.parameters = {
  19575. radius: radius,
  19576. height: height,
  19577. radialSegments: radialSegments,
  19578. heightSegments: heightSegments,
  19579. openEnded: openEnded,
  19580. thetaStart: thetaStart,
  19581. thetaLength: thetaLength
  19582. };
  19583. }
  19584. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  19585. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  19586. /**
  19587. * @author benaadams / https://twitter.com/ben_a_adams
  19588. * @author Mugen87 / https://github.com/Mugen87
  19589. * @author hughes
  19590. */
  19591. // CircleGeometry
  19592. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  19593. Geometry.call( this );
  19594. this.type = 'CircleGeometry';
  19595. this.parameters = {
  19596. radius: radius,
  19597. segments: segments,
  19598. thetaStart: thetaStart,
  19599. thetaLength: thetaLength
  19600. };
  19601. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  19602. this.mergeVertices();
  19603. }
  19604. CircleGeometry.prototype = Object.create( Geometry.prototype );
  19605. CircleGeometry.prototype.constructor = CircleGeometry;
  19606. // CircleBufferGeometry
  19607. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  19608. BufferGeometry.call( this );
  19609. this.type = 'CircleBufferGeometry';
  19610. this.parameters = {
  19611. radius: radius,
  19612. segments: segments,
  19613. thetaStart: thetaStart,
  19614. thetaLength: thetaLength
  19615. };
  19616. radius = radius || 1;
  19617. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19618. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19619. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19620. // buffers
  19621. var indices = [];
  19622. var vertices = [];
  19623. var normals = [];
  19624. var uvs = [];
  19625. // helper variables
  19626. var i, s;
  19627. var vertex = new Vector3();
  19628. var uv = new Vector2();
  19629. // center point
  19630. vertices.push( 0, 0, 0 );
  19631. normals.push( 0, 0, 1 );
  19632. uvs.push( 0.5, 0.5 );
  19633. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  19634. var segment = thetaStart + s / segments * thetaLength;
  19635. // vertex
  19636. vertex.x = radius * Math.cos( segment );
  19637. vertex.y = radius * Math.sin( segment );
  19638. vertices.push( vertex.x, vertex.y, vertex.z );
  19639. // normal
  19640. normals.push( 0, 0, 1 );
  19641. // uvs
  19642. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19643. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19644. uvs.push( uv.x, uv.y );
  19645. }
  19646. // indices
  19647. for ( i = 1; i <= segments; i ++ ) {
  19648. indices.push( i, i + 1, 0 );
  19649. }
  19650. // build geometry
  19651. this.setIndex( indices );
  19652. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19653. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19654. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19655. }
  19656. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19657. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19658. var Geometries = /*#__PURE__*/Object.freeze({
  19659. __proto__: null,
  19660. WireframeGeometry: WireframeGeometry,
  19661. ParametricGeometry: ParametricGeometry,
  19662. ParametricBufferGeometry: ParametricBufferGeometry,
  19663. TetrahedronGeometry: TetrahedronGeometry,
  19664. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19665. OctahedronGeometry: OctahedronGeometry,
  19666. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19667. IcosahedronGeometry: IcosahedronGeometry,
  19668. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19669. DodecahedronGeometry: DodecahedronGeometry,
  19670. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19671. PolyhedronGeometry: PolyhedronGeometry,
  19672. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19673. TubeGeometry: TubeGeometry,
  19674. TubeBufferGeometry: TubeBufferGeometry,
  19675. TorusKnotGeometry: TorusKnotGeometry,
  19676. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19677. TorusGeometry: TorusGeometry,
  19678. TorusBufferGeometry: TorusBufferGeometry,
  19679. TextGeometry: TextGeometry,
  19680. TextBufferGeometry: TextBufferGeometry,
  19681. SphereGeometry: SphereGeometry,
  19682. SphereBufferGeometry: SphereBufferGeometry,
  19683. RingGeometry: RingGeometry,
  19684. RingBufferGeometry: RingBufferGeometry,
  19685. PlaneGeometry: PlaneGeometry,
  19686. PlaneBufferGeometry: PlaneBufferGeometry,
  19687. LatheGeometry: LatheGeometry,
  19688. LatheBufferGeometry: LatheBufferGeometry,
  19689. ShapeGeometry: ShapeGeometry,
  19690. ShapeBufferGeometry: ShapeBufferGeometry,
  19691. ExtrudeGeometry: ExtrudeGeometry,
  19692. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19693. EdgesGeometry: EdgesGeometry,
  19694. ConeGeometry: ConeGeometry,
  19695. ConeBufferGeometry: ConeBufferGeometry,
  19696. CylinderGeometry: CylinderGeometry,
  19697. CylinderBufferGeometry: CylinderBufferGeometry,
  19698. CircleGeometry: CircleGeometry,
  19699. CircleBufferGeometry: CircleBufferGeometry,
  19700. BoxGeometry: BoxGeometry,
  19701. BoxBufferGeometry: BoxBufferGeometry
  19702. });
  19703. /**
  19704. * @author mrdoob / http://mrdoob.com/
  19705. *
  19706. * parameters = {
  19707. * color: <THREE.Color>
  19708. * }
  19709. */
  19710. function ShadowMaterial( parameters ) {
  19711. Material.call( this );
  19712. this.type = 'ShadowMaterial';
  19713. this.color = new Color( 0x000000 );
  19714. this.transparent = true;
  19715. this.setValues( parameters );
  19716. }
  19717. ShadowMaterial.prototype = Object.create( Material.prototype );
  19718. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19719. ShadowMaterial.prototype.isShadowMaterial = true;
  19720. ShadowMaterial.prototype.copy = function ( source ) {
  19721. Material.prototype.copy.call( this, source );
  19722. this.color.copy( source.color );
  19723. return this;
  19724. };
  19725. /**
  19726. * @author mrdoob / http://mrdoob.com/
  19727. */
  19728. function RawShaderMaterial( parameters ) {
  19729. ShaderMaterial.call( this, parameters );
  19730. this.type = 'RawShaderMaterial';
  19731. }
  19732. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19733. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19734. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19735. /**
  19736. * @author WestLangley / http://github.com/WestLangley
  19737. *
  19738. * parameters = {
  19739. * color: <hex>,
  19740. * roughness: <float>,
  19741. * metalness: <float>,
  19742. * opacity: <float>,
  19743. *
  19744. * map: new THREE.Texture( <Image> ),
  19745. *
  19746. * lightMap: new THREE.Texture( <Image> ),
  19747. * lightMapIntensity: <float>
  19748. *
  19749. * aoMap: new THREE.Texture( <Image> ),
  19750. * aoMapIntensity: <float>
  19751. *
  19752. * emissive: <hex>,
  19753. * emissiveIntensity: <float>
  19754. * emissiveMap: new THREE.Texture( <Image> ),
  19755. *
  19756. * bumpMap: new THREE.Texture( <Image> ),
  19757. * bumpScale: <float>,
  19758. *
  19759. * normalMap: new THREE.Texture( <Image> ),
  19760. * normalMapType: THREE.TangentSpaceNormalMap,
  19761. * normalScale: <Vector2>,
  19762. *
  19763. * displacementMap: new THREE.Texture( <Image> ),
  19764. * displacementScale: <float>,
  19765. * displacementBias: <float>,
  19766. *
  19767. * roughnessMap: new THREE.Texture( <Image> ),
  19768. *
  19769. * metalnessMap: new THREE.Texture( <Image> ),
  19770. *
  19771. * alphaMap: new THREE.Texture( <Image> ),
  19772. *
  19773. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19774. * envMapIntensity: <float>
  19775. *
  19776. * refractionRatio: <float>,
  19777. *
  19778. * wireframe: <boolean>,
  19779. * wireframeLinewidth: <float>,
  19780. *
  19781. * skinning: <bool>,
  19782. * morphTargets: <bool>,
  19783. * morphNormals: <bool>
  19784. * }
  19785. */
  19786. function MeshStandardMaterial( parameters ) {
  19787. Material.call( this );
  19788. this.defines = { 'STANDARD': '' };
  19789. this.type = 'MeshStandardMaterial';
  19790. this.color = new Color( 0xffffff ); // diffuse
  19791. this.roughness = 1.0;
  19792. this.metalness = 0.0;
  19793. this.map = null;
  19794. this.lightMap = null;
  19795. this.lightMapIntensity = 1.0;
  19796. this.aoMap = null;
  19797. this.aoMapIntensity = 1.0;
  19798. this.emissive = new Color( 0x000000 );
  19799. this.emissiveIntensity = 1.0;
  19800. this.emissiveMap = null;
  19801. this.bumpMap = null;
  19802. this.bumpScale = 1;
  19803. this.normalMap = null;
  19804. this.normalMapType = TangentSpaceNormalMap;
  19805. this.normalScale = new Vector2( 1, 1 );
  19806. this.displacementMap = null;
  19807. this.displacementScale = 1;
  19808. this.displacementBias = 0;
  19809. this.roughnessMap = null;
  19810. this.metalnessMap = null;
  19811. this.alphaMap = null;
  19812. this.envMap = null;
  19813. this.envMapIntensity = 1.0;
  19814. this.refractionRatio = 0.98;
  19815. this.wireframe = false;
  19816. this.wireframeLinewidth = 1;
  19817. this.wireframeLinecap = 'round';
  19818. this.wireframeLinejoin = 'round';
  19819. this.skinning = false;
  19820. this.morphTargets = false;
  19821. this.morphNormals = false;
  19822. this.vertexTangents = false;
  19823. this.setValues( parameters );
  19824. }
  19825. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  19826. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19827. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19828. MeshStandardMaterial.prototype.copy = function ( source ) {
  19829. Material.prototype.copy.call( this, source );
  19830. this.defines = { 'STANDARD': '' };
  19831. this.color.copy( source.color );
  19832. this.roughness = source.roughness;
  19833. this.metalness = source.metalness;
  19834. this.map = source.map;
  19835. this.lightMap = source.lightMap;
  19836. this.lightMapIntensity = source.lightMapIntensity;
  19837. this.aoMap = source.aoMap;
  19838. this.aoMapIntensity = source.aoMapIntensity;
  19839. this.emissive.copy( source.emissive );
  19840. this.emissiveMap = source.emissiveMap;
  19841. this.emissiveIntensity = source.emissiveIntensity;
  19842. this.bumpMap = source.bumpMap;
  19843. this.bumpScale = source.bumpScale;
  19844. this.normalMap = source.normalMap;
  19845. this.normalMapType = source.normalMapType;
  19846. this.normalScale.copy( source.normalScale );
  19847. this.displacementMap = source.displacementMap;
  19848. this.displacementScale = source.displacementScale;
  19849. this.displacementBias = source.displacementBias;
  19850. this.roughnessMap = source.roughnessMap;
  19851. this.metalnessMap = source.metalnessMap;
  19852. this.alphaMap = source.alphaMap;
  19853. this.envMap = source.envMap;
  19854. this.envMapIntensity = source.envMapIntensity;
  19855. this.refractionRatio = source.refractionRatio;
  19856. this.wireframe = source.wireframe;
  19857. this.wireframeLinewidth = source.wireframeLinewidth;
  19858. this.wireframeLinecap = source.wireframeLinecap;
  19859. this.wireframeLinejoin = source.wireframeLinejoin;
  19860. this.skinning = source.skinning;
  19861. this.morphTargets = source.morphTargets;
  19862. this.morphNormals = source.morphNormals;
  19863. this.vertexTangents = source.vertexTangents;
  19864. return this;
  19865. };
  19866. /**
  19867. * @author WestLangley / http://github.com/WestLangley
  19868. *
  19869. * parameters = {
  19870. * clearcoat: <float>,
  19871. * clearcoatMap: new THREE.Texture( <Image> ),
  19872. * clearcoatRoughness: <float>,
  19873. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19874. * clearcoatNormalScale: <Vector2>,
  19875. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19876. *
  19877. * reflectivity: <float>,
  19878. *
  19879. * sheen: <Color>,
  19880. *
  19881. * transparency: <float>
  19882. * }
  19883. */
  19884. function MeshPhysicalMaterial( parameters ) {
  19885. MeshStandardMaterial.call( this );
  19886. this.defines = {
  19887. 'STANDARD': '',
  19888. 'PHYSICAL': ''
  19889. };
  19890. this.type = 'MeshPhysicalMaterial';
  19891. this.clearcoat = 0.0;
  19892. this.clearcoatMap = null;
  19893. this.clearcoatRoughness = 0.0;
  19894. this.clearcoatRoughnessMap = null;
  19895. this.clearcoatNormalScale = new Vector2( 1, 1 );
  19896. this.clearcoatNormalMap = null;
  19897. this.reflectivity = 0.5; // maps to F0 = 0.04
  19898. this.sheen = null; // null will disable sheen bsdf
  19899. this.transparency = 0.0;
  19900. this.setValues( parameters );
  19901. }
  19902. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  19903. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19904. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19905. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  19906. MeshStandardMaterial.prototype.copy.call( this, source );
  19907. this.defines = {
  19908. 'STANDARD': '',
  19909. 'PHYSICAL': ''
  19910. };
  19911. this.clearcoat = source.clearcoat;
  19912. this.clearcoatMap = source.clearcoatMap;
  19913. this.clearcoatRoughness = source.clearcoatRoughness;
  19914. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19915. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19916. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  19917. this.reflectivity = source.reflectivity;
  19918. if ( source.sheen ) {
  19919. this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  19920. } else {
  19921. this.sheen = null;
  19922. }
  19923. this.transparency = source.transparency;
  19924. return this;
  19925. };
  19926. /**
  19927. * @author mrdoob / http://mrdoob.com/
  19928. * @author alteredq / http://alteredqualia.com/
  19929. *
  19930. * parameters = {
  19931. * color: <hex>,
  19932. * specular: <hex>,
  19933. * shininess: <float>,
  19934. * opacity: <float>,
  19935. *
  19936. * map: new THREE.Texture( <Image> ),
  19937. *
  19938. * lightMap: new THREE.Texture( <Image> ),
  19939. * lightMapIntensity: <float>
  19940. *
  19941. * aoMap: new THREE.Texture( <Image> ),
  19942. * aoMapIntensity: <float>
  19943. *
  19944. * emissive: <hex>,
  19945. * emissiveIntensity: <float>
  19946. * emissiveMap: new THREE.Texture( <Image> ),
  19947. *
  19948. * bumpMap: new THREE.Texture( <Image> ),
  19949. * bumpScale: <float>,
  19950. *
  19951. * normalMap: new THREE.Texture( <Image> ),
  19952. * normalMapType: THREE.TangentSpaceNormalMap,
  19953. * normalScale: <Vector2>,
  19954. *
  19955. * displacementMap: new THREE.Texture( <Image> ),
  19956. * displacementScale: <float>,
  19957. * displacementBias: <float>,
  19958. *
  19959. * specularMap: new THREE.Texture( <Image> ),
  19960. *
  19961. * alphaMap: new THREE.Texture( <Image> ),
  19962. *
  19963. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19964. * combine: THREE.MultiplyOperation,
  19965. * reflectivity: <float>,
  19966. * refractionRatio: <float>,
  19967. *
  19968. * wireframe: <boolean>,
  19969. * wireframeLinewidth: <float>,
  19970. *
  19971. * skinning: <bool>,
  19972. * morphTargets: <bool>,
  19973. * morphNormals: <bool>
  19974. * }
  19975. */
  19976. function MeshPhongMaterial( parameters ) {
  19977. Material.call( this );
  19978. this.type = 'MeshPhongMaterial';
  19979. this.color = new Color( 0xffffff ); // diffuse
  19980. this.specular = new Color( 0x111111 );
  19981. this.shininess = 30;
  19982. this.map = null;
  19983. this.lightMap = null;
  19984. this.lightMapIntensity = 1.0;
  19985. this.aoMap = null;
  19986. this.aoMapIntensity = 1.0;
  19987. this.emissive = new Color( 0x000000 );
  19988. this.emissiveIntensity = 1.0;
  19989. this.emissiveMap = null;
  19990. this.bumpMap = null;
  19991. this.bumpScale = 1;
  19992. this.normalMap = null;
  19993. this.normalMapType = TangentSpaceNormalMap;
  19994. this.normalScale = new Vector2( 1, 1 );
  19995. this.displacementMap = null;
  19996. this.displacementScale = 1;
  19997. this.displacementBias = 0;
  19998. this.specularMap = null;
  19999. this.alphaMap = null;
  20000. this.envMap = null;
  20001. this.combine = MultiplyOperation;
  20002. this.reflectivity = 1;
  20003. this.refractionRatio = 0.98;
  20004. this.wireframe = false;
  20005. this.wireframeLinewidth = 1;
  20006. this.wireframeLinecap = 'round';
  20007. this.wireframeLinejoin = 'round';
  20008. this.skinning = false;
  20009. this.morphTargets = false;
  20010. this.morphNormals = false;
  20011. this.setValues( parameters );
  20012. }
  20013. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  20014. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20015. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20016. MeshPhongMaterial.prototype.copy = function ( source ) {
  20017. Material.prototype.copy.call( this, source );
  20018. this.color.copy( source.color );
  20019. this.specular.copy( source.specular );
  20020. this.shininess = source.shininess;
  20021. this.map = source.map;
  20022. this.lightMap = source.lightMap;
  20023. this.lightMapIntensity = source.lightMapIntensity;
  20024. this.aoMap = source.aoMap;
  20025. this.aoMapIntensity = source.aoMapIntensity;
  20026. this.emissive.copy( source.emissive );
  20027. this.emissiveMap = source.emissiveMap;
  20028. this.emissiveIntensity = source.emissiveIntensity;
  20029. this.bumpMap = source.bumpMap;
  20030. this.bumpScale = source.bumpScale;
  20031. this.normalMap = source.normalMap;
  20032. this.normalMapType = source.normalMapType;
  20033. this.normalScale.copy( source.normalScale );
  20034. this.displacementMap = source.displacementMap;
  20035. this.displacementScale = source.displacementScale;
  20036. this.displacementBias = source.displacementBias;
  20037. this.specularMap = source.specularMap;
  20038. this.alphaMap = source.alphaMap;
  20039. this.envMap = source.envMap;
  20040. this.combine = source.combine;
  20041. this.reflectivity = source.reflectivity;
  20042. this.refractionRatio = source.refractionRatio;
  20043. this.wireframe = source.wireframe;
  20044. this.wireframeLinewidth = source.wireframeLinewidth;
  20045. this.wireframeLinecap = source.wireframeLinecap;
  20046. this.wireframeLinejoin = source.wireframeLinejoin;
  20047. this.skinning = source.skinning;
  20048. this.morphTargets = source.morphTargets;
  20049. this.morphNormals = source.morphNormals;
  20050. return this;
  20051. };
  20052. /**
  20053. * @author takahirox / http://github.com/takahirox
  20054. *
  20055. * parameters = {
  20056. * color: <hex>,
  20057. * specular: <hex>,
  20058. * shininess: <float>,
  20059. *
  20060. * map: new THREE.Texture( <Image> ),
  20061. * gradientMap: new THREE.Texture( <Image> ),
  20062. *
  20063. * lightMap: new THREE.Texture( <Image> ),
  20064. * lightMapIntensity: <float>
  20065. *
  20066. * aoMap: new THREE.Texture( <Image> ),
  20067. * aoMapIntensity: <float>
  20068. *
  20069. * emissive: <hex>,
  20070. * emissiveIntensity: <float>
  20071. * emissiveMap: new THREE.Texture( <Image> ),
  20072. *
  20073. * bumpMap: new THREE.Texture( <Image> ),
  20074. * bumpScale: <float>,
  20075. *
  20076. * normalMap: new THREE.Texture( <Image> ),
  20077. * normalMapType: THREE.TangentSpaceNormalMap,
  20078. * normalScale: <Vector2>,
  20079. *
  20080. * displacementMap: new THREE.Texture( <Image> ),
  20081. * displacementScale: <float>,
  20082. * displacementBias: <float>,
  20083. *
  20084. * specularMap: new THREE.Texture( <Image> ),
  20085. *
  20086. * alphaMap: new THREE.Texture( <Image> ),
  20087. *
  20088. * wireframe: <boolean>,
  20089. * wireframeLinewidth: <float>,
  20090. *
  20091. * skinning: <bool>,
  20092. * morphTargets: <bool>,
  20093. * morphNormals: <bool>
  20094. * }
  20095. */
  20096. function MeshToonMaterial( parameters ) {
  20097. Material.call( this );
  20098. this.defines = { 'TOON': '' };
  20099. this.type = 'MeshToonMaterial';
  20100. this.color = new Color( 0xffffff );
  20101. this.specular = new Color( 0x111111 );
  20102. this.shininess = 30;
  20103. this.map = null;
  20104. this.gradientMap = null;
  20105. this.lightMap = null;
  20106. this.lightMapIntensity = 1.0;
  20107. this.aoMap = null;
  20108. this.aoMapIntensity = 1.0;
  20109. this.emissive = new Color( 0x000000 );
  20110. this.emissiveIntensity = 1.0;
  20111. this.emissiveMap = null;
  20112. this.bumpMap = null;
  20113. this.bumpScale = 1;
  20114. this.normalMap = null;
  20115. this.normalMapType = TangentSpaceNormalMap;
  20116. this.normalScale = new Vector2( 1, 1 );
  20117. this.displacementMap = null;
  20118. this.displacementScale = 1;
  20119. this.displacementBias = 0;
  20120. this.specularMap = null;
  20121. this.alphaMap = null;
  20122. this.wireframe = false;
  20123. this.wireframeLinewidth = 1;
  20124. this.wireframeLinecap = 'round';
  20125. this.wireframeLinejoin = 'round';
  20126. this.skinning = false;
  20127. this.morphTargets = false;
  20128. this.morphNormals = false;
  20129. this.setValues( parameters );
  20130. }
  20131. MeshToonMaterial.prototype = Object.create( Material.prototype );
  20132. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20133. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20134. MeshToonMaterial.prototype.copy = function ( source ) {
  20135. Material.prototype.copy.call( this, source );
  20136. this.color.copy( source.color );
  20137. this.specular.copy( source.specular );
  20138. this.shininess = source.shininess;
  20139. this.map = source.map;
  20140. this.gradientMap = source.gradientMap;
  20141. this.lightMap = source.lightMap;
  20142. this.lightMapIntensity = source.lightMapIntensity;
  20143. this.aoMap = source.aoMap;
  20144. this.aoMapIntensity = source.aoMapIntensity;
  20145. this.emissive.copy( source.emissive );
  20146. this.emissiveMap = source.emissiveMap;
  20147. this.emissiveIntensity = source.emissiveIntensity;
  20148. this.bumpMap = source.bumpMap;
  20149. this.bumpScale = source.bumpScale;
  20150. this.normalMap = source.normalMap;
  20151. this.normalMapType = source.normalMapType;
  20152. this.normalScale.copy( source.normalScale );
  20153. this.displacementMap = source.displacementMap;
  20154. this.displacementScale = source.displacementScale;
  20155. this.displacementBias = source.displacementBias;
  20156. this.specularMap = source.specularMap;
  20157. this.alphaMap = source.alphaMap;
  20158. this.wireframe = source.wireframe;
  20159. this.wireframeLinewidth = source.wireframeLinewidth;
  20160. this.wireframeLinecap = source.wireframeLinecap;
  20161. this.wireframeLinejoin = source.wireframeLinejoin;
  20162. this.skinning = source.skinning;
  20163. this.morphTargets = source.morphTargets;
  20164. this.morphNormals = source.morphNormals;
  20165. return this;
  20166. };
  20167. /**
  20168. * @author mrdoob / http://mrdoob.com/
  20169. * @author WestLangley / http://github.com/WestLangley
  20170. *
  20171. * parameters = {
  20172. * opacity: <float>,
  20173. *
  20174. * bumpMap: new THREE.Texture( <Image> ),
  20175. * bumpScale: <float>,
  20176. *
  20177. * normalMap: new THREE.Texture( <Image> ),
  20178. * normalMapType: THREE.TangentSpaceNormalMap,
  20179. * normalScale: <Vector2>,
  20180. *
  20181. * displacementMap: new THREE.Texture( <Image> ),
  20182. * displacementScale: <float>,
  20183. * displacementBias: <float>,
  20184. *
  20185. * wireframe: <boolean>,
  20186. * wireframeLinewidth: <float>
  20187. *
  20188. * skinning: <bool>,
  20189. * morphTargets: <bool>,
  20190. * morphNormals: <bool>
  20191. * }
  20192. */
  20193. function MeshNormalMaterial( parameters ) {
  20194. Material.call( this );
  20195. this.type = 'MeshNormalMaterial';
  20196. this.bumpMap = null;
  20197. this.bumpScale = 1;
  20198. this.normalMap = null;
  20199. this.normalMapType = TangentSpaceNormalMap;
  20200. this.normalScale = new Vector2( 1, 1 );
  20201. this.displacementMap = null;
  20202. this.displacementScale = 1;
  20203. this.displacementBias = 0;
  20204. this.wireframe = false;
  20205. this.wireframeLinewidth = 1;
  20206. this.fog = false;
  20207. this.skinning = false;
  20208. this.morphTargets = false;
  20209. this.morphNormals = false;
  20210. this.setValues( parameters );
  20211. }
  20212. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  20213. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20214. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20215. MeshNormalMaterial.prototype.copy = function ( source ) {
  20216. Material.prototype.copy.call( this, source );
  20217. this.bumpMap = source.bumpMap;
  20218. this.bumpScale = source.bumpScale;
  20219. this.normalMap = source.normalMap;
  20220. this.normalMapType = source.normalMapType;
  20221. this.normalScale.copy( source.normalScale );
  20222. this.displacementMap = source.displacementMap;
  20223. this.displacementScale = source.displacementScale;
  20224. this.displacementBias = source.displacementBias;
  20225. this.wireframe = source.wireframe;
  20226. this.wireframeLinewidth = source.wireframeLinewidth;
  20227. this.skinning = source.skinning;
  20228. this.morphTargets = source.morphTargets;
  20229. this.morphNormals = source.morphNormals;
  20230. return this;
  20231. };
  20232. /**
  20233. * @author mrdoob / http://mrdoob.com/
  20234. * @author alteredq / http://alteredqualia.com/
  20235. *
  20236. * parameters = {
  20237. * color: <hex>,
  20238. * opacity: <float>,
  20239. *
  20240. * map: new THREE.Texture( <Image> ),
  20241. *
  20242. * lightMap: new THREE.Texture( <Image> ),
  20243. * lightMapIntensity: <float>
  20244. *
  20245. * aoMap: new THREE.Texture( <Image> ),
  20246. * aoMapIntensity: <float>
  20247. *
  20248. * emissive: <hex>,
  20249. * emissiveIntensity: <float>
  20250. * emissiveMap: new THREE.Texture( <Image> ),
  20251. *
  20252. * specularMap: new THREE.Texture( <Image> ),
  20253. *
  20254. * alphaMap: new THREE.Texture( <Image> ),
  20255. *
  20256. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20257. * combine: THREE.Multiply,
  20258. * reflectivity: <float>,
  20259. * refractionRatio: <float>,
  20260. *
  20261. * wireframe: <boolean>,
  20262. * wireframeLinewidth: <float>,
  20263. *
  20264. * skinning: <bool>,
  20265. * morphTargets: <bool>,
  20266. * morphNormals: <bool>
  20267. * }
  20268. */
  20269. function MeshLambertMaterial( parameters ) {
  20270. Material.call( this );
  20271. this.type = 'MeshLambertMaterial';
  20272. this.color = new Color( 0xffffff ); // diffuse
  20273. this.map = null;
  20274. this.lightMap = null;
  20275. this.lightMapIntensity = 1.0;
  20276. this.aoMap = null;
  20277. this.aoMapIntensity = 1.0;
  20278. this.emissive = new Color( 0x000000 );
  20279. this.emissiveIntensity = 1.0;
  20280. this.emissiveMap = null;
  20281. this.specularMap = null;
  20282. this.alphaMap = null;
  20283. this.envMap = null;
  20284. this.combine = MultiplyOperation;
  20285. this.reflectivity = 1;
  20286. this.refractionRatio = 0.98;
  20287. this.wireframe = false;
  20288. this.wireframeLinewidth = 1;
  20289. this.wireframeLinecap = 'round';
  20290. this.wireframeLinejoin = 'round';
  20291. this.skinning = false;
  20292. this.morphTargets = false;
  20293. this.morphNormals = false;
  20294. this.setValues( parameters );
  20295. }
  20296. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  20297. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20298. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20299. MeshLambertMaterial.prototype.copy = function ( source ) {
  20300. Material.prototype.copy.call( this, source );
  20301. this.color.copy( source.color );
  20302. this.map = source.map;
  20303. this.lightMap = source.lightMap;
  20304. this.lightMapIntensity = source.lightMapIntensity;
  20305. this.aoMap = source.aoMap;
  20306. this.aoMapIntensity = source.aoMapIntensity;
  20307. this.emissive.copy( source.emissive );
  20308. this.emissiveMap = source.emissiveMap;
  20309. this.emissiveIntensity = source.emissiveIntensity;
  20310. this.specularMap = source.specularMap;
  20311. this.alphaMap = source.alphaMap;
  20312. this.envMap = source.envMap;
  20313. this.combine = source.combine;
  20314. this.reflectivity = source.reflectivity;
  20315. this.refractionRatio = source.refractionRatio;
  20316. this.wireframe = source.wireframe;
  20317. this.wireframeLinewidth = source.wireframeLinewidth;
  20318. this.wireframeLinecap = source.wireframeLinecap;
  20319. this.wireframeLinejoin = source.wireframeLinejoin;
  20320. this.skinning = source.skinning;
  20321. this.morphTargets = source.morphTargets;
  20322. this.morphNormals = source.morphNormals;
  20323. return this;
  20324. };
  20325. /**
  20326. * @author WestLangley / http://github.com/WestLangley
  20327. *
  20328. * parameters = {
  20329. * color: <hex>,
  20330. * opacity: <float>,
  20331. *
  20332. * matcap: new THREE.Texture( <Image> ),
  20333. *
  20334. * map: new THREE.Texture( <Image> ),
  20335. *
  20336. * bumpMap: new THREE.Texture( <Image> ),
  20337. * bumpScale: <float>,
  20338. *
  20339. * normalMap: new THREE.Texture( <Image> ),
  20340. * normalMapType: THREE.TangentSpaceNormalMap,
  20341. * normalScale: <Vector2>,
  20342. *
  20343. * displacementMap: new THREE.Texture( <Image> ),
  20344. * displacementScale: <float>,
  20345. * displacementBias: <float>,
  20346. *
  20347. * alphaMap: new THREE.Texture( <Image> ),
  20348. *
  20349. * skinning: <bool>,
  20350. * morphTargets: <bool>,
  20351. * morphNormals: <bool>
  20352. * }
  20353. */
  20354. function MeshMatcapMaterial( parameters ) {
  20355. Material.call( this );
  20356. this.defines = { 'MATCAP': '' };
  20357. this.type = 'MeshMatcapMaterial';
  20358. this.color = new Color( 0xffffff ); // diffuse
  20359. this.matcap = null;
  20360. this.map = null;
  20361. this.bumpMap = null;
  20362. this.bumpScale = 1;
  20363. this.normalMap = null;
  20364. this.normalMapType = TangentSpaceNormalMap;
  20365. this.normalScale = new Vector2( 1, 1 );
  20366. this.displacementMap = null;
  20367. this.displacementScale = 1;
  20368. this.displacementBias = 0;
  20369. this.alphaMap = null;
  20370. this.skinning = false;
  20371. this.morphTargets = false;
  20372. this.morphNormals = false;
  20373. this.setValues( parameters );
  20374. }
  20375. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  20376. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20377. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20378. MeshMatcapMaterial.prototype.copy = function ( source ) {
  20379. Material.prototype.copy.call( this, source );
  20380. this.defines = { 'MATCAP': '' };
  20381. this.color.copy( source.color );
  20382. this.matcap = source.matcap;
  20383. this.map = source.map;
  20384. this.bumpMap = source.bumpMap;
  20385. this.bumpScale = source.bumpScale;
  20386. this.normalMap = source.normalMap;
  20387. this.normalMapType = source.normalMapType;
  20388. this.normalScale.copy( source.normalScale );
  20389. this.displacementMap = source.displacementMap;
  20390. this.displacementScale = source.displacementScale;
  20391. this.displacementBias = source.displacementBias;
  20392. this.alphaMap = source.alphaMap;
  20393. this.skinning = source.skinning;
  20394. this.morphTargets = source.morphTargets;
  20395. this.morphNormals = source.morphNormals;
  20396. return this;
  20397. };
  20398. /**
  20399. * @author alteredq / http://alteredqualia.com/
  20400. *
  20401. * parameters = {
  20402. * color: <hex>,
  20403. * opacity: <float>,
  20404. *
  20405. * linewidth: <float>,
  20406. *
  20407. * scale: <float>,
  20408. * dashSize: <float>,
  20409. * gapSize: <float>
  20410. * }
  20411. */
  20412. function LineDashedMaterial( parameters ) {
  20413. LineBasicMaterial.call( this );
  20414. this.type = 'LineDashedMaterial';
  20415. this.scale = 1;
  20416. this.dashSize = 3;
  20417. this.gapSize = 1;
  20418. this.setValues( parameters );
  20419. }
  20420. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  20421. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20422. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20423. LineDashedMaterial.prototype.copy = function ( source ) {
  20424. LineBasicMaterial.prototype.copy.call( this, source );
  20425. this.scale = source.scale;
  20426. this.dashSize = source.dashSize;
  20427. this.gapSize = source.gapSize;
  20428. return this;
  20429. };
  20430. var Materials = /*#__PURE__*/Object.freeze({
  20431. __proto__: null,
  20432. ShadowMaterial: ShadowMaterial,
  20433. SpriteMaterial: SpriteMaterial,
  20434. RawShaderMaterial: RawShaderMaterial,
  20435. ShaderMaterial: ShaderMaterial,
  20436. PointsMaterial: PointsMaterial,
  20437. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20438. MeshStandardMaterial: MeshStandardMaterial,
  20439. MeshPhongMaterial: MeshPhongMaterial,
  20440. MeshToonMaterial: MeshToonMaterial,
  20441. MeshNormalMaterial: MeshNormalMaterial,
  20442. MeshLambertMaterial: MeshLambertMaterial,
  20443. MeshDepthMaterial: MeshDepthMaterial,
  20444. MeshDistanceMaterial: MeshDistanceMaterial,
  20445. MeshBasicMaterial: MeshBasicMaterial,
  20446. MeshMatcapMaterial: MeshMatcapMaterial,
  20447. LineDashedMaterial: LineDashedMaterial,
  20448. LineBasicMaterial: LineBasicMaterial,
  20449. Material: Material
  20450. });
  20451. /**
  20452. * @author tschw
  20453. * @author Ben Houston / http://clara.io/
  20454. * @author David Sarno / http://lighthaus.us/
  20455. */
  20456. var AnimationUtils = {
  20457. // same as Array.prototype.slice, but also works on typed arrays
  20458. arraySlice: function ( array, from, to ) {
  20459. if ( AnimationUtils.isTypedArray( array ) ) {
  20460. // in ios9 array.subarray(from, undefined) will return empty array
  20461. // but array.subarray(from) or array.subarray(from, len) is correct
  20462. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20463. }
  20464. return array.slice( from, to );
  20465. },
  20466. // converts an array to a specific type
  20467. convertArray: function ( array, type, forceClone ) {
  20468. if ( ! array || // let 'undefined' and 'null' pass
  20469. ! forceClone && array.constructor === type ) return array;
  20470. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20471. return new type( array ); // create typed array
  20472. }
  20473. return Array.prototype.slice.call( array ); // create Array
  20474. },
  20475. isTypedArray: function ( object ) {
  20476. return ArrayBuffer.isView( object ) &&
  20477. ! ( object instanceof DataView );
  20478. },
  20479. // returns an array by which times and values can be sorted
  20480. getKeyframeOrder: function ( times ) {
  20481. function compareTime( i, j ) {
  20482. return times[ i ] - times[ j ];
  20483. }
  20484. var n = times.length;
  20485. var result = new Array( n );
  20486. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  20487. result.sort( compareTime );
  20488. return result;
  20489. },
  20490. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20491. sortedArray: function ( values, stride, order ) {
  20492. var nValues = values.length;
  20493. var result = new values.constructor( nValues );
  20494. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20495. var srcOffset = order[ i ] * stride;
  20496. for ( var j = 0; j !== stride; ++ j ) {
  20497. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20498. }
  20499. }
  20500. return result;
  20501. },
  20502. // function for parsing AOS keyframe formats
  20503. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20504. var i = 1, key = jsonKeys[ 0 ];
  20505. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20506. key = jsonKeys[ i ++ ];
  20507. }
  20508. if ( key === undefined ) return; // no data
  20509. var value = key[ valuePropertyName ];
  20510. if ( value === undefined ) return; // no data
  20511. if ( Array.isArray( value ) ) {
  20512. do {
  20513. value = key[ valuePropertyName ];
  20514. if ( value !== undefined ) {
  20515. times.push( key.time );
  20516. values.push.apply( values, value ); // push all elements
  20517. }
  20518. key = jsonKeys[ i ++ ];
  20519. } while ( key !== undefined );
  20520. } else if ( value.toArray !== undefined ) {
  20521. // ...assume THREE.Math-ish
  20522. do {
  20523. value = key[ valuePropertyName ];
  20524. if ( value !== undefined ) {
  20525. times.push( key.time );
  20526. value.toArray( values, values.length );
  20527. }
  20528. key = jsonKeys[ i ++ ];
  20529. } while ( key !== undefined );
  20530. } else {
  20531. // otherwise push as-is
  20532. do {
  20533. value = key[ valuePropertyName ];
  20534. if ( value !== undefined ) {
  20535. times.push( key.time );
  20536. values.push( value );
  20537. }
  20538. key = jsonKeys[ i ++ ];
  20539. } while ( key !== undefined );
  20540. }
  20541. },
  20542. subclip: function ( sourceClip, name, startFrame, endFrame, fps ) {
  20543. fps = fps || 30;
  20544. var clip = sourceClip.clone();
  20545. clip.name = name;
  20546. var tracks = [];
  20547. for ( var i = 0; i < clip.tracks.length; ++ i ) {
  20548. var track = clip.tracks[ i ];
  20549. var valueSize = track.getValueSize();
  20550. var times = [];
  20551. var values = [];
  20552. for ( var j = 0; j < track.times.length; ++ j ) {
  20553. var frame = track.times[ j ] * fps;
  20554. if ( frame < startFrame || frame >= endFrame ) continue;
  20555. times.push( track.times[ j ] );
  20556. for ( var k = 0; k < valueSize; ++ k ) {
  20557. values.push( track.values[ j * valueSize + k ] );
  20558. }
  20559. }
  20560. if ( times.length === 0 ) continue;
  20561. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  20562. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  20563. tracks.push( track );
  20564. }
  20565. clip.tracks = tracks;
  20566. // find minimum .times value across all tracks in the trimmed clip
  20567. var minStartTime = Infinity;
  20568. for ( var i = 0; i < clip.tracks.length; ++ i ) {
  20569. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  20570. minStartTime = clip.tracks[ i ].times[ 0 ];
  20571. }
  20572. }
  20573. // shift all tracks such that clip begins at t=0
  20574. for ( var i = 0; i < clip.tracks.length; ++ i ) {
  20575. clip.tracks[ i ].shift( - 1 * minStartTime );
  20576. }
  20577. clip.resetDuration();
  20578. return clip;
  20579. },
  20580. makeClipAdditive: function ( targetClip, referenceFrame, referenceClip, fps ) {
  20581. if ( referenceFrame === undefined ) referenceFrame = 0;
  20582. if ( referenceClip === undefined ) referenceClip = targetClip;
  20583. if ( fps === undefined || fps <= 0 ) fps = 30;
  20584. var numTracks = targetClip.tracks.length;
  20585. var referenceTime = referenceFrame / fps;
  20586. // Make each track's values relative to the values at the reference frame
  20587. for ( var i = 0; i < numTracks; ++ i ) {
  20588. var referenceTrack = referenceClip.tracks[ i ];
  20589. var referenceTrackType = referenceTrack.ValueTypeName;
  20590. // Skip this track if it's non-numeric
  20591. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  20592. // Find the track in the target clip whose name and type matches the reference track
  20593. var targetTrack = targetClip.tracks.find( function ( track ) {
  20594. return track.name === referenceTrack.name
  20595. && track.ValueTypeName === referenceTrackType;
  20596. } );
  20597. if ( targetTrack === undefined ) continue;
  20598. var valueSize = referenceTrack.getValueSize();
  20599. var lastIndex = referenceTrack.times.length - 1;
  20600. var referenceValue;
  20601. // Find the value to subtract out of the track
  20602. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  20603. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20604. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, 0, referenceTrack.valueSize );
  20605. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  20606. // Reference frame is after the last keyframe, so just use the last keyframe
  20607. var startIndex = lastIndex * valueSize;
  20608. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex );
  20609. } else {
  20610. // Interpolate to the reference value
  20611. var interpolant = referenceTrack.createInterpolant();
  20612. interpolant.evaluate( referenceTime );
  20613. referenceValue = interpolant.resultBuffer;
  20614. }
  20615. // Conjugate the quaternion
  20616. if ( referenceTrackType === 'quaternion' ) {
  20617. var referenceQuat = new Quaternion(
  20618. referenceValue[ 0 ],
  20619. referenceValue[ 1 ],
  20620. referenceValue[ 2 ],
  20621. referenceValue[ 3 ]
  20622. ).normalize().conjugate();
  20623. referenceQuat.toArray( referenceValue );
  20624. }
  20625. // Subtract the reference value from all of the track values
  20626. var numTimes = targetTrack.times.length;
  20627. for ( var j = 0; j < numTimes; ++ j ) {
  20628. var valueStart = j * valueSize;
  20629. if ( referenceTrackType === 'quaternion' ) {
  20630. // Multiply the conjugate for quaternion track types
  20631. Quaternion.multiplyQuaternionsFlat(
  20632. targetTrack.values,
  20633. valueStart,
  20634. referenceValue,
  20635. 0,
  20636. targetTrack.values,
  20637. valueStart
  20638. );
  20639. } else {
  20640. // Subtract each value for all other numeric track types
  20641. for ( var k = 0; k < valueSize; ++ k ) {
  20642. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  20643. }
  20644. }
  20645. }
  20646. }
  20647. targetClip.blendMode = AdditiveAnimationBlendMode;
  20648. return targetClip;
  20649. }
  20650. };
  20651. /**
  20652. * Abstract base class of interpolants over parametric samples.
  20653. *
  20654. * The parameter domain is one dimensional, typically the time or a path
  20655. * along a curve defined by the data.
  20656. *
  20657. * The sample values can have any dimensionality and derived classes may
  20658. * apply special interpretations to the data.
  20659. *
  20660. * This class provides the interval seek in a Template Method, deferring
  20661. * the actual interpolation to derived classes.
  20662. *
  20663. * Time complexity is O(1) for linear access crossing at most two points
  20664. * and O(log N) for random access, where N is the number of positions.
  20665. *
  20666. * References:
  20667. *
  20668. * http://www.oodesign.com/template-method-pattern.html
  20669. *
  20670. * @author tschw
  20671. */
  20672. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20673. this.parameterPositions = parameterPositions;
  20674. this._cachedIndex = 0;
  20675. this.resultBuffer = resultBuffer !== undefined ?
  20676. resultBuffer : new sampleValues.constructor( sampleSize );
  20677. this.sampleValues = sampleValues;
  20678. this.valueSize = sampleSize;
  20679. }
  20680. Object.assign( Interpolant.prototype, {
  20681. evaluate: function ( t ) {
  20682. var pp = this.parameterPositions,
  20683. i1 = this._cachedIndex,
  20684. t1 = pp[ i1 ],
  20685. t0 = pp[ i1 - 1 ];
  20686. validate_interval: {
  20687. seek: {
  20688. var right;
  20689. linear_scan: {
  20690. //- See http://jsperf.com/comparison-to-undefined/3
  20691. //- slower code:
  20692. //-
  20693. //- if ( t >= t1 || t1 === undefined ) {
  20694. forward_scan: if ( ! ( t < t1 ) ) {
  20695. for ( var giveUpAt = i1 + 2; ; ) {
  20696. if ( t1 === undefined ) {
  20697. if ( t < t0 ) break forward_scan;
  20698. // after end
  20699. i1 = pp.length;
  20700. this._cachedIndex = i1;
  20701. return this.afterEnd_( i1 - 1, t, t0 );
  20702. }
  20703. if ( i1 === giveUpAt ) break; // this loop
  20704. t0 = t1;
  20705. t1 = pp[ ++ i1 ];
  20706. if ( t < t1 ) {
  20707. // we have arrived at the sought interval
  20708. break seek;
  20709. }
  20710. }
  20711. // prepare binary search on the right side of the index
  20712. right = pp.length;
  20713. break linear_scan;
  20714. }
  20715. //- slower code:
  20716. //- if ( t < t0 || t0 === undefined ) {
  20717. if ( ! ( t >= t0 ) ) {
  20718. // looping?
  20719. var t1global = pp[ 1 ];
  20720. if ( t < t1global ) {
  20721. i1 = 2; // + 1, using the scan for the details
  20722. t0 = t1global;
  20723. }
  20724. // linear reverse scan
  20725. for ( var giveUpAt = i1 - 2; ; ) {
  20726. if ( t0 === undefined ) {
  20727. // before start
  20728. this._cachedIndex = 0;
  20729. return this.beforeStart_( 0, t, t1 );
  20730. }
  20731. if ( i1 === giveUpAt ) break; // this loop
  20732. t1 = t0;
  20733. t0 = pp[ -- i1 - 1 ];
  20734. if ( t >= t0 ) {
  20735. // we have arrived at the sought interval
  20736. break seek;
  20737. }
  20738. }
  20739. // prepare binary search on the left side of the index
  20740. right = i1;
  20741. i1 = 0;
  20742. break linear_scan;
  20743. }
  20744. // the interval is valid
  20745. break validate_interval;
  20746. } // linear scan
  20747. // binary search
  20748. while ( i1 < right ) {
  20749. var mid = ( i1 + right ) >>> 1;
  20750. if ( t < pp[ mid ] ) {
  20751. right = mid;
  20752. } else {
  20753. i1 = mid + 1;
  20754. }
  20755. }
  20756. t1 = pp[ i1 ];
  20757. t0 = pp[ i1 - 1 ];
  20758. // check boundary cases, again
  20759. if ( t0 === undefined ) {
  20760. this._cachedIndex = 0;
  20761. return this.beforeStart_( 0, t, t1 );
  20762. }
  20763. if ( t1 === undefined ) {
  20764. i1 = pp.length;
  20765. this._cachedIndex = i1;
  20766. return this.afterEnd_( i1 - 1, t0, t );
  20767. }
  20768. } // seek
  20769. this._cachedIndex = i1;
  20770. this.intervalChanged_( i1, t0, t1 );
  20771. } // validate_interval
  20772. return this.interpolate_( i1, t0, t, t1 );
  20773. },
  20774. settings: null, // optional, subclass-specific settings structure
  20775. // Note: The indirection allows central control of many interpolants.
  20776. // --- Protected interface
  20777. DefaultSettings_: {},
  20778. getSettings_: function () {
  20779. return this.settings || this.DefaultSettings_;
  20780. },
  20781. copySampleValue_: function ( index ) {
  20782. // copies a sample value to the result buffer
  20783. var result = this.resultBuffer,
  20784. values = this.sampleValues,
  20785. stride = this.valueSize,
  20786. offset = index * stride;
  20787. for ( var i = 0; i !== stride; ++ i ) {
  20788. result[ i ] = values[ offset + i ];
  20789. }
  20790. return result;
  20791. },
  20792. // Template methods for derived classes:
  20793. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20794. throw new Error( 'call to abstract method' );
  20795. // implementations shall return this.resultBuffer
  20796. },
  20797. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20798. // empty
  20799. }
  20800. } );
  20801. // DECLARE ALIAS AFTER assign prototype
  20802. Object.assign( Interpolant.prototype, {
  20803. //( 0, t, t0 ), returns this.resultBuffer
  20804. beforeStart_: Interpolant.prototype.copySampleValue_,
  20805. //( N-1, tN-1, t ), returns this.resultBuffer
  20806. afterEnd_: Interpolant.prototype.copySampleValue_,
  20807. } );
  20808. /**
  20809. * Fast and simple cubic spline interpolant.
  20810. *
  20811. * It was derived from a Hermitian construction setting the first derivative
  20812. * at each sample position to the linear slope between neighboring positions
  20813. * over their parameter interval.
  20814. *
  20815. * @author tschw
  20816. */
  20817. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20818. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20819. this._weightPrev = - 0;
  20820. this._offsetPrev = - 0;
  20821. this._weightNext = - 0;
  20822. this._offsetNext = - 0;
  20823. }
  20824. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20825. constructor: CubicInterpolant,
  20826. DefaultSettings_: {
  20827. endingStart: ZeroCurvatureEnding,
  20828. endingEnd: ZeroCurvatureEnding
  20829. },
  20830. intervalChanged_: function ( i1, t0, t1 ) {
  20831. var pp = this.parameterPositions,
  20832. iPrev = i1 - 2,
  20833. iNext = i1 + 1,
  20834. tPrev = pp[ iPrev ],
  20835. tNext = pp[ iNext ];
  20836. if ( tPrev === undefined ) {
  20837. switch ( this.getSettings_().endingStart ) {
  20838. case ZeroSlopeEnding:
  20839. // f'(t0) = 0
  20840. iPrev = i1;
  20841. tPrev = 2 * t0 - t1;
  20842. break;
  20843. case WrapAroundEnding:
  20844. // use the other end of the curve
  20845. iPrev = pp.length - 2;
  20846. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20847. break;
  20848. default: // ZeroCurvatureEnding
  20849. // f''(t0) = 0 a.k.a. Natural Spline
  20850. iPrev = i1;
  20851. tPrev = t1;
  20852. }
  20853. }
  20854. if ( tNext === undefined ) {
  20855. switch ( this.getSettings_().endingEnd ) {
  20856. case ZeroSlopeEnding:
  20857. // f'(tN) = 0
  20858. iNext = i1;
  20859. tNext = 2 * t1 - t0;
  20860. break;
  20861. case WrapAroundEnding:
  20862. // use the other end of the curve
  20863. iNext = 1;
  20864. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20865. break;
  20866. default: // ZeroCurvatureEnding
  20867. // f''(tN) = 0, a.k.a. Natural Spline
  20868. iNext = i1 - 1;
  20869. tNext = t0;
  20870. }
  20871. }
  20872. var halfDt = ( t1 - t0 ) * 0.5,
  20873. stride = this.valueSize;
  20874. this._weightPrev = halfDt / ( t0 - tPrev );
  20875. this._weightNext = halfDt / ( tNext - t1 );
  20876. this._offsetPrev = iPrev * stride;
  20877. this._offsetNext = iNext * stride;
  20878. },
  20879. interpolate_: function ( i1, t0, t, t1 ) {
  20880. var result = this.resultBuffer,
  20881. values = this.sampleValues,
  20882. stride = this.valueSize,
  20883. o1 = i1 * stride, o0 = o1 - stride,
  20884. oP = this._offsetPrev, oN = this._offsetNext,
  20885. wP = this._weightPrev, wN = this._weightNext,
  20886. p = ( t - t0 ) / ( t1 - t0 ),
  20887. pp = p * p,
  20888. ppp = pp * p;
  20889. // evaluate polynomials
  20890. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20891. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20892. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20893. var sN = wN * ppp - wN * pp;
  20894. // combine data linearly
  20895. for ( var i = 0; i !== stride; ++ i ) {
  20896. result[ i ] =
  20897. sP * values[ oP + i ] +
  20898. s0 * values[ o0 + i ] +
  20899. s1 * values[ o1 + i ] +
  20900. sN * values[ oN + i ];
  20901. }
  20902. return result;
  20903. }
  20904. } );
  20905. /**
  20906. * @author tschw
  20907. */
  20908. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20909. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20910. }
  20911. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20912. constructor: LinearInterpolant,
  20913. interpolate_: function ( i1, t0, t, t1 ) {
  20914. var result = this.resultBuffer,
  20915. values = this.sampleValues,
  20916. stride = this.valueSize,
  20917. offset1 = i1 * stride,
  20918. offset0 = offset1 - stride,
  20919. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20920. weight0 = 1 - weight1;
  20921. for ( var i = 0; i !== stride; ++ i ) {
  20922. result[ i ] =
  20923. values[ offset0 + i ] * weight0 +
  20924. values[ offset1 + i ] * weight1;
  20925. }
  20926. return result;
  20927. }
  20928. } );
  20929. /**
  20930. *
  20931. * Interpolant that evaluates to the sample value at the position preceeding
  20932. * the parameter.
  20933. *
  20934. * @author tschw
  20935. */
  20936. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20937. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20938. }
  20939. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20940. constructor: DiscreteInterpolant,
  20941. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20942. return this.copySampleValue_( i1 - 1 );
  20943. }
  20944. } );
  20945. /**
  20946. *
  20947. * A timed sequence of keyframes for a specific property.
  20948. *
  20949. *
  20950. * @author Ben Houston / http://clara.io/
  20951. * @author David Sarno / http://lighthaus.us/
  20952. * @author tschw
  20953. */
  20954. function KeyframeTrack( name, times, values, interpolation ) {
  20955. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20956. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20957. this.name = name;
  20958. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20959. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20960. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20961. }
  20962. // Static methods
  20963. Object.assign( KeyframeTrack, {
  20964. // Serialization (in static context, because of constructor invocation
  20965. // and automatic invocation of .toJSON):
  20966. toJSON: function ( track ) {
  20967. var trackType = track.constructor;
  20968. var json;
  20969. // derived classes can define a static toJSON method
  20970. if ( trackType.toJSON !== undefined ) {
  20971. json = trackType.toJSON( track );
  20972. } else {
  20973. // by default, we assume the data can be serialized as-is
  20974. json = {
  20975. 'name': track.name,
  20976. 'times': AnimationUtils.convertArray( track.times, Array ),
  20977. 'values': AnimationUtils.convertArray( track.values, Array )
  20978. };
  20979. var interpolation = track.getInterpolation();
  20980. if ( interpolation !== track.DefaultInterpolation ) {
  20981. json.interpolation = interpolation;
  20982. }
  20983. }
  20984. json.type = track.ValueTypeName; // mandatory
  20985. return json;
  20986. }
  20987. } );
  20988. Object.assign( KeyframeTrack.prototype, {
  20989. constructor: KeyframeTrack,
  20990. TimeBufferType: Float32Array,
  20991. ValueBufferType: Float32Array,
  20992. DefaultInterpolation: InterpolateLinear,
  20993. InterpolantFactoryMethodDiscrete: function ( result ) {
  20994. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20995. },
  20996. InterpolantFactoryMethodLinear: function ( result ) {
  20997. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20998. },
  20999. InterpolantFactoryMethodSmooth: function ( result ) {
  21000. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  21001. },
  21002. setInterpolation: function ( interpolation ) {
  21003. var factoryMethod;
  21004. switch ( interpolation ) {
  21005. case InterpolateDiscrete:
  21006. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21007. break;
  21008. case InterpolateLinear:
  21009. factoryMethod = this.InterpolantFactoryMethodLinear;
  21010. break;
  21011. case InterpolateSmooth:
  21012. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21013. break;
  21014. }
  21015. if ( factoryMethod === undefined ) {
  21016. var message = "unsupported interpolation for " +
  21017. this.ValueTypeName + " keyframe track named " + this.name;
  21018. if ( this.createInterpolant === undefined ) {
  21019. // fall back to default, unless the default itself is messed up
  21020. if ( interpolation !== this.DefaultInterpolation ) {
  21021. this.setInterpolation( this.DefaultInterpolation );
  21022. } else {
  21023. throw new Error( message ); // fatal, in this case
  21024. }
  21025. }
  21026. console.warn( 'THREE.KeyframeTrack:', message );
  21027. return this;
  21028. }
  21029. this.createInterpolant = factoryMethod;
  21030. return this;
  21031. },
  21032. getInterpolation: function () {
  21033. switch ( this.createInterpolant ) {
  21034. case this.InterpolantFactoryMethodDiscrete:
  21035. return InterpolateDiscrete;
  21036. case this.InterpolantFactoryMethodLinear:
  21037. return InterpolateLinear;
  21038. case this.InterpolantFactoryMethodSmooth:
  21039. return InterpolateSmooth;
  21040. }
  21041. },
  21042. getValueSize: function () {
  21043. return this.values.length / this.times.length;
  21044. },
  21045. // move all keyframes either forwards or backwards in time
  21046. shift: function ( timeOffset ) {
  21047. if ( timeOffset !== 0.0 ) {
  21048. var times = this.times;
  21049. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21050. times[ i ] += timeOffset;
  21051. }
  21052. }
  21053. return this;
  21054. },
  21055. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21056. scale: function ( timeScale ) {
  21057. if ( timeScale !== 1.0 ) {
  21058. var times = this.times;
  21059. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21060. times[ i ] *= timeScale;
  21061. }
  21062. }
  21063. return this;
  21064. },
  21065. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21066. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21067. trim: function ( startTime, endTime ) {
  21068. var times = this.times,
  21069. nKeys = times.length,
  21070. from = 0,
  21071. to = nKeys - 1;
  21072. while ( from !== nKeys && times[ from ] < startTime ) {
  21073. ++ from;
  21074. }
  21075. while ( to !== - 1 && times[ to ] > endTime ) {
  21076. -- to;
  21077. }
  21078. ++ to; // inclusive -> exclusive bound
  21079. if ( from !== 0 || to !== nKeys ) {
  21080. // empty tracks are forbidden, so keep at least one keyframe
  21081. if ( from >= to ) {
  21082. to = Math.max( to, 1 );
  21083. from = to - 1;
  21084. }
  21085. var stride = this.getValueSize();
  21086. this.times = AnimationUtils.arraySlice( times, from, to );
  21087. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  21088. }
  21089. return this;
  21090. },
  21091. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21092. validate: function () {
  21093. var valid = true;
  21094. var valueSize = this.getValueSize();
  21095. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  21096. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  21097. valid = false;
  21098. }
  21099. var times = this.times,
  21100. values = this.values,
  21101. nKeys = times.length;
  21102. if ( nKeys === 0 ) {
  21103. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  21104. valid = false;
  21105. }
  21106. var prevTime = null;
  21107. for ( var i = 0; i !== nKeys; i ++ ) {
  21108. var currTime = times[ i ];
  21109. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  21110. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  21111. valid = false;
  21112. break;
  21113. }
  21114. if ( prevTime !== null && prevTime > currTime ) {
  21115. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  21116. valid = false;
  21117. break;
  21118. }
  21119. prevTime = currTime;
  21120. }
  21121. if ( values !== undefined ) {
  21122. if ( AnimationUtils.isTypedArray( values ) ) {
  21123. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  21124. var value = values[ i ];
  21125. if ( isNaN( value ) ) {
  21126. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  21127. valid = false;
  21128. break;
  21129. }
  21130. }
  21131. }
  21132. }
  21133. return valid;
  21134. },
  21135. // removes equivalent sequential keys as common in morph target sequences
  21136. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21137. optimize: function () {
  21138. // times or values may be shared with other tracks, so overwriting is unsafe
  21139. var times = AnimationUtils.arraySlice( this.times ),
  21140. values = AnimationUtils.arraySlice( this.values ),
  21141. stride = this.getValueSize(),
  21142. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21143. writeIndex = 1,
  21144. lastIndex = times.length - 1;
  21145. for ( var i = 1; i < lastIndex; ++ i ) {
  21146. var keep = false;
  21147. var time = times[ i ];
  21148. var timeNext = times[ i + 1 ];
  21149. // remove adjacent keyframes scheduled at the same time
  21150. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  21151. if ( ! smoothInterpolation ) {
  21152. // remove unnecessary keyframes same as their neighbors
  21153. var offset = i * stride,
  21154. offsetP = offset - stride,
  21155. offsetN = offset + stride;
  21156. for ( var j = 0; j !== stride; ++ j ) {
  21157. var value = values[ offset + j ];
  21158. if ( value !== values[ offsetP + j ] ||
  21159. value !== values[ offsetN + j ] ) {
  21160. keep = true;
  21161. break;
  21162. }
  21163. }
  21164. } else {
  21165. keep = true;
  21166. }
  21167. }
  21168. // in-place compaction
  21169. if ( keep ) {
  21170. if ( i !== writeIndex ) {
  21171. times[ writeIndex ] = times[ i ];
  21172. var readOffset = i * stride,
  21173. writeOffset = writeIndex * stride;
  21174. for ( var j = 0; j !== stride; ++ j ) {
  21175. values[ writeOffset + j ] = values[ readOffset + j ];
  21176. }
  21177. }
  21178. ++ writeIndex;
  21179. }
  21180. }
  21181. // flush last keyframe (compaction looks ahead)
  21182. if ( lastIndex > 0 ) {
  21183. times[ writeIndex ] = times[ lastIndex ];
  21184. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  21185. values[ writeOffset + j ] = values[ readOffset + j ];
  21186. }
  21187. ++ writeIndex;
  21188. }
  21189. if ( writeIndex !== times.length ) {
  21190. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  21191. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  21192. } else {
  21193. this.times = times;
  21194. this.values = values;
  21195. }
  21196. return this;
  21197. },
  21198. clone: function () {
  21199. var times = AnimationUtils.arraySlice( this.times, 0 );
  21200. var values = AnimationUtils.arraySlice( this.values, 0 );
  21201. var TypedKeyframeTrack = this.constructor;
  21202. var track = new TypedKeyframeTrack( this.name, times, values );
  21203. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21204. track.createInterpolant = this.createInterpolant;
  21205. return track;
  21206. }
  21207. } );
  21208. /**
  21209. *
  21210. * A Track of Boolean keyframe values.
  21211. *
  21212. *
  21213. * @author Ben Houston / http://clara.io/
  21214. * @author David Sarno / http://lighthaus.us/
  21215. * @author tschw
  21216. */
  21217. function BooleanKeyframeTrack( name, times, values ) {
  21218. KeyframeTrack.call( this, name, times, values );
  21219. }
  21220. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21221. constructor: BooleanKeyframeTrack,
  21222. ValueTypeName: 'bool',
  21223. ValueBufferType: Array,
  21224. DefaultInterpolation: InterpolateDiscrete,
  21225. InterpolantFactoryMethodLinear: undefined,
  21226. InterpolantFactoryMethodSmooth: undefined
  21227. // Note: Actually this track could have a optimized / compressed
  21228. // representation of a single value and a custom interpolant that
  21229. // computes "firstValue ^ isOdd( index )".
  21230. } );
  21231. /**
  21232. *
  21233. * A Track of keyframe values that represent color.
  21234. *
  21235. *
  21236. * @author Ben Houston / http://clara.io/
  21237. * @author David Sarno / http://lighthaus.us/
  21238. * @author tschw
  21239. */
  21240. function ColorKeyframeTrack( name, times, values, interpolation ) {
  21241. KeyframeTrack.call( this, name, times, values, interpolation );
  21242. }
  21243. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21244. constructor: ColorKeyframeTrack,
  21245. ValueTypeName: 'color'
  21246. // ValueBufferType is inherited
  21247. // DefaultInterpolation is inherited
  21248. // Note: Very basic implementation and nothing special yet.
  21249. // However, this is the place for color space parameterization.
  21250. } );
  21251. /**
  21252. *
  21253. * A Track of numeric keyframe values.
  21254. *
  21255. * @author Ben Houston / http://clara.io/
  21256. * @author David Sarno / http://lighthaus.us/
  21257. * @author tschw
  21258. */
  21259. function NumberKeyframeTrack( name, times, values, interpolation ) {
  21260. KeyframeTrack.call( this, name, times, values, interpolation );
  21261. }
  21262. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21263. constructor: NumberKeyframeTrack,
  21264. ValueTypeName: 'number'
  21265. // ValueBufferType is inherited
  21266. // DefaultInterpolation is inherited
  21267. } );
  21268. /**
  21269. * Spherical linear unit quaternion interpolant.
  21270. *
  21271. * @author tschw
  21272. */
  21273. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21274. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21275. }
  21276. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21277. constructor: QuaternionLinearInterpolant,
  21278. interpolate_: function ( i1, t0, t, t1 ) {
  21279. var result = this.resultBuffer,
  21280. values = this.sampleValues,
  21281. stride = this.valueSize,
  21282. offset = i1 * stride,
  21283. alpha = ( t - t0 ) / ( t1 - t0 );
  21284. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  21285. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  21286. }
  21287. return result;
  21288. }
  21289. } );
  21290. /**
  21291. *
  21292. * A Track of quaternion keyframe values.
  21293. *
  21294. * @author Ben Houston / http://clara.io/
  21295. * @author David Sarno / http://lighthaus.us/
  21296. * @author tschw
  21297. */
  21298. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  21299. KeyframeTrack.call( this, name, times, values, interpolation );
  21300. }
  21301. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21302. constructor: QuaternionKeyframeTrack,
  21303. ValueTypeName: 'quaternion',
  21304. // ValueBufferType is inherited
  21305. DefaultInterpolation: InterpolateLinear,
  21306. InterpolantFactoryMethodLinear: function ( result ) {
  21307. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21308. },
  21309. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21310. } );
  21311. /**
  21312. *
  21313. * A Track that interpolates Strings
  21314. *
  21315. *
  21316. * @author Ben Houston / http://clara.io/
  21317. * @author David Sarno / http://lighthaus.us/
  21318. * @author tschw
  21319. */
  21320. function StringKeyframeTrack( name, times, values, interpolation ) {
  21321. KeyframeTrack.call( this, name, times, values, interpolation );
  21322. }
  21323. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21324. constructor: StringKeyframeTrack,
  21325. ValueTypeName: 'string',
  21326. ValueBufferType: Array,
  21327. DefaultInterpolation: InterpolateDiscrete,
  21328. InterpolantFactoryMethodLinear: undefined,
  21329. InterpolantFactoryMethodSmooth: undefined
  21330. } );
  21331. /**
  21332. *
  21333. * A Track of vectored keyframe values.
  21334. *
  21335. *
  21336. * @author Ben Houston / http://clara.io/
  21337. * @author David Sarno / http://lighthaus.us/
  21338. * @author tschw
  21339. */
  21340. function VectorKeyframeTrack( name, times, values, interpolation ) {
  21341. KeyframeTrack.call( this, name, times, values, interpolation );
  21342. }
  21343. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21344. constructor: VectorKeyframeTrack,
  21345. ValueTypeName: 'vector'
  21346. // ValueBufferType is inherited
  21347. // DefaultInterpolation is inherited
  21348. } );
  21349. /**
  21350. *
  21351. * Reusable set of Tracks that represent an animation.
  21352. *
  21353. * @author Ben Houston / http://clara.io/
  21354. * @author David Sarno / http://lighthaus.us/
  21355. */
  21356. function AnimationClip( name, duration, tracks, blendMode ) {
  21357. this.name = name;
  21358. this.tracks = tracks;
  21359. this.duration = ( duration !== undefined ) ? duration : - 1;
  21360. this.blendMode = ( blendMode !== undefined ) ? blendMode : NormalAnimationBlendMode;
  21361. this.uuid = MathUtils.generateUUID();
  21362. // this means it should figure out its duration by scanning the tracks
  21363. if ( this.duration < 0 ) {
  21364. this.resetDuration();
  21365. }
  21366. }
  21367. function getTrackTypeForValueTypeName( typeName ) {
  21368. switch ( typeName.toLowerCase() ) {
  21369. case 'scalar':
  21370. case 'double':
  21371. case 'float':
  21372. case 'number':
  21373. case 'integer':
  21374. return NumberKeyframeTrack;
  21375. case 'vector':
  21376. case 'vector2':
  21377. case 'vector3':
  21378. case 'vector4':
  21379. return VectorKeyframeTrack;
  21380. case 'color':
  21381. return ColorKeyframeTrack;
  21382. case 'quaternion':
  21383. return QuaternionKeyframeTrack;
  21384. case 'bool':
  21385. case 'boolean':
  21386. return BooleanKeyframeTrack;
  21387. case 'string':
  21388. return StringKeyframeTrack;
  21389. }
  21390. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  21391. }
  21392. function parseKeyframeTrack( json ) {
  21393. if ( json.type === undefined ) {
  21394. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  21395. }
  21396. var trackType = getTrackTypeForValueTypeName( json.type );
  21397. if ( json.times === undefined ) {
  21398. var times = [], values = [];
  21399. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  21400. json.times = times;
  21401. json.values = values;
  21402. }
  21403. // derived classes can define a static parse method
  21404. if ( trackType.parse !== undefined ) {
  21405. return trackType.parse( json );
  21406. } else {
  21407. // by default, we assume a constructor compatible with the base
  21408. return new trackType( json.name, json.times, json.values, json.interpolation );
  21409. }
  21410. }
  21411. Object.assign( AnimationClip, {
  21412. parse: function ( json ) {
  21413. var tracks = [],
  21414. jsonTracks = json.tracks,
  21415. frameTime = 1.0 / ( json.fps || 1.0 );
  21416. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21417. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  21418. }
  21419. return new AnimationClip( json.name, json.duration, tracks, json.blendMode );
  21420. },
  21421. toJSON: function ( clip ) {
  21422. var tracks = [],
  21423. clipTracks = clip.tracks;
  21424. var json = {
  21425. 'name': clip.name,
  21426. 'duration': clip.duration,
  21427. 'tracks': tracks,
  21428. 'uuid': clip.uuid,
  21429. 'blendMode': clip.blendMode
  21430. };
  21431. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21432. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21433. }
  21434. return json;
  21435. },
  21436. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21437. var numMorphTargets = morphTargetSequence.length;
  21438. var tracks = [];
  21439. for ( var i = 0; i < numMorphTargets; i ++ ) {
  21440. var times = [];
  21441. var values = [];
  21442. times.push(
  21443. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21444. i,
  21445. ( i + 1 ) % numMorphTargets );
  21446. values.push( 0, 1, 0 );
  21447. var order = AnimationUtils.getKeyframeOrder( times );
  21448. times = AnimationUtils.sortedArray( times, 1, order );
  21449. values = AnimationUtils.sortedArray( values, 1, order );
  21450. // if there is a key at the first frame, duplicate it as the
  21451. // last frame as well for perfect loop.
  21452. if ( ! noLoop && times[ 0 ] === 0 ) {
  21453. times.push( numMorphTargets );
  21454. values.push( values[ 0 ] );
  21455. }
  21456. tracks.push(
  21457. new NumberKeyframeTrack(
  21458. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21459. times, values
  21460. ).scale( 1.0 / fps ) );
  21461. }
  21462. return new AnimationClip( name, - 1, tracks );
  21463. },
  21464. findByName: function ( objectOrClipArray, name ) {
  21465. var clipArray = objectOrClipArray;
  21466. if ( ! Array.isArray( objectOrClipArray ) ) {
  21467. var o = objectOrClipArray;
  21468. clipArray = o.geometry && o.geometry.animations || o.animations;
  21469. }
  21470. for ( var i = 0; i < clipArray.length; i ++ ) {
  21471. if ( clipArray[ i ].name === name ) {
  21472. return clipArray[ i ];
  21473. }
  21474. }
  21475. return null;
  21476. },
  21477. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21478. var animationToMorphTargets = {};
  21479. // tested with https://regex101.com/ on trick sequences
  21480. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21481. var pattern = /^([\w-]*?)([\d]+)$/;
  21482. // sort morph target names into animation groups based
  21483. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21484. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  21485. var morphTarget = morphTargets[ i ];
  21486. var parts = morphTarget.name.match( pattern );
  21487. if ( parts && parts.length > 1 ) {
  21488. var name = parts[ 1 ];
  21489. var animationMorphTargets = animationToMorphTargets[ name ];
  21490. if ( ! animationMorphTargets ) {
  21491. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21492. }
  21493. animationMorphTargets.push( morphTarget );
  21494. }
  21495. }
  21496. var clips = [];
  21497. for ( var name in animationToMorphTargets ) {
  21498. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21499. }
  21500. return clips;
  21501. },
  21502. // parse the animation.hierarchy format
  21503. parseAnimation: function ( animation, bones ) {
  21504. if ( ! animation ) {
  21505. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21506. return null;
  21507. }
  21508. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21509. // only return track if there are actually keys.
  21510. if ( animationKeys.length !== 0 ) {
  21511. var times = [];
  21512. var values = [];
  21513. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21514. // empty keys are filtered out, so check again
  21515. if ( times.length !== 0 ) {
  21516. destTracks.push( new trackType( trackName, times, values ) );
  21517. }
  21518. }
  21519. };
  21520. var tracks = [];
  21521. var clipName = animation.name || 'default';
  21522. // automatic length determination in AnimationClip.
  21523. var duration = animation.length || - 1;
  21524. var fps = animation.fps || 30;
  21525. var blendMode = animation.blendMode;
  21526. var hierarchyTracks = animation.hierarchy || [];
  21527. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  21528. var animationKeys = hierarchyTracks[ h ].keys;
  21529. // skip empty tracks
  21530. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21531. // process morph targets
  21532. if ( animationKeys[ 0 ].morphTargets ) {
  21533. // figure out all morph targets used in this track
  21534. var morphTargetNames = {};
  21535. for ( var k = 0; k < animationKeys.length; k ++ ) {
  21536. if ( animationKeys[ k ].morphTargets ) {
  21537. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21538. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21539. }
  21540. }
  21541. }
  21542. // create a track for each morph target with all zero
  21543. // morphTargetInfluences except for the keys in which
  21544. // the morphTarget is named.
  21545. for ( var morphTargetName in morphTargetNames ) {
  21546. var times = [];
  21547. var values = [];
  21548. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21549. var animationKey = animationKeys[ k ];
  21550. times.push( animationKey.time );
  21551. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21552. }
  21553. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21554. }
  21555. duration = morphTargetNames.length * ( fps || 1.0 );
  21556. } else {
  21557. // ...assume skeletal animation
  21558. var boneName = '.bones[' + bones[ h ].name + ']';
  21559. addNonemptyTrack(
  21560. VectorKeyframeTrack, boneName + '.position',
  21561. animationKeys, 'pos', tracks );
  21562. addNonemptyTrack(
  21563. QuaternionKeyframeTrack, boneName + '.quaternion',
  21564. animationKeys, 'rot', tracks );
  21565. addNonemptyTrack(
  21566. VectorKeyframeTrack, boneName + '.scale',
  21567. animationKeys, 'scl', tracks );
  21568. }
  21569. }
  21570. if ( tracks.length === 0 ) {
  21571. return null;
  21572. }
  21573. var clip = new AnimationClip( clipName, duration, tracks, blendMode );
  21574. return clip;
  21575. }
  21576. } );
  21577. Object.assign( AnimationClip.prototype, {
  21578. resetDuration: function () {
  21579. var tracks = this.tracks, duration = 0;
  21580. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  21581. var track = this.tracks[ i ];
  21582. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21583. }
  21584. this.duration = duration;
  21585. return this;
  21586. },
  21587. trim: function () {
  21588. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21589. this.tracks[ i ].trim( 0, this.duration );
  21590. }
  21591. return this;
  21592. },
  21593. validate: function () {
  21594. var valid = true;
  21595. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21596. valid = valid && this.tracks[ i ].validate();
  21597. }
  21598. return valid;
  21599. },
  21600. optimize: function () {
  21601. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21602. this.tracks[ i ].optimize();
  21603. }
  21604. return this;
  21605. },
  21606. clone: function () {
  21607. var tracks = [];
  21608. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21609. tracks.push( this.tracks[ i ].clone() );
  21610. }
  21611. return new AnimationClip( this.name, this.duration, tracks, this.blendMode );
  21612. }
  21613. } );
  21614. /**
  21615. * @author mrdoob / http://mrdoob.com/
  21616. */
  21617. var Cache = {
  21618. enabled: false,
  21619. files: {},
  21620. add: function ( key, file ) {
  21621. if ( this.enabled === false ) return;
  21622. // console.log( 'THREE.Cache', 'Adding key:', key );
  21623. this.files[ key ] = file;
  21624. },
  21625. get: function ( key ) {
  21626. if ( this.enabled === false ) return;
  21627. // console.log( 'THREE.Cache', 'Checking key:', key );
  21628. return this.files[ key ];
  21629. },
  21630. remove: function ( key ) {
  21631. delete this.files[ key ];
  21632. },
  21633. clear: function () {
  21634. this.files = {};
  21635. }
  21636. };
  21637. /**
  21638. * @author mrdoob / http://mrdoob.com/
  21639. */
  21640. function LoadingManager( onLoad, onProgress, onError ) {
  21641. var scope = this;
  21642. var isLoading = false;
  21643. var itemsLoaded = 0;
  21644. var itemsTotal = 0;
  21645. var urlModifier = undefined;
  21646. var handlers = [];
  21647. // Refer to #5689 for the reason why we don't set .onStart
  21648. // in the constructor
  21649. this.onStart = undefined;
  21650. this.onLoad = onLoad;
  21651. this.onProgress = onProgress;
  21652. this.onError = onError;
  21653. this.itemStart = function ( url ) {
  21654. itemsTotal ++;
  21655. if ( isLoading === false ) {
  21656. if ( scope.onStart !== undefined ) {
  21657. scope.onStart( url, itemsLoaded, itemsTotal );
  21658. }
  21659. }
  21660. isLoading = true;
  21661. };
  21662. this.itemEnd = function ( url ) {
  21663. itemsLoaded ++;
  21664. if ( scope.onProgress !== undefined ) {
  21665. scope.onProgress( url, itemsLoaded, itemsTotal );
  21666. }
  21667. if ( itemsLoaded === itemsTotal ) {
  21668. isLoading = false;
  21669. if ( scope.onLoad !== undefined ) {
  21670. scope.onLoad();
  21671. }
  21672. }
  21673. };
  21674. this.itemError = function ( url ) {
  21675. if ( scope.onError !== undefined ) {
  21676. scope.onError( url );
  21677. }
  21678. };
  21679. this.resolveURL = function ( url ) {
  21680. if ( urlModifier ) {
  21681. return urlModifier( url );
  21682. }
  21683. return url;
  21684. };
  21685. this.setURLModifier = function ( transform ) {
  21686. urlModifier = transform;
  21687. return this;
  21688. };
  21689. this.addHandler = function ( regex, loader ) {
  21690. handlers.push( regex, loader );
  21691. return this;
  21692. };
  21693. this.removeHandler = function ( regex ) {
  21694. var index = handlers.indexOf( regex );
  21695. if ( index !== - 1 ) {
  21696. handlers.splice( index, 2 );
  21697. }
  21698. return this;
  21699. };
  21700. this.getHandler = function ( file ) {
  21701. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  21702. var regex = handlers[ i ];
  21703. var loader = handlers[ i + 1 ];
  21704. if ( regex.global ) regex.lastIndex = 0; // see #17920
  21705. if ( regex.test( file ) ) {
  21706. return loader;
  21707. }
  21708. }
  21709. return null;
  21710. };
  21711. }
  21712. var DefaultLoadingManager = new LoadingManager();
  21713. /**
  21714. * @author alteredq / http://alteredqualia.com/
  21715. */
  21716. function Loader( manager ) {
  21717. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21718. this.crossOrigin = 'anonymous';
  21719. this.path = '';
  21720. this.resourcePath = '';
  21721. this.requestHeader = {};
  21722. }
  21723. Object.assign( Loader.prototype, {
  21724. load: function ( /* url, onLoad, onProgress, onError */ ) {},
  21725. loadAsync: function ( url, onProgress ) {
  21726. var scope = this;
  21727. return new Promise( function ( resolve, reject ) {
  21728. scope.load( url, resolve, onProgress, reject );
  21729. } );
  21730. },
  21731. parse: function ( /* data */ ) {},
  21732. setCrossOrigin: function ( crossOrigin ) {
  21733. this.crossOrigin = crossOrigin;
  21734. return this;
  21735. },
  21736. setPath: function ( path ) {
  21737. this.path = path;
  21738. return this;
  21739. },
  21740. setResourcePath: function ( resourcePath ) {
  21741. this.resourcePath = resourcePath;
  21742. return this;
  21743. },
  21744. setRequestHeader: function ( requestHeader ) {
  21745. this.requestHeader = requestHeader;
  21746. return this;
  21747. }
  21748. } );
  21749. /**
  21750. * @author mrdoob / http://mrdoob.com/
  21751. */
  21752. var loading = {};
  21753. function FileLoader( manager ) {
  21754. Loader.call( this, manager );
  21755. }
  21756. FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21757. constructor: FileLoader,
  21758. load: function ( url, onLoad, onProgress, onError ) {
  21759. if ( url === undefined ) url = '';
  21760. if ( this.path !== undefined ) url = this.path + url;
  21761. url = this.manager.resolveURL( url );
  21762. var scope = this;
  21763. var cached = Cache.get( url );
  21764. if ( cached !== undefined ) {
  21765. scope.manager.itemStart( url );
  21766. setTimeout( function () {
  21767. if ( onLoad ) onLoad( cached );
  21768. scope.manager.itemEnd( url );
  21769. }, 0 );
  21770. return cached;
  21771. }
  21772. // Check if request is duplicate
  21773. if ( loading[ url ] !== undefined ) {
  21774. loading[ url ].push( {
  21775. onLoad: onLoad,
  21776. onProgress: onProgress,
  21777. onError: onError
  21778. } );
  21779. return;
  21780. }
  21781. // Check for data: URI
  21782. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21783. var dataUriRegexResult = url.match( dataUriRegex );
  21784. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21785. if ( dataUriRegexResult ) {
  21786. var mimeType = dataUriRegexResult[ 1 ];
  21787. var isBase64 = !! dataUriRegexResult[ 2 ];
  21788. var data = dataUriRegexResult[ 3 ];
  21789. data = decodeURIComponent( data );
  21790. if ( isBase64 ) data = atob( data );
  21791. try {
  21792. var response;
  21793. var responseType = ( this.responseType || '' ).toLowerCase();
  21794. switch ( responseType ) {
  21795. case 'arraybuffer':
  21796. case 'blob':
  21797. var view = new Uint8Array( data.length );
  21798. for ( var i = 0; i < data.length; i ++ ) {
  21799. view[ i ] = data.charCodeAt( i );
  21800. }
  21801. if ( responseType === 'blob' ) {
  21802. response = new Blob( [ view.buffer ], { type: mimeType } );
  21803. } else {
  21804. response = view.buffer;
  21805. }
  21806. break;
  21807. case 'document':
  21808. var parser = new DOMParser();
  21809. response = parser.parseFromString( data, mimeType );
  21810. break;
  21811. case 'json':
  21812. response = JSON.parse( data );
  21813. break;
  21814. default: // 'text' or other
  21815. response = data;
  21816. break;
  21817. }
  21818. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21819. setTimeout( function () {
  21820. if ( onLoad ) onLoad( response );
  21821. scope.manager.itemEnd( url );
  21822. }, 0 );
  21823. } catch ( error ) {
  21824. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21825. setTimeout( function () {
  21826. if ( onError ) onError( error );
  21827. scope.manager.itemError( url );
  21828. scope.manager.itemEnd( url );
  21829. }, 0 );
  21830. }
  21831. } else {
  21832. // Initialise array for duplicate requests
  21833. loading[ url ] = [];
  21834. loading[ url ].push( {
  21835. onLoad: onLoad,
  21836. onProgress: onProgress,
  21837. onError: onError
  21838. } );
  21839. var request = new XMLHttpRequest();
  21840. request.open( 'GET', url, true );
  21841. request.addEventListener( 'load', function ( event ) {
  21842. var response = this.response;
  21843. var callbacks = loading[ url ];
  21844. delete loading[ url ];
  21845. if ( this.status === 200 || this.status === 0 ) {
  21846. // Some browsers return HTTP Status 0 when using non-http protocol
  21847. // e.g. 'file://' or 'data://'. Handle as success.
  21848. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  21849. // Add to cache only on HTTP success, so that we do not cache
  21850. // error response bodies as proper responses to requests.
  21851. Cache.add( url, response );
  21852. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21853. var callback = callbacks[ i ];
  21854. if ( callback.onLoad ) callback.onLoad( response );
  21855. }
  21856. scope.manager.itemEnd( url );
  21857. } else {
  21858. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21859. var callback = callbacks[ i ];
  21860. if ( callback.onError ) callback.onError( event );
  21861. }
  21862. scope.manager.itemError( url );
  21863. scope.manager.itemEnd( url );
  21864. }
  21865. }, false );
  21866. request.addEventListener( 'progress', function ( event ) {
  21867. var callbacks = loading[ url ];
  21868. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21869. var callback = callbacks[ i ];
  21870. if ( callback.onProgress ) callback.onProgress( event );
  21871. }
  21872. }, false );
  21873. request.addEventListener( 'error', function ( event ) {
  21874. var callbacks = loading[ url ];
  21875. delete loading[ url ];
  21876. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21877. var callback = callbacks[ i ];
  21878. if ( callback.onError ) callback.onError( event );
  21879. }
  21880. scope.manager.itemError( url );
  21881. scope.manager.itemEnd( url );
  21882. }, false );
  21883. request.addEventListener( 'abort', function ( event ) {
  21884. var callbacks = loading[ url ];
  21885. delete loading[ url ];
  21886. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21887. var callback = callbacks[ i ];
  21888. if ( callback.onError ) callback.onError( event );
  21889. }
  21890. scope.manager.itemError( url );
  21891. scope.manager.itemEnd( url );
  21892. }, false );
  21893. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  21894. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  21895. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  21896. for ( var header in this.requestHeader ) {
  21897. request.setRequestHeader( header, this.requestHeader[ header ] );
  21898. }
  21899. request.send( null );
  21900. }
  21901. scope.manager.itemStart( url );
  21902. return request;
  21903. },
  21904. setResponseType: function ( value ) {
  21905. this.responseType = value;
  21906. return this;
  21907. },
  21908. setWithCredentials: function ( value ) {
  21909. this.withCredentials = value;
  21910. return this;
  21911. },
  21912. setMimeType: function ( value ) {
  21913. this.mimeType = value;
  21914. return this;
  21915. }
  21916. } );
  21917. /**
  21918. * @author bhouston / http://clara.io/
  21919. */
  21920. function AnimationLoader( manager ) {
  21921. Loader.call( this, manager );
  21922. }
  21923. AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21924. constructor: AnimationLoader,
  21925. load: function ( url, onLoad, onProgress, onError ) {
  21926. var scope = this;
  21927. var loader = new FileLoader( scope.manager );
  21928. loader.setPath( scope.path );
  21929. loader.load( url, function ( text ) {
  21930. try {
  21931. onLoad( scope.parse( JSON.parse( text ) ) );
  21932. } catch ( e ) {
  21933. if ( onError ) {
  21934. onError( e );
  21935. } else {
  21936. console.error( e );
  21937. }
  21938. scope.manager.itemError( url );
  21939. }
  21940. }, onProgress, onError );
  21941. },
  21942. parse: function ( json ) {
  21943. var animations = [];
  21944. for ( var i = 0; i < json.length; i ++ ) {
  21945. var clip = AnimationClip.parse( json[ i ] );
  21946. animations.push( clip );
  21947. }
  21948. return animations;
  21949. }
  21950. } );
  21951. /**
  21952. * @author mrdoob / http://mrdoob.com/
  21953. *
  21954. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21955. *
  21956. * Sub classes have to implement the parse() method which will be used in load().
  21957. */
  21958. function CompressedTextureLoader( manager ) {
  21959. Loader.call( this, manager );
  21960. }
  21961. CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21962. constructor: CompressedTextureLoader,
  21963. load: function ( url, onLoad, onProgress, onError ) {
  21964. var scope = this;
  21965. var images = [];
  21966. var texture = new CompressedTexture();
  21967. texture.image = images;
  21968. var loader = new FileLoader( this.manager );
  21969. loader.setPath( this.path );
  21970. loader.setResponseType( 'arraybuffer' );
  21971. function loadTexture( i ) {
  21972. loader.load( url[ i ], function ( buffer ) {
  21973. var texDatas = scope.parse( buffer, true );
  21974. images[ i ] = {
  21975. width: texDatas.width,
  21976. height: texDatas.height,
  21977. format: texDatas.format,
  21978. mipmaps: texDatas.mipmaps
  21979. };
  21980. loaded += 1;
  21981. if ( loaded === 6 ) {
  21982. if ( texDatas.mipmapCount === 1 )
  21983. texture.minFilter = LinearFilter;
  21984. texture.format = texDatas.format;
  21985. texture.needsUpdate = true;
  21986. if ( onLoad ) onLoad( texture );
  21987. }
  21988. }, onProgress, onError );
  21989. }
  21990. if ( Array.isArray( url ) ) {
  21991. var loaded = 0;
  21992. for ( var i = 0, il = url.length; i < il; ++ i ) {
  21993. loadTexture( i );
  21994. }
  21995. } else {
  21996. // compressed cubemap texture stored in a single DDS file
  21997. loader.load( url, function ( buffer ) {
  21998. var texDatas = scope.parse( buffer, true );
  21999. if ( texDatas.isCubemap ) {
  22000. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22001. for ( var f = 0; f < faces; f ++ ) {
  22002. images[ f ] = { mipmaps: [] };
  22003. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  22004. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  22005. images[ f ].format = texDatas.format;
  22006. images[ f ].width = texDatas.width;
  22007. images[ f ].height = texDatas.height;
  22008. }
  22009. }
  22010. } else {
  22011. texture.image.width = texDatas.width;
  22012. texture.image.height = texDatas.height;
  22013. texture.mipmaps = texDatas.mipmaps;
  22014. }
  22015. if ( texDatas.mipmapCount === 1 ) {
  22016. texture.minFilter = LinearFilter;
  22017. }
  22018. texture.format = texDatas.format;
  22019. texture.needsUpdate = true;
  22020. if ( onLoad ) onLoad( texture );
  22021. }, onProgress, onError );
  22022. }
  22023. return texture;
  22024. }
  22025. } );
  22026. /**
  22027. * @author Nikos M. / https://github.com/foo123/
  22028. *
  22029. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22030. *
  22031. * Sub classes have to implement the parse() method which will be used in load().
  22032. */
  22033. function DataTextureLoader( manager ) {
  22034. Loader.call( this, manager );
  22035. }
  22036. DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22037. constructor: DataTextureLoader,
  22038. load: function ( url, onLoad, onProgress, onError ) {
  22039. var scope = this;
  22040. var texture = new DataTexture();
  22041. var loader = new FileLoader( this.manager );
  22042. loader.setResponseType( 'arraybuffer' );
  22043. loader.setPath( this.path );
  22044. loader.load( url, function ( buffer ) {
  22045. var texData = scope.parse( buffer );
  22046. if ( ! texData ) return;
  22047. if ( texData.image !== undefined ) {
  22048. texture.image = texData.image;
  22049. } else if ( texData.data !== undefined ) {
  22050. texture.image.width = texData.width;
  22051. texture.image.height = texData.height;
  22052. texture.image.data = texData.data;
  22053. }
  22054. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22055. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22056. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22057. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22058. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22059. if ( texData.format !== undefined ) {
  22060. texture.format = texData.format;
  22061. }
  22062. if ( texData.type !== undefined ) {
  22063. texture.type = texData.type;
  22064. }
  22065. if ( texData.mipmaps !== undefined ) {
  22066. texture.mipmaps = texData.mipmaps;
  22067. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22068. }
  22069. if ( texData.mipmapCount === 1 ) {
  22070. texture.minFilter = LinearFilter;
  22071. }
  22072. texture.needsUpdate = true;
  22073. if ( onLoad ) onLoad( texture, texData );
  22074. }, onProgress, onError );
  22075. return texture;
  22076. }
  22077. } );
  22078. /**
  22079. * @author mrdoob / http://mrdoob.com/
  22080. */
  22081. function ImageLoader( manager ) {
  22082. Loader.call( this, manager );
  22083. }
  22084. ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22085. constructor: ImageLoader,
  22086. load: function ( url, onLoad, onProgress, onError ) {
  22087. if ( this.path !== undefined ) url = this.path + url;
  22088. url = this.manager.resolveURL( url );
  22089. var scope = this;
  22090. var cached = Cache.get( url );
  22091. if ( cached !== undefined ) {
  22092. scope.manager.itemStart( url );
  22093. setTimeout( function () {
  22094. if ( onLoad ) onLoad( cached );
  22095. scope.manager.itemEnd( url );
  22096. }, 0 );
  22097. return cached;
  22098. }
  22099. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  22100. function onImageLoad() {
  22101. image.removeEventListener( 'load', onImageLoad, false );
  22102. image.removeEventListener( 'error', onImageError, false );
  22103. Cache.add( url, this );
  22104. if ( onLoad ) onLoad( this );
  22105. scope.manager.itemEnd( url );
  22106. }
  22107. function onImageError( event ) {
  22108. image.removeEventListener( 'load', onImageLoad, false );
  22109. image.removeEventListener( 'error', onImageError, false );
  22110. if ( onError ) onError( event );
  22111. scope.manager.itemError( url );
  22112. scope.manager.itemEnd( url );
  22113. }
  22114. image.addEventListener( 'load', onImageLoad, false );
  22115. image.addEventListener( 'error', onImageError, false );
  22116. if ( url.substr( 0, 5 ) !== 'data:' ) {
  22117. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  22118. }
  22119. scope.manager.itemStart( url );
  22120. image.src = url;
  22121. return image;
  22122. }
  22123. } );
  22124. /**
  22125. * @author mrdoob / http://mrdoob.com/
  22126. */
  22127. function CubeTextureLoader( manager ) {
  22128. Loader.call( this, manager );
  22129. }
  22130. CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22131. constructor: CubeTextureLoader,
  22132. load: function ( urls, onLoad, onProgress, onError ) {
  22133. var texture = new CubeTexture();
  22134. var loader = new ImageLoader( this.manager );
  22135. loader.setCrossOrigin( this.crossOrigin );
  22136. loader.setPath( this.path );
  22137. var loaded = 0;
  22138. function loadTexture( i ) {
  22139. loader.load( urls[ i ], function ( image ) {
  22140. texture.images[ i ] = image;
  22141. loaded ++;
  22142. if ( loaded === 6 ) {
  22143. texture.needsUpdate = true;
  22144. if ( onLoad ) onLoad( texture );
  22145. }
  22146. }, undefined, onError );
  22147. }
  22148. for ( var i = 0; i < urls.length; ++ i ) {
  22149. loadTexture( i );
  22150. }
  22151. return texture;
  22152. }
  22153. } );
  22154. /**
  22155. * @author mrdoob / http://mrdoob.com/
  22156. */
  22157. function TextureLoader( manager ) {
  22158. Loader.call( this, manager );
  22159. }
  22160. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22161. constructor: TextureLoader,
  22162. load: function ( url, onLoad, onProgress, onError ) {
  22163. var texture = new Texture();
  22164. var loader = new ImageLoader( this.manager );
  22165. loader.setCrossOrigin( this.crossOrigin );
  22166. loader.setPath( this.path );
  22167. loader.load( url, function ( image ) {
  22168. texture.image = image;
  22169. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22170. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  22171. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22172. texture.needsUpdate = true;
  22173. if ( onLoad !== undefined ) {
  22174. onLoad( texture );
  22175. }
  22176. }, onProgress, onError );
  22177. return texture;
  22178. }
  22179. } );
  22180. /**
  22181. * @author zz85 / http://www.lab4games.net/zz85/blog
  22182. * Extensible curve object
  22183. *
  22184. * Some common of curve methods:
  22185. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22186. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22187. * .getPoints(), .getSpacedPoints()
  22188. * .getLength()
  22189. * .updateArcLengths()
  22190. *
  22191. * This following curves inherit from THREE.Curve:
  22192. *
  22193. * -- 2D curves --
  22194. * THREE.ArcCurve
  22195. * THREE.CubicBezierCurve
  22196. * THREE.EllipseCurve
  22197. * THREE.LineCurve
  22198. * THREE.QuadraticBezierCurve
  22199. * THREE.SplineCurve
  22200. *
  22201. * -- 3D curves --
  22202. * THREE.CatmullRomCurve3
  22203. * THREE.CubicBezierCurve3
  22204. * THREE.LineCurve3
  22205. * THREE.QuadraticBezierCurve3
  22206. *
  22207. * A series of curves can be represented as a THREE.CurvePath.
  22208. *
  22209. **/
  22210. /**************************************************************
  22211. * Abstract Curve base class
  22212. **************************************************************/
  22213. function Curve() {
  22214. this.type = 'Curve';
  22215. this.arcLengthDivisions = 200;
  22216. }
  22217. Object.assign( Curve.prototype, {
  22218. // Virtual base class method to overwrite and implement in subclasses
  22219. // - t [0 .. 1]
  22220. getPoint: function ( /* t, optionalTarget */ ) {
  22221. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  22222. return null;
  22223. },
  22224. // Get point at relative position in curve according to arc length
  22225. // - u [0 .. 1]
  22226. getPointAt: function ( u, optionalTarget ) {
  22227. var t = this.getUtoTmapping( u );
  22228. return this.getPoint( t, optionalTarget );
  22229. },
  22230. // Get sequence of points using getPoint( t )
  22231. getPoints: function ( divisions ) {
  22232. if ( divisions === undefined ) divisions = 5;
  22233. var points = [];
  22234. for ( var d = 0; d <= divisions; d ++ ) {
  22235. points.push( this.getPoint( d / divisions ) );
  22236. }
  22237. return points;
  22238. },
  22239. // Get sequence of points using getPointAt( u )
  22240. getSpacedPoints: function ( divisions ) {
  22241. if ( divisions === undefined ) divisions = 5;
  22242. var points = [];
  22243. for ( var d = 0; d <= divisions; d ++ ) {
  22244. points.push( this.getPointAt( d / divisions ) );
  22245. }
  22246. return points;
  22247. },
  22248. // Get total curve arc length
  22249. getLength: function () {
  22250. var lengths = this.getLengths();
  22251. return lengths[ lengths.length - 1 ];
  22252. },
  22253. // Get list of cumulative segment lengths
  22254. getLengths: function ( divisions ) {
  22255. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  22256. if ( this.cacheArcLengths &&
  22257. ( this.cacheArcLengths.length === divisions + 1 ) &&
  22258. ! this.needsUpdate ) {
  22259. return this.cacheArcLengths;
  22260. }
  22261. this.needsUpdate = false;
  22262. var cache = [];
  22263. var current, last = this.getPoint( 0 );
  22264. var p, sum = 0;
  22265. cache.push( 0 );
  22266. for ( p = 1; p <= divisions; p ++ ) {
  22267. current = this.getPoint( p / divisions );
  22268. sum += current.distanceTo( last );
  22269. cache.push( sum );
  22270. last = current;
  22271. }
  22272. this.cacheArcLengths = cache;
  22273. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22274. },
  22275. updateArcLengths: function () {
  22276. this.needsUpdate = true;
  22277. this.getLengths();
  22278. },
  22279. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22280. getUtoTmapping: function ( u, distance ) {
  22281. var arcLengths = this.getLengths();
  22282. var i = 0, il = arcLengths.length;
  22283. var targetArcLength; // The targeted u distance value to get
  22284. if ( distance ) {
  22285. targetArcLength = distance;
  22286. } else {
  22287. targetArcLength = u * arcLengths[ il - 1 ];
  22288. }
  22289. // binary search for the index with largest value smaller than target u distance
  22290. var low = 0, high = il - 1, comparison;
  22291. while ( low <= high ) {
  22292. 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
  22293. comparison = arcLengths[ i ] - targetArcLength;
  22294. if ( comparison < 0 ) {
  22295. low = i + 1;
  22296. } else if ( comparison > 0 ) {
  22297. high = i - 1;
  22298. } else {
  22299. high = i;
  22300. break;
  22301. // DONE
  22302. }
  22303. }
  22304. i = high;
  22305. if ( arcLengths[ i ] === targetArcLength ) {
  22306. return i / ( il - 1 );
  22307. }
  22308. // we could get finer grain at lengths, or use simple interpolation between two points
  22309. var lengthBefore = arcLengths[ i ];
  22310. var lengthAfter = arcLengths[ i + 1 ];
  22311. var segmentLength = lengthAfter - lengthBefore;
  22312. // determine where we are between the 'before' and 'after' points
  22313. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  22314. // add that fractional amount to t
  22315. var t = ( i + segmentFraction ) / ( il - 1 );
  22316. return t;
  22317. },
  22318. // Returns a unit vector tangent at t
  22319. // In case any sub curve does not implement its tangent derivation,
  22320. // 2 points a small delta apart will be used to find its gradient
  22321. // which seems to give a reasonable approximation
  22322. getTangent: function ( t, optionalTarget ) {
  22323. var delta = 0.0001;
  22324. var t1 = t - delta;
  22325. var t2 = t + delta;
  22326. // Capping in case of danger
  22327. if ( t1 < 0 ) t1 = 0;
  22328. if ( t2 > 1 ) t2 = 1;
  22329. var pt1 = this.getPoint( t1 );
  22330. var pt2 = this.getPoint( t2 );
  22331. var tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  22332. tangent.copy( pt2 ).sub( pt1 ).normalize();
  22333. return tangent;
  22334. },
  22335. getTangentAt: function ( u, optionalTarget ) {
  22336. var t = this.getUtoTmapping( u );
  22337. return this.getTangent( t, optionalTarget );
  22338. },
  22339. computeFrenetFrames: function ( segments, closed ) {
  22340. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22341. var normal = new Vector3();
  22342. var tangents = [];
  22343. var normals = [];
  22344. var binormals = [];
  22345. var vec = new Vector3();
  22346. var mat = new Matrix4();
  22347. var i, u, theta;
  22348. // compute the tangent vectors for each segment on the curve
  22349. for ( i = 0; i <= segments; i ++ ) {
  22350. u = i / segments;
  22351. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  22352. tangents[ i ].normalize();
  22353. }
  22354. // select an initial normal vector perpendicular to the first tangent vector,
  22355. // and in the direction of the minimum tangent xyz component
  22356. normals[ 0 ] = new Vector3();
  22357. binormals[ 0 ] = new Vector3();
  22358. var min = Number.MAX_VALUE;
  22359. var tx = Math.abs( tangents[ 0 ].x );
  22360. var ty = Math.abs( tangents[ 0 ].y );
  22361. var tz = Math.abs( tangents[ 0 ].z );
  22362. if ( tx <= min ) {
  22363. min = tx;
  22364. normal.set( 1, 0, 0 );
  22365. }
  22366. if ( ty <= min ) {
  22367. min = ty;
  22368. normal.set( 0, 1, 0 );
  22369. }
  22370. if ( tz <= min ) {
  22371. normal.set( 0, 0, 1 );
  22372. }
  22373. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22374. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22375. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22376. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22377. for ( i = 1; i <= segments; i ++ ) {
  22378. normals[ i ] = normals[ i - 1 ].clone();
  22379. binormals[ i ] = binormals[ i - 1 ].clone();
  22380. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  22381. if ( vec.length() > Number.EPSILON ) {
  22382. vec.normalize();
  22383. theta = Math.acos( MathUtils.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  22384. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22385. }
  22386. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22387. }
  22388. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22389. if ( closed === true ) {
  22390. theta = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  22391. theta /= segments;
  22392. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  22393. theta = - theta;
  22394. }
  22395. for ( i = 1; i <= segments; i ++ ) {
  22396. // twist a little...
  22397. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  22398. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22399. }
  22400. }
  22401. return {
  22402. tangents: tangents,
  22403. normals: normals,
  22404. binormals: binormals
  22405. };
  22406. },
  22407. clone: function () {
  22408. return new this.constructor().copy( this );
  22409. },
  22410. copy: function ( source ) {
  22411. this.arcLengthDivisions = source.arcLengthDivisions;
  22412. return this;
  22413. },
  22414. toJSON: function () {
  22415. var data = {
  22416. metadata: {
  22417. version: 4.5,
  22418. type: 'Curve',
  22419. generator: 'Curve.toJSON'
  22420. }
  22421. };
  22422. data.arcLengthDivisions = this.arcLengthDivisions;
  22423. data.type = this.type;
  22424. return data;
  22425. },
  22426. fromJSON: function ( json ) {
  22427. this.arcLengthDivisions = json.arcLengthDivisions;
  22428. return this;
  22429. }
  22430. } );
  22431. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22432. Curve.call( this );
  22433. this.type = 'EllipseCurve';
  22434. this.aX = aX || 0;
  22435. this.aY = aY || 0;
  22436. this.xRadius = xRadius || 1;
  22437. this.yRadius = yRadius || 1;
  22438. this.aStartAngle = aStartAngle || 0;
  22439. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22440. this.aClockwise = aClockwise || false;
  22441. this.aRotation = aRotation || 0;
  22442. }
  22443. EllipseCurve.prototype = Object.create( Curve.prototype );
  22444. EllipseCurve.prototype.constructor = EllipseCurve;
  22445. EllipseCurve.prototype.isEllipseCurve = true;
  22446. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22447. var point = optionalTarget || new Vector2();
  22448. var twoPi = Math.PI * 2;
  22449. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22450. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  22451. // ensures that deltaAngle is 0 .. 2 PI
  22452. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  22453. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  22454. if ( deltaAngle < Number.EPSILON ) {
  22455. if ( samePoints ) {
  22456. deltaAngle = 0;
  22457. } else {
  22458. deltaAngle = twoPi;
  22459. }
  22460. }
  22461. if ( this.aClockwise === true && ! samePoints ) {
  22462. if ( deltaAngle === twoPi ) {
  22463. deltaAngle = - twoPi;
  22464. } else {
  22465. deltaAngle = deltaAngle - twoPi;
  22466. }
  22467. }
  22468. var angle = this.aStartAngle + t * deltaAngle;
  22469. var x = this.aX + this.xRadius * Math.cos( angle );
  22470. var y = this.aY + this.yRadius * Math.sin( angle );
  22471. if ( this.aRotation !== 0 ) {
  22472. var cos = Math.cos( this.aRotation );
  22473. var sin = Math.sin( this.aRotation );
  22474. var tx = x - this.aX;
  22475. var ty = y - this.aY;
  22476. // Rotate the point about the center of the ellipse.
  22477. x = tx * cos - ty * sin + this.aX;
  22478. y = tx * sin + ty * cos + this.aY;
  22479. }
  22480. return point.set( x, y );
  22481. };
  22482. EllipseCurve.prototype.copy = function ( source ) {
  22483. Curve.prototype.copy.call( this, source );
  22484. this.aX = source.aX;
  22485. this.aY = source.aY;
  22486. this.xRadius = source.xRadius;
  22487. this.yRadius = source.yRadius;
  22488. this.aStartAngle = source.aStartAngle;
  22489. this.aEndAngle = source.aEndAngle;
  22490. this.aClockwise = source.aClockwise;
  22491. this.aRotation = source.aRotation;
  22492. return this;
  22493. };
  22494. EllipseCurve.prototype.toJSON = function () {
  22495. var data = Curve.prototype.toJSON.call( this );
  22496. data.aX = this.aX;
  22497. data.aY = this.aY;
  22498. data.xRadius = this.xRadius;
  22499. data.yRadius = this.yRadius;
  22500. data.aStartAngle = this.aStartAngle;
  22501. data.aEndAngle = this.aEndAngle;
  22502. data.aClockwise = this.aClockwise;
  22503. data.aRotation = this.aRotation;
  22504. return data;
  22505. };
  22506. EllipseCurve.prototype.fromJSON = function ( json ) {
  22507. Curve.prototype.fromJSON.call( this, json );
  22508. this.aX = json.aX;
  22509. this.aY = json.aY;
  22510. this.xRadius = json.xRadius;
  22511. this.yRadius = json.yRadius;
  22512. this.aStartAngle = json.aStartAngle;
  22513. this.aEndAngle = json.aEndAngle;
  22514. this.aClockwise = json.aClockwise;
  22515. this.aRotation = json.aRotation;
  22516. return this;
  22517. };
  22518. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22519. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22520. this.type = 'ArcCurve';
  22521. }
  22522. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  22523. ArcCurve.prototype.constructor = ArcCurve;
  22524. ArcCurve.prototype.isArcCurve = true;
  22525. /**
  22526. * @author zz85 https://github.com/zz85
  22527. *
  22528. * Centripetal CatmullRom Curve - which is useful for avoiding
  22529. * cusps and self-intersections in non-uniform catmull rom curves.
  22530. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22531. *
  22532. * curve.type accepts centripetal(default), chordal and catmullrom
  22533. * curve.tension is used for catmullrom which defaults to 0.5
  22534. */
  22535. /*
  22536. Based on an optimized c++ solution in
  22537. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22538. - http://ideone.com/NoEbVM
  22539. This CubicPoly class could be used for reusing some variables and calculations,
  22540. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22541. which can be placed in CurveUtils.
  22542. */
  22543. function CubicPoly() {
  22544. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  22545. /*
  22546. * Compute coefficients for a cubic polynomial
  22547. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22548. * such that
  22549. * p(0) = x0, p(1) = x1
  22550. * and
  22551. * p'(0) = t0, p'(1) = t1.
  22552. */
  22553. function init( x0, x1, t0, t1 ) {
  22554. c0 = x0;
  22555. c1 = t0;
  22556. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  22557. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22558. }
  22559. return {
  22560. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  22561. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  22562. },
  22563. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  22564. // compute tangents when parameterized in [t1,t2]
  22565. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  22566. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  22567. // rescale tangents for parametrization in [0,1]
  22568. t1 *= dt1;
  22569. t2 *= dt1;
  22570. init( x1, x2, t1, t2 );
  22571. },
  22572. calc: function ( t ) {
  22573. var t2 = t * t;
  22574. var t3 = t2 * t;
  22575. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22576. }
  22577. };
  22578. }
  22579. //
  22580. var tmp = new Vector3();
  22581. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  22582. function CatmullRomCurve3( points, closed, curveType, tension ) {
  22583. Curve.call( this );
  22584. this.type = 'CatmullRomCurve3';
  22585. this.points = points || [];
  22586. this.closed = closed || false;
  22587. this.curveType = curveType || 'centripetal';
  22588. this.tension = tension || 0.5;
  22589. }
  22590. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  22591. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22592. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22593. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22594. var point = optionalTarget || new Vector3();
  22595. var points = this.points;
  22596. var l = points.length;
  22597. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  22598. var intPoint = Math.floor( p );
  22599. var weight = p - intPoint;
  22600. if ( this.closed ) {
  22601. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  22602. } else if ( weight === 0 && intPoint === l - 1 ) {
  22603. intPoint = l - 2;
  22604. weight = 1;
  22605. }
  22606. var p0, p1, p2, p3; // 4 points
  22607. if ( this.closed || intPoint > 0 ) {
  22608. p0 = points[ ( intPoint - 1 ) % l ];
  22609. } else {
  22610. // extrapolate first point
  22611. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  22612. p0 = tmp;
  22613. }
  22614. p1 = points[ intPoint % l ];
  22615. p2 = points[ ( intPoint + 1 ) % l ];
  22616. if ( this.closed || intPoint + 2 < l ) {
  22617. p3 = points[ ( intPoint + 2 ) % l ];
  22618. } else {
  22619. // extrapolate last point
  22620. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  22621. p3 = tmp;
  22622. }
  22623. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  22624. // init Centripetal / Chordal Catmull-Rom
  22625. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22626. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  22627. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  22628. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  22629. // safety check for repeated points
  22630. if ( dt1 < 1e-4 ) dt1 = 1.0;
  22631. if ( dt0 < 1e-4 ) dt0 = dt1;
  22632. if ( dt2 < 1e-4 ) dt2 = dt1;
  22633. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  22634. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  22635. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  22636. } else if ( this.curveType === 'catmullrom' ) {
  22637. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  22638. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  22639. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  22640. }
  22641. point.set(
  22642. px.calc( weight ),
  22643. py.calc( weight ),
  22644. pz.calc( weight )
  22645. );
  22646. return point;
  22647. };
  22648. CatmullRomCurve3.prototype.copy = function ( source ) {
  22649. Curve.prototype.copy.call( this, source );
  22650. this.points = [];
  22651. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22652. var point = source.points[ i ];
  22653. this.points.push( point.clone() );
  22654. }
  22655. this.closed = source.closed;
  22656. this.curveType = source.curveType;
  22657. this.tension = source.tension;
  22658. return this;
  22659. };
  22660. CatmullRomCurve3.prototype.toJSON = function () {
  22661. var data = Curve.prototype.toJSON.call( this );
  22662. data.points = [];
  22663. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22664. var point = this.points[ i ];
  22665. data.points.push( point.toArray() );
  22666. }
  22667. data.closed = this.closed;
  22668. data.curveType = this.curveType;
  22669. data.tension = this.tension;
  22670. return data;
  22671. };
  22672. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  22673. Curve.prototype.fromJSON.call( this, json );
  22674. this.points = [];
  22675. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22676. var point = json.points[ i ];
  22677. this.points.push( new Vector3().fromArray( point ) );
  22678. }
  22679. this.closed = json.closed;
  22680. this.curveType = json.curveType;
  22681. this.tension = json.tension;
  22682. return this;
  22683. };
  22684. /**
  22685. * @author zz85 / http://www.lab4games.net/zz85/blog
  22686. *
  22687. * Bezier Curves formulas obtained from
  22688. * http://en.wikipedia.org/wiki/Bézier_curve
  22689. */
  22690. function CatmullRom( t, p0, p1, p2, p3 ) {
  22691. var v0 = ( p2 - p0 ) * 0.5;
  22692. var v1 = ( p3 - p1 ) * 0.5;
  22693. var t2 = t * t;
  22694. var t3 = t * t2;
  22695. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  22696. }
  22697. //
  22698. function QuadraticBezierP0( t, p ) {
  22699. var k = 1 - t;
  22700. return k * k * p;
  22701. }
  22702. function QuadraticBezierP1( t, p ) {
  22703. return 2 * ( 1 - t ) * t * p;
  22704. }
  22705. function QuadraticBezierP2( t, p ) {
  22706. return t * t * p;
  22707. }
  22708. function QuadraticBezier( t, p0, p1, p2 ) {
  22709. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  22710. QuadraticBezierP2( t, p2 );
  22711. }
  22712. //
  22713. function CubicBezierP0( t, p ) {
  22714. var k = 1 - t;
  22715. return k * k * k * p;
  22716. }
  22717. function CubicBezierP1( t, p ) {
  22718. var k = 1 - t;
  22719. return 3 * k * k * t * p;
  22720. }
  22721. function CubicBezierP2( t, p ) {
  22722. return 3 * ( 1 - t ) * t * t * p;
  22723. }
  22724. function CubicBezierP3( t, p ) {
  22725. return t * t * t * p;
  22726. }
  22727. function CubicBezier( t, p0, p1, p2, p3 ) {
  22728. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  22729. CubicBezierP3( t, p3 );
  22730. }
  22731. function CubicBezierCurve( v0, v1, v2, v3 ) {
  22732. Curve.call( this );
  22733. this.type = 'CubicBezierCurve';
  22734. this.v0 = v0 || new Vector2();
  22735. this.v1 = v1 || new Vector2();
  22736. this.v2 = v2 || new Vector2();
  22737. this.v3 = v3 || new Vector2();
  22738. }
  22739. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  22740. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22741. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22742. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22743. var point = optionalTarget || new Vector2();
  22744. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22745. point.set(
  22746. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22747. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  22748. );
  22749. return point;
  22750. };
  22751. CubicBezierCurve.prototype.copy = function ( source ) {
  22752. Curve.prototype.copy.call( this, source );
  22753. this.v0.copy( source.v0 );
  22754. this.v1.copy( source.v1 );
  22755. this.v2.copy( source.v2 );
  22756. this.v3.copy( source.v3 );
  22757. return this;
  22758. };
  22759. CubicBezierCurve.prototype.toJSON = function () {
  22760. var data = Curve.prototype.toJSON.call( this );
  22761. data.v0 = this.v0.toArray();
  22762. data.v1 = this.v1.toArray();
  22763. data.v2 = this.v2.toArray();
  22764. data.v3 = this.v3.toArray();
  22765. return data;
  22766. };
  22767. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  22768. Curve.prototype.fromJSON.call( this, json );
  22769. this.v0.fromArray( json.v0 );
  22770. this.v1.fromArray( json.v1 );
  22771. this.v2.fromArray( json.v2 );
  22772. this.v3.fromArray( json.v3 );
  22773. return this;
  22774. };
  22775. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  22776. Curve.call( this );
  22777. this.type = 'CubicBezierCurve3';
  22778. this.v0 = v0 || new Vector3();
  22779. this.v1 = v1 || new Vector3();
  22780. this.v2 = v2 || new Vector3();
  22781. this.v3 = v3 || new Vector3();
  22782. }
  22783. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  22784. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22785. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22786. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22787. var point = optionalTarget || new Vector3();
  22788. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22789. point.set(
  22790. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22791. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  22792. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  22793. );
  22794. return point;
  22795. };
  22796. CubicBezierCurve3.prototype.copy = function ( source ) {
  22797. Curve.prototype.copy.call( this, source );
  22798. this.v0.copy( source.v0 );
  22799. this.v1.copy( source.v1 );
  22800. this.v2.copy( source.v2 );
  22801. this.v3.copy( source.v3 );
  22802. return this;
  22803. };
  22804. CubicBezierCurve3.prototype.toJSON = function () {
  22805. var data = Curve.prototype.toJSON.call( this );
  22806. data.v0 = this.v0.toArray();
  22807. data.v1 = this.v1.toArray();
  22808. data.v2 = this.v2.toArray();
  22809. data.v3 = this.v3.toArray();
  22810. return data;
  22811. };
  22812. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  22813. Curve.prototype.fromJSON.call( this, json );
  22814. this.v0.fromArray( json.v0 );
  22815. this.v1.fromArray( json.v1 );
  22816. this.v2.fromArray( json.v2 );
  22817. this.v3.fromArray( json.v3 );
  22818. return this;
  22819. };
  22820. function LineCurve( v1, v2 ) {
  22821. Curve.call( this );
  22822. this.type = 'LineCurve';
  22823. this.v1 = v1 || new Vector2();
  22824. this.v2 = v2 || new Vector2();
  22825. }
  22826. LineCurve.prototype = Object.create( Curve.prototype );
  22827. LineCurve.prototype.constructor = LineCurve;
  22828. LineCurve.prototype.isLineCurve = true;
  22829. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22830. var point = optionalTarget || new Vector2();
  22831. if ( t === 1 ) {
  22832. point.copy( this.v2 );
  22833. } else {
  22834. point.copy( this.v2 ).sub( this.v1 );
  22835. point.multiplyScalar( t ).add( this.v1 );
  22836. }
  22837. return point;
  22838. };
  22839. // Line curve is linear, so we can overwrite default getPointAt
  22840. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  22841. return this.getPoint( u, optionalTarget );
  22842. };
  22843. LineCurve.prototype.getTangent = function ( t, optionalTarget ) {
  22844. var tangent = optionalTarget || new Vector2();
  22845. var tangent = tangent.copy( this.v2 ).sub( this.v1 ).normalize();
  22846. return tangent;
  22847. };
  22848. LineCurve.prototype.copy = function ( source ) {
  22849. Curve.prototype.copy.call( this, source );
  22850. this.v1.copy( source.v1 );
  22851. this.v2.copy( source.v2 );
  22852. return this;
  22853. };
  22854. LineCurve.prototype.toJSON = function () {
  22855. var data = Curve.prototype.toJSON.call( this );
  22856. data.v1 = this.v1.toArray();
  22857. data.v2 = this.v2.toArray();
  22858. return data;
  22859. };
  22860. LineCurve.prototype.fromJSON = function ( json ) {
  22861. Curve.prototype.fromJSON.call( this, json );
  22862. this.v1.fromArray( json.v1 );
  22863. this.v2.fromArray( json.v2 );
  22864. return this;
  22865. };
  22866. function LineCurve3( v1, v2 ) {
  22867. Curve.call( this );
  22868. this.type = 'LineCurve3';
  22869. this.v1 = v1 || new Vector3();
  22870. this.v2 = v2 || new Vector3();
  22871. }
  22872. LineCurve3.prototype = Object.create( Curve.prototype );
  22873. LineCurve3.prototype.constructor = LineCurve3;
  22874. LineCurve3.prototype.isLineCurve3 = true;
  22875. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22876. var point = optionalTarget || new Vector3();
  22877. if ( t === 1 ) {
  22878. point.copy( this.v2 );
  22879. } else {
  22880. point.copy( this.v2 ).sub( this.v1 );
  22881. point.multiplyScalar( t ).add( this.v1 );
  22882. }
  22883. return point;
  22884. };
  22885. // Line curve is linear, so we can overwrite default getPointAt
  22886. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  22887. return this.getPoint( u, optionalTarget );
  22888. };
  22889. LineCurve3.prototype.copy = function ( source ) {
  22890. Curve.prototype.copy.call( this, source );
  22891. this.v1.copy( source.v1 );
  22892. this.v2.copy( source.v2 );
  22893. return this;
  22894. };
  22895. LineCurve3.prototype.toJSON = function () {
  22896. var data = Curve.prototype.toJSON.call( this );
  22897. data.v1 = this.v1.toArray();
  22898. data.v2 = this.v2.toArray();
  22899. return data;
  22900. };
  22901. LineCurve3.prototype.fromJSON = function ( json ) {
  22902. Curve.prototype.fromJSON.call( this, json );
  22903. this.v1.fromArray( json.v1 );
  22904. this.v2.fromArray( json.v2 );
  22905. return this;
  22906. };
  22907. function QuadraticBezierCurve( v0, v1, v2 ) {
  22908. Curve.call( this );
  22909. this.type = 'QuadraticBezierCurve';
  22910. this.v0 = v0 || new Vector2();
  22911. this.v1 = v1 || new Vector2();
  22912. this.v2 = v2 || new Vector2();
  22913. }
  22914. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  22915. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22916. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22917. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22918. var point = optionalTarget || new Vector2();
  22919. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22920. point.set(
  22921. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22922. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22923. );
  22924. return point;
  22925. };
  22926. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22927. Curve.prototype.copy.call( this, source );
  22928. this.v0.copy( source.v0 );
  22929. this.v1.copy( source.v1 );
  22930. this.v2.copy( source.v2 );
  22931. return this;
  22932. };
  22933. QuadraticBezierCurve.prototype.toJSON = function () {
  22934. var data = Curve.prototype.toJSON.call( this );
  22935. data.v0 = this.v0.toArray();
  22936. data.v1 = this.v1.toArray();
  22937. data.v2 = this.v2.toArray();
  22938. return data;
  22939. };
  22940. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22941. Curve.prototype.fromJSON.call( this, json );
  22942. this.v0.fromArray( json.v0 );
  22943. this.v1.fromArray( json.v1 );
  22944. this.v2.fromArray( json.v2 );
  22945. return this;
  22946. };
  22947. function QuadraticBezierCurve3( v0, v1, v2 ) {
  22948. Curve.call( this );
  22949. this.type = 'QuadraticBezierCurve3';
  22950. this.v0 = v0 || new Vector3();
  22951. this.v1 = v1 || new Vector3();
  22952. this.v2 = v2 || new Vector3();
  22953. }
  22954. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22955. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22956. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22957. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22958. var point = optionalTarget || new Vector3();
  22959. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22960. point.set(
  22961. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22962. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22963. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22964. );
  22965. return point;
  22966. };
  22967. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22968. Curve.prototype.copy.call( this, source );
  22969. this.v0.copy( source.v0 );
  22970. this.v1.copy( source.v1 );
  22971. this.v2.copy( source.v2 );
  22972. return this;
  22973. };
  22974. QuadraticBezierCurve3.prototype.toJSON = function () {
  22975. var data = Curve.prototype.toJSON.call( this );
  22976. data.v0 = this.v0.toArray();
  22977. data.v1 = this.v1.toArray();
  22978. data.v2 = this.v2.toArray();
  22979. return data;
  22980. };
  22981. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  22982. Curve.prototype.fromJSON.call( this, json );
  22983. this.v0.fromArray( json.v0 );
  22984. this.v1.fromArray( json.v1 );
  22985. this.v2.fromArray( json.v2 );
  22986. return this;
  22987. };
  22988. function SplineCurve( points /* array of Vector2 */ ) {
  22989. Curve.call( this );
  22990. this.type = 'SplineCurve';
  22991. this.points = points || [];
  22992. }
  22993. SplineCurve.prototype = Object.create( Curve.prototype );
  22994. SplineCurve.prototype.constructor = SplineCurve;
  22995. SplineCurve.prototype.isSplineCurve = true;
  22996. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22997. var point = optionalTarget || new Vector2();
  22998. var points = this.points;
  22999. var p = ( points.length - 1 ) * t;
  23000. var intPoint = Math.floor( p );
  23001. var weight = p - intPoint;
  23002. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  23003. var p1 = points[ intPoint ];
  23004. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  23005. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  23006. point.set(
  23007. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  23008. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  23009. );
  23010. return point;
  23011. };
  23012. SplineCurve.prototype.copy = function ( source ) {
  23013. Curve.prototype.copy.call( this, source );
  23014. this.points = [];
  23015. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  23016. var point = source.points[ i ];
  23017. this.points.push( point.clone() );
  23018. }
  23019. return this;
  23020. };
  23021. SplineCurve.prototype.toJSON = function () {
  23022. var data = Curve.prototype.toJSON.call( this );
  23023. data.points = [];
  23024. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  23025. var point = this.points[ i ];
  23026. data.points.push( point.toArray() );
  23027. }
  23028. return data;
  23029. };
  23030. SplineCurve.prototype.fromJSON = function ( json ) {
  23031. Curve.prototype.fromJSON.call( this, json );
  23032. this.points = [];
  23033. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  23034. var point = json.points[ i ];
  23035. this.points.push( new Vector2().fromArray( point ) );
  23036. }
  23037. return this;
  23038. };
  23039. var Curves = /*#__PURE__*/Object.freeze({
  23040. __proto__: null,
  23041. ArcCurve: ArcCurve,
  23042. CatmullRomCurve3: CatmullRomCurve3,
  23043. CubicBezierCurve: CubicBezierCurve,
  23044. CubicBezierCurve3: CubicBezierCurve3,
  23045. EllipseCurve: EllipseCurve,
  23046. LineCurve: LineCurve,
  23047. LineCurve3: LineCurve3,
  23048. QuadraticBezierCurve: QuadraticBezierCurve,
  23049. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23050. SplineCurve: SplineCurve
  23051. });
  23052. /**
  23053. * @author zz85 / http://www.lab4games.net/zz85/blog
  23054. *
  23055. **/
  23056. /**************************************************************
  23057. * Curved Path - a curve path is simply a array of connected
  23058. * curves, but retains the api of a curve
  23059. **************************************************************/
  23060. function CurvePath() {
  23061. Curve.call( this );
  23062. this.type = 'CurvePath';
  23063. this.curves = [];
  23064. this.autoClose = false; // Automatically closes the path
  23065. }
  23066. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  23067. constructor: CurvePath,
  23068. add: function ( curve ) {
  23069. this.curves.push( curve );
  23070. },
  23071. closePath: function () {
  23072. // Add a line curve if start and end of lines are not connected
  23073. var startPoint = this.curves[ 0 ].getPoint( 0 );
  23074. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  23075. if ( ! startPoint.equals( endPoint ) ) {
  23076. this.curves.push( new LineCurve( endPoint, startPoint ) );
  23077. }
  23078. },
  23079. // To get accurate point with reference to
  23080. // entire path distance at time t,
  23081. // following has to be done:
  23082. // 1. Length of each sub path have to be known
  23083. // 2. Locate and identify type of curve
  23084. // 3. Get t for the curve
  23085. // 4. Return curve.getPointAt(t')
  23086. getPoint: function ( t ) {
  23087. var d = t * this.getLength();
  23088. var curveLengths = this.getCurveLengths();
  23089. var i = 0;
  23090. // To think about boundaries points.
  23091. while ( i < curveLengths.length ) {
  23092. if ( curveLengths[ i ] >= d ) {
  23093. var diff = curveLengths[ i ] - d;
  23094. var curve = this.curves[ i ];
  23095. var segmentLength = curve.getLength();
  23096. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23097. return curve.getPointAt( u );
  23098. }
  23099. i ++;
  23100. }
  23101. return null;
  23102. // loop where sum != 0, sum > d , sum+1 <d
  23103. },
  23104. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23105. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23106. // getPoint() depends on getLength
  23107. getLength: function () {
  23108. var lens = this.getCurveLengths();
  23109. return lens[ lens.length - 1 ];
  23110. },
  23111. // cacheLengths must be recalculated.
  23112. updateArcLengths: function () {
  23113. this.needsUpdate = true;
  23114. this.cacheLengths = null;
  23115. this.getCurveLengths();
  23116. },
  23117. // Compute lengths and cache them
  23118. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23119. getCurveLengths: function () {
  23120. // We use cache values if curves and cache array are same length
  23121. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  23122. return this.cacheLengths;
  23123. }
  23124. // Get length of sub-curve
  23125. // Push sums into cached array
  23126. var lengths = [], sums = 0;
  23127. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  23128. sums += this.curves[ i ].getLength();
  23129. lengths.push( sums );
  23130. }
  23131. this.cacheLengths = lengths;
  23132. return lengths;
  23133. },
  23134. getSpacedPoints: function ( divisions ) {
  23135. if ( divisions === undefined ) divisions = 40;
  23136. var points = [];
  23137. for ( var i = 0; i <= divisions; i ++ ) {
  23138. points.push( this.getPoint( i / divisions ) );
  23139. }
  23140. if ( this.autoClose ) {
  23141. points.push( points[ 0 ] );
  23142. }
  23143. return points;
  23144. },
  23145. getPoints: function ( divisions ) {
  23146. divisions = divisions || 12;
  23147. var points = [], last;
  23148. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  23149. var curve = curves[ i ];
  23150. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  23151. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  23152. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  23153. : divisions;
  23154. var pts = curve.getPoints( resolution );
  23155. for ( var j = 0; j < pts.length; j ++ ) {
  23156. var point = pts[ j ];
  23157. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  23158. points.push( point );
  23159. last = point;
  23160. }
  23161. }
  23162. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  23163. points.push( points[ 0 ] );
  23164. }
  23165. return points;
  23166. },
  23167. copy: function ( source ) {
  23168. Curve.prototype.copy.call( this, source );
  23169. this.curves = [];
  23170. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  23171. var curve = source.curves[ i ];
  23172. this.curves.push( curve.clone() );
  23173. }
  23174. this.autoClose = source.autoClose;
  23175. return this;
  23176. },
  23177. toJSON: function () {
  23178. var data = Curve.prototype.toJSON.call( this );
  23179. data.autoClose = this.autoClose;
  23180. data.curves = [];
  23181. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  23182. var curve = this.curves[ i ];
  23183. data.curves.push( curve.toJSON() );
  23184. }
  23185. return data;
  23186. },
  23187. fromJSON: function ( json ) {
  23188. Curve.prototype.fromJSON.call( this, json );
  23189. this.autoClose = json.autoClose;
  23190. this.curves = [];
  23191. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  23192. var curve = json.curves[ i ];
  23193. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  23194. }
  23195. return this;
  23196. }
  23197. } );
  23198. /**
  23199. * @author zz85 / http://www.lab4games.net/zz85/blog
  23200. * Creates free form 2d path using series of points, lines or curves.
  23201. **/
  23202. function Path( points ) {
  23203. CurvePath.call( this );
  23204. this.type = 'Path';
  23205. this.currentPoint = new Vector2();
  23206. if ( points ) {
  23207. this.setFromPoints( points );
  23208. }
  23209. }
  23210. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  23211. constructor: Path,
  23212. setFromPoints: function ( points ) {
  23213. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  23214. for ( var i = 1, l = points.length; i < l; i ++ ) {
  23215. this.lineTo( points[ i ].x, points[ i ].y );
  23216. }
  23217. return this;
  23218. },
  23219. moveTo: function ( x, y ) {
  23220. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  23221. return this;
  23222. },
  23223. lineTo: function ( x, y ) {
  23224. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  23225. this.curves.push( curve );
  23226. this.currentPoint.set( x, y );
  23227. return this;
  23228. },
  23229. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23230. var curve = new QuadraticBezierCurve(
  23231. this.currentPoint.clone(),
  23232. new Vector2( aCPx, aCPy ),
  23233. new Vector2( aX, aY )
  23234. );
  23235. this.curves.push( curve );
  23236. this.currentPoint.set( aX, aY );
  23237. return this;
  23238. },
  23239. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23240. var curve = new CubicBezierCurve(
  23241. this.currentPoint.clone(),
  23242. new Vector2( aCP1x, aCP1y ),
  23243. new Vector2( aCP2x, aCP2y ),
  23244. new Vector2( aX, aY )
  23245. );
  23246. this.curves.push( curve );
  23247. this.currentPoint.set( aX, aY );
  23248. return this;
  23249. },
  23250. splineThru: function ( pts /*Array of Vector*/ ) {
  23251. var npts = [ this.currentPoint.clone() ].concat( pts );
  23252. var curve = new SplineCurve( npts );
  23253. this.curves.push( curve );
  23254. this.currentPoint.copy( pts[ pts.length - 1 ] );
  23255. return this;
  23256. },
  23257. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23258. var x0 = this.currentPoint.x;
  23259. var y0 = this.currentPoint.y;
  23260. this.absarc( aX + x0, aY + y0, aRadius,
  23261. aStartAngle, aEndAngle, aClockwise );
  23262. return this;
  23263. },
  23264. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23265. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  23266. return this;
  23267. },
  23268. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23269. var x0 = this.currentPoint.x;
  23270. var y0 = this.currentPoint.y;
  23271. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23272. return this;
  23273. },
  23274. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23275. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23276. if ( this.curves.length > 0 ) {
  23277. // if a previous curve is present, attempt to join
  23278. var firstPoint = curve.getPoint( 0 );
  23279. if ( ! firstPoint.equals( this.currentPoint ) ) {
  23280. this.lineTo( firstPoint.x, firstPoint.y );
  23281. }
  23282. }
  23283. this.curves.push( curve );
  23284. var lastPoint = curve.getPoint( 1 );
  23285. this.currentPoint.copy( lastPoint );
  23286. return this;
  23287. },
  23288. copy: function ( source ) {
  23289. CurvePath.prototype.copy.call( this, source );
  23290. this.currentPoint.copy( source.currentPoint );
  23291. return this;
  23292. },
  23293. toJSON: function () {
  23294. var data = CurvePath.prototype.toJSON.call( this );
  23295. data.currentPoint = this.currentPoint.toArray();
  23296. return data;
  23297. },
  23298. fromJSON: function ( json ) {
  23299. CurvePath.prototype.fromJSON.call( this, json );
  23300. this.currentPoint.fromArray( json.currentPoint );
  23301. return this;
  23302. }
  23303. } );
  23304. /**
  23305. * @author zz85 / http://www.lab4games.net/zz85/blog
  23306. * Defines a 2d shape plane using paths.
  23307. **/
  23308. // STEP 1 Create a path.
  23309. // STEP 2 Turn path into shape.
  23310. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  23311. // STEP 3a - Extract points from each shape, turn to vertices
  23312. // STEP 3b - Triangulate each shape, add faces.
  23313. function Shape( points ) {
  23314. Path.call( this, points );
  23315. this.uuid = MathUtils.generateUUID();
  23316. this.type = 'Shape';
  23317. this.holes = [];
  23318. }
  23319. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  23320. constructor: Shape,
  23321. getPointsHoles: function ( divisions ) {
  23322. var holesPts = [];
  23323. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  23324. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  23325. }
  23326. return holesPts;
  23327. },
  23328. // get points of shape and holes (keypoints based on segments parameter)
  23329. extractPoints: function ( divisions ) {
  23330. return {
  23331. shape: this.getPoints( divisions ),
  23332. holes: this.getPointsHoles( divisions )
  23333. };
  23334. },
  23335. copy: function ( source ) {
  23336. Path.prototype.copy.call( this, source );
  23337. this.holes = [];
  23338. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  23339. var hole = source.holes[ i ];
  23340. this.holes.push( hole.clone() );
  23341. }
  23342. return this;
  23343. },
  23344. toJSON: function () {
  23345. var data = Path.prototype.toJSON.call( this );
  23346. data.uuid = this.uuid;
  23347. data.holes = [];
  23348. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  23349. var hole = this.holes[ i ];
  23350. data.holes.push( hole.toJSON() );
  23351. }
  23352. return data;
  23353. },
  23354. fromJSON: function ( json ) {
  23355. Path.prototype.fromJSON.call( this, json );
  23356. this.uuid = json.uuid;
  23357. this.holes = [];
  23358. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  23359. var hole = json.holes[ i ];
  23360. this.holes.push( new Path().fromJSON( hole ) );
  23361. }
  23362. return this;
  23363. }
  23364. } );
  23365. /**
  23366. * @author mrdoob / http://mrdoob.com/
  23367. * @author alteredq / http://alteredqualia.com/
  23368. */
  23369. function Light( color, intensity ) {
  23370. Object3D.call( this );
  23371. this.type = 'Light';
  23372. this.color = new Color( color );
  23373. this.intensity = intensity !== undefined ? intensity : 1;
  23374. this.receiveShadow = undefined;
  23375. }
  23376. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23377. constructor: Light,
  23378. isLight: true,
  23379. copy: function ( source ) {
  23380. Object3D.prototype.copy.call( this, source );
  23381. this.color.copy( source.color );
  23382. this.intensity = source.intensity;
  23383. return this;
  23384. },
  23385. toJSON: function ( meta ) {
  23386. var data = Object3D.prototype.toJSON.call( this, meta );
  23387. data.object.color = this.color.getHex();
  23388. data.object.intensity = this.intensity;
  23389. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  23390. if ( this.distance !== undefined ) data.object.distance = this.distance;
  23391. if ( this.angle !== undefined ) data.object.angle = this.angle;
  23392. if ( this.decay !== undefined ) data.object.decay = this.decay;
  23393. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  23394. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  23395. return data;
  23396. }
  23397. } );
  23398. /**
  23399. * @author alteredq / http://alteredqualia.com/
  23400. */
  23401. function HemisphereLight( skyColor, groundColor, intensity ) {
  23402. Light.call( this, skyColor, intensity );
  23403. this.type = 'HemisphereLight';
  23404. this.castShadow = undefined;
  23405. this.position.copy( Object3D.DefaultUp );
  23406. this.updateMatrix();
  23407. this.groundColor = new Color( groundColor );
  23408. }
  23409. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23410. constructor: HemisphereLight,
  23411. isHemisphereLight: true,
  23412. copy: function ( source ) {
  23413. Light.prototype.copy.call( this, source );
  23414. this.groundColor.copy( source.groundColor );
  23415. return this;
  23416. }
  23417. } );
  23418. /**
  23419. * @author mrdoob / http://mrdoob.com/
  23420. */
  23421. function LightShadow( camera ) {
  23422. this.camera = camera;
  23423. this.bias = 0;
  23424. this.radius = 1;
  23425. this.mapSize = new Vector2( 512, 512 );
  23426. this.map = null;
  23427. this.mapPass = null;
  23428. this.matrix = new Matrix4();
  23429. this._frustum = new Frustum();
  23430. this._frameExtents = new Vector2( 1, 1 );
  23431. this._viewportCount = 1;
  23432. this._viewports = [
  23433. new Vector4( 0, 0, 1, 1 )
  23434. ];
  23435. }
  23436. Object.assign( LightShadow.prototype, {
  23437. _projScreenMatrix: new Matrix4(),
  23438. _lightPositionWorld: new Vector3(),
  23439. _lookTarget: new Vector3(),
  23440. getViewportCount: function () {
  23441. return this._viewportCount;
  23442. },
  23443. getFrustum: function () {
  23444. return this._frustum;
  23445. },
  23446. updateMatrices: function ( light ) {
  23447. var shadowCamera = this.camera,
  23448. shadowMatrix = this.matrix,
  23449. projScreenMatrix = this._projScreenMatrix,
  23450. lookTarget = this._lookTarget,
  23451. lightPositionWorld = this._lightPositionWorld;
  23452. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23453. shadowCamera.position.copy( lightPositionWorld );
  23454. lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  23455. shadowCamera.lookAt( lookTarget );
  23456. shadowCamera.updateMatrixWorld();
  23457. projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23458. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23459. shadowMatrix.set(
  23460. 0.5, 0.0, 0.0, 0.5,
  23461. 0.0, 0.5, 0.0, 0.5,
  23462. 0.0, 0.0, 0.5, 0.5,
  23463. 0.0, 0.0, 0.0, 1.0
  23464. );
  23465. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  23466. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  23467. },
  23468. getViewport: function ( viewportIndex ) {
  23469. return this._viewports[ viewportIndex ];
  23470. },
  23471. getFrameExtents: function () {
  23472. return this._frameExtents;
  23473. },
  23474. copy: function ( source ) {
  23475. this.camera = source.camera.clone();
  23476. this.bias = source.bias;
  23477. this.radius = source.radius;
  23478. this.mapSize.copy( source.mapSize );
  23479. return this;
  23480. },
  23481. clone: function () {
  23482. return new this.constructor().copy( this );
  23483. },
  23484. toJSON: function () {
  23485. var object = {};
  23486. if ( this.bias !== 0 ) object.bias = this.bias;
  23487. if ( this.radius !== 1 ) object.radius = this.radius;
  23488. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  23489. object.camera = this.camera.toJSON( false ).object;
  23490. delete object.camera.matrix;
  23491. return object;
  23492. }
  23493. } );
  23494. /**
  23495. * @author mrdoob / http://mrdoob.com/
  23496. */
  23497. function SpotLightShadow() {
  23498. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  23499. }
  23500. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23501. constructor: SpotLightShadow,
  23502. isSpotLightShadow: true,
  23503. updateMatrices: function ( light ) {
  23504. var camera = this.camera;
  23505. var fov = MathUtils.RAD2DEG * 2 * light.angle;
  23506. var aspect = this.mapSize.width / this.mapSize.height;
  23507. var far = light.distance || camera.far;
  23508. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  23509. camera.fov = fov;
  23510. camera.aspect = aspect;
  23511. camera.far = far;
  23512. camera.updateProjectionMatrix();
  23513. }
  23514. LightShadow.prototype.updateMatrices.call( this, light );
  23515. }
  23516. } );
  23517. /**
  23518. * @author alteredq / http://alteredqualia.com/
  23519. */
  23520. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  23521. Light.call( this, color, intensity );
  23522. this.type = 'SpotLight';
  23523. this.position.copy( Object3D.DefaultUp );
  23524. this.updateMatrix();
  23525. this.target = new Object3D();
  23526. Object.defineProperty( this, 'power', {
  23527. get: function () {
  23528. // intensity = power per solid angle.
  23529. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23530. return this.intensity * Math.PI;
  23531. },
  23532. set: function ( power ) {
  23533. // intensity = power per solid angle.
  23534. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23535. this.intensity = power / Math.PI;
  23536. }
  23537. } );
  23538. this.distance = ( distance !== undefined ) ? distance : 0;
  23539. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  23540. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  23541. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23542. this.shadow = new SpotLightShadow();
  23543. }
  23544. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23545. constructor: SpotLight,
  23546. isSpotLight: true,
  23547. copy: function ( source ) {
  23548. Light.prototype.copy.call( this, source );
  23549. this.distance = source.distance;
  23550. this.angle = source.angle;
  23551. this.penumbra = source.penumbra;
  23552. this.decay = source.decay;
  23553. this.target = source.target.clone();
  23554. this.shadow = source.shadow.clone();
  23555. return this;
  23556. }
  23557. } );
  23558. function PointLightShadow() {
  23559. LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  23560. this._frameExtents = new Vector2( 4, 2 );
  23561. this._viewportCount = 6;
  23562. this._viewports = [
  23563. // These viewports map a cube-map onto a 2D texture with the
  23564. // following orientation:
  23565. //
  23566. // xzXZ
  23567. // y Y
  23568. //
  23569. // X - Positive x direction
  23570. // x - Negative x direction
  23571. // Y - Positive y direction
  23572. // y - Negative y direction
  23573. // Z - Positive z direction
  23574. // z - Negative z direction
  23575. // positive X
  23576. new Vector4( 2, 1, 1, 1 ),
  23577. // negative X
  23578. new Vector4( 0, 1, 1, 1 ),
  23579. // positive Z
  23580. new Vector4( 3, 1, 1, 1 ),
  23581. // negative Z
  23582. new Vector4( 1, 1, 1, 1 ),
  23583. // positive Y
  23584. new Vector4( 3, 0, 1, 1 ),
  23585. // negative Y
  23586. new Vector4( 1, 0, 1, 1 )
  23587. ];
  23588. this._cubeDirections = [
  23589. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  23590. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  23591. ];
  23592. this._cubeUps = [
  23593. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  23594. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  23595. ];
  23596. }
  23597. PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23598. constructor: PointLightShadow,
  23599. isPointLightShadow: true,
  23600. updateMatrices: function ( light, viewportIndex ) {
  23601. if ( viewportIndex === undefined ) viewportIndex = 0;
  23602. var camera = this.camera,
  23603. shadowMatrix = this.matrix,
  23604. lightPositionWorld = this._lightPositionWorld,
  23605. lookTarget = this._lookTarget,
  23606. projScreenMatrix = this._projScreenMatrix;
  23607. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23608. camera.position.copy( lightPositionWorld );
  23609. lookTarget.copy( camera.position );
  23610. lookTarget.add( this._cubeDirections[ viewportIndex ] );
  23611. camera.up.copy( this._cubeUps[ viewportIndex ] );
  23612. camera.lookAt( lookTarget );
  23613. camera.updateMatrixWorld();
  23614. shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
  23615. projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  23616. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23617. }
  23618. } );
  23619. /**
  23620. * @author mrdoob / http://mrdoob.com/
  23621. */
  23622. function PointLight( color, intensity, distance, decay ) {
  23623. Light.call( this, color, intensity );
  23624. this.type = 'PointLight';
  23625. Object.defineProperty( this, 'power', {
  23626. get: function () {
  23627. // intensity = power per solid angle.
  23628. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23629. return this.intensity * 4 * Math.PI;
  23630. },
  23631. set: function ( power ) {
  23632. // intensity = power per solid angle.
  23633. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23634. this.intensity = power / ( 4 * Math.PI );
  23635. }
  23636. } );
  23637. this.distance = ( distance !== undefined ) ? distance : 0;
  23638. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23639. this.shadow = new PointLightShadow();
  23640. }
  23641. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23642. constructor: PointLight,
  23643. isPointLight: true,
  23644. copy: function ( source ) {
  23645. Light.prototype.copy.call( this, source );
  23646. this.distance = source.distance;
  23647. this.decay = source.decay;
  23648. this.shadow = source.shadow.clone();
  23649. return this;
  23650. }
  23651. } );
  23652. /**
  23653. * @author alteredq / http://alteredqualia.com/
  23654. * @author arose / http://github.com/arose
  23655. */
  23656. function OrthographicCamera( left, right, top, bottom, near, far ) {
  23657. Camera.call( this );
  23658. this.type = 'OrthographicCamera';
  23659. this.zoom = 1;
  23660. this.view = null;
  23661. this.left = ( left !== undefined ) ? left : - 1;
  23662. this.right = ( right !== undefined ) ? right : 1;
  23663. this.top = ( top !== undefined ) ? top : 1;
  23664. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  23665. this.near = ( near !== undefined ) ? near : 0.1;
  23666. this.far = ( far !== undefined ) ? far : 2000;
  23667. this.updateProjectionMatrix();
  23668. }
  23669. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  23670. constructor: OrthographicCamera,
  23671. isOrthographicCamera: true,
  23672. copy: function ( source, recursive ) {
  23673. Camera.prototype.copy.call( this, source, recursive );
  23674. this.left = source.left;
  23675. this.right = source.right;
  23676. this.top = source.top;
  23677. this.bottom = source.bottom;
  23678. this.near = source.near;
  23679. this.far = source.far;
  23680. this.zoom = source.zoom;
  23681. this.view = source.view === null ? null : Object.assign( {}, source.view );
  23682. return this;
  23683. },
  23684. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  23685. if ( this.view === null ) {
  23686. this.view = {
  23687. enabled: true,
  23688. fullWidth: 1,
  23689. fullHeight: 1,
  23690. offsetX: 0,
  23691. offsetY: 0,
  23692. width: 1,
  23693. height: 1
  23694. };
  23695. }
  23696. this.view.enabled = true;
  23697. this.view.fullWidth = fullWidth;
  23698. this.view.fullHeight = fullHeight;
  23699. this.view.offsetX = x;
  23700. this.view.offsetY = y;
  23701. this.view.width = width;
  23702. this.view.height = height;
  23703. this.updateProjectionMatrix();
  23704. },
  23705. clearViewOffset: function () {
  23706. if ( this.view !== null ) {
  23707. this.view.enabled = false;
  23708. }
  23709. this.updateProjectionMatrix();
  23710. },
  23711. updateProjectionMatrix: function () {
  23712. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  23713. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  23714. var cx = ( this.right + this.left ) / 2;
  23715. var cy = ( this.top + this.bottom ) / 2;
  23716. var left = cx - dx;
  23717. var right = cx + dx;
  23718. var top = cy + dy;
  23719. var bottom = cy - dy;
  23720. if ( this.view !== null && this.view.enabled ) {
  23721. var scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  23722. var scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  23723. left += scaleW * this.view.offsetX;
  23724. right = left + scaleW * this.view.width;
  23725. top -= scaleH * this.view.offsetY;
  23726. bottom = top - scaleH * this.view.height;
  23727. }
  23728. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  23729. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  23730. },
  23731. toJSON: function ( meta ) {
  23732. var data = Object3D.prototype.toJSON.call( this, meta );
  23733. data.object.zoom = this.zoom;
  23734. data.object.left = this.left;
  23735. data.object.right = this.right;
  23736. data.object.top = this.top;
  23737. data.object.bottom = this.bottom;
  23738. data.object.near = this.near;
  23739. data.object.far = this.far;
  23740. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  23741. return data;
  23742. }
  23743. } );
  23744. /**
  23745. * @author mrdoob / http://mrdoob.com/
  23746. */
  23747. function DirectionalLightShadow() {
  23748. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  23749. }
  23750. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23751. constructor: DirectionalLightShadow,
  23752. isDirectionalLightShadow: true,
  23753. updateMatrices: function ( light ) {
  23754. LightShadow.prototype.updateMatrices.call( this, light );
  23755. }
  23756. } );
  23757. /**
  23758. * @author mrdoob / http://mrdoob.com/
  23759. * @author alteredq / http://alteredqualia.com/
  23760. */
  23761. function DirectionalLight( color, intensity ) {
  23762. Light.call( this, color, intensity );
  23763. this.type = 'DirectionalLight';
  23764. this.position.copy( Object3D.DefaultUp );
  23765. this.updateMatrix();
  23766. this.target = new Object3D();
  23767. this.shadow = new DirectionalLightShadow();
  23768. }
  23769. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23770. constructor: DirectionalLight,
  23771. isDirectionalLight: true,
  23772. copy: function ( source ) {
  23773. Light.prototype.copy.call( this, source );
  23774. this.target = source.target.clone();
  23775. this.shadow = source.shadow.clone();
  23776. return this;
  23777. }
  23778. } );
  23779. /**
  23780. * @author mrdoob / http://mrdoob.com/
  23781. */
  23782. function AmbientLight( color, intensity ) {
  23783. Light.call( this, color, intensity );
  23784. this.type = 'AmbientLight';
  23785. this.castShadow = undefined;
  23786. }
  23787. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23788. constructor: AmbientLight,
  23789. isAmbientLight: true
  23790. } );
  23791. /**
  23792. * @author abelnation / http://github.com/abelnation
  23793. */
  23794. function RectAreaLight( color, intensity, width, height ) {
  23795. Light.call( this, color, intensity );
  23796. this.type = 'RectAreaLight';
  23797. this.width = ( width !== undefined ) ? width : 10;
  23798. this.height = ( height !== undefined ) ? height : 10;
  23799. }
  23800. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23801. constructor: RectAreaLight,
  23802. isRectAreaLight: true,
  23803. copy: function ( source ) {
  23804. Light.prototype.copy.call( this, source );
  23805. this.width = source.width;
  23806. this.height = source.height;
  23807. return this;
  23808. },
  23809. toJSON: function ( meta ) {
  23810. var data = Light.prototype.toJSON.call( this, meta );
  23811. data.object.width = this.width;
  23812. data.object.height = this.height;
  23813. return data;
  23814. }
  23815. } );
  23816. /**
  23817. * @author bhouston / http://clara.io
  23818. * @author WestLangley / http://github.com/WestLangley
  23819. *
  23820. * Primary reference:
  23821. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23822. *
  23823. * Secondary reference:
  23824. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23825. */
  23826. // 3-band SH defined by 9 coefficients
  23827. function SphericalHarmonics3() {
  23828. this.coefficients = [];
  23829. for ( var i = 0; i < 9; i ++ ) {
  23830. this.coefficients.push( new Vector3() );
  23831. }
  23832. }
  23833. Object.assign( SphericalHarmonics3.prototype, {
  23834. isSphericalHarmonics3: true,
  23835. set: function ( coefficients ) {
  23836. for ( var i = 0; i < 9; i ++ ) {
  23837. this.coefficients[ i ].copy( coefficients[ i ] );
  23838. }
  23839. return this;
  23840. },
  23841. zero: function () {
  23842. for ( var i = 0; i < 9; i ++ ) {
  23843. this.coefficients[ i ].set( 0, 0, 0 );
  23844. }
  23845. return this;
  23846. },
  23847. // get the radiance in the direction of the normal
  23848. // target is a Vector3
  23849. getAt: function ( normal, target ) {
  23850. // normal is assumed to be unit length
  23851. var x = normal.x, y = normal.y, z = normal.z;
  23852. var coeff = this.coefficients;
  23853. // band 0
  23854. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  23855. // band 1
  23856. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  23857. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  23858. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  23859. // band 2
  23860. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  23861. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  23862. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  23863. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  23864. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  23865. return target;
  23866. },
  23867. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23868. // target is a Vector3
  23869. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23870. getIrradianceAt: function ( normal, target ) {
  23871. // normal is assumed to be unit length
  23872. var x = normal.x, y = normal.y, z = normal.z;
  23873. var coeff = this.coefficients;
  23874. // band 0
  23875. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  23876. // band 1
  23877. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  23878. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  23879. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  23880. // band 2
  23881. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  23882. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  23883. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  23884. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  23885. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  23886. return target;
  23887. },
  23888. add: function ( sh ) {
  23889. for ( var i = 0; i < 9; i ++ ) {
  23890. this.coefficients[ i ].add( sh.coefficients[ i ] );
  23891. }
  23892. return this;
  23893. },
  23894. addScaledSH: function ( sh, s ) {
  23895. for ( var i = 0; i < 9; i ++ ) {
  23896. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  23897. }
  23898. return this;
  23899. },
  23900. scale: function ( s ) {
  23901. for ( var i = 0; i < 9; i ++ ) {
  23902. this.coefficients[ i ].multiplyScalar( s );
  23903. }
  23904. return this;
  23905. },
  23906. lerp: function ( sh, alpha ) {
  23907. for ( var i = 0; i < 9; i ++ ) {
  23908. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  23909. }
  23910. return this;
  23911. },
  23912. equals: function ( sh ) {
  23913. for ( var i = 0; i < 9; i ++ ) {
  23914. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  23915. return false;
  23916. }
  23917. }
  23918. return true;
  23919. },
  23920. copy: function ( sh ) {
  23921. return this.set( sh.coefficients );
  23922. },
  23923. clone: function () {
  23924. return new this.constructor().copy( this );
  23925. },
  23926. fromArray: function ( array, offset ) {
  23927. if ( offset === undefined ) offset = 0;
  23928. var coefficients = this.coefficients;
  23929. for ( var i = 0; i < 9; i ++ ) {
  23930. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  23931. }
  23932. return this;
  23933. },
  23934. toArray: function ( array, offset ) {
  23935. if ( array === undefined ) array = [];
  23936. if ( offset === undefined ) offset = 0;
  23937. var coefficients = this.coefficients;
  23938. for ( var i = 0; i < 9; i ++ ) {
  23939. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  23940. }
  23941. return array;
  23942. }
  23943. } );
  23944. Object.assign( SphericalHarmonics3, {
  23945. // evaluate the basis functions
  23946. // shBasis is an Array[ 9 ]
  23947. getBasisAt: function ( normal, shBasis ) {
  23948. // normal is assumed to be unit length
  23949. var x = normal.x, y = normal.y, z = normal.z;
  23950. // band 0
  23951. shBasis[ 0 ] = 0.282095;
  23952. // band 1
  23953. shBasis[ 1 ] = 0.488603 * y;
  23954. shBasis[ 2 ] = 0.488603 * z;
  23955. shBasis[ 3 ] = 0.488603 * x;
  23956. // band 2
  23957. shBasis[ 4 ] = 1.092548 * x * y;
  23958. shBasis[ 5 ] = 1.092548 * y * z;
  23959. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  23960. shBasis[ 7 ] = 1.092548 * x * z;
  23961. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  23962. }
  23963. } );
  23964. /**
  23965. * @author WestLangley / http://github.com/WestLangley
  23966. *
  23967. * A LightProbe is a source of indirect-diffuse light
  23968. */
  23969. function LightProbe( sh, intensity ) {
  23970. Light.call( this, undefined, intensity );
  23971. this.type = 'LightProbe';
  23972. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  23973. }
  23974. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  23975. constructor: LightProbe,
  23976. isLightProbe: true,
  23977. copy: function ( source ) {
  23978. Light.prototype.copy.call( this, source );
  23979. this.sh.copy( source.sh );
  23980. return this;
  23981. },
  23982. fromJSON: function ( json ) {
  23983. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23984. this.sh.fromArray( json.sh );
  23985. return this;
  23986. },
  23987. toJSON: function ( meta ) {
  23988. var data = Light.prototype.toJSON.call( this, meta );
  23989. data.object.sh = this.sh.toArray();
  23990. return data;
  23991. }
  23992. } );
  23993. /**
  23994. * @author mrdoob / http://mrdoob.com/
  23995. */
  23996. function MaterialLoader( manager ) {
  23997. Loader.call( this, manager );
  23998. this.textures = {};
  23999. }
  24000. MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24001. constructor: MaterialLoader,
  24002. load: function ( url, onLoad, onProgress, onError ) {
  24003. var scope = this;
  24004. var loader = new FileLoader( scope.manager );
  24005. loader.setPath( scope.path );
  24006. loader.load( url, function ( text ) {
  24007. try {
  24008. onLoad( scope.parse( JSON.parse( text ) ) );
  24009. } catch ( e ) {
  24010. if ( onError ) {
  24011. onError( e );
  24012. } else {
  24013. console.error( e );
  24014. }
  24015. scope.manager.itemError( url );
  24016. }
  24017. }, onProgress, onError );
  24018. },
  24019. parse: function ( json ) {
  24020. var textures = this.textures;
  24021. function getTexture( name ) {
  24022. if ( textures[ name ] === undefined ) {
  24023. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  24024. }
  24025. return textures[ name ];
  24026. }
  24027. var material = new Materials[ json.type ]();
  24028. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  24029. if ( json.name !== undefined ) material.name = json.name;
  24030. if ( json.color !== undefined ) material.color.setHex( json.color );
  24031. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  24032. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  24033. if ( json.sheen !== undefined ) material.sheen = new Color().setHex( json.sheen );
  24034. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  24035. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  24036. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  24037. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  24038. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  24039. if ( json.fog !== undefined ) material.fog = json.fog;
  24040. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  24041. if ( json.blending !== undefined ) material.blending = json.blending;
  24042. if ( json.combine !== undefined ) material.combine = json.combine;
  24043. if ( json.side !== undefined ) material.side = json.side;
  24044. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  24045. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  24046. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  24047. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  24048. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  24049. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  24050. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  24051. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  24052. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  24053. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  24054. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  24055. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  24056. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  24057. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  24058. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  24059. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  24060. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  24061. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  24062. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  24063. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  24064. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  24065. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  24066. if ( json.scale !== undefined ) material.scale = json.scale;
  24067. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  24068. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24069. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24070. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  24071. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  24072. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  24073. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  24074. if ( json.vertexTangents !== undefined ) material.vertexTangents = json.vertexTangents;
  24075. if ( json.visible !== undefined ) material.visible = json.visible;
  24076. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  24077. if ( json.userData !== undefined ) material.userData = json.userData;
  24078. if ( json.vertexColors !== undefined ) {
  24079. if ( typeof json.vertexColors === 'number' ) {
  24080. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  24081. } else {
  24082. material.vertexColors = json.vertexColors;
  24083. }
  24084. }
  24085. // Shader Material
  24086. if ( json.uniforms !== undefined ) {
  24087. for ( var name in json.uniforms ) {
  24088. var uniform = json.uniforms[ name ];
  24089. material.uniforms[ name ] = {};
  24090. switch ( uniform.type ) {
  24091. case 't':
  24092. material.uniforms[ name ].value = getTexture( uniform.value );
  24093. break;
  24094. case 'c':
  24095. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  24096. break;
  24097. case 'v2':
  24098. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  24099. break;
  24100. case 'v3':
  24101. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  24102. break;
  24103. case 'v4':
  24104. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  24105. break;
  24106. case 'm3':
  24107. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  24108. case 'm4':
  24109. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  24110. break;
  24111. default:
  24112. material.uniforms[ name ].value = uniform.value;
  24113. }
  24114. }
  24115. }
  24116. if ( json.defines !== undefined ) material.defines = json.defines;
  24117. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  24118. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  24119. if ( json.extensions !== undefined ) {
  24120. for ( var key in json.extensions ) {
  24121. material.extensions[ key ] = json.extensions[ key ];
  24122. }
  24123. }
  24124. // Deprecated
  24125. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  24126. // for PointsMaterial
  24127. if ( json.size !== undefined ) material.size = json.size;
  24128. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  24129. // maps
  24130. if ( json.map !== undefined ) material.map = getTexture( json.map );
  24131. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  24132. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  24133. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  24134. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  24135. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  24136. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  24137. if ( json.normalScale !== undefined ) {
  24138. var normalScale = json.normalScale;
  24139. if ( Array.isArray( normalScale ) === false ) {
  24140. // Blender exporter used to export a scalar. See #7459
  24141. normalScale = [ normalScale, normalScale ];
  24142. }
  24143. material.normalScale = new Vector2().fromArray( normalScale );
  24144. }
  24145. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  24146. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  24147. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  24148. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  24149. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  24150. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  24151. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  24152. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  24153. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  24154. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  24155. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  24156. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  24157. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  24158. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  24159. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  24160. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  24161. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  24162. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  24163. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  24164. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  24165. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  24166. return material;
  24167. },
  24168. setTextures: function ( value ) {
  24169. this.textures = value;
  24170. return this;
  24171. }
  24172. } );
  24173. /**
  24174. * @author Don McCurdy / https://www.donmccurdy.com
  24175. */
  24176. var LoaderUtils = {
  24177. decodeText: function ( array ) {
  24178. if ( typeof TextDecoder !== 'undefined' ) {
  24179. return new TextDecoder().decode( array );
  24180. }
  24181. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24182. // throws a "maximum call stack size exceeded" error for large arrays.
  24183. var s = '';
  24184. for ( var i = 0, il = array.length; i < il; i ++ ) {
  24185. // Implicitly assumes little-endian.
  24186. s += String.fromCharCode( array[ i ] );
  24187. }
  24188. try {
  24189. // merges multi-byte utf-8 characters.
  24190. return decodeURIComponent( escape( s ) );
  24191. } catch ( e ) { // see #16358
  24192. return s;
  24193. }
  24194. },
  24195. extractUrlBase: function ( url ) {
  24196. var index = url.lastIndexOf( '/' );
  24197. if ( index === - 1 ) return './';
  24198. return url.substr( 0, index + 1 );
  24199. }
  24200. };
  24201. /**
  24202. * @author benaadams / https://twitter.com/ben_a_adams
  24203. */
  24204. function InstancedBufferGeometry() {
  24205. BufferGeometry.call( this );
  24206. this.type = 'InstancedBufferGeometry';
  24207. this.instanceCount = Infinity;
  24208. }
  24209. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  24210. constructor: InstancedBufferGeometry,
  24211. isInstancedBufferGeometry: true,
  24212. copy: function ( source ) {
  24213. BufferGeometry.prototype.copy.call( this, source );
  24214. this.instanceCount = source.instanceCount;
  24215. return this;
  24216. },
  24217. clone: function () {
  24218. return new this.constructor().copy( this );
  24219. },
  24220. toJSON: function () {
  24221. var data = BufferGeometry.prototype.toJSON.call( this );
  24222. data.instanceCount = this.instanceCount;
  24223. data.isInstancedBufferGeometry = true;
  24224. return data;
  24225. }
  24226. } );
  24227. /**
  24228. * @author benaadams / https://twitter.com/ben_a_adams
  24229. */
  24230. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  24231. if ( typeof ( normalized ) === 'number' ) {
  24232. meshPerAttribute = normalized;
  24233. normalized = false;
  24234. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  24235. }
  24236. BufferAttribute.call( this, array, itemSize, normalized );
  24237. this.meshPerAttribute = meshPerAttribute || 1;
  24238. }
  24239. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  24240. constructor: InstancedBufferAttribute,
  24241. isInstancedBufferAttribute: true,
  24242. copy: function ( source ) {
  24243. BufferAttribute.prototype.copy.call( this, source );
  24244. this.meshPerAttribute = source.meshPerAttribute;
  24245. return this;
  24246. },
  24247. toJSON: function () {
  24248. var data = BufferAttribute.prototype.toJSON.call( this );
  24249. data.meshPerAttribute = this.meshPerAttribute;
  24250. data.isInstancedBufferAttribute = true;
  24251. return data;
  24252. }
  24253. } );
  24254. /**
  24255. * @author mrdoob / http://mrdoob.com/
  24256. */
  24257. function BufferGeometryLoader( manager ) {
  24258. Loader.call( this, manager );
  24259. }
  24260. BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24261. constructor: BufferGeometryLoader,
  24262. load: function ( url, onLoad, onProgress, onError ) {
  24263. var scope = this;
  24264. var loader = new FileLoader( scope.manager );
  24265. loader.setPath( scope.path );
  24266. loader.load( url, function ( text ) {
  24267. try {
  24268. onLoad( scope.parse( JSON.parse( text ) ) );
  24269. } catch ( e ) {
  24270. if ( onError ) {
  24271. onError( e );
  24272. } else {
  24273. console.error( e );
  24274. }
  24275. scope.manager.itemError( url );
  24276. }
  24277. }, onProgress, onError );
  24278. },
  24279. parse: function ( json ) {
  24280. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24281. var index = json.data.index;
  24282. if ( index !== undefined ) {
  24283. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  24284. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  24285. }
  24286. var attributes = json.data.attributes;
  24287. for ( var key in attributes ) {
  24288. var attribute = attributes[ key ];
  24289. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  24290. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24291. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  24292. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24293. geometry.setAttribute( key, bufferAttribute );
  24294. }
  24295. var morphAttributes = json.data.morphAttributes;
  24296. if ( morphAttributes ) {
  24297. for ( var key in morphAttributes ) {
  24298. var attributeArray = morphAttributes[ key ];
  24299. var array = [];
  24300. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  24301. var attribute = attributeArray[ i ];
  24302. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  24303. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  24304. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24305. array.push( bufferAttribute );
  24306. }
  24307. geometry.morphAttributes[ key ] = array;
  24308. }
  24309. }
  24310. var morphTargetsRelative = json.data.morphTargetsRelative;
  24311. if ( morphTargetsRelative ) {
  24312. geometry.morphTargetsRelative = true;
  24313. }
  24314. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24315. if ( groups !== undefined ) {
  24316. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  24317. var group = groups[ i ];
  24318. geometry.addGroup( group.start, group.count, group.materialIndex );
  24319. }
  24320. }
  24321. var boundingSphere = json.data.boundingSphere;
  24322. if ( boundingSphere !== undefined ) {
  24323. var center = new Vector3();
  24324. if ( boundingSphere.center !== undefined ) {
  24325. center.fromArray( boundingSphere.center );
  24326. }
  24327. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  24328. }
  24329. if ( json.name ) geometry.name = json.name;
  24330. if ( json.userData ) geometry.userData = json.userData;
  24331. return geometry;
  24332. }
  24333. } );
  24334. var TYPED_ARRAYS = {
  24335. Int8Array: Int8Array,
  24336. Uint8Array: Uint8Array,
  24337. // Workaround for IE11 pre KB2929437. See #11440
  24338. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24339. Int16Array: Int16Array,
  24340. Uint16Array: Uint16Array,
  24341. Int32Array: Int32Array,
  24342. Uint32Array: Uint32Array,
  24343. Float32Array: Float32Array,
  24344. Float64Array: Float64Array
  24345. };
  24346. /**
  24347. * @author mrdoob / http://mrdoob.com/
  24348. */
  24349. function ObjectLoader( manager ) {
  24350. Loader.call( this, manager );
  24351. }
  24352. ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24353. constructor: ObjectLoader,
  24354. load: function ( url, onLoad, onProgress, onError ) {
  24355. var scope = this;
  24356. var path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  24357. this.resourcePath = this.resourcePath || path;
  24358. var loader = new FileLoader( scope.manager );
  24359. loader.setPath( this.path );
  24360. loader.load( url, function ( text ) {
  24361. var json = null;
  24362. try {
  24363. json = JSON.parse( text );
  24364. } catch ( error ) {
  24365. if ( onError !== undefined ) onError( error );
  24366. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  24367. return;
  24368. }
  24369. var metadata = json.metadata;
  24370. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  24371. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  24372. return;
  24373. }
  24374. scope.parse( json, onLoad );
  24375. }, onProgress, onError );
  24376. },
  24377. parse: function ( json, onLoad ) {
  24378. var shapes = this.parseShape( json.shapes );
  24379. var geometries = this.parseGeometries( json.geometries, shapes );
  24380. var images = this.parseImages( json.images, function () {
  24381. if ( onLoad !== undefined ) onLoad( object );
  24382. } );
  24383. var textures = this.parseTextures( json.textures, images );
  24384. var materials = this.parseMaterials( json.materials, textures );
  24385. var object = this.parseObject( json.object, geometries, materials );
  24386. if ( json.animations ) {
  24387. object.animations = this.parseAnimations( json.animations );
  24388. }
  24389. if ( json.images === undefined || json.images.length === 0 ) {
  24390. if ( onLoad !== undefined ) onLoad( object );
  24391. }
  24392. return object;
  24393. },
  24394. parseShape: function ( json ) {
  24395. var shapes = {};
  24396. if ( json !== undefined ) {
  24397. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24398. var shape = new Shape().fromJSON( json[ i ] );
  24399. shapes[ shape.uuid ] = shape;
  24400. }
  24401. }
  24402. return shapes;
  24403. },
  24404. parseGeometries: function ( json, shapes ) {
  24405. var geometries = {};
  24406. if ( json !== undefined ) {
  24407. var bufferGeometryLoader = new BufferGeometryLoader();
  24408. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24409. var geometry;
  24410. var data = json[ i ];
  24411. switch ( data.type ) {
  24412. case 'PlaneGeometry':
  24413. case 'PlaneBufferGeometry':
  24414. geometry = new Geometries[ data.type ](
  24415. data.width,
  24416. data.height,
  24417. data.widthSegments,
  24418. data.heightSegments
  24419. );
  24420. break;
  24421. case 'BoxGeometry':
  24422. case 'BoxBufferGeometry':
  24423. case 'CubeGeometry': // backwards compatible
  24424. geometry = new Geometries[ data.type ](
  24425. data.width,
  24426. data.height,
  24427. data.depth,
  24428. data.widthSegments,
  24429. data.heightSegments,
  24430. data.depthSegments
  24431. );
  24432. break;
  24433. case 'CircleGeometry':
  24434. case 'CircleBufferGeometry':
  24435. geometry = new Geometries[ data.type ](
  24436. data.radius,
  24437. data.segments,
  24438. data.thetaStart,
  24439. data.thetaLength
  24440. );
  24441. break;
  24442. case 'CylinderGeometry':
  24443. case 'CylinderBufferGeometry':
  24444. geometry = new Geometries[ data.type ](
  24445. data.radiusTop,
  24446. data.radiusBottom,
  24447. data.height,
  24448. data.radialSegments,
  24449. data.heightSegments,
  24450. data.openEnded,
  24451. data.thetaStart,
  24452. data.thetaLength
  24453. );
  24454. break;
  24455. case 'ConeGeometry':
  24456. case 'ConeBufferGeometry':
  24457. geometry = new Geometries[ data.type ](
  24458. data.radius,
  24459. data.height,
  24460. data.radialSegments,
  24461. data.heightSegments,
  24462. data.openEnded,
  24463. data.thetaStart,
  24464. data.thetaLength
  24465. );
  24466. break;
  24467. case 'SphereGeometry':
  24468. case 'SphereBufferGeometry':
  24469. geometry = new Geometries[ data.type ](
  24470. data.radius,
  24471. data.widthSegments,
  24472. data.heightSegments,
  24473. data.phiStart,
  24474. data.phiLength,
  24475. data.thetaStart,
  24476. data.thetaLength
  24477. );
  24478. break;
  24479. case 'DodecahedronGeometry':
  24480. case 'DodecahedronBufferGeometry':
  24481. case 'IcosahedronGeometry':
  24482. case 'IcosahedronBufferGeometry':
  24483. case 'OctahedronGeometry':
  24484. case 'OctahedronBufferGeometry':
  24485. case 'TetrahedronGeometry':
  24486. case 'TetrahedronBufferGeometry':
  24487. geometry = new Geometries[ data.type ](
  24488. data.radius,
  24489. data.detail
  24490. );
  24491. break;
  24492. case 'RingGeometry':
  24493. case 'RingBufferGeometry':
  24494. geometry = new Geometries[ data.type ](
  24495. data.innerRadius,
  24496. data.outerRadius,
  24497. data.thetaSegments,
  24498. data.phiSegments,
  24499. data.thetaStart,
  24500. data.thetaLength
  24501. );
  24502. break;
  24503. case 'TorusGeometry':
  24504. case 'TorusBufferGeometry':
  24505. geometry = new Geometries[ data.type ](
  24506. data.radius,
  24507. data.tube,
  24508. data.radialSegments,
  24509. data.tubularSegments,
  24510. data.arc
  24511. );
  24512. break;
  24513. case 'TorusKnotGeometry':
  24514. case 'TorusKnotBufferGeometry':
  24515. geometry = new Geometries[ data.type ](
  24516. data.radius,
  24517. data.tube,
  24518. data.tubularSegments,
  24519. data.radialSegments,
  24520. data.p,
  24521. data.q
  24522. );
  24523. break;
  24524. case 'TubeGeometry':
  24525. case 'TubeBufferGeometry':
  24526. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24527. // User defined curves or instances of CurvePath will not be deserialized.
  24528. geometry = new Geometries[ data.type ](
  24529. new Curves[ data.path.type ]().fromJSON( data.path ),
  24530. data.tubularSegments,
  24531. data.radius,
  24532. data.radialSegments,
  24533. data.closed
  24534. );
  24535. break;
  24536. case 'LatheGeometry':
  24537. case 'LatheBufferGeometry':
  24538. geometry = new Geometries[ data.type ](
  24539. data.points,
  24540. data.segments,
  24541. data.phiStart,
  24542. data.phiLength
  24543. );
  24544. break;
  24545. case 'PolyhedronGeometry':
  24546. case 'PolyhedronBufferGeometry':
  24547. geometry = new Geometries[ data.type ](
  24548. data.vertices,
  24549. data.indices,
  24550. data.radius,
  24551. data.details
  24552. );
  24553. break;
  24554. case 'ShapeGeometry':
  24555. case 'ShapeBufferGeometry':
  24556. var geometryShapes = [];
  24557. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24558. var shape = shapes[ data.shapes[ j ] ];
  24559. geometryShapes.push( shape );
  24560. }
  24561. geometry = new Geometries[ data.type ](
  24562. geometryShapes,
  24563. data.curveSegments
  24564. );
  24565. break;
  24566. case 'ExtrudeGeometry':
  24567. case 'ExtrudeBufferGeometry':
  24568. var geometryShapes = [];
  24569. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24570. var shape = shapes[ data.shapes[ j ] ];
  24571. geometryShapes.push( shape );
  24572. }
  24573. var extrudePath = data.options.extrudePath;
  24574. if ( extrudePath !== undefined ) {
  24575. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  24576. }
  24577. geometry = new Geometries[ data.type ](
  24578. geometryShapes,
  24579. data.options
  24580. );
  24581. break;
  24582. case 'BufferGeometry':
  24583. case 'InstancedBufferGeometry':
  24584. geometry = bufferGeometryLoader.parse( data );
  24585. break;
  24586. case 'Geometry':
  24587. console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' );
  24588. break;
  24589. default:
  24590. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  24591. continue;
  24592. }
  24593. geometry.uuid = data.uuid;
  24594. if ( data.name !== undefined ) geometry.name = data.name;
  24595. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  24596. geometries[ data.uuid ] = geometry;
  24597. }
  24598. }
  24599. return geometries;
  24600. },
  24601. parseMaterials: function ( json, textures ) {
  24602. var cache = {}; // MultiMaterial
  24603. var materials = {};
  24604. if ( json !== undefined ) {
  24605. var loader = new MaterialLoader();
  24606. loader.setTextures( textures );
  24607. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24608. var data = json[ i ];
  24609. if ( data.type === 'MultiMaterial' ) {
  24610. // Deprecated
  24611. var array = [];
  24612. for ( var j = 0; j < data.materials.length; j ++ ) {
  24613. var material = data.materials[ j ];
  24614. if ( cache[ material.uuid ] === undefined ) {
  24615. cache[ material.uuid ] = loader.parse( material );
  24616. }
  24617. array.push( cache[ material.uuid ] );
  24618. }
  24619. materials[ data.uuid ] = array;
  24620. } else {
  24621. if ( cache[ data.uuid ] === undefined ) {
  24622. cache[ data.uuid ] = loader.parse( data );
  24623. }
  24624. materials[ data.uuid ] = cache[ data.uuid ];
  24625. }
  24626. }
  24627. }
  24628. return materials;
  24629. },
  24630. parseAnimations: function ( json ) {
  24631. var animations = [];
  24632. for ( var i = 0; i < json.length; i ++ ) {
  24633. var data = json[ i ];
  24634. var clip = AnimationClip.parse( data );
  24635. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  24636. animations.push( clip );
  24637. }
  24638. return animations;
  24639. },
  24640. parseImages: function ( json, onLoad ) {
  24641. var scope = this;
  24642. var images = {};
  24643. function loadImage( url ) {
  24644. scope.manager.itemStart( url );
  24645. return loader.load( url, function () {
  24646. scope.manager.itemEnd( url );
  24647. }, undefined, function () {
  24648. scope.manager.itemError( url );
  24649. scope.manager.itemEnd( url );
  24650. } );
  24651. }
  24652. if ( json !== undefined && json.length > 0 ) {
  24653. var manager = new LoadingManager( onLoad );
  24654. var loader = new ImageLoader( manager );
  24655. loader.setCrossOrigin( this.crossOrigin );
  24656. for ( var i = 0, il = json.length; i < il; i ++ ) {
  24657. var image = json[ i ];
  24658. var url = image.url;
  24659. if ( Array.isArray( url ) ) {
  24660. // load array of images e.g CubeTexture
  24661. images[ image.uuid ] = [];
  24662. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  24663. var currentUrl = url[ j ];
  24664. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  24665. images[ image.uuid ].push( loadImage( path ) );
  24666. }
  24667. } else {
  24668. // load single image
  24669. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  24670. images[ image.uuid ] = loadImage( path );
  24671. }
  24672. }
  24673. }
  24674. return images;
  24675. },
  24676. parseTextures: function ( json, images ) {
  24677. function parseConstant( value, type ) {
  24678. if ( typeof value === 'number' ) return value;
  24679. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  24680. return type[ value ];
  24681. }
  24682. var textures = {};
  24683. if ( json !== undefined ) {
  24684. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24685. var data = json[ i ];
  24686. if ( data.image === undefined ) {
  24687. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  24688. }
  24689. if ( images[ data.image ] === undefined ) {
  24690. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  24691. }
  24692. var texture;
  24693. if ( Array.isArray( images[ data.image ] ) ) {
  24694. texture = new CubeTexture( images[ data.image ] );
  24695. } else {
  24696. texture = new Texture( images[ data.image ] );
  24697. }
  24698. texture.needsUpdate = true;
  24699. texture.uuid = data.uuid;
  24700. if ( data.name !== undefined ) texture.name = data.name;
  24701. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  24702. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  24703. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  24704. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  24705. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  24706. if ( data.wrap !== undefined ) {
  24707. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  24708. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  24709. }
  24710. if ( data.format !== undefined ) texture.format = data.format;
  24711. if ( data.type !== undefined ) texture.type = data.type;
  24712. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  24713. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  24714. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  24715. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  24716. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  24717. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  24718. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  24719. textures[ data.uuid ] = texture;
  24720. }
  24721. }
  24722. return textures;
  24723. },
  24724. parseObject: function ( data, geometries, materials ) {
  24725. var object;
  24726. function getGeometry( name ) {
  24727. if ( geometries[ name ] === undefined ) {
  24728. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  24729. }
  24730. return geometries[ name ];
  24731. }
  24732. function getMaterial( name ) {
  24733. if ( name === undefined ) return undefined;
  24734. if ( Array.isArray( name ) ) {
  24735. var array = [];
  24736. for ( var i = 0, l = name.length; i < l; i ++ ) {
  24737. var uuid = name[ i ];
  24738. if ( materials[ uuid ] === undefined ) {
  24739. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  24740. }
  24741. array.push( materials[ uuid ] );
  24742. }
  24743. return array;
  24744. }
  24745. if ( materials[ name ] === undefined ) {
  24746. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  24747. }
  24748. return materials[ name ];
  24749. }
  24750. switch ( data.type ) {
  24751. case 'Scene':
  24752. object = new Scene();
  24753. if ( data.background !== undefined ) {
  24754. if ( Number.isInteger( data.background ) ) {
  24755. object.background = new Color( data.background );
  24756. }
  24757. }
  24758. if ( data.fog !== undefined ) {
  24759. if ( data.fog.type === 'Fog' ) {
  24760. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  24761. } else if ( data.fog.type === 'FogExp2' ) {
  24762. object.fog = new FogExp2( data.fog.color, data.fog.density );
  24763. }
  24764. }
  24765. break;
  24766. case 'PerspectiveCamera':
  24767. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  24768. if ( data.focus !== undefined ) object.focus = data.focus;
  24769. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24770. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  24771. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  24772. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24773. break;
  24774. case 'OrthographicCamera':
  24775. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  24776. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24777. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24778. break;
  24779. case 'AmbientLight':
  24780. object = new AmbientLight( data.color, data.intensity );
  24781. break;
  24782. case 'DirectionalLight':
  24783. object = new DirectionalLight( data.color, data.intensity );
  24784. break;
  24785. case 'PointLight':
  24786. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  24787. break;
  24788. case 'RectAreaLight':
  24789. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  24790. break;
  24791. case 'SpotLight':
  24792. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  24793. break;
  24794. case 'HemisphereLight':
  24795. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  24796. break;
  24797. case 'LightProbe':
  24798. object = new LightProbe().fromJSON( data );
  24799. break;
  24800. case 'SkinnedMesh':
  24801. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  24802. case 'Mesh':
  24803. var geometry = getGeometry( data.geometry );
  24804. var material = getMaterial( data.material );
  24805. object = new Mesh( geometry, material );
  24806. break;
  24807. case 'InstancedMesh':
  24808. var geometry = getGeometry( data.geometry );
  24809. var material = getMaterial( data.material );
  24810. var count = data.count;
  24811. var instanceMatrix = data.instanceMatrix;
  24812. object = new InstancedMesh( geometry, material, count );
  24813. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  24814. break;
  24815. case 'LOD':
  24816. object = new LOD();
  24817. break;
  24818. case 'Line':
  24819. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  24820. break;
  24821. case 'LineLoop':
  24822. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  24823. break;
  24824. case 'LineSegments':
  24825. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  24826. break;
  24827. case 'PointCloud':
  24828. case 'Points':
  24829. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  24830. break;
  24831. case 'Sprite':
  24832. object = new Sprite( getMaterial( data.material ) );
  24833. break;
  24834. case 'Group':
  24835. object = new Group();
  24836. break;
  24837. default:
  24838. object = new Object3D();
  24839. }
  24840. object.uuid = data.uuid;
  24841. if ( data.name !== undefined ) object.name = data.name;
  24842. if ( data.matrix !== undefined ) {
  24843. object.matrix.fromArray( data.matrix );
  24844. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24845. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  24846. } else {
  24847. if ( data.position !== undefined ) object.position.fromArray( data.position );
  24848. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  24849. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  24850. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  24851. }
  24852. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  24853. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  24854. if ( data.shadow ) {
  24855. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  24856. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  24857. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  24858. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  24859. }
  24860. if ( data.visible !== undefined ) object.visible = data.visible;
  24861. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  24862. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  24863. if ( data.userData !== undefined ) object.userData = data.userData;
  24864. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  24865. if ( data.children !== undefined ) {
  24866. var children = data.children;
  24867. for ( var i = 0; i < children.length; i ++ ) {
  24868. object.add( this.parseObject( children[ i ], geometries, materials ) );
  24869. }
  24870. }
  24871. if ( data.type === 'LOD' ) {
  24872. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  24873. var levels = data.levels;
  24874. for ( var l = 0; l < levels.length; l ++ ) {
  24875. var level = levels[ l ];
  24876. var child = object.getObjectByProperty( 'uuid', level.object );
  24877. if ( child !== undefined ) {
  24878. object.addLevel( child, level.distance );
  24879. }
  24880. }
  24881. }
  24882. return object;
  24883. }
  24884. } );
  24885. var TEXTURE_MAPPING = {
  24886. UVMapping: UVMapping,
  24887. CubeReflectionMapping: CubeReflectionMapping,
  24888. CubeRefractionMapping: CubeRefractionMapping,
  24889. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24890. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24891. SphericalReflectionMapping: SphericalReflectionMapping,
  24892. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24893. CubeUVRefractionMapping: CubeUVRefractionMapping
  24894. };
  24895. var TEXTURE_WRAPPING = {
  24896. RepeatWrapping: RepeatWrapping,
  24897. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24898. MirroredRepeatWrapping: MirroredRepeatWrapping
  24899. };
  24900. var TEXTURE_FILTER = {
  24901. NearestFilter: NearestFilter,
  24902. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24903. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24904. LinearFilter: LinearFilter,
  24905. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24906. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24907. };
  24908. /**
  24909. * @author thespite / http://clicktorelease.com/
  24910. */
  24911. function ImageBitmapLoader( manager ) {
  24912. if ( typeof createImageBitmap === 'undefined' ) {
  24913. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  24914. }
  24915. if ( typeof fetch === 'undefined' ) {
  24916. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  24917. }
  24918. Loader.call( this, manager );
  24919. this.options = undefined;
  24920. }
  24921. ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24922. constructor: ImageBitmapLoader,
  24923. setOptions: function setOptions( options ) {
  24924. this.options = options;
  24925. return this;
  24926. },
  24927. load: function ( url, onLoad, onProgress, onError ) {
  24928. if ( url === undefined ) url = '';
  24929. if ( this.path !== undefined ) url = this.path + url;
  24930. url = this.manager.resolveURL( url );
  24931. var scope = this;
  24932. var cached = Cache.get( url );
  24933. if ( cached !== undefined ) {
  24934. scope.manager.itemStart( url );
  24935. setTimeout( function () {
  24936. if ( onLoad ) onLoad( cached );
  24937. scope.manager.itemEnd( url );
  24938. }, 0 );
  24939. return cached;
  24940. }
  24941. fetch( url ).then( function ( res ) {
  24942. return res.blob();
  24943. } ).then( function ( blob ) {
  24944. if ( scope.options === undefined ) {
  24945. // Workaround for FireFox. It causes an error if you pass options.
  24946. return createImageBitmap( blob );
  24947. } else {
  24948. return createImageBitmap( blob, scope.options );
  24949. }
  24950. } ).then( function ( imageBitmap ) {
  24951. Cache.add( url, imageBitmap );
  24952. if ( onLoad ) onLoad( imageBitmap );
  24953. scope.manager.itemEnd( url );
  24954. } ).catch( function ( e ) {
  24955. if ( onError ) onError( e );
  24956. scope.manager.itemError( url );
  24957. scope.manager.itemEnd( url );
  24958. } );
  24959. scope.manager.itemStart( url );
  24960. }
  24961. } );
  24962. /**
  24963. * @author zz85 / http://www.lab4games.net/zz85/blog
  24964. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  24965. **/
  24966. function ShapePath() {
  24967. this.type = 'ShapePath';
  24968. this.color = new Color();
  24969. this.subPaths = [];
  24970. this.currentPath = null;
  24971. }
  24972. Object.assign( ShapePath.prototype, {
  24973. moveTo: function ( x, y ) {
  24974. this.currentPath = new Path();
  24975. this.subPaths.push( this.currentPath );
  24976. this.currentPath.moveTo( x, y );
  24977. return this;
  24978. },
  24979. lineTo: function ( x, y ) {
  24980. this.currentPath.lineTo( x, y );
  24981. return this;
  24982. },
  24983. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  24984. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  24985. return this;
  24986. },
  24987. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  24988. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  24989. return this;
  24990. },
  24991. splineThru: function ( pts ) {
  24992. this.currentPath.splineThru( pts );
  24993. return this;
  24994. },
  24995. toShapes: function ( isCCW, noHoles ) {
  24996. function toShapesNoHoles( inSubpaths ) {
  24997. var shapes = [];
  24998. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  24999. var tmpPath = inSubpaths[ i ];
  25000. var tmpShape = new Shape();
  25001. tmpShape.curves = tmpPath.curves;
  25002. shapes.push( tmpShape );
  25003. }
  25004. return shapes;
  25005. }
  25006. function isPointInsidePolygon( inPt, inPolygon ) {
  25007. var polyLen = inPolygon.length;
  25008. // inPt on polygon contour => immediate success or
  25009. // toggling of inside/outside at every single! intersection point of an edge
  25010. // with the horizontal line through inPt, left of inPt
  25011. // not counting lowerY endpoints of edges and whole edges on that line
  25012. var inside = false;
  25013. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  25014. var edgeLowPt = inPolygon[ p ];
  25015. var edgeHighPt = inPolygon[ q ];
  25016. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25017. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25018. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  25019. // not parallel
  25020. if ( edgeDy < 0 ) {
  25021. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  25022. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  25023. }
  25024. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  25025. if ( inPt.y === edgeLowPt.y ) {
  25026. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  25027. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25028. } else {
  25029. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  25030. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  25031. if ( perpEdge < 0 ) continue;
  25032. inside = ! inside; // true intersection left of inPt
  25033. }
  25034. } else {
  25035. // parallel or collinear
  25036. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  25037. // edge lies on the same horizontal line as inPt
  25038. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  25039. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  25040. // continue;
  25041. }
  25042. }
  25043. return inside;
  25044. }
  25045. var isClockWise = ShapeUtils.isClockWise;
  25046. var subPaths = this.subPaths;
  25047. if ( subPaths.length === 0 ) return [];
  25048. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  25049. var solid, tmpPath, tmpShape, shapes = [];
  25050. if ( subPaths.length === 1 ) {
  25051. tmpPath = subPaths[ 0 ];
  25052. tmpShape = new Shape();
  25053. tmpShape.curves = tmpPath.curves;
  25054. shapes.push( tmpShape );
  25055. return shapes;
  25056. }
  25057. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  25058. holesFirst = isCCW ? ! holesFirst : holesFirst;
  25059. // console.log("Holes first", holesFirst);
  25060. var betterShapeHoles = [];
  25061. var newShapes = [];
  25062. var newShapeHoles = [];
  25063. var mainIdx = 0;
  25064. var tmpPoints;
  25065. newShapes[ mainIdx ] = undefined;
  25066. newShapeHoles[ mainIdx ] = [];
  25067. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  25068. tmpPath = subPaths[ i ];
  25069. tmpPoints = tmpPath.getPoints();
  25070. solid = isClockWise( tmpPoints );
  25071. solid = isCCW ? ! solid : solid;
  25072. if ( solid ) {
  25073. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  25074. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  25075. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  25076. if ( holesFirst ) mainIdx ++;
  25077. newShapeHoles[ mainIdx ] = [];
  25078. //console.log('cw', i);
  25079. } else {
  25080. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  25081. //console.log('ccw', i);
  25082. }
  25083. }
  25084. // only Holes? -> probably all Shapes with wrong orientation
  25085. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  25086. if ( newShapes.length > 1 ) {
  25087. var ambiguous = false;
  25088. var toChange = [];
  25089. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25090. betterShapeHoles[ sIdx ] = [];
  25091. }
  25092. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25093. var sho = newShapeHoles[ sIdx ];
  25094. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  25095. var ho = sho[ hIdx ];
  25096. var hole_unassigned = true;
  25097. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  25098. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  25099. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  25100. if ( hole_unassigned ) {
  25101. hole_unassigned = false;
  25102. betterShapeHoles[ s2Idx ].push( ho );
  25103. } else {
  25104. ambiguous = true;
  25105. }
  25106. }
  25107. }
  25108. if ( hole_unassigned ) {
  25109. betterShapeHoles[ sIdx ].push( ho );
  25110. }
  25111. }
  25112. }
  25113. // console.log("ambiguous: ", ambiguous);
  25114. if ( toChange.length > 0 ) {
  25115. // console.log("to change: ", toChange);
  25116. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  25117. }
  25118. }
  25119. var tmpHoles;
  25120. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  25121. tmpShape = newShapes[ i ].s;
  25122. shapes.push( tmpShape );
  25123. tmpHoles = newShapeHoles[ i ];
  25124. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  25125. tmpShape.holes.push( tmpHoles[ j ].h );
  25126. }
  25127. }
  25128. //console.log("shape", shapes);
  25129. return shapes;
  25130. }
  25131. } );
  25132. /**
  25133. * @author zz85 / http://www.lab4games.net/zz85/blog
  25134. * @author mrdoob / http://mrdoob.com/
  25135. */
  25136. function Font( data ) {
  25137. this.type = 'Font';
  25138. this.data = data;
  25139. }
  25140. Object.assign( Font.prototype, {
  25141. isFont: true,
  25142. generateShapes: function ( text, size ) {
  25143. if ( size === undefined ) size = 100;
  25144. var shapes = [];
  25145. var paths = createPaths( text, size, this.data );
  25146. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  25147. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  25148. }
  25149. return shapes;
  25150. }
  25151. } );
  25152. function createPaths( text, size, data ) {
  25153. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // workaround for IE11, see #13988
  25154. var scale = size / data.resolution;
  25155. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  25156. var paths = [];
  25157. var offsetX = 0, offsetY = 0;
  25158. for ( var i = 0; i < chars.length; i ++ ) {
  25159. var char = chars[ i ];
  25160. if ( char === '\n' ) {
  25161. offsetX = 0;
  25162. offsetY -= line_height;
  25163. } else {
  25164. var ret = createPath( char, scale, offsetX, offsetY, data );
  25165. offsetX += ret.offsetX;
  25166. paths.push( ret.path );
  25167. }
  25168. }
  25169. return paths;
  25170. }
  25171. function createPath( char, scale, offsetX, offsetY, data ) {
  25172. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  25173. if ( ! glyph ) {
  25174. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  25175. return;
  25176. }
  25177. var path = new ShapePath();
  25178. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25179. if ( glyph.o ) {
  25180. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  25181. for ( var i = 0, l = outline.length; i < l; ) {
  25182. var action = outline[ i ++ ];
  25183. switch ( action ) {
  25184. case 'm': // moveTo
  25185. x = outline[ i ++ ] * scale + offsetX;
  25186. y = outline[ i ++ ] * scale + offsetY;
  25187. path.moveTo( x, y );
  25188. break;
  25189. case 'l': // lineTo
  25190. x = outline[ i ++ ] * scale + offsetX;
  25191. y = outline[ i ++ ] * scale + offsetY;
  25192. path.lineTo( x, y );
  25193. break;
  25194. case 'q': // quadraticCurveTo
  25195. cpx = outline[ i ++ ] * scale + offsetX;
  25196. cpy = outline[ i ++ ] * scale + offsetY;
  25197. cpx1 = outline[ i ++ ] * scale + offsetX;
  25198. cpy1 = outline[ i ++ ] * scale + offsetY;
  25199. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  25200. break;
  25201. case 'b': // bezierCurveTo
  25202. cpx = outline[ i ++ ] * scale + offsetX;
  25203. cpy = outline[ i ++ ] * scale + offsetY;
  25204. cpx1 = outline[ i ++ ] * scale + offsetX;
  25205. cpy1 = outline[ i ++ ] * scale + offsetY;
  25206. cpx2 = outline[ i ++ ] * scale + offsetX;
  25207. cpy2 = outline[ i ++ ] * scale + offsetY;
  25208. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  25209. break;
  25210. }
  25211. }
  25212. }
  25213. return { offsetX: glyph.ha * scale, path: path };
  25214. }
  25215. /**
  25216. * @author mrdoob / http://mrdoob.com/
  25217. */
  25218. function FontLoader( manager ) {
  25219. Loader.call( this, manager );
  25220. }
  25221. FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25222. constructor: FontLoader,
  25223. load: function ( url, onLoad, onProgress, onError ) {
  25224. var scope = this;
  25225. var loader = new FileLoader( this.manager );
  25226. loader.setPath( this.path );
  25227. loader.load( url, function ( text ) {
  25228. var json;
  25229. try {
  25230. json = JSON.parse( text );
  25231. } catch ( e ) {
  25232. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  25233. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  25234. }
  25235. var font = scope.parse( json );
  25236. if ( onLoad ) onLoad( font );
  25237. }, onProgress, onError );
  25238. },
  25239. parse: function ( json ) {
  25240. return new Font( json );
  25241. }
  25242. } );
  25243. /**
  25244. * @author mrdoob / http://mrdoob.com/
  25245. */
  25246. var _context;
  25247. var AudioContext = {
  25248. getContext: function () {
  25249. if ( _context === undefined ) {
  25250. _context = new ( window.AudioContext || window.webkitAudioContext )();
  25251. }
  25252. return _context;
  25253. },
  25254. setContext: function ( value ) {
  25255. _context = value;
  25256. }
  25257. };
  25258. /**
  25259. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25260. */
  25261. function AudioLoader( manager ) {
  25262. Loader.call( this, manager );
  25263. }
  25264. AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25265. constructor: AudioLoader,
  25266. load: function ( url, onLoad, onProgress, onError ) {
  25267. var scope = this;
  25268. var loader = new FileLoader( scope.manager );
  25269. loader.setResponseType( 'arraybuffer' );
  25270. loader.setPath( scope.path );
  25271. loader.load( url, function ( buffer ) {
  25272. try {
  25273. // Create a copy of the buffer. The `decodeAudioData` method
  25274. // detaches the buffer when complete, preventing reuse.
  25275. var bufferCopy = buffer.slice( 0 );
  25276. var context = AudioContext.getContext();
  25277. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  25278. onLoad( audioBuffer );
  25279. } );
  25280. } catch ( e ) {
  25281. if ( onError ) {
  25282. onError( e );
  25283. } else {
  25284. console.error( e );
  25285. }
  25286. scope.manager.itemError( url );
  25287. }
  25288. }, onProgress, onError );
  25289. }
  25290. } );
  25291. /**
  25292. * @author WestLangley / http://github.com/WestLangley
  25293. */
  25294. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  25295. LightProbe.call( this, undefined, intensity );
  25296. var color1 = new Color().set( skyColor );
  25297. var color2 = new Color().set( groundColor );
  25298. var sky = new Vector3( color1.r, color1.g, color1.b );
  25299. var ground = new Vector3( color2.r, color2.g, color2.b );
  25300. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25301. var c0 = Math.sqrt( Math.PI );
  25302. var c1 = c0 * Math.sqrt( 0.75 );
  25303. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  25304. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  25305. }
  25306. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25307. constructor: HemisphereLightProbe,
  25308. isHemisphereLightProbe: true,
  25309. copy: function ( source ) { // modifying colors not currently supported
  25310. LightProbe.prototype.copy.call( this, source );
  25311. return this;
  25312. },
  25313. toJSON: function ( meta ) {
  25314. var data = LightProbe.prototype.toJSON.call( this, meta );
  25315. // data.sh = this.sh.toArray(); // todo
  25316. return data;
  25317. }
  25318. } );
  25319. /**
  25320. * @author WestLangley / http://github.com/WestLangley
  25321. */
  25322. function AmbientLightProbe( color, intensity ) {
  25323. LightProbe.call( this, undefined, intensity );
  25324. var color1 = new Color().set( color );
  25325. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25326. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  25327. }
  25328. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25329. constructor: AmbientLightProbe,
  25330. isAmbientLightProbe: true,
  25331. copy: function ( source ) { // modifying color not currently supported
  25332. LightProbe.prototype.copy.call( this, source );
  25333. return this;
  25334. },
  25335. toJSON: function ( meta ) {
  25336. var data = LightProbe.prototype.toJSON.call( this, meta );
  25337. // data.sh = this.sh.toArray(); // todo
  25338. return data;
  25339. }
  25340. } );
  25341. var _eyeRight = new Matrix4();
  25342. var _eyeLeft = new Matrix4();
  25343. /**
  25344. * @author mrdoob / http://mrdoob.com/
  25345. */
  25346. function StereoCamera() {
  25347. this.type = 'StereoCamera';
  25348. this.aspect = 1;
  25349. this.eyeSep = 0.064;
  25350. this.cameraL = new PerspectiveCamera();
  25351. this.cameraL.layers.enable( 1 );
  25352. this.cameraL.matrixAutoUpdate = false;
  25353. this.cameraR = new PerspectiveCamera();
  25354. this.cameraR.layers.enable( 2 );
  25355. this.cameraR.matrixAutoUpdate = false;
  25356. this._cache = {
  25357. focus: null,
  25358. fov: null,
  25359. aspect: null,
  25360. near: null,
  25361. far: null,
  25362. zoom: null,
  25363. eyeSep: null
  25364. };
  25365. }
  25366. Object.assign( StereoCamera.prototype, {
  25367. update: function ( camera ) {
  25368. var cache = this._cache;
  25369. var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  25370. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  25371. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  25372. if ( needsUpdate ) {
  25373. cache.focus = camera.focus;
  25374. cache.fov = camera.fov;
  25375. cache.aspect = camera.aspect * this.aspect;
  25376. cache.near = camera.near;
  25377. cache.far = camera.far;
  25378. cache.zoom = camera.zoom;
  25379. cache.eyeSep = this.eyeSep;
  25380. // Off-axis stereoscopic effect based on
  25381. // http://paulbourke.net/stereographics/stereorender/
  25382. var projectionMatrix = camera.projectionMatrix.clone();
  25383. var eyeSepHalf = cache.eyeSep / 2;
  25384. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25385. var ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  25386. var xmin, xmax;
  25387. // translate xOffset
  25388. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  25389. _eyeRight.elements[ 12 ] = eyeSepHalf;
  25390. // for left eye
  25391. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  25392. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25393. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25394. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25395. this.cameraL.projectionMatrix.copy( projectionMatrix );
  25396. // for right eye
  25397. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  25398. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25399. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25400. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25401. this.cameraR.projectionMatrix.copy( projectionMatrix );
  25402. }
  25403. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  25404. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  25405. }
  25406. } );
  25407. /**
  25408. * @author alteredq / http://alteredqualia.com/
  25409. */
  25410. function Clock( autoStart ) {
  25411. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25412. this.startTime = 0;
  25413. this.oldTime = 0;
  25414. this.elapsedTime = 0;
  25415. this.running = false;
  25416. }
  25417. Object.assign( Clock.prototype, {
  25418. start: function () {
  25419. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25420. this.oldTime = this.startTime;
  25421. this.elapsedTime = 0;
  25422. this.running = true;
  25423. },
  25424. stop: function () {
  25425. this.getElapsedTime();
  25426. this.running = false;
  25427. this.autoStart = false;
  25428. },
  25429. getElapsedTime: function () {
  25430. this.getDelta();
  25431. return this.elapsedTime;
  25432. },
  25433. getDelta: function () {
  25434. var diff = 0;
  25435. if ( this.autoStart && ! this.running ) {
  25436. this.start();
  25437. return 0;
  25438. }
  25439. if ( this.running ) {
  25440. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25441. diff = ( newTime - this.oldTime ) / 1000;
  25442. this.oldTime = newTime;
  25443. this.elapsedTime += diff;
  25444. }
  25445. return diff;
  25446. }
  25447. } );
  25448. /**
  25449. * @author mrdoob / http://mrdoob.com/
  25450. */
  25451. var _position$2 = new Vector3();
  25452. var _quaternion$3 = new Quaternion();
  25453. var _scale$1 = new Vector3();
  25454. var _orientation = new Vector3();
  25455. function AudioListener() {
  25456. Object3D.call( this );
  25457. this.type = 'AudioListener';
  25458. this.context = AudioContext.getContext();
  25459. this.gain = this.context.createGain();
  25460. this.gain.connect( this.context.destination );
  25461. this.filter = null;
  25462. this.timeDelta = 0;
  25463. // private
  25464. this._clock = new Clock();
  25465. }
  25466. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25467. constructor: AudioListener,
  25468. getInput: function () {
  25469. return this.gain;
  25470. },
  25471. removeFilter: function ( ) {
  25472. if ( this.filter !== null ) {
  25473. this.gain.disconnect( this.filter );
  25474. this.filter.disconnect( this.context.destination );
  25475. this.gain.connect( this.context.destination );
  25476. this.filter = null;
  25477. }
  25478. return this;
  25479. },
  25480. getFilter: function () {
  25481. return this.filter;
  25482. },
  25483. setFilter: function ( value ) {
  25484. if ( this.filter !== null ) {
  25485. this.gain.disconnect( this.filter );
  25486. this.filter.disconnect( this.context.destination );
  25487. } else {
  25488. this.gain.disconnect( this.context.destination );
  25489. }
  25490. this.filter = value;
  25491. this.gain.connect( this.filter );
  25492. this.filter.connect( this.context.destination );
  25493. return this;
  25494. },
  25495. getMasterVolume: function () {
  25496. return this.gain.gain.value;
  25497. },
  25498. setMasterVolume: function ( value ) {
  25499. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25500. return this;
  25501. },
  25502. updateMatrixWorld: function ( force ) {
  25503. Object3D.prototype.updateMatrixWorld.call( this, force );
  25504. var listener = this.context.listener;
  25505. var up = this.up;
  25506. this.timeDelta = this._clock.getDelta();
  25507. this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 );
  25508. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  25509. if ( listener.positionX ) {
  25510. // code path for Chrome (see #14393)
  25511. var endTime = this.context.currentTime + this.timeDelta;
  25512. listener.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  25513. listener.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  25514. listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  25515. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  25516. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  25517. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  25518. listener.upX.linearRampToValueAtTime( up.x, endTime );
  25519. listener.upY.linearRampToValueAtTime( up.y, endTime );
  25520. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  25521. } else {
  25522. listener.setPosition( _position$2.x, _position$2.y, _position$2.z );
  25523. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  25524. }
  25525. }
  25526. } );
  25527. /**
  25528. * @author mrdoob / http://mrdoob.com/
  25529. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25530. */
  25531. function Audio( listener ) {
  25532. Object3D.call( this );
  25533. this.type = 'Audio';
  25534. this.listener = listener;
  25535. this.context = listener.context;
  25536. this.gain = this.context.createGain();
  25537. this.gain.connect( listener.getInput() );
  25538. this.autoplay = false;
  25539. this.buffer = null;
  25540. this.detune = 0;
  25541. this.loop = false;
  25542. this.loopStart = 0;
  25543. this.loopEnd = 0;
  25544. this.offset = 0;
  25545. this.duration = undefined;
  25546. this.playbackRate = 1;
  25547. this.isPlaying = false;
  25548. this.hasPlaybackControl = true;
  25549. this.sourceType = 'empty';
  25550. this._startedAt = 0;
  25551. this._progress = 0;
  25552. this.filters = [];
  25553. }
  25554. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25555. constructor: Audio,
  25556. getOutput: function () {
  25557. return this.gain;
  25558. },
  25559. setNodeSource: function ( audioNode ) {
  25560. this.hasPlaybackControl = false;
  25561. this.sourceType = 'audioNode';
  25562. this.source = audioNode;
  25563. this.connect();
  25564. return this;
  25565. },
  25566. setMediaElementSource: function ( mediaElement ) {
  25567. this.hasPlaybackControl = false;
  25568. this.sourceType = 'mediaNode';
  25569. this.source = this.context.createMediaElementSource( mediaElement );
  25570. this.connect();
  25571. return this;
  25572. },
  25573. setMediaStreamSource: function ( mediaStream ) {
  25574. this.hasPlaybackControl = false;
  25575. this.sourceType = 'mediaStreamNode';
  25576. this.source = this.context.createMediaStreamSource( mediaStream );
  25577. this.connect();
  25578. return this;
  25579. },
  25580. setBuffer: function ( audioBuffer ) {
  25581. this.buffer = audioBuffer;
  25582. this.sourceType = 'buffer';
  25583. if ( this.autoplay ) this.play();
  25584. return this;
  25585. },
  25586. play: function ( delay ) {
  25587. if ( delay === undefined ) delay = 0;
  25588. if ( this.isPlaying === true ) {
  25589. console.warn( 'THREE.Audio: Audio is already playing.' );
  25590. return;
  25591. }
  25592. if ( this.hasPlaybackControl === false ) {
  25593. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25594. return;
  25595. }
  25596. this._startedAt = this.context.currentTime + delay;
  25597. var source = this.context.createBufferSource();
  25598. source.buffer = this.buffer;
  25599. source.loop = this.loop;
  25600. source.loopStart = this.loopStart;
  25601. source.loopEnd = this.loopEnd;
  25602. source.onended = this.onEnded.bind( this );
  25603. source.start( this._startedAt, this._progress + this.offset, this.duration );
  25604. this.isPlaying = true;
  25605. this.source = source;
  25606. this.setDetune( this.detune );
  25607. this.setPlaybackRate( this.playbackRate );
  25608. return this.connect();
  25609. },
  25610. pause: function () {
  25611. if ( this.hasPlaybackControl === false ) {
  25612. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25613. return;
  25614. }
  25615. if ( this.isPlaying === true ) {
  25616. // update current progress
  25617. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  25618. if ( this.loop === true ) {
  25619. // ensure _progress does not exceed duration with looped audios
  25620. this._progress = this._progress % ( this.duration || this.buffer.duration );
  25621. }
  25622. this.source.stop();
  25623. this.source.onended = null;
  25624. this.isPlaying = false;
  25625. }
  25626. return this;
  25627. },
  25628. stop: function () {
  25629. if ( this.hasPlaybackControl === false ) {
  25630. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25631. return;
  25632. }
  25633. this._progress = 0;
  25634. this.source.stop();
  25635. this.source.onended = null;
  25636. this.isPlaying = false;
  25637. return this;
  25638. },
  25639. connect: function () {
  25640. if ( this.filters.length > 0 ) {
  25641. this.source.connect( this.filters[ 0 ] );
  25642. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25643. this.filters[ i - 1 ].connect( this.filters[ i ] );
  25644. }
  25645. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  25646. } else {
  25647. this.source.connect( this.getOutput() );
  25648. }
  25649. return this;
  25650. },
  25651. disconnect: function () {
  25652. if ( this.filters.length > 0 ) {
  25653. this.source.disconnect( this.filters[ 0 ] );
  25654. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25655. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  25656. }
  25657. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  25658. } else {
  25659. this.source.disconnect( this.getOutput() );
  25660. }
  25661. return this;
  25662. },
  25663. getFilters: function () {
  25664. return this.filters;
  25665. },
  25666. setFilters: function ( value ) {
  25667. if ( ! value ) value = [];
  25668. if ( this.isPlaying === true ) {
  25669. this.disconnect();
  25670. this.filters = value;
  25671. this.connect();
  25672. } else {
  25673. this.filters = value;
  25674. }
  25675. return this;
  25676. },
  25677. setDetune: function ( value ) {
  25678. this.detune = value;
  25679. if ( this.source.detune === undefined ) return; // only set detune when available
  25680. if ( this.isPlaying === true ) {
  25681. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  25682. }
  25683. return this;
  25684. },
  25685. getDetune: function () {
  25686. return this.detune;
  25687. },
  25688. getFilter: function () {
  25689. return this.getFilters()[ 0 ];
  25690. },
  25691. setFilter: function ( filter ) {
  25692. return this.setFilters( filter ? [ filter ] : [] );
  25693. },
  25694. setPlaybackRate: function ( value ) {
  25695. if ( this.hasPlaybackControl === false ) {
  25696. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25697. return;
  25698. }
  25699. this.playbackRate = value;
  25700. if ( this.isPlaying === true ) {
  25701. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  25702. }
  25703. return this;
  25704. },
  25705. getPlaybackRate: function () {
  25706. return this.playbackRate;
  25707. },
  25708. onEnded: function () {
  25709. this.isPlaying = false;
  25710. },
  25711. getLoop: function () {
  25712. if ( this.hasPlaybackControl === false ) {
  25713. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25714. return false;
  25715. }
  25716. return this.loop;
  25717. },
  25718. setLoop: function ( value ) {
  25719. if ( this.hasPlaybackControl === false ) {
  25720. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25721. return;
  25722. }
  25723. this.loop = value;
  25724. if ( this.isPlaying === true ) {
  25725. this.source.loop = this.loop;
  25726. }
  25727. return this;
  25728. },
  25729. setLoopStart: function ( value ) {
  25730. this.loopStart = value;
  25731. return this;
  25732. },
  25733. setLoopEnd: function ( value ) {
  25734. this.loopEnd = value;
  25735. return this;
  25736. },
  25737. getVolume: function () {
  25738. return this.gain.gain.value;
  25739. },
  25740. setVolume: function ( value ) {
  25741. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25742. return this;
  25743. }
  25744. } );
  25745. /**
  25746. * @author mrdoob / http://mrdoob.com/
  25747. */
  25748. var _position$3 = new Vector3();
  25749. var _quaternion$4 = new Quaternion();
  25750. var _scale$2 = new Vector3();
  25751. var _orientation$1 = new Vector3();
  25752. function PositionalAudio( listener ) {
  25753. Audio.call( this, listener );
  25754. this.panner = this.context.createPanner();
  25755. this.panner.panningModel = 'HRTF';
  25756. this.panner.connect( this.gain );
  25757. }
  25758. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  25759. constructor: PositionalAudio,
  25760. getOutput: function () {
  25761. return this.panner;
  25762. },
  25763. getRefDistance: function () {
  25764. return this.panner.refDistance;
  25765. },
  25766. setRefDistance: function ( value ) {
  25767. this.panner.refDistance = value;
  25768. return this;
  25769. },
  25770. getRolloffFactor: function () {
  25771. return this.panner.rolloffFactor;
  25772. },
  25773. setRolloffFactor: function ( value ) {
  25774. this.panner.rolloffFactor = value;
  25775. return this;
  25776. },
  25777. getDistanceModel: function () {
  25778. return this.panner.distanceModel;
  25779. },
  25780. setDistanceModel: function ( value ) {
  25781. this.panner.distanceModel = value;
  25782. return this;
  25783. },
  25784. getMaxDistance: function () {
  25785. return this.panner.maxDistance;
  25786. },
  25787. setMaxDistance: function ( value ) {
  25788. this.panner.maxDistance = value;
  25789. return this;
  25790. },
  25791. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  25792. this.panner.coneInnerAngle = coneInnerAngle;
  25793. this.panner.coneOuterAngle = coneOuterAngle;
  25794. this.panner.coneOuterGain = coneOuterGain;
  25795. return this;
  25796. },
  25797. updateMatrixWorld: function ( force ) {
  25798. Object3D.prototype.updateMatrixWorld.call( this, force );
  25799. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  25800. this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 );
  25801. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  25802. var panner = this.panner;
  25803. if ( panner.positionX ) {
  25804. // code path for Chrome and Firefox (see #14393)
  25805. var endTime = this.context.currentTime + this.listener.timeDelta;
  25806. panner.positionX.linearRampToValueAtTime( _position$3.x, endTime );
  25807. panner.positionY.linearRampToValueAtTime( _position$3.y, endTime );
  25808. panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime );
  25809. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  25810. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  25811. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  25812. } else {
  25813. panner.setPosition( _position$3.x, _position$3.y, _position$3.z );
  25814. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  25815. }
  25816. }
  25817. } );
  25818. /**
  25819. * @author mrdoob / http://mrdoob.com/
  25820. */
  25821. function AudioAnalyser( audio, fftSize ) {
  25822. this.analyser = audio.context.createAnalyser();
  25823. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25824. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  25825. audio.getOutput().connect( this.analyser );
  25826. }
  25827. Object.assign( AudioAnalyser.prototype, {
  25828. getFrequencyData: function () {
  25829. this.analyser.getByteFrequencyData( this.data );
  25830. return this.data;
  25831. },
  25832. getAverageFrequency: function () {
  25833. var value = 0, data = this.getFrequencyData();
  25834. for ( var i = 0; i < data.length; i ++ ) {
  25835. value += data[ i ];
  25836. }
  25837. return value / data.length;
  25838. }
  25839. } );
  25840. /**
  25841. *
  25842. * Buffered scene graph property that allows weighted accumulation.
  25843. *
  25844. *
  25845. * @author Ben Houston / http://clara.io/
  25846. * @author David Sarno / http://lighthaus.us/
  25847. * @author tschw
  25848. */
  25849. function PropertyMixer( binding, typeName, valueSize ) {
  25850. this.binding = binding;
  25851. this.valueSize = valueSize;
  25852. var mixFunction,
  25853. mixFunctionAdditive,
  25854. setIdentity;
  25855. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25856. //
  25857. // interpolators can use .buffer as their .result
  25858. // the data then goes to 'incoming'
  25859. //
  25860. // 'accu0' and 'accu1' are used frame-interleaved for
  25861. // the cumulative result and are compared to detect
  25862. // changes
  25863. //
  25864. // 'orig' stores the original state of the property
  25865. //
  25866. // 'add' is used for additive cumulative results
  25867. //
  25868. // 'work' is optional and is only present for quaternion types. It is used
  25869. // to store intermediate quaternion multiplication results
  25870. switch ( typeName ) {
  25871. case 'quaternion':
  25872. mixFunction = this._slerp;
  25873. mixFunctionAdditive = this._slerpAdditive;
  25874. setIdentity = this._setAdditiveIdentityQuaternion;
  25875. this.buffer = new Float64Array( valueSize * 6 );
  25876. this._workIndex = 5;
  25877. break;
  25878. case 'string':
  25879. case 'bool':
  25880. mixFunction = this._select;
  25881. // Use the regular mix function and for additive on these types,
  25882. // additive is not relevant for non-numeric types
  25883. mixFunctionAdditive = this._select;
  25884. setIdentity = this._setAdditiveIdentityOther;
  25885. this.buffer = new Array( valueSize * 5 );
  25886. break;
  25887. default:
  25888. mixFunction = this._lerp;
  25889. mixFunctionAdditive = this._lerpAdditive;
  25890. setIdentity = this._setAdditiveIdentityNumeric;
  25891. this.buffer = new Float64Array( valueSize * 5 );
  25892. }
  25893. this._mixBufferRegion = mixFunction;
  25894. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25895. this._setIdentity = setIdentity;
  25896. this._origIndex = 3;
  25897. this._addIndex = 4;
  25898. this.cumulativeWeight = 0;
  25899. this.cumulativeWeightAdditive = 0;
  25900. this.useCount = 0;
  25901. this.referenceCount = 0;
  25902. }
  25903. Object.assign( PropertyMixer.prototype, {
  25904. // accumulate data in the 'incoming' region into 'accu<i>'
  25905. accumulate: function ( accuIndex, weight ) {
  25906. // note: happily accumulating nothing when weight = 0, the caller knows
  25907. // the weight and shouldn't have made the call in the first place
  25908. var buffer = this.buffer,
  25909. stride = this.valueSize,
  25910. offset = accuIndex * stride + stride,
  25911. currentWeight = this.cumulativeWeight;
  25912. if ( currentWeight === 0 ) {
  25913. // accuN := incoming * weight
  25914. for ( var i = 0; i !== stride; ++ i ) {
  25915. buffer[ offset + i ] = buffer[ i ];
  25916. }
  25917. currentWeight = weight;
  25918. } else {
  25919. // accuN := accuN + incoming * weight
  25920. currentWeight += weight;
  25921. var mix = weight / currentWeight;
  25922. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25923. }
  25924. this.cumulativeWeight = currentWeight;
  25925. },
  25926. // accumulate data in the 'incoming' region into 'add'
  25927. accumulateAdditive: function ( weight ) {
  25928. var buffer = this.buffer,
  25929. stride = this.valueSize,
  25930. offset = stride * this._addIndex;
  25931. if ( this.cumulativeWeightAdditive === 0 ) {
  25932. // add = identity
  25933. this._setIdentity();
  25934. }
  25935. // add := add + incoming * weight
  25936. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  25937. this.cumulativeWeightAdditive += weight;
  25938. },
  25939. // apply the state of 'accu<i>' to the binding when accus differ
  25940. apply: function ( accuIndex ) {
  25941. var stride = this.valueSize,
  25942. buffer = this.buffer,
  25943. offset = accuIndex * stride + stride,
  25944. weight = this.cumulativeWeight,
  25945. weightAdditive = this.cumulativeWeightAdditive,
  25946. binding = this.binding;
  25947. this.cumulativeWeight = 0;
  25948. this.cumulativeWeightAdditive = 0;
  25949. if ( weight < 1 ) {
  25950. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25951. var originalValueOffset = stride * this._origIndex;
  25952. this._mixBufferRegion(
  25953. buffer, offset, originalValueOffset, 1 - weight, stride );
  25954. }
  25955. if ( weightAdditive > 0 ) {
  25956. // accuN := accuN + additive accuN
  25957. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  25958. }
  25959. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  25960. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25961. // value has changed -> update scene graph
  25962. binding.setValue( buffer, offset );
  25963. break;
  25964. }
  25965. }
  25966. },
  25967. // remember the state of the bound property and copy it to both accus
  25968. saveOriginalState: function () {
  25969. var binding = this.binding;
  25970. var buffer = this.buffer,
  25971. stride = this.valueSize,
  25972. originalValueOffset = stride * this._origIndex;
  25973. binding.getValue( buffer, originalValueOffset );
  25974. // accu[0..1] := orig -- initially detect changes against the original
  25975. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25976. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25977. }
  25978. // Add to identity for additive
  25979. this._setIdentity();
  25980. this.cumulativeWeight = 0;
  25981. this.cumulativeWeightAdditive = 0;
  25982. },
  25983. // apply the state previously taken via 'saveOriginalState' to the binding
  25984. restoreOriginalState: function () {
  25985. var originalValueOffset = this.valueSize * 3;
  25986. this.binding.setValue( this.buffer, originalValueOffset );
  25987. },
  25988. _setAdditiveIdentityNumeric: function () {
  25989. var startIndex = this._addIndex * this.valueSize;
  25990. var endIndex = startIndex + this.valueSize;
  25991. for ( var i = startIndex; i < endIndex; i ++ ) {
  25992. this.buffer[ i ] = 0;
  25993. }
  25994. },
  25995. _setAdditiveIdentityQuaternion: function () {
  25996. this._setAdditiveIdentityNumeric();
  25997. this.buffer[ this._addIndex * 4 + 3 ] = 1;
  25998. },
  25999. _setAdditiveIdentityOther: function () {
  26000. var startIndex = this._origIndex * this.valueSize;
  26001. var targetIndex = this._addIndex * this.valueSize;
  26002. for ( var i = 0; i < this.valueSize; i ++ ) {
  26003. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  26004. }
  26005. },
  26006. // mix functions
  26007. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26008. if ( t >= 0.5 ) {
  26009. for ( var i = 0; i !== stride; ++ i ) {
  26010. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  26011. }
  26012. }
  26013. },
  26014. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  26015. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  26016. },
  26017. _slerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26018. var workOffset = this._workIndex * stride;
  26019. // Store result in intermediate buffer offset
  26020. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  26021. // Slerp to the intermediate result
  26022. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  26023. },
  26024. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26025. var s = 1 - t;
  26026. for ( var i = 0; i !== stride; ++ i ) {
  26027. var j = dstOffset + i;
  26028. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  26029. }
  26030. },
  26031. _lerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26032. for ( var i = 0; i !== stride; ++ i ) {
  26033. var j = dstOffset + i;
  26034. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  26035. }
  26036. }
  26037. } );
  26038. /**
  26039. *
  26040. * A reference to a real property in the scene graph.
  26041. *
  26042. *
  26043. * @author Ben Houston / http://clara.io/
  26044. * @author David Sarno / http://lighthaus.us/
  26045. * @author tschw
  26046. */
  26047. // Characters [].:/ are reserved for track binding syntax.
  26048. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26049. var _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  26050. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26051. // only latin characters, and the unicode \p{L} is not yet supported. So
  26052. // instead, we exclude reserved characters and match everything else.
  26053. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26054. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  26055. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26056. // be matched to parse the rest of the track name.
  26057. var _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  26058. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26059. var _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  26060. // Object on target node, and accessor. May not contain reserved
  26061. // characters. Accessor may contain any character except closing bracket.
  26062. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  26063. // Property and accessor. May not contain reserved characters. Accessor may
  26064. // contain any non-bracket characters.
  26065. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  26066. var _trackRe = new RegExp( ''
  26067. + '^'
  26068. + _directoryRe
  26069. + _nodeRe
  26070. + _objectRe
  26071. + _propertyRe
  26072. + '$'
  26073. );
  26074. var _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  26075. function Composite( targetGroup, path, optionalParsedPath ) {
  26076. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  26077. this._targetGroup = targetGroup;
  26078. this._bindings = targetGroup.subscribe_( path, parsedPath );
  26079. }
  26080. Object.assign( Composite.prototype, {
  26081. getValue: function ( array, offset ) {
  26082. this.bind(); // bind all binding
  26083. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26084. binding = this._bindings[ firstValidIndex ];
  26085. // and only call .getValue on the first
  26086. if ( binding !== undefined ) binding.getValue( array, offset );
  26087. },
  26088. setValue: function ( array, offset ) {
  26089. var bindings = this._bindings;
  26090. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26091. bindings[ i ].setValue( array, offset );
  26092. }
  26093. },
  26094. bind: function () {
  26095. var bindings = this._bindings;
  26096. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26097. bindings[ i ].bind();
  26098. }
  26099. },
  26100. unbind: function () {
  26101. var bindings = this._bindings;
  26102. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26103. bindings[ i ].unbind();
  26104. }
  26105. }
  26106. } );
  26107. function PropertyBinding( rootNode, path, parsedPath ) {
  26108. this.path = path;
  26109. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  26110. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  26111. this.rootNode = rootNode;
  26112. }
  26113. Object.assign( PropertyBinding, {
  26114. Composite: Composite,
  26115. create: function ( root, path, parsedPath ) {
  26116. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  26117. return new PropertyBinding( root, path, parsedPath );
  26118. } else {
  26119. return new PropertyBinding.Composite( root, path, parsedPath );
  26120. }
  26121. },
  26122. /**
  26123. * Replaces spaces with underscores and removes unsupported characters from
  26124. * node names, to ensure compatibility with parseTrackName().
  26125. *
  26126. * @param {string} name Node name to be sanitized.
  26127. * @return {string}
  26128. */
  26129. sanitizeNodeName: function ( name ) {
  26130. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  26131. },
  26132. parseTrackName: function ( trackName ) {
  26133. var matches = _trackRe.exec( trackName );
  26134. if ( ! matches ) {
  26135. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  26136. }
  26137. var results = {
  26138. // directoryName: matches[ 1 ], // (tschw) currently unused
  26139. nodeName: matches[ 2 ],
  26140. objectName: matches[ 3 ],
  26141. objectIndex: matches[ 4 ],
  26142. propertyName: matches[ 5 ], // required
  26143. propertyIndex: matches[ 6 ]
  26144. };
  26145. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  26146. if ( lastDot !== undefined && lastDot !== - 1 ) {
  26147. var objectName = results.nodeName.substring( lastDot + 1 );
  26148. // Object names must be checked against a whitelist. Otherwise, there
  26149. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26150. // 'bar' could be the objectName, or part of a nodeName (which can
  26151. // include '.' characters).
  26152. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  26153. results.nodeName = results.nodeName.substring( 0, lastDot );
  26154. results.objectName = objectName;
  26155. }
  26156. }
  26157. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  26158. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  26159. }
  26160. return results;
  26161. },
  26162. findNode: function ( root, nodeName ) {
  26163. if ( ! nodeName || nodeName === "" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  26164. return root;
  26165. }
  26166. // search into skeleton bones.
  26167. if ( root.skeleton ) {
  26168. var bone = root.skeleton.getBoneByName( nodeName );
  26169. if ( bone !== undefined ) {
  26170. return bone;
  26171. }
  26172. }
  26173. // search into node subtree.
  26174. if ( root.children ) {
  26175. var searchNodeSubtree = function ( children ) {
  26176. for ( var i = 0; i < children.length; i ++ ) {
  26177. var childNode = children[ i ];
  26178. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  26179. return childNode;
  26180. }
  26181. var result = searchNodeSubtree( childNode.children );
  26182. if ( result ) return result;
  26183. }
  26184. return null;
  26185. };
  26186. var subTreeNode = searchNodeSubtree( root.children );
  26187. if ( subTreeNode ) {
  26188. return subTreeNode;
  26189. }
  26190. }
  26191. return null;
  26192. }
  26193. } );
  26194. Object.assign( PropertyBinding.prototype, { // prototype, continued
  26195. // these are used to "bind" a nonexistent property
  26196. _getValue_unavailable: function () {},
  26197. _setValue_unavailable: function () {},
  26198. BindingType: {
  26199. Direct: 0,
  26200. EntireArray: 1,
  26201. ArrayElement: 2,
  26202. HasFromToArray: 3
  26203. },
  26204. Versioning: {
  26205. None: 0,
  26206. NeedsUpdate: 1,
  26207. MatrixWorldNeedsUpdate: 2
  26208. },
  26209. GetterByBindingType: [
  26210. function getValue_direct( buffer, offset ) {
  26211. buffer[ offset ] = this.node[ this.propertyName ];
  26212. },
  26213. function getValue_array( buffer, offset ) {
  26214. var source = this.resolvedProperty;
  26215. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  26216. buffer[ offset ++ ] = source[ i ];
  26217. }
  26218. },
  26219. function getValue_arrayElement( buffer, offset ) {
  26220. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  26221. },
  26222. function getValue_toArray( buffer, offset ) {
  26223. this.resolvedProperty.toArray( buffer, offset );
  26224. }
  26225. ],
  26226. SetterByBindingTypeAndVersioning: [
  26227. [
  26228. // Direct
  26229. function setValue_direct( buffer, offset ) {
  26230. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26231. },
  26232. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  26233. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26234. this.targetObject.needsUpdate = true;
  26235. },
  26236. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26237. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26238. this.targetObject.matrixWorldNeedsUpdate = true;
  26239. }
  26240. ], [
  26241. // EntireArray
  26242. function setValue_array( buffer, offset ) {
  26243. var dest = this.resolvedProperty;
  26244. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26245. dest[ i ] = buffer[ offset ++ ];
  26246. }
  26247. },
  26248. function setValue_array_setNeedsUpdate( buffer, offset ) {
  26249. var dest = this.resolvedProperty;
  26250. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26251. dest[ i ] = buffer[ offset ++ ];
  26252. }
  26253. this.targetObject.needsUpdate = true;
  26254. },
  26255. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26256. var dest = this.resolvedProperty;
  26257. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  26258. dest[ i ] = buffer[ offset ++ ];
  26259. }
  26260. this.targetObject.matrixWorldNeedsUpdate = true;
  26261. }
  26262. ], [
  26263. // ArrayElement
  26264. function setValue_arrayElement( buffer, offset ) {
  26265. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26266. },
  26267. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  26268. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26269. this.targetObject.needsUpdate = true;
  26270. },
  26271. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26272. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26273. this.targetObject.matrixWorldNeedsUpdate = true;
  26274. }
  26275. ], [
  26276. // HasToFromArray
  26277. function setValue_fromArray( buffer, offset ) {
  26278. this.resolvedProperty.fromArray( buffer, offset );
  26279. },
  26280. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  26281. this.resolvedProperty.fromArray( buffer, offset );
  26282. this.targetObject.needsUpdate = true;
  26283. },
  26284. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26285. this.resolvedProperty.fromArray( buffer, offset );
  26286. this.targetObject.matrixWorldNeedsUpdate = true;
  26287. }
  26288. ]
  26289. ],
  26290. getValue: function getValue_unbound( targetArray, offset ) {
  26291. this.bind();
  26292. this.getValue( targetArray, offset );
  26293. // Note: This class uses a State pattern on a per-method basis:
  26294. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26295. // prototype version of these methods with one that represents
  26296. // the bound state. When the property is not found, the methods
  26297. // become no-ops.
  26298. },
  26299. setValue: function getValue_unbound( sourceArray, offset ) {
  26300. this.bind();
  26301. this.setValue( sourceArray, offset );
  26302. },
  26303. // create getter / setter pair for a property in the scene graph
  26304. bind: function () {
  26305. var targetObject = this.node,
  26306. parsedPath = this.parsedPath,
  26307. objectName = parsedPath.objectName,
  26308. propertyName = parsedPath.propertyName,
  26309. propertyIndex = parsedPath.propertyIndex;
  26310. if ( ! targetObject ) {
  26311. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  26312. this.node = targetObject;
  26313. }
  26314. // set fail state so we can just 'return' on error
  26315. this.getValue = this._getValue_unavailable;
  26316. this.setValue = this._setValue_unavailable;
  26317. // ensure there is a value node
  26318. if ( ! targetObject ) {
  26319. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  26320. return;
  26321. }
  26322. if ( objectName ) {
  26323. var objectIndex = parsedPath.objectIndex;
  26324. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26325. switch ( objectName ) {
  26326. case 'materials':
  26327. if ( ! targetObject.material ) {
  26328. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  26329. return;
  26330. }
  26331. if ( ! targetObject.material.materials ) {
  26332. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  26333. return;
  26334. }
  26335. targetObject = targetObject.material.materials;
  26336. break;
  26337. case 'bones':
  26338. if ( ! targetObject.skeleton ) {
  26339. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  26340. return;
  26341. }
  26342. // potential future optimization: skip this if propertyIndex is already an integer
  26343. // and convert the integer string to a true integer.
  26344. targetObject = targetObject.skeleton.bones;
  26345. // support resolving morphTarget names into indices.
  26346. for ( var i = 0; i < targetObject.length; i ++ ) {
  26347. if ( targetObject[ i ].name === objectIndex ) {
  26348. objectIndex = i;
  26349. break;
  26350. }
  26351. }
  26352. break;
  26353. default:
  26354. if ( targetObject[ objectName ] === undefined ) {
  26355. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  26356. return;
  26357. }
  26358. targetObject = targetObject[ objectName ];
  26359. }
  26360. if ( objectIndex !== undefined ) {
  26361. if ( targetObject[ objectIndex ] === undefined ) {
  26362. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  26363. return;
  26364. }
  26365. targetObject = targetObject[ objectIndex ];
  26366. }
  26367. }
  26368. // resolve property
  26369. var nodeProperty = targetObject[ propertyName ];
  26370. if ( nodeProperty === undefined ) {
  26371. var nodeName = parsedPath.nodeName;
  26372. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  26373. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  26374. return;
  26375. }
  26376. // determine versioning scheme
  26377. var versioning = this.Versioning.None;
  26378. this.targetObject = targetObject;
  26379. if ( targetObject.needsUpdate !== undefined ) { // material
  26380. versioning = this.Versioning.NeedsUpdate;
  26381. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  26382. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26383. }
  26384. // determine how the property gets bound
  26385. var bindingType = this.BindingType.Direct;
  26386. if ( propertyIndex !== undefined ) {
  26387. // access a sub element of the property array (only primitives are supported right now)
  26388. if ( propertyName === "morphTargetInfluences" ) {
  26389. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26390. // support resolving morphTarget names into indices.
  26391. if ( ! targetObject.geometry ) {
  26392. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  26393. return;
  26394. }
  26395. if ( targetObject.geometry.isBufferGeometry ) {
  26396. if ( ! targetObject.geometry.morphAttributes ) {
  26397. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  26398. return;
  26399. }
  26400. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  26401. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  26402. }
  26403. } else {
  26404. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this );
  26405. return;
  26406. }
  26407. }
  26408. bindingType = this.BindingType.ArrayElement;
  26409. this.resolvedProperty = nodeProperty;
  26410. this.propertyIndex = propertyIndex;
  26411. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  26412. // must use copy for Object3D.Euler/Quaternion
  26413. bindingType = this.BindingType.HasFromToArray;
  26414. this.resolvedProperty = nodeProperty;
  26415. } else if ( Array.isArray( nodeProperty ) ) {
  26416. bindingType = this.BindingType.EntireArray;
  26417. this.resolvedProperty = nodeProperty;
  26418. } else {
  26419. this.propertyName = propertyName;
  26420. }
  26421. // select getter / setter
  26422. this.getValue = this.GetterByBindingType[ bindingType ];
  26423. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  26424. },
  26425. unbind: function () {
  26426. this.node = null;
  26427. // back to the prototype version of getValue / setValue
  26428. // note: avoiding to mutate the shape of 'this' via 'delete'
  26429. this.getValue = this._getValue_unbound;
  26430. this.setValue = this._setValue_unbound;
  26431. }
  26432. } );
  26433. // DECLARE ALIAS AFTER assign prototype
  26434. Object.assign( PropertyBinding.prototype, {
  26435. // initial state of these methods that calls 'bind'
  26436. _getValue_unbound: PropertyBinding.prototype.getValue,
  26437. _setValue_unbound: PropertyBinding.prototype.setValue,
  26438. } );
  26439. /**
  26440. *
  26441. * A group of objects that receives a shared animation state.
  26442. *
  26443. * Usage:
  26444. *
  26445. * - Add objects you would otherwise pass as 'root' to the
  26446. * constructor or the .clipAction method of AnimationMixer.
  26447. *
  26448. * - Instead pass this object as 'root'.
  26449. *
  26450. * - You can also add and remove objects later when the mixer
  26451. * is running.
  26452. *
  26453. * Note:
  26454. *
  26455. * Objects of this class appear as one object to the mixer,
  26456. * so cache control of the individual objects must be done
  26457. * on the group.
  26458. *
  26459. * Limitation:
  26460. *
  26461. * - The animated properties must be compatible among the
  26462. * all objects in the group.
  26463. *
  26464. * - A single property can either be controlled through a
  26465. * target group or directly, but not both.
  26466. *
  26467. * @author tschw
  26468. */
  26469. function AnimationObjectGroup() {
  26470. this.uuid = MathUtils.generateUUID();
  26471. // cached objects followed by the active ones
  26472. this._objects = Array.prototype.slice.call( arguments );
  26473. this.nCachedObjects_ = 0; // threshold
  26474. // note: read by PropertyBinding.Composite
  26475. var indices = {};
  26476. this._indicesByUUID = indices; // for bookkeeping
  26477. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26478. indices[ arguments[ i ].uuid ] = i;
  26479. }
  26480. this._paths = []; // inside: string
  26481. this._parsedPaths = []; // inside: { we don't care, here }
  26482. this._bindings = []; // inside: Array< PropertyBinding >
  26483. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26484. var scope = this;
  26485. this.stats = {
  26486. objects: {
  26487. get total() {
  26488. return scope._objects.length;
  26489. },
  26490. get inUse() {
  26491. return this.total - scope.nCachedObjects_;
  26492. }
  26493. },
  26494. get bindingsPerObject() {
  26495. return scope._bindings.length;
  26496. }
  26497. };
  26498. }
  26499. Object.assign( AnimationObjectGroup.prototype, {
  26500. isAnimationObjectGroup: true,
  26501. add: function () {
  26502. var objects = this._objects,
  26503. nObjects = objects.length,
  26504. nCachedObjects = this.nCachedObjects_,
  26505. indicesByUUID = this._indicesByUUID,
  26506. paths = this._paths,
  26507. parsedPaths = this._parsedPaths,
  26508. bindings = this._bindings,
  26509. nBindings = bindings.length,
  26510. knownObject = undefined;
  26511. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26512. var object = arguments[ i ],
  26513. uuid = object.uuid,
  26514. index = indicesByUUID[ uuid ];
  26515. if ( index === undefined ) {
  26516. // unknown object -> add it to the ACTIVE region
  26517. index = nObjects ++;
  26518. indicesByUUID[ uuid ] = index;
  26519. objects.push( object );
  26520. // accounting is done, now do the same for all bindings
  26521. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26522. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  26523. }
  26524. } else if ( index < nCachedObjects ) {
  26525. knownObject = objects[ index ];
  26526. // move existing object to the ACTIVE region
  26527. var firstActiveIndex = -- nCachedObjects,
  26528. lastCachedObject = objects[ firstActiveIndex ];
  26529. indicesByUUID[ lastCachedObject.uuid ] = index;
  26530. objects[ index ] = lastCachedObject;
  26531. indicesByUUID[ uuid ] = firstActiveIndex;
  26532. objects[ firstActiveIndex ] = object;
  26533. // accounting is done, now do the same for all bindings
  26534. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26535. var bindingsForPath = bindings[ j ],
  26536. lastCached = bindingsForPath[ firstActiveIndex ],
  26537. binding = bindingsForPath[ index ];
  26538. bindingsForPath[ index ] = lastCached;
  26539. if ( binding === undefined ) {
  26540. // since we do not bother to create new bindings
  26541. // for objects that are cached, the binding may
  26542. // or may not exist
  26543. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  26544. }
  26545. bindingsForPath[ firstActiveIndex ] = binding;
  26546. }
  26547. } else if ( objects[ index ] !== knownObject ) {
  26548. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  26549. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  26550. } // else the object is already where we want it to be
  26551. } // for arguments
  26552. this.nCachedObjects_ = nCachedObjects;
  26553. },
  26554. remove: function () {
  26555. var objects = this._objects,
  26556. nCachedObjects = this.nCachedObjects_,
  26557. indicesByUUID = this._indicesByUUID,
  26558. bindings = this._bindings,
  26559. nBindings = bindings.length;
  26560. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26561. var object = arguments[ i ],
  26562. uuid = object.uuid,
  26563. index = indicesByUUID[ uuid ];
  26564. if ( index !== undefined && index >= nCachedObjects ) {
  26565. // move existing object into the CACHED region
  26566. var lastCachedIndex = nCachedObjects ++,
  26567. firstActiveObject = objects[ lastCachedIndex ];
  26568. indicesByUUID[ firstActiveObject.uuid ] = index;
  26569. objects[ index ] = firstActiveObject;
  26570. indicesByUUID[ uuid ] = lastCachedIndex;
  26571. objects[ lastCachedIndex ] = object;
  26572. // accounting is done, now do the same for all bindings
  26573. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26574. var bindingsForPath = bindings[ j ],
  26575. firstActive = bindingsForPath[ lastCachedIndex ],
  26576. binding = bindingsForPath[ index ];
  26577. bindingsForPath[ index ] = firstActive;
  26578. bindingsForPath[ lastCachedIndex ] = binding;
  26579. }
  26580. }
  26581. } // for arguments
  26582. this.nCachedObjects_ = nCachedObjects;
  26583. },
  26584. // remove & forget
  26585. uncache: function () {
  26586. var objects = this._objects,
  26587. nObjects = objects.length,
  26588. nCachedObjects = this.nCachedObjects_,
  26589. indicesByUUID = this._indicesByUUID,
  26590. bindings = this._bindings,
  26591. nBindings = bindings.length;
  26592. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26593. var object = arguments[ i ],
  26594. uuid = object.uuid,
  26595. index = indicesByUUID[ uuid ];
  26596. if ( index !== undefined ) {
  26597. delete indicesByUUID[ uuid ];
  26598. if ( index < nCachedObjects ) {
  26599. // object is cached, shrink the CACHED region
  26600. var firstActiveIndex = -- nCachedObjects,
  26601. lastCachedObject = objects[ firstActiveIndex ],
  26602. lastIndex = -- nObjects,
  26603. lastObject = objects[ lastIndex ];
  26604. // last cached object takes this object's place
  26605. indicesByUUID[ lastCachedObject.uuid ] = index;
  26606. objects[ index ] = lastCachedObject;
  26607. // last object goes to the activated slot and pop
  26608. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  26609. objects[ firstActiveIndex ] = lastObject;
  26610. objects.pop();
  26611. // accounting is done, now do the same for all bindings
  26612. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26613. var bindingsForPath = bindings[ j ],
  26614. lastCached = bindingsForPath[ firstActiveIndex ],
  26615. last = bindingsForPath[ lastIndex ];
  26616. bindingsForPath[ index ] = lastCached;
  26617. bindingsForPath[ firstActiveIndex ] = last;
  26618. bindingsForPath.pop();
  26619. }
  26620. } else {
  26621. // object is active, just swap with the last and pop
  26622. var lastIndex = -- nObjects,
  26623. lastObject = objects[ lastIndex ];
  26624. indicesByUUID[ lastObject.uuid ] = index;
  26625. objects[ index ] = lastObject;
  26626. objects.pop();
  26627. // accounting is done, now do the same for all bindings
  26628. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26629. var bindingsForPath = bindings[ j ];
  26630. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  26631. bindingsForPath.pop();
  26632. }
  26633. } // cached or active
  26634. } // if object is known
  26635. } // for arguments
  26636. this.nCachedObjects_ = nCachedObjects;
  26637. },
  26638. // Internal interface used by befriended PropertyBinding.Composite:
  26639. subscribe_: function ( path, parsedPath ) {
  26640. // returns an array of bindings for the given path that is changed
  26641. // according to the contained objects in the group
  26642. var indicesByPath = this._bindingsIndicesByPath,
  26643. index = indicesByPath[ path ],
  26644. bindings = this._bindings;
  26645. if ( index !== undefined ) return bindings[ index ];
  26646. var paths = this._paths,
  26647. parsedPaths = this._parsedPaths,
  26648. objects = this._objects,
  26649. nObjects = objects.length,
  26650. nCachedObjects = this.nCachedObjects_,
  26651. bindingsForPath = new Array( nObjects );
  26652. index = bindings.length;
  26653. indicesByPath[ path ] = index;
  26654. paths.push( path );
  26655. parsedPaths.push( parsedPath );
  26656. bindings.push( bindingsForPath );
  26657. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  26658. var object = objects[ i ];
  26659. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  26660. }
  26661. return bindingsForPath;
  26662. },
  26663. unsubscribe_: function ( path ) {
  26664. // tells the group to forget about a property path and no longer
  26665. // update the array previously obtained with 'subscribe_'
  26666. var indicesByPath = this._bindingsIndicesByPath,
  26667. index = indicesByPath[ path ];
  26668. if ( index !== undefined ) {
  26669. var paths = this._paths,
  26670. parsedPaths = this._parsedPaths,
  26671. bindings = this._bindings,
  26672. lastBindingsIndex = bindings.length - 1,
  26673. lastBindings = bindings[ lastBindingsIndex ],
  26674. lastBindingsPath = path[ lastBindingsIndex ];
  26675. indicesByPath[ lastBindingsPath ] = index;
  26676. bindings[ index ] = lastBindings;
  26677. bindings.pop();
  26678. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  26679. parsedPaths.pop();
  26680. paths[ index ] = paths[ lastBindingsIndex ];
  26681. paths.pop();
  26682. }
  26683. }
  26684. } );
  26685. /**
  26686. *
  26687. * Action provided by AnimationMixer for scheduling clip playback on specific
  26688. * objects.
  26689. *
  26690. * @author Ben Houston / http://clara.io/
  26691. * @author David Sarno / http://lighthaus.us/
  26692. * @author tschw
  26693. *
  26694. */
  26695. function AnimationAction( mixer, clip, localRoot, blendMode ) {
  26696. this._mixer = mixer;
  26697. this._clip = clip;
  26698. this._localRoot = localRoot || null;
  26699. this.blendMode = blendMode || clip.blendMode;
  26700. var tracks = clip.tracks,
  26701. nTracks = tracks.length,
  26702. interpolants = new Array( nTracks );
  26703. var interpolantSettings = {
  26704. endingStart: ZeroCurvatureEnding,
  26705. endingEnd: ZeroCurvatureEnding
  26706. };
  26707. for ( var i = 0; i !== nTracks; ++ i ) {
  26708. var interpolant = tracks[ i ].createInterpolant( null );
  26709. interpolants[ i ] = interpolant;
  26710. interpolant.settings = interpolantSettings;
  26711. }
  26712. this._interpolantSettings = interpolantSettings;
  26713. this._interpolants = interpolants; // bound by the mixer
  26714. // inside: PropertyMixer (managed by the mixer)
  26715. this._propertyBindings = new Array( nTracks );
  26716. this._cacheIndex = null; // for the memory manager
  26717. this._byClipCacheIndex = null; // for the memory manager
  26718. this._timeScaleInterpolant = null;
  26719. this._weightInterpolant = null;
  26720. this.loop = LoopRepeat;
  26721. this._loopCount = - 1;
  26722. // global mixer time when the action is to be started
  26723. // it's set back to 'null' upon start of the action
  26724. this._startTime = null;
  26725. // scaled local time of the action
  26726. // gets clamped or wrapped to 0..clip.duration according to loop
  26727. this.time = 0;
  26728. this.timeScale = 1;
  26729. this._effectiveTimeScale = 1;
  26730. this.weight = 1;
  26731. this._effectiveWeight = 1;
  26732. this.repetitions = Infinity; // no. of repetitions when looping
  26733. this.paused = false; // true -> zero effective time scale
  26734. this.enabled = true; // false -> zero effective weight
  26735. this.clampWhenFinished = false;// keep feeding the last frame?
  26736. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  26737. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  26738. }
  26739. Object.assign( AnimationAction.prototype, {
  26740. // State & Scheduling
  26741. play: function () {
  26742. this._mixer._activateAction( this );
  26743. return this;
  26744. },
  26745. stop: function () {
  26746. this._mixer._deactivateAction( this );
  26747. return this.reset();
  26748. },
  26749. reset: function () {
  26750. this.paused = false;
  26751. this.enabled = true;
  26752. this.time = 0; // restart clip
  26753. this._loopCount = - 1;// forget previous loops
  26754. this._startTime = null;// forget scheduling
  26755. return this.stopFading().stopWarping();
  26756. },
  26757. isRunning: function () {
  26758. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  26759. this._startTime === null && this._mixer._isActiveAction( this );
  26760. },
  26761. // return true when play has been called
  26762. isScheduled: function () {
  26763. return this._mixer._isActiveAction( this );
  26764. },
  26765. startAt: function ( time ) {
  26766. this._startTime = time;
  26767. return this;
  26768. },
  26769. setLoop: function ( mode, repetitions ) {
  26770. this.loop = mode;
  26771. this.repetitions = repetitions;
  26772. return this;
  26773. },
  26774. // Weight
  26775. // set the weight stopping any scheduled fading
  26776. // although .enabled = false yields an effective weight of zero, this
  26777. // method does *not* change .enabled, because it would be confusing
  26778. setEffectiveWeight: function ( weight ) {
  26779. this.weight = weight;
  26780. // note: same logic as when updated at runtime
  26781. this._effectiveWeight = this.enabled ? weight : 0;
  26782. return this.stopFading();
  26783. },
  26784. // return the weight considering fading and .enabled
  26785. getEffectiveWeight: function () {
  26786. return this._effectiveWeight;
  26787. },
  26788. fadeIn: function ( duration ) {
  26789. return this._scheduleFading( duration, 0, 1 );
  26790. },
  26791. fadeOut: function ( duration ) {
  26792. return this._scheduleFading( duration, 1, 0 );
  26793. },
  26794. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  26795. fadeOutAction.fadeOut( duration );
  26796. this.fadeIn( duration );
  26797. if ( warp ) {
  26798. var fadeInDuration = this._clip.duration,
  26799. fadeOutDuration = fadeOutAction._clip.duration,
  26800. startEndRatio = fadeOutDuration / fadeInDuration,
  26801. endStartRatio = fadeInDuration / fadeOutDuration;
  26802. fadeOutAction.warp( 1.0, startEndRatio, duration );
  26803. this.warp( endStartRatio, 1.0, duration );
  26804. }
  26805. return this;
  26806. },
  26807. crossFadeTo: function ( fadeInAction, duration, warp ) {
  26808. return fadeInAction.crossFadeFrom( this, duration, warp );
  26809. },
  26810. stopFading: function () {
  26811. var weightInterpolant = this._weightInterpolant;
  26812. if ( weightInterpolant !== null ) {
  26813. this._weightInterpolant = null;
  26814. this._mixer._takeBackControlInterpolant( weightInterpolant );
  26815. }
  26816. return this;
  26817. },
  26818. // Time Scale Control
  26819. // set the time scale stopping any scheduled warping
  26820. // although .paused = true yields an effective time scale of zero, this
  26821. // method does *not* change .paused, because it would be confusing
  26822. setEffectiveTimeScale: function ( timeScale ) {
  26823. this.timeScale = timeScale;
  26824. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26825. return this.stopWarping();
  26826. },
  26827. // return the time scale considering warping and .paused
  26828. getEffectiveTimeScale: function () {
  26829. return this._effectiveTimeScale;
  26830. },
  26831. setDuration: function ( duration ) {
  26832. this.timeScale = this._clip.duration / duration;
  26833. return this.stopWarping();
  26834. },
  26835. syncWith: function ( action ) {
  26836. this.time = action.time;
  26837. this.timeScale = action.timeScale;
  26838. return this.stopWarping();
  26839. },
  26840. halt: function ( duration ) {
  26841. return this.warp( this._effectiveTimeScale, 0, duration );
  26842. },
  26843. warp: function ( startTimeScale, endTimeScale, duration ) {
  26844. var mixer = this._mixer, now = mixer.time,
  26845. interpolant = this._timeScaleInterpolant,
  26846. timeScale = this.timeScale;
  26847. if ( interpolant === null ) {
  26848. interpolant = mixer._lendControlInterpolant();
  26849. this._timeScaleInterpolant = interpolant;
  26850. }
  26851. var times = interpolant.parameterPositions,
  26852. values = interpolant.sampleValues;
  26853. times[ 0 ] = now;
  26854. times[ 1 ] = now + duration;
  26855. values[ 0 ] = startTimeScale / timeScale;
  26856. values[ 1 ] = endTimeScale / timeScale;
  26857. return this;
  26858. },
  26859. stopWarping: function () {
  26860. var timeScaleInterpolant = this._timeScaleInterpolant;
  26861. if ( timeScaleInterpolant !== null ) {
  26862. this._timeScaleInterpolant = null;
  26863. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  26864. }
  26865. return this;
  26866. },
  26867. // Object Accessors
  26868. getMixer: function () {
  26869. return this._mixer;
  26870. },
  26871. getClip: function () {
  26872. return this._clip;
  26873. },
  26874. getRoot: function () {
  26875. return this._localRoot || this._mixer._root;
  26876. },
  26877. // Interna
  26878. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  26879. // called by the mixer
  26880. if ( ! this.enabled ) {
  26881. // call ._updateWeight() to update ._effectiveWeight
  26882. this._updateWeight( time );
  26883. return;
  26884. }
  26885. var startTime = this._startTime;
  26886. if ( startTime !== null ) {
  26887. // check for scheduled start of action
  26888. var timeRunning = ( time - startTime ) * timeDirection;
  26889. if ( timeRunning < 0 || timeDirection === 0 ) {
  26890. return; // yet to come / don't decide when delta = 0
  26891. }
  26892. // start
  26893. this._startTime = null; // unschedule
  26894. deltaTime = timeDirection * timeRunning;
  26895. }
  26896. // apply time scale and advance time
  26897. deltaTime *= this._updateTimeScale( time );
  26898. var clipTime = this._updateTime( deltaTime );
  26899. // note: _updateTime may disable the action resulting in
  26900. // an effective weight of 0
  26901. var weight = this._updateWeight( time );
  26902. if ( weight > 0 ) {
  26903. var interpolants = this._interpolants;
  26904. var propertyMixers = this._propertyBindings;
  26905. switch ( this.blendMode ) {
  26906. case AdditiveAnimationBlendMode:
  26907. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  26908. interpolants[ j ].evaluate( clipTime );
  26909. propertyMixers[ j ].accumulateAdditive( weight );
  26910. }
  26911. break;
  26912. case NormalAnimationBlendMode:
  26913. default:
  26914. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  26915. interpolants[ j ].evaluate( clipTime );
  26916. propertyMixers[ j ].accumulate( accuIndex, weight );
  26917. }
  26918. }
  26919. }
  26920. },
  26921. _updateWeight: function ( time ) {
  26922. var weight = 0;
  26923. if ( this.enabled ) {
  26924. weight = this.weight;
  26925. var interpolant = this._weightInterpolant;
  26926. if ( interpolant !== null ) {
  26927. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26928. weight *= interpolantValue;
  26929. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26930. this.stopFading();
  26931. if ( interpolantValue === 0 ) {
  26932. // faded out, disable
  26933. this.enabled = false;
  26934. }
  26935. }
  26936. }
  26937. }
  26938. this._effectiveWeight = weight;
  26939. return weight;
  26940. },
  26941. _updateTimeScale: function ( time ) {
  26942. var timeScale = 0;
  26943. if ( ! this.paused ) {
  26944. timeScale = this.timeScale;
  26945. var interpolant = this._timeScaleInterpolant;
  26946. if ( interpolant !== null ) {
  26947. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26948. timeScale *= interpolantValue;
  26949. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26950. this.stopWarping();
  26951. if ( timeScale === 0 ) {
  26952. // motion has halted, pause
  26953. this.paused = true;
  26954. } else {
  26955. // warp done - apply final time scale
  26956. this.timeScale = timeScale;
  26957. }
  26958. }
  26959. }
  26960. }
  26961. this._effectiveTimeScale = timeScale;
  26962. return timeScale;
  26963. },
  26964. _updateTime: function ( deltaTime ) {
  26965. var time = this.time + deltaTime;
  26966. var duration = this._clip.duration;
  26967. var loop = this.loop;
  26968. var loopCount = this._loopCount;
  26969. var pingPong = ( loop === LoopPingPong );
  26970. if ( deltaTime === 0 ) {
  26971. if ( loopCount === - 1 ) return time;
  26972. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26973. }
  26974. if ( loop === LoopOnce ) {
  26975. if ( loopCount === - 1 ) {
  26976. // just started
  26977. this._loopCount = 0;
  26978. this._setEndings( true, true, false );
  26979. }
  26980. handle_stop: {
  26981. if ( time >= duration ) {
  26982. time = duration;
  26983. } else if ( time < 0 ) {
  26984. time = 0;
  26985. } else {
  26986. this.time = time;
  26987. break handle_stop;
  26988. }
  26989. if ( this.clampWhenFinished ) this.paused = true;
  26990. else this.enabled = false;
  26991. this.time = time;
  26992. this._mixer.dispatchEvent( {
  26993. type: 'finished', action: this,
  26994. direction: deltaTime < 0 ? - 1 : 1
  26995. } );
  26996. }
  26997. } else { // repetitive Repeat or PingPong
  26998. if ( loopCount === - 1 ) {
  26999. // just started
  27000. if ( deltaTime >= 0 ) {
  27001. loopCount = 0;
  27002. this._setEndings( true, this.repetitions === 0, pingPong );
  27003. } else {
  27004. // when looping in reverse direction, the initial
  27005. // transition through zero counts as a repetition,
  27006. // so leave loopCount at -1
  27007. this._setEndings( this.repetitions === 0, true, pingPong );
  27008. }
  27009. }
  27010. if ( time >= duration || time < 0 ) {
  27011. // wrap around
  27012. var loopDelta = Math.floor( time / duration ); // signed
  27013. time -= duration * loopDelta;
  27014. loopCount += Math.abs( loopDelta );
  27015. var pending = this.repetitions - loopCount;
  27016. if ( pending <= 0 ) {
  27017. // have to stop (switch state, clamp time, fire event)
  27018. if ( this.clampWhenFinished ) this.paused = true;
  27019. else this.enabled = false;
  27020. time = deltaTime > 0 ? duration : 0;
  27021. this.time = time;
  27022. this._mixer.dispatchEvent( {
  27023. type: 'finished', action: this,
  27024. direction: deltaTime > 0 ? 1 : - 1
  27025. } );
  27026. } else {
  27027. // keep running
  27028. if ( pending === 1 ) {
  27029. // entering the last round
  27030. var atStart = deltaTime < 0;
  27031. this._setEndings( atStart, ! atStart, pingPong );
  27032. } else {
  27033. this._setEndings( false, false, pingPong );
  27034. }
  27035. this._loopCount = loopCount;
  27036. this.time = time;
  27037. this._mixer.dispatchEvent( {
  27038. type: 'loop', action: this, loopDelta: loopDelta
  27039. } );
  27040. }
  27041. } else {
  27042. this.time = time;
  27043. }
  27044. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  27045. // invert time for the "pong round"
  27046. return duration - time;
  27047. }
  27048. }
  27049. return time;
  27050. },
  27051. _setEndings: function ( atStart, atEnd, pingPong ) {
  27052. var settings = this._interpolantSettings;
  27053. if ( pingPong ) {
  27054. settings.endingStart = ZeroSlopeEnding;
  27055. settings.endingEnd = ZeroSlopeEnding;
  27056. } else {
  27057. // assuming for LoopOnce atStart == atEnd == true
  27058. if ( atStart ) {
  27059. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27060. } else {
  27061. settings.endingStart = WrapAroundEnding;
  27062. }
  27063. if ( atEnd ) {
  27064. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27065. } else {
  27066. settings.endingEnd = WrapAroundEnding;
  27067. }
  27068. }
  27069. },
  27070. _scheduleFading: function ( duration, weightNow, weightThen ) {
  27071. var mixer = this._mixer, now = mixer.time,
  27072. interpolant = this._weightInterpolant;
  27073. if ( interpolant === null ) {
  27074. interpolant = mixer._lendControlInterpolant();
  27075. this._weightInterpolant = interpolant;
  27076. }
  27077. var times = interpolant.parameterPositions,
  27078. values = interpolant.sampleValues;
  27079. times[ 0 ] = now;
  27080. values[ 0 ] = weightNow;
  27081. times[ 1 ] = now + duration;
  27082. values[ 1 ] = weightThen;
  27083. return this;
  27084. }
  27085. } );
  27086. /**
  27087. *
  27088. * Player for AnimationClips.
  27089. *
  27090. *
  27091. * @author Ben Houston / http://clara.io/
  27092. * @author David Sarno / http://lighthaus.us/
  27093. * @author tschw
  27094. */
  27095. function AnimationMixer( root ) {
  27096. this._root = root;
  27097. this._initMemoryManager();
  27098. this._accuIndex = 0;
  27099. this.time = 0;
  27100. this.timeScale = 1.0;
  27101. }
  27102. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  27103. constructor: AnimationMixer,
  27104. _bindAction: function ( action, prototypeAction ) {
  27105. var root = action._localRoot || this._root,
  27106. tracks = action._clip.tracks,
  27107. nTracks = tracks.length,
  27108. bindings = action._propertyBindings,
  27109. interpolants = action._interpolants,
  27110. rootUuid = root.uuid,
  27111. bindingsByRoot = this._bindingsByRootAndName,
  27112. bindingsByName = bindingsByRoot[ rootUuid ];
  27113. if ( bindingsByName === undefined ) {
  27114. bindingsByName = {};
  27115. bindingsByRoot[ rootUuid ] = bindingsByName;
  27116. }
  27117. for ( var i = 0; i !== nTracks; ++ i ) {
  27118. var track = tracks[ i ],
  27119. trackName = track.name,
  27120. binding = bindingsByName[ trackName ];
  27121. if ( binding !== undefined ) {
  27122. bindings[ i ] = binding;
  27123. } else {
  27124. binding = bindings[ i ];
  27125. if ( binding !== undefined ) {
  27126. // existing binding, make sure the cache knows
  27127. if ( binding._cacheIndex === null ) {
  27128. ++ binding.referenceCount;
  27129. this._addInactiveBinding( binding, rootUuid, trackName );
  27130. }
  27131. continue;
  27132. }
  27133. var path = prototypeAction && prototypeAction.
  27134. _propertyBindings[ i ].binding.parsedPath;
  27135. binding = new PropertyMixer(
  27136. PropertyBinding.create( root, trackName, path ),
  27137. track.ValueTypeName, track.getValueSize() );
  27138. ++ binding.referenceCount;
  27139. this._addInactiveBinding( binding, rootUuid, trackName );
  27140. bindings[ i ] = binding;
  27141. }
  27142. interpolants[ i ].resultBuffer = binding.buffer;
  27143. }
  27144. },
  27145. _activateAction: function ( action ) {
  27146. if ( ! this._isActiveAction( action ) ) {
  27147. if ( action._cacheIndex === null ) {
  27148. // this action has been forgotten by the cache, but the user
  27149. // appears to be still using it -> rebind
  27150. var rootUuid = ( action._localRoot || this._root ).uuid,
  27151. clipUuid = action._clip.uuid,
  27152. actionsForClip = this._actionsByClip[ clipUuid ];
  27153. this._bindAction( action,
  27154. actionsForClip && actionsForClip.knownActions[ 0 ] );
  27155. this._addInactiveAction( action, clipUuid, rootUuid );
  27156. }
  27157. var bindings = action._propertyBindings;
  27158. // increment reference counts / sort out state
  27159. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27160. var binding = bindings[ i ];
  27161. if ( binding.useCount ++ === 0 ) {
  27162. this._lendBinding( binding );
  27163. binding.saveOriginalState();
  27164. }
  27165. }
  27166. this._lendAction( action );
  27167. }
  27168. },
  27169. _deactivateAction: function ( action ) {
  27170. if ( this._isActiveAction( action ) ) {
  27171. var bindings = action._propertyBindings;
  27172. // decrement reference counts / sort out state
  27173. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27174. var binding = bindings[ i ];
  27175. if ( -- binding.useCount === 0 ) {
  27176. binding.restoreOriginalState();
  27177. this._takeBackBinding( binding );
  27178. }
  27179. }
  27180. this._takeBackAction( action );
  27181. }
  27182. },
  27183. // Memory manager
  27184. _initMemoryManager: function () {
  27185. this._actions = []; // 'nActiveActions' followed by inactive ones
  27186. this._nActiveActions = 0;
  27187. this._actionsByClip = {};
  27188. // inside:
  27189. // {
  27190. // knownActions: Array< AnimationAction > - used as prototypes
  27191. // actionByRoot: AnimationAction - lookup
  27192. // }
  27193. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27194. this._nActiveBindings = 0;
  27195. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27196. this._controlInterpolants = []; // same game as above
  27197. this._nActiveControlInterpolants = 0;
  27198. var scope = this;
  27199. this.stats = {
  27200. actions: {
  27201. get total() {
  27202. return scope._actions.length;
  27203. },
  27204. get inUse() {
  27205. return scope._nActiveActions;
  27206. }
  27207. },
  27208. bindings: {
  27209. get total() {
  27210. return scope._bindings.length;
  27211. },
  27212. get inUse() {
  27213. return scope._nActiveBindings;
  27214. }
  27215. },
  27216. controlInterpolants: {
  27217. get total() {
  27218. return scope._controlInterpolants.length;
  27219. },
  27220. get inUse() {
  27221. return scope._nActiveControlInterpolants;
  27222. }
  27223. }
  27224. };
  27225. },
  27226. // Memory management for AnimationAction objects
  27227. _isActiveAction: function ( action ) {
  27228. var index = action._cacheIndex;
  27229. return index !== null && index < this._nActiveActions;
  27230. },
  27231. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  27232. var actions = this._actions,
  27233. actionsByClip = this._actionsByClip,
  27234. actionsForClip = actionsByClip[ clipUuid ];
  27235. if ( actionsForClip === undefined ) {
  27236. actionsForClip = {
  27237. knownActions: [ action ],
  27238. actionByRoot: {}
  27239. };
  27240. action._byClipCacheIndex = 0;
  27241. actionsByClip[ clipUuid ] = actionsForClip;
  27242. } else {
  27243. var knownActions = actionsForClip.knownActions;
  27244. action._byClipCacheIndex = knownActions.length;
  27245. knownActions.push( action );
  27246. }
  27247. action._cacheIndex = actions.length;
  27248. actions.push( action );
  27249. actionsForClip.actionByRoot[ rootUuid ] = action;
  27250. },
  27251. _removeInactiveAction: function ( action ) {
  27252. var actions = this._actions,
  27253. lastInactiveAction = actions[ actions.length - 1 ],
  27254. cacheIndex = action._cacheIndex;
  27255. lastInactiveAction._cacheIndex = cacheIndex;
  27256. actions[ cacheIndex ] = lastInactiveAction;
  27257. actions.pop();
  27258. action._cacheIndex = null;
  27259. var clipUuid = action._clip.uuid,
  27260. actionsByClip = this._actionsByClip,
  27261. actionsForClip = actionsByClip[ clipUuid ],
  27262. knownActionsForClip = actionsForClip.knownActions,
  27263. lastKnownAction =
  27264. knownActionsForClip[ knownActionsForClip.length - 1 ],
  27265. byClipCacheIndex = action._byClipCacheIndex;
  27266. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27267. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  27268. knownActionsForClip.pop();
  27269. action._byClipCacheIndex = null;
  27270. var actionByRoot = actionsForClip.actionByRoot,
  27271. rootUuid = ( action._localRoot || this._root ).uuid;
  27272. delete actionByRoot[ rootUuid ];
  27273. if ( knownActionsForClip.length === 0 ) {
  27274. delete actionsByClip[ clipUuid ];
  27275. }
  27276. this._removeInactiveBindingsForAction( action );
  27277. },
  27278. _removeInactiveBindingsForAction: function ( action ) {
  27279. var bindings = action._propertyBindings;
  27280. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  27281. var binding = bindings[ i ];
  27282. if ( -- binding.referenceCount === 0 ) {
  27283. this._removeInactiveBinding( binding );
  27284. }
  27285. }
  27286. },
  27287. _lendAction: function ( action ) {
  27288. // [ active actions | inactive actions ]
  27289. // [ active actions >| inactive actions ]
  27290. // s a
  27291. // <-swap->
  27292. // a s
  27293. var actions = this._actions,
  27294. prevIndex = action._cacheIndex,
  27295. lastActiveIndex = this._nActiveActions ++,
  27296. firstInactiveAction = actions[ lastActiveIndex ];
  27297. action._cacheIndex = lastActiveIndex;
  27298. actions[ lastActiveIndex ] = action;
  27299. firstInactiveAction._cacheIndex = prevIndex;
  27300. actions[ prevIndex ] = firstInactiveAction;
  27301. },
  27302. _takeBackAction: function ( action ) {
  27303. // [ active actions | inactive actions ]
  27304. // [ active actions |< inactive actions ]
  27305. // a s
  27306. // <-swap->
  27307. // s a
  27308. var actions = this._actions,
  27309. prevIndex = action._cacheIndex,
  27310. firstInactiveIndex = -- this._nActiveActions,
  27311. lastActiveAction = actions[ firstInactiveIndex ];
  27312. action._cacheIndex = firstInactiveIndex;
  27313. actions[ firstInactiveIndex ] = action;
  27314. lastActiveAction._cacheIndex = prevIndex;
  27315. actions[ prevIndex ] = lastActiveAction;
  27316. },
  27317. // Memory management for PropertyMixer objects
  27318. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  27319. var bindingsByRoot = this._bindingsByRootAndName,
  27320. bindingByName = bindingsByRoot[ rootUuid ],
  27321. bindings = this._bindings;
  27322. if ( bindingByName === undefined ) {
  27323. bindingByName = {};
  27324. bindingsByRoot[ rootUuid ] = bindingByName;
  27325. }
  27326. bindingByName[ trackName ] = binding;
  27327. binding._cacheIndex = bindings.length;
  27328. bindings.push( binding );
  27329. },
  27330. _removeInactiveBinding: function ( binding ) {
  27331. var bindings = this._bindings,
  27332. propBinding = binding.binding,
  27333. rootUuid = propBinding.rootNode.uuid,
  27334. trackName = propBinding.path,
  27335. bindingsByRoot = this._bindingsByRootAndName,
  27336. bindingByName = bindingsByRoot[ rootUuid ],
  27337. lastInactiveBinding = bindings[ bindings.length - 1 ],
  27338. cacheIndex = binding._cacheIndex;
  27339. lastInactiveBinding._cacheIndex = cacheIndex;
  27340. bindings[ cacheIndex ] = lastInactiveBinding;
  27341. bindings.pop();
  27342. delete bindingByName[ trackName ];
  27343. if ( Object.keys( bindingByName ).length === 0 ) {
  27344. delete bindingsByRoot[ rootUuid ];
  27345. }
  27346. },
  27347. _lendBinding: function ( binding ) {
  27348. var bindings = this._bindings,
  27349. prevIndex = binding._cacheIndex,
  27350. lastActiveIndex = this._nActiveBindings ++,
  27351. firstInactiveBinding = bindings[ lastActiveIndex ];
  27352. binding._cacheIndex = lastActiveIndex;
  27353. bindings[ lastActiveIndex ] = binding;
  27354. firstInactiveBinding._cacheIndex = prevIndex;
  27355. bindings[ prevIndex ] = firstInactiveBinding;
  27356. },
  27357. _takeBackBinding: function ( binding ) {
  27358. var bindings = this._bindings,
  27359. prevIndex = binding._cacheIndex,
  27360. firstInactiveIndex = -- this._nActiveBindings,
  27361. lastActiveBinding = bindings[ firstInactiveIndex ];
  27362. binding._cacheIndex = firstInactiveIndex;
  27363. bindings[ firstInactiveIndex ] = binding;
  27364. lastActiveBinding._cacheIndex = prevIndex;
  27365. bindings[ prevIndex ] = lastActiveBinding;
  27366. },
  27367. // Memory management of Interpolants for weight and time scale
  27368. _lendControlInterpolant: function () {
  27369. var interpolants = this._controlInterpolants,
  27370. lastActiveIndex = this._nActiveControlInterpolants ++,
  27371. interpolant = interpolants[ lastActiveIndex ];
  27372. if ( interpolant === undefined ) {
  27373. interpolant = new LinearInterpolant(
  27374. new Float32Array( 2 ), new Float32Array( 2 ),
  27375. 1, this._controlInterpolantsResultBuffer );
  27376. interpolant.__cacheIndex = lastActiveIndex;
  27377. interpolants[ lastActiveIndex ] = interpolant;
  27378. }
  27379. return interpolant;
  27380. },
  27381. _takeBackControlInterpolant: function ( interpolant ) {
  27382. var interpolants = this._controlInterpolants,
  27383. prevIndex = interpolant.__cacheIndex,
  27384. firstInactiveIndex = -- this._nActiveControlInterpolants,
  27385. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  27386. interpolant.__cacheIndex = firstInactiveIndex;
  27387. interpolants[ firstInactiveIndex ] = interpolant;
  27388. lastActiveInterpolant.__cacheIndex = prevIndex;
  27389. interpolants[ prevIndex ] = lastActiveInterpolant;
  27390. },
  27391. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  27392. // return an action for a clip optionally using a custom root target
  27393. // object (this method allocates a lot of dynamic memory in case a
  27394. // previously unknown clip/root combination is specified)
  27395. clipAction: function ( clip, optionalRoot, blendMode ) {
  27396. var root = optionalRoot || this._root,
  27397. rootUuid = root.uuid,
  27398. clipObject = typeof clip === 'string' ?
  27399. AnimationClip.findByName( root, clip ) : clip,
  27400. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  27401. actionsForClip = this._actionsByClip[ clipUuid ],
  27402. prototypeAction = null;
  27403. if ( blendMode === undefined ) {
  27404. if ( clipObject !== null ) {
  27405. blendMode = clipObject.blendMode;
  27406. } else {
  27407. blendMode = NormalAnimationBlendMode;
  27408. }
  27409. }
  27410. if ( actionsForClip !== undefined ) {
  27411. var existingAction =
  27412. actionsForClip.actionByRoot[ rootUuid ];
  27413. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  27414. return existingAction;
  27415. }
  27416. // we know the clip, so we don't have to parse all
  27417. // the bindings again but can just copy
  27418. prototypeAction = actionsForClip.knownActions[ 0 ];
  27419. // also, take the clip from the prototype action
  27420. if ( clipObject === null )
  27421. clipObject = prototypeAction._clip;
  27422. }
  27423. // clip must be known when specified via string
  27424. if ( clipObject === null ) return null;
  27425. // allocate all resources required to run it
  27426. var newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  27427. this._bindAction( newAction, prototypeAction );
  27428. // and make the action known to the memory manager
  27429. this._addInactiveAction( newAction, clipUuid, rootUuid );
  27430. return newAction;
  27431. },
  27432. // get an existing action
  27433. existingAction: function ( clip, optionalRoot ) {
  27434. var root = optionalRoot || this._root,
  27435. rootUuid = root.uuid,
  27436. clipObject = typeof clip === 'string' ?
  27437. AnimationClip.findByName( root, clip ) : clip,
  27438. clipUuid = clipObject ? clipObject.uuid : clip,
  27439. actionsForClip = this._actionsByClip[ clipUuid ];
  27440. if ( actionsForClip !== undefined ) {
  27441. return actionsForClip.actionByRoot[ rootUuid ] || null;
  27442. }
  27443. return null;
  27444. },
  27445. // deactivates all previously scheduled actions
  27446. stopAllAction: function () {
  27447. var actions = this._actions,
  27448. nActions = this._nActiveActions;
  27449. for ( var i = nActions - 1; i >= 0; -- i ) {
  27450. actions[ i ].stop();
  27451. }
  27452. return this;
  27453. },
  27454. // advance the time and update apply the animation
  27455. update: function ( deltaTime ) {
  27456. deltaTime *= this.timeScale;
  27457. var actions = this._actions,
  27458. nActions = this._nActiveActions,
  27459. time = this.time += deltaTime,
  27460. timeDirection = Math.sign( deltaTime ),
  27461. accuIndex = this._accuIndex ^= 1;
  27462. // run active actions
  27463. for ( var i = 0; i !== nActions; ++ i ) {
  27464. var action = actions[ i ];
  27465. action._update( time, deltaTime, timeDirection, accuIndex );
  27466. }
  27467. // update scene graph
  27468. var bindings = this._bindings,
  27469. nBindings = this._nActiveBindings;
  27470. for ( var i = 0; i !== nBindings; ++ i ) {
  27471. bindings[ i ].apply( accuIndex );
  27472. }
  27473. return this;
  27474. },
  27475. // Allows you to seek to a specific time in an animation.
  27476. setTime: function ( timeInSeconds ) {
  27477. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27478. for ( var i = 0; i < this._actions.length; i ++ ) {
  27479. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27480. }
  27481. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  27482. },
  27483. // return this mixer's root target object
  27484. getRoot: function () {
  27485. return this._root;
  27486. },
  27487. // free all resources specific to a particular clip
  27488. uncacheClip: function ( clip ) {
  27489. var actions = this._actions,
  27490. clipUuid = clip.uuid,
  27491. actionsByClip = this._actionsByClip,
  27492. actionsForClip = actionsByClip[ clipUuid ];
  27493. if ( actionsForClip !== undefined ) {
  27494. // note: just calling _removeInactiveAction would mess up the
  27495. // iteration state and also require updating the state we can
  27496. // just throw away
  27497. var actionsToRemove = actionsForClip.knownActions;
  27498. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  27499. var action = actionsToRemove[ i ];
  27500. this._deactivateAction( action );
  27501. var cacheIndex = action._cacheIndex,
  27502. lastInactiveAction = actions[ actions.length - 1 ];
  27503. action._cacheIndex = null;
  27504. action._byClipCacheIndex = null;
  27505. lastInactiveAction._cacheIndex = cacheIndex;
  27506. actions[ cacheIndex ] = lastInactiveAction;
  27507. actions.pop();
  27508. this._removeInactiveBindingsForAction( action );
  27509. }
  27510. delete actionsByClip[ clipUuid ];
  27511. }
  27512. },
  27513. // free all resources specific to a particular root target object
  27514. uncacheRoot: function ( root ) {
  27515. var rootUuid = root.uuid,
  27516. actionsByClip = this._actionsByClip;
  27517. for ( var clipUuid in actionsByClip ) {
  27518. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  27519. action = actionByRoot[ rootUuid ];
  27520. if ( action !== undefined ) {
  27521. this._deactivateAction( action );
  27522. this._removeInactiveAction( action );
  27523. }
  27524. }
  27525. var bindingsByRoot = this._bindingsByRootAndName,
  27526. bindingByName = bindingsByRoot[ rootUuid ];
  27527. if ( bindingByName !== undefined ) {
  27528. for ( var trackName in bindingByName ) {
  27529. var binding = bindingByName[ trackName ];
  27530. binding.restoreOriginalState();
  27531. this._removeInactiveBinding( binding );
  27532. }
  27533. }
  27534. },
  27535. // remove a targeted clip from the cache
  27536. uncacheAction: function ( clip, optionalRoot ) {
  27537. var action = this.existingAction( clip, optionalRoot );
  27538. if ( action !== null ) {
  27539. this._deactivateAction( action );
  27540. this._removeInactiveAction( action );
  27541. }
  27542. }
  27543. } );
  27544. /**
  27545. * @author mrdoob / http://mrdoob.com/
  27546. */
  27547. function Uniform( value ) {
  27548. if ( typeof value === 'string' ) {
  27549. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  27550. value = arguments[ 1 ];
  27551. }
  27552. this.value = value;
  27553. }
  27554. Uniform.prototype.clone = function () {
  27555. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  27556. };
  27557. /**
  27558. * @author benaadams / https://twitter.com/ben_a_adams
  27559. */
  27560. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  27561. InterleavedBuffer.call( this, array, stride );
  27562. this.meshPerAttribute = meshPerAttribute || 1;
  27563. }
  27564. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  27565. constructor: InstancedInterleavedBuffer,
  27566. isInstancedInterleavedBuffer: true,
  27567. copy: function ( source ) {
  27568. InterleavedBuffer.prototype.copy.call( this, source );
  27569. this.meshPerAttribute = source.meshPerAttribute;
  27570. return this;
  27571. }
  27572. } );
  27573. /**
  27574. * @author mrdoob / http://mrdoob.com/
  27575. * @author bhouston / http://clara.io/
  27576. * @author stephomi / http://stephaneginier.com/
  27577. */
  27578. function Raycaster( origin, direction, near, far ) {
  27579. this.ray = new Ray( origin, direction );
  27580. // direction is assumed to be normalized (for accurate distance calculations)
  27581. this.near = near || 0;
  27582. this.far = far || Infinity;
  27583. this.camera = null;
  27584. this.layers = new Layers();
  27585. this.params = {
  27586. Mesh: {},
  27587. Line: { threshold: 1 },
  27588. LOD: {},
  27589. Points: { threshold: 1 },
  27590. Sprite: {}
  27591. };
  27592. Object.defineProperties( this.params, {
  27593. PointCloud: {
  27594. get: function () {
  27595. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  27596. return this.Points;
  27597. }
  27598. }
  27599. } );
  27600. }
  27601. function ascSort( a, b ) {
  27602. return a.distance - b.distance;
  27603. }
  27604. function intersectObject( object, raycaster, intersects, recursive ) {
  27605. if ( object.layers.test( raycaster.layers ) ) {
  27606. object.raycast( raycaster, intersects );
  27607. }
  27608. if ( recursive === true ) {
  27609. var children = object.children;
  27610. for ( var i = 0, l = children.length; i < l; i ++ ) {
  27611. intersectObject( children[ i ], raycaster, intersects, true );
  27612. }
  27613. }
  27614. }
  27615. Object.assign( Raycaster.prototype, {
  27616. set: function ( origin, direction ) {
  27617. // direction is assumed to be normalized (for accurate distance calculations)
  27618. this.ray.set( origin, direction );
  27619. },
  27620. setFromCamera: function ( coords, camera ) {
  27621. if ( ( camera && camera.isPerspectiveCamera ) ) {
  27622. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27623. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27624. this.camera = camera;
  27625. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  27626. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27627. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27628. this.camera = camera;
  27629. } else {
  27630. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  27631. }
  27632. },
  27633. intersectObject: function ( object, recursive, optionalTarget ) {
  27634. var intersects = optionalTarget || [];
  27635. intersectObject( object, this, intersects, recursive );
  27636. intersects.sort( ascSort );
  27637. return intersects;
  27638. },
  27639. intersectObjects: function ( objects, recursive, optionalTarget ) {
  27640. var intersects = optionalTarget || [];
  27641. if ( Array.isArray( objects ) === false ) {
  27642. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  27643. return intersects;
  27644. }
  27645. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  27646. intersectObject( objects[ i ], this, intersects, recursive );
  27647. }
  27648. intersects.sort( ascSort );
  27649. return intersects;
  27650. }
  27651. } );
  27652. /**
  27653. * @author bhouston / http://clara.io
  27654. * @author WestLangley / http://github.com/WestLangley
  27655. *
  27656. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27657. *
  27658. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27659. * The azimuthal angle (theta) is measured from the positive z-axis.
  27660. */
  27661. function Spherical( radius, phi, theta ) {
  27662. this.radius = ( radius !== undefined ) ? radius : 1.0;
  27663. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  27664. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  27665. return this;
  27666. }
  27667. Object.assign( Spherical.prototype, {
  27668. set: function ( radius, phi, theta ) {
  27669. this.radius = radius;
  27670. this.phi = phi;
  27671. this.theta = theta;
  27672. return this;
  27673. },
  27674. clone: function () {
  27675. return new this.constructor().copy( this );
  27676. },
  27677. copy: function ( other ) {
  27678. this.radius = other.radius;
  27679. this.phi = other.phi;
  27680. this.theta = other.theta;
  27681. return this;
  27682. },
  27683. // restrict phi to be betwee EPS and PI-EPS
  27684. makeSafe: function () {
  27685. var EPS = 0.000001;
  27686. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  27687. return this;
  27688. },
  27689. setFromVector3: function ( v ) {
  27690. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27691. },
  27692. setFromCartesianCoords: function ( x, y, z ) {
  27693. this.radius = Math.sqrt( x * x + y * y + z * z );
  27694. if ( this.radius === 0 ) {
  27695. this.theta = 0;
  27696. this.phi = 0;
  27697. } else {
  27698. this.theta = Math.atan2( x, z );
  27699. this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
  27700. }
  27701. return this;
  27702. }
  27703. } );
  27704. /**
  27705. * @author Mugen87 / https://github.com/Mugen87
  27706. *
  27707. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27708. *
  27709. */
  27710. function Cylindrical( radius, theta, y ) {
  27711. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27712. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27713. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  27714. return this;
  27715. }
  27716. Object.assign( Cylindrical.prototype, {
  27717. set: function ( radius, theta, y ) {
  27718. this.radius = radius;
  27719. this.theta = theta;
  27720. this.y = y;
  27721. return this;
  27722. },
  27723. clone: function () {
  27724. return new this.constructor().copy( this );
  27725. },
  27726. copy: function ( other ) {
  27727. this.radius = other.radius;
  27728. this.theta = other.theta;
  27729. this.y = other.y;
  27730. return this;
  27731. },
  27732. setFromVector3: function ( v ) {
  27733. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27734. },
  27735. setFromCartesianCoords: function ( x, y, z ) {
  27736. this.radius = Math.sqrt( x * x + z * z );
  27737. this.theta = Math.atan2( x, z );
  27738. this.y = y;
  27739. return this;
  27740. }
  27741. } );
  27742. /**
  27743. * @author bhouston / http://clara.io
  27744. */
  27745. var _vector$7 = new Vector2();
  27746. function Box2( min, max ) {
  27747. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  27748. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  27749. }
  27750. Object.assign( Box2.prototype, {
  27751. set: function ( min, max ) {
  27752. this.min.copy( min );
  27753. this.max.copy( max );
  27754. return this;
  27755. },
  27756. setFromPoints: function ( points ) {
  27757. this.makeEmpty();
  27758. for ( var i = 0, il = points.length; i < il; i ++ ) {
  27759. this.expandByPoint( points[ i ] );
  27760. }
  27761. return this;
  27762. },
  27763. setFromCenterAndSize: function ( center, size ) {
  27764. var halfSize = _vector$7.copy( size ).multiplyScalar( 0.5 );
  27765. this.min.copy( center ).sub( halfSize );
  27766. this.max.copy( center ).add( halfSize );
  27767. return this;
  27768. },
  27769. clone: function () {
  27770. return new this.constructor().copy( this );
  27771. },
  27772. copy: function ( box ) {
  27773. this.min.copy( box.min );
  27774. this.max.copy( box.max );
  27775. return this;
  27776. },
  27777. makeEmpty: function () {
  27778. this.min.x = this.min.y = + Infinity;
  27779. this.max.x = this.max.y = - Infinity;
  27780. return this;
  27781. },
  27782. isEmpty: function () {
  27783. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27784. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  27785. },
  27786. getCenter: function ( target ) {
  27787. if ( target === undefined ) {
  27788. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  27789. target = new Vector2();
  27790. }
  27791. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  27792. },
  27793. getSize: function ( target ) {
  27794. if ( target === undefined ) {
  27795. console.warn( 'THREE.Box2: .getSize() target is now required' );
  27796. target = new Vector2();
  27797. }
  27798. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  27799. },
  27800. expandByPoint: function ( point ) {
  27801. this.min.min( point );
  27802. this.max.max( point );
  27803. return this;
  27804. },
  27805. expandByVector: function ( vector ) {
  27806. this.min.sub( vector );
  27807. this.max.add( vector );
  27808. return this;
  27809. },
  27810. expandByScalar: function ( scalar ) {
  27811. this.min.addScalar( - scalar );
  27812. this.max.addScalar( scalar );
  27813. return this;
  27814. },
  27815. containsPoint: function ( point ) {
  27816. return point.x < this.min.x || point.x > this.max.x ||
  27817. point.y < this.min.y || point.y > this.max.y ? false : true;
  27818. },
  27819. containsBox: function ( box ) {
  27820. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  27821. this.min.y <= box.min.y && box.max.y <= this.max.y;
  27822. },
  27823. getParameter: function ( point, target ) {
  27824. // This can potentially have a divide by zero if the box
  27825. // has a size dimension of 0.
  27826. if ( target === undefined ) {
  27827. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  27828. target = new Vector2();
  27829. }
  27830. return target.set(
  27831. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  27832. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  27833. );
  27834. },
  27835. intersectsBox: function ( box ) {
  27836. // using 4 splitting planes to rule out intersections
  27837. return box.max.x < this.min.x || box.min.x > this.max.x ||
  27838. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  27839. },
  27840. clampPoint: function ( point, target ) {
  27841. if ( target === undefined ) {
  27842. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  27843. target = new Vector2();
  27844. }
  27845. return target.copy( point ).clamp( this.min, this.max );
  27846. },
  27847. distanceToPoint: function ( point ) {
  27848. var clampedPoint = _vector$7.copy( point ).clamp( this.min, this.max );
  27849. return clampedPoint.sub( point ).length();
  27850. },
  27851. intersect: function ( box ) {
  27852. this.min.max( box.min );
  27853. this.max.min( box.max );
  27854. return this;
  27855. },
  27856. union: function ( box ) {
  27857. this.min.min( box.min );
  27858. this.max.max( box.max );
  27859. return this;
  27860. },
  27861. translate: function ( offset ) {
  27862. this.min.add( offset );
  27863. this.max.add( offset );
  27864. return this;
  27865. },
  27866. equals: function ( box ) {
  27867. return box.min.equals( this.min ) && box.max.equals( this.max );
  27868. }
  27869. } );
  27870. /**
  27871. * @author bhouston / http://clara.io
  27872. */
  27873. var _startP = new Vector3();
  27874. var _startEnd = new Vector3();
  27875. function Line3( start, end ) {
  27876. this.start = ( start !== undefined ) ? start : new Vector3();
  27877. this.end = ( end !== undefined ) ? end : new Vector3();
  27878. }
  27879. Object.assign( Line3.prototype, {
  27880. set: function ( start, end ) {
  27881. this.start.copy( start );
  27882. this.end.copy( end );
  27883. return this;
  27884. },
  27885. clone: function () {
  27886. return new this.constructor().copy( this );
  27887. },
  27888. copy: function ( line ) {
  27889. this.start.copy( line.start );
  27890. this.end.copy( line.end );
  27891. return this;
  27892. },
  27893. getCenter: function ( target ) {
  27894. if ( target === undefined ) {
  27895. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  27896. target = new Vector3();
  27897. }
  27898. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  27899. },
  27900. delta: function ( target ) {
  27901. if ( target === undefined ) {
  27902. console.warn( 'THREE.Line3: .delta() target is now required' );
  27903. target = new Vector3();
  27904. }
  27905. return target.subVectors( this.end, this.start );
  27906. },
  27907. distanceSq: function () {
  27908. return this.start.distanceToSquared( this.end );
  27909. },
  27910. distance: function () {
  27911. return this.start.distanceTo( this.end );
  27912. },
  27913. at: function ( t, target ) {
  27914. if ( target === undefined ) {
  27915. console.warn( 'THREE.Line3: .at() target is now required' );
  27916. target = new Vector3();
  27917. }
  27918. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27919. },
  27920. closestPointToPointParameter: function ( point, clampToLine ) {
  27921. _startP.subVectors( point, this.start );
  27922. _startEnd.subVectors( this.end, this.start );
  27923. var startEnd2 = _startEnd.dot( _startEnd );
  27924. var startEnd_startP = _startEnd.dot( _startP );
  27925. var t = startEnd_startP / startEnd2;
  27926. if ( clampToLine ) {
  27927. t = MathUtils.clamp( t, 0, 1 );
  27928. }
  27929. return t;
  27930. },
  27931. closestPointToPoint: function ( point, clampToLine, target ) {
  27932. var t = this.closestPointToPointParameter( point, clampToLine );
  27933. if ( target === undefined ) {
  27934. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27935. target = new Vector3();
  27936. }
  27937. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27938. },
  27939. applyMatrix4: function ( matrix ) {
  27940. this.start.applyMatrix4( matrix );
  27941. this.end.applyMatrix4( matrix );
  27942. return this;
  27943. },
  27944. equals: function ( line ) {
  27945. return line.start.equals( this.start ) && line.end.equals( this.end );
  27946. }
  27947. } );
  27948. /**
  27949. * @author alteredq / http://alteredqualia.com/
  27950. */
  27951. function ImmediateRenderObject( material ) {
  27952. Object3D.call( this );
  27953. this.material = material;
  27954. this.render = function ( /* renderCallback */ ) {};
  27955. this.hasPositions = false;
  27956. this.hasNormals = false;
  27957. this.hasColors = false;
  27958. this.hasUvs = false;
  27959. this.positionArray = null;
  27960. this.normalArray = null;
  27961. this.colorArray = null;
  27962. this.uvArray = null;
  27963. this.count = 0;
  27964. }
  27965. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27966. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27967. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27968. /**
  27969. * @author alteredq / http://alteredqualia.com/
  27970. * @author mrdoob / http://mrdoob.com/
  27971. * @author WestLangley / http://github.com/WestLangley
  27972. */
  27973. var _vector$8 = new Vector3();
  27974. function SpotLightHelper( light, color ) {
  27975. Object3D.call( this );
  27976. this.light = light;
  27977. this.light.updateMatrixWorld();
  27978. this.matrix = light.matrixWorld;
  27979. this.matrixAutoUpdate = false;
  27980. this.color = color;
  27981. var geometry = new BufferGeometry();
  27982. var positions = [
  27983. 0, 0, 0, 0, 0, 1,
  27984. 0, 0, 0, 1, 0, 1,
  27985. 0, 0, 0, - 1, 0, 1,
  27986. 0, 0, 0, 0, 1, 1,
  27987. 0, 0, 0, 0, - 1, 1
  27988. ];
  27989. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27990. var p1 = ( i / l ) * Math.PI * 2;
  27991. var p2 = ( j / l ) * Math.PI * 2;
  27992. positions.push(
  27993. Math.cos( p1 ), Math.sin( p1 ), 1,
  27994. Math.cos( p2 ), Math.sin( p2 ), 1
  27995. );
  27996. }
  27997. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27998. var material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  27999. this.cone = new LineSegments( geometry, material );
  28000. this.add( this.cone );
  28001. this.update();
  28002. }
  28003. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  28004. SpotLightHelper.prototype.constructor = SpotLightHelper;
  28005. SpotLightHelper.prototype.dispose = function () {
  28006. this.cone.geometry.dispose();
  28007. this.cone.material.dispose();
  28008. };
  28009. SpotLightHelper.prototype.update = function () {
  28010. this.light.updateMatrixWorld();
  28011. var coneLength = this.light.distance ? this.light.distance : 1000;
  28012. var coneWidth = coneLength * Math.tan( this.light.angle );
  28013. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  28014. _vector$8.setFromMatrixPosition( this.light.target.matrixWorld );
  28015. this.cone.lookAt( _vector$8 );
  28016. if ( this.color !== undefined ) {
  28017. this.cone.material.color.set( this.color );
  28018. } else {
  28019. this.cone.material.color.copy( this.light.color );
  28020. }
  28021. };
  28022. /**
  28023. * @author Sean Griffin / http://twitter.com/sgrif
  28024. * @author Michael Guerrero / http://realitymeltdown.com
  28025. * @author mrdoob / http://mrdoob.com/
  28026. * @author ikerr / http://verold.com
  28027. * @author Mugen87 / https://github.com/Mugen87
  28028. */
  28029. var _vector$9 = new Vector3();
  28030. var _boneMatrix = new Matrix4();
  28031. var _matrixWorldInv = new Matrix4();
  28032. function getBoneList( object ) {
  28033. var boneList = [];
  28034. if ( object && object.isBone ) {
  28035. boneList.push( object );
  28036. }
  28037. for ( var i = 0; i < object.children.length; i ++ ) {
  28038. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  28039. }
  28040. return boneList;
  28041. }
  28042. function SkeletonHelper( object ) {
  28043. var bones = getBoneList( object );
  28044. var geometry = new BufferGeometry();
  28045. var vertices = [];
  28046. var colors = [];
  28047. var color1 = new Color( 0, 0, 1 );
  28048. var color2 = new Color( 0, 1, 0 );
  28049. for ( var i = 0; i < bones.length; i ++ ) {
  28050. var bone = bones[ i ];
  28051. if ( bone.parent && bone.parent.isBone ) {
  28052. vertices.push( 0, 0, 0 );
  28053. vertices.push( 0, 0, 0 );
  28054. colors.push( color1.r, color1.g, color1.b );
  28055. colors.push( color2.r, color2.g, color2.b );
  28056. }
  28057. }
  28058. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28059. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28060. var material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  28061. LineSegments.call( this, geometry, material );
  28062. this.type = 'SkeletonHelper';
  28063. this.root = object;
  28064. this.bones = bones;
  28065. this.matrix = object.matrixWorld;
  28066. this.matrixAutoUpdate = false;
  28067. }
  28068. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  28069. SkeletonHelper.prototype.constructor = SkeletonHelper;
  28070. SkeletonHelper.prototype.isSkeletonHelper = true;
  28071. SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
  28072. var bones = this.bones;
  28073. var geometry = this.geometry;
  28074. var position = geometry.getAttribute( 'position' );
  28075. _matrixWorldInv.getInverse( this.root.matrixWorld );
  28076. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  28077. var bone = bones[ i ];
  28078. if ( bone.parent && bone.parent.isBone ) {
  28079. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  28080. _vector$9.setFromMatrixPosition( _boneMatrix );
  28081. position.setXYZ( j, _vector$9.x, _vector$9.y, _vector$9.z );
  28082. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  28083. _vector$9.setFromMatrixPosition( _boneMatrix );
  28084. position.setXYZ( j + 1, _vector$9.x, _vector$9.y, _vector$9.z );
  28085. j += 2;
  28086. }
  28087. }
  28088. geometry.getAttribute( 'position' ).needsUpdate = true;
  28089. Object3D.prototype.updateMatrixWorld.call( this, force );
  28090. };
  28091. /**
  28092. * @author alteredq / http://alteredqualia.com/
  28093. * @author mrdoob / http://mrdoob.com/
  28094. */
  28095. function PointLightHelper( light, sphereSize, color ) {
  28096. this.light = light;
  28097. this.light.updateMatrixWorld();
  28098. this.color = color;
  28099. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  28100. var material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28101. Mesh.call( this, geometry, material );
  28102. this.type = 'PointLightHelper';
  28103. this.matrix = this.light.matrixWorld;
  28104. this.matrixAutoUpdate = false;
  28105. this.update();
  28106. /*
  28107. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28108. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28109. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28110. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28111. var d = light.distance;
  28112. if ( d === 0.0 ) {
  28113. this.lightDistance.visible = false;
  28114. } else {
  28115. this.lightDistance.scale.set( d, d, d );
  28116. }
  28117. this.add( this.lightDistance );
  28118. */
  28119. }
  28120. PointLightHelper.prototype = Object.create( Mesh.prototype );
  28121. PointLightHelper.prototype.constructor = PointLightHelper;
  28122. PointLightHelper.prototype.dispose = function () {
  28123. this.geometry.dispose();
  28124. this.material.dispose();
  28125. };
  28126. PointLightHelper.prototype.update = function () {
  28127. if ( this.color !== undefined ) {
  28128. this.material.color.set( this.color );
  28129. } else {
  28130. this.material.color.copy( this.light.color );
  28131. }
  28132. /*
  28133. var d = this.light.distance;
  28134. if ( d === 0.0 ) {
  28135. this.lightDistance.visible = false;
  28136. } else {
  28137. this.lightDistance.visible = true;
  28138. this.lightDistance.scale.set( d, d, d );
  28139. }
  28140. */
  28141. };
  28142. /**
  28143. * @author alteredq / http://alteredqualia.com/
  28144. * @author mrdoob / http://mrdoob.com/
  28145. * @author Mugen87 / https://github.com/Mugen87
  28146. */
  28147. var _vector$a = new Vector3();
  28148. var _color1 = new Color();
  28149. var _color2 = new Color();
  28150. function HemisphereLightHelper( light, size, color ) {
  28151. Object3D.call( this );
  28152. this.light = light;
  28153. this.light.updateMatrixWorld();
  28154. this.matrix = light.matrixWorld;
  28155. this.matrixAutoUpdate = false;
  28156. this.color = color;
  28157. var geometry = new OctahedronBufferGeometry( size );
  28158. geometry.rotateY( Math.PI * 0.5 );
  28159. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28160. if ( this.color === undefined ) this.material.vertexColors = true;
  28161. var position = geometry.getAttribute( 'position' );
  28162. var colors = new Float32Array( position.count * 3 );
  28163. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  28164. this.add( new Mesh( geometry, this.material ) );
  28165. this.update();
  28166. }
  28167. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  28168. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  28169. HemisphereLightHelper.prototype.dispose = function () {
  28170. this.children[ 0 ].geometry.dispose();
  28171. this.children[ 0 ].material.dispose();
  28172. };
  28173. HemisphereLightHelper.prototype.update = function () {
  28174. var mesh = this.children[ 0 ];
  28175. if ( this.color !== undefined ) {
  28176. this.material.color.set( this.color );
  28177. } else {
  28178. var colors = mesh.geometry.getAttribute( 'color' );
  28179. _color1.copy( this.light.color );
  28180. _color2.copy( this.light.groundColor );
  28181. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  28182. var color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  28183. colors.setXYZ( i, color.r, color.g, color.b );
  28184. }
  28185. colors.needsUpdate = true;
  28186. }
  28187. mesh.lookAt( _vector$a.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  28188. };
  28189. /**
  28190. * @author mrdoob / http://mrdoob.com/
  28191. */
  28192. function GridHelper( size, divisions, color1, color2 ) {
  28193. size = size || 10;
  28194. divisions = divisions || 10;
  28195. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28196. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28197. var center = divisions / 2;
  28198. var step = size / divisions;
  28199. var halfSize = size / 2;
  28200. var vertices = [], colors = [];
  28201. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  28202. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  28203. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  28204. var color = i === center ? color1 : color2;
  28205. color.toArray( colors, j ); j += 3;
  28206. color.toArray( colors, j ); j += 3;
  28207. color.toArray( colors, j ); j += 3;
  28208. color.toArray( colors, j ); j += 3;
  28209. }
  28210. var geometry = new BufferGeometry();
  28211. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28212. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28213. var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28214. LineSegments.call( this, geometry, material );
  28215. this.type = 'GridHelper';
  28216. }
  28217. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  28218. constructor: GridHelper,
  28219. copy: function ( source ) {
  28220. LineSegments.prototype.copy.call( this, source );
  28221. this.geometry.copy( source.geometry );
  28222. this.material.copy( source.material );
  28223. return this;
  28224. },
  28225. clone: function () {
  28226. return new this.constructor().copy( this );
  28227. }
  28228. } );
  28229. /**
  28230. * @author mrdoob / http://mrdoob.com/
  28231. * @author Mugen87 / http://github.com/Mugen87
  28232. * @author Hectate / http://www.github.com/Hectate
  28233. */
  28234. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  28235. radius = radius || 10;
  28236. radials = radials || 16;
  28237. circles = circles || 8;
  28238. divisions = divisions || 64;
  28239. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28240. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28241. var vertices = [];
  28242. var colors = [];
  28243. var x, z;
  28244. var v, i, j, r, color;
  28245. // create the radials
  28246. for ( i = 0; i <= radials; i ++ ) {
  28247. v = ( i / radials ) * ( Math.PI * 2 );
  28248. x = Math.sin( v ) * radius;
  28249. z = Math.cos( v ) * radius;
  28250. vertices.push( 0, 0, 0 );
  28251. vertices.push( x, 0, z );
  28252. color = ( i & 1 ) ? color1 : color2;
  28253. colors.push( color.r, color.g, color.b );
  28254. colors.push( color.r, color.g, color.b );
  28255. }
  28256. // create the circles
  28257. for ( i = 0; i <= circles; i ++ ) {
  28258. color = ( i & 1 ) ? color1 : color2;
  28259. r = radius - ( radius / circles * i );
  28260. for ( j = 0; j < divisions; j ++ ) {
  28261. // first vertex
  28262. v = ( j / divisions ) * ( Math.PI * 2 );
  28263. x = Math.sin( v ) * r;
  28264. z = Math.cos( v ) * r;
  28265. vertices.push( x, 0, z );
  28266. colors.push( color.r, color.g, color.b );
  28267. // second vertex
  28268. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  28269. x = Math.sin( v ) * r;
  28270. z = Math.cos( v ) * r;
  28271. vertices.push( x, 0, z );
  28272. colors.push( color.r, color.g, color.b );
  28273. }
  28274. }
  28275. var geometry = new BufferGeometry();
  28276. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28277. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28278. var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28279. LineSegments.call( this, geometry, material );
  28280. this.type = 'PolarGridHelper';
  28281. }
  28282. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  28283. PolarGridHelper.prototype.constructor = PolarGridHelper;
  28284. /**
  28285. * @author alteredq / http://alteredqualia.com/
  28286. * @author mrdoob / http://mrdoob.com/
  28287. * @author WestLangley / http://github.com/WestLangley
  28288. */
  28289. var _v1$5 = new Vector3();
  28290. var _v2$3 = new Vector3();
  28291. var _v3$1 = new Vector3();
  28292. function DirectionalLightHelper( light, size, color ) {
  28293. Object3D.call( this );
  28294. this.light = light;
  28295. this.light.updateMatrixWorld();
  28296. this.matrix = light.matrixWorld;
  28297. this.matrixAutoUpdate = false;
  28298. this.color = color;
  28299. if ( size === undefined ) size = 1;
  28300. var geometry = new BufferGeometry();
  28301. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  28302. - size, size, 0,
  28303. size, size, 0,
  28304. size, - size, 0,
  28305. - size, - size, 0,
  28306. - size, size, 0
  28307. ], 3 ) );
  28308. var material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28309. this.lightPlane = new Line( geometry, material );
  28310. this.add( this.lightPlane );
  28311. geometry = new BufferGeometry();
  28312. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  28313. this.targetLine = new Line( geometry, material );
  28314. this.add( this.targetLine );
  28315. this.update();
  28316. }
  28317. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  28318. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  28319. DirectionalLightHelper.prototype.dispose = function () {
  28320. this.lightPlane.geometry.dispose();
  28321. this.lightPlane.material.dispose();
  28322. this.targetLine.geometry.dispose();
  28323. this.targetLine.material.dispose();
  28324. };
  28325. DirectionalLightHelper.prototype.update = function () {
  28326. _v1$5.setFromMatrixPosition( this.light.matrixWorld );
  28327. _v2$3.setFromMatrixPosition( this.light.target.matrixWorld );
  28328. _v3$1.subVectors( _v2$3, _v1$5 );
  28329. this.lightPlane.lookAt( _v2$3 );
  28330. if ( this.color !== undefined ) {
  28331. this.lightPlane.material.color.set( this.color );
  28332. this.targetLine.material.color.set( this.color );
  28333. } else {
  28334. this.lightPlane.material.color.copy( this.light.color );
  28335. this.targetLine.material.color.copy( this.light.color );
  28336. }
  28337. this.targetLine.lookAt( _v2$3 );
  28338. this.targetLine.scale.z = _v3$1.length();
  28339. };
  28340. /**
  28341. * @author alteredq / http://alteredqualia.com/
  28342. * @author Mugen87 / https://github.com/Mugen87
  28343. *
  28344. * - shows frustum, line of sight and up of the camera
  28345. * - suitable for fast updates
  28346. * - based on frustum visualization in lightgl.js shadowmap example
  28347. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28348. */
  28349. var _vector$b = new Vector3();
  28350. var _camera = new Camera();
  28351. function CameraHelper( camera ) {
  28352. var geometry = new BufferGeometry();
  28353. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  28354. var vertices = [];
  28355. var colors = [];
  28356. var pointMap = {};
  28357. // colors
  28358. var colorFrustum = new Color( 0xffaa00 );
  28359. var colorCone = new Color( 0xff0000 );
  28360. var colorUp = new Color( 0x00aaff );
  28361. var colorTarget = new Color( 0xffffff );
  28362. var colorCross = new Color( 0x333333 );
  28363. // near
  28364. addLine( 'n1', 'n2', colorFrustum );
  28365. addLine( 'n2', 'n4', colorFrustum );
  28366. addLine( 'n4', 'n3', colorFrustum );
  28367. addLine( 'n3', 'n1', colorFrustum );
  28368. // far
  28369. addLine( 'f1', 'f2', colorFrustum );
  28370. addLine( 'f2', 'f4', colorFrustum );
  28371. addLine( 'f4', 'f3', colorFrustum );
  28372. addLine( 'f3', 'f1', colorFrustum );
  28373. // sides
  28374. addLine( 'n1', 'f1', colorFrustum );
  28375. addLine( 'n2', 'f2', colorFrustum );
  28376. addLine( 'n3', 'f3', colorFrustum );
  28377. addLine( 'n4', 'f4', colorFrustum );
  28378. // cone
  28379. addLine( 'p', 'n1', colorCone );
  28380. addLine( 'p', 'n2', colorCone );
  28381. addLine( 'p', 'n3', colorCone );
  28382. addLine( 'p', 'n4', colorCone );
  28383. // up
  28384. addLine( 'u1', 'u2', colorUp );
  28385. addLine( 'u2', 'u3', colorUp );
  28386. addLine( 'u3', 'u1', colorUp );
  28387. // target
  28388. addLine( 'c', 't', colorTarget );
  28389. addLine( 'p', 'c', colorCross );
  28390. // cross
  28391. addLine( 'cn1', 'cn2', colorCross );
  28392. addLine( 'cn3', 'cn4', colorCross );
  28393. addLine( 'cf1', 'cf2', colorCross );
  28394. addLine( 'cf3', 'cf4', colorCross );
  28395. function addLine( a, b, color ) {
  28396. addPoint( a, color );
  28397. addPoint( b, color );
  28398. }
  28399. function addPoint( id, color ) {
  28400. vertices.push( 0, 0, 0 );
  28401. colors.push( color.r, color.g, color.b );
  28402. if ( pointMap[ id ] === undefined ) {
  28403. pointMap[ id ] = [];
  28404. }
  28405. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  28406. }
  28407. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28408. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28409. LineSegments.call( this, geometry, material );
  28410. this.type = 'CameraHelper';
  28411. this.camera = camera;
  28412. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  28413. this.matrix = camera.matrixWorld;
  28414. this.matrixAutoUpdate = false;
  28415. this.pointMap = pointMap;
  28416. this.update();
  28417. }
  28418. CameraHelper.prototype = Object.create( LineSegments.prototype );
  28419. CameraHelper.prototype.constructor = CameraHelper;
  28420. CameraHelper.prototype.update = function () {
  28421. var geometry = this.geometry;
  28422. var pointMap = this.pointMap;
  28423. var w = 1, h = 1;
  28424. // we need just camera projection matrix inverse
  28425. // world matrix must be identity
  28426. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  28427. // center / target
  28428. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  28429. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  28430. // near
  28431. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  28432. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  28433. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  28434. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  28435. // far
  28436. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  28437. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  28438. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  28439. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  28440. // up
  28441. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  28442. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  28443. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  28444. // cross
  28445. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  28446. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  28447. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  28448. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  28449. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  28450. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  28451. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  28452. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  28453. geometry.getAttribute( 'position' ).needsUpdate = true;
  28454. };
  28455. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  28456. _vector$b.set( x, y, z ).unproject( camera );
  28457. var points = pointMap[ point ];
  28458. if ( points !== undefined ) {
  28459. var position = geometry.getAttribute( 'position' );
  28460. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28461. position.setXYZ( points[ i ], _vector$b.x, _vector$b.y, _vector$b.z );
  28462. }
  28463. }
  28464. }
  28465. /**
  28466. * @author mrdoob / http://mrdoob.com/
  28467. * @author Mugen87 / http://github.com/Mugen87
  28468. */
  28469. var _box$3 = new Box3();
  28470. function BoxHelper( object, color ) {
  28471. this.object = object;
  28472. if ( color === undefined ) color = 0xffff00;
  28473. var 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 ] );
  28474. var positions = new Float32Array( 8 * 3 );
  28475. var geometry = new BufferGeometry();
  28476. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28477. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28478. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28479. this.type = 'BoxHelper';
  28480. this.matrixAutoUpdate = false;
  28481. this.update();
  28482. }
  28483. BoxHelper.prototype = Object.create( LineSegments.prototype );
  28484. BoxHelper.prototype.constructor = BoxHelper;
  28485. BoxHelper.prototype.update = function ( object ) {
  28486. if ( object !== undefined ) {
  28487. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28488. }
  28489. if ( this.object !== undefined ) {
  28490. _box$3.setFromObject( this.object );
  28491. }
  28492. if ( _box$3.isEmpty() ) return;
  28493. var min = _box$3.min;
  28494. var max = _box$3.max;
  28495. /*
  28496. 5____4
  28497. 1/___0/|
  28498. | 6__|_7
  28499. 2/___3/
  28500. 0: max.x, max.y, max.z
  28501. 1: min.x, max.y, max.z
  28502. 2: min.x, min.y, max.z
  28503. 3: max.x, min.y, max.z
  28504. 4: max.x, max.y, min.z
  28505. 5: min.x, max.y, min.z
  28506. 6: min.x, min.y, min.z
  28507. 7: max.x, min.y, min.z
  28508. */
  28509. var position = this.geometry.attributes.position;
  28510. var array = position.array;
  28511. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28512. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28513. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28514. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28515. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28516. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28517. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28518. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28519. position.needsUpdate = true;
  28520. this.geometry.computeBoundingSphere();
  28521. };
  28522. BoxHelper.prototype.setFromObject = function ( object ) {
  28523. this.object = object;
  28524. this.update();
  28525. return this;
  28526. };
  28527. BoxHelper.prototype.copy = function ( source ) {
  28528. LineSegments.prototype.copy.call( this, source );
  28529. this.object = source.object;
  28530. return this;
  28531. };
  28532. BoxHelper.prototype.clone = function () {
  28533. return new this.constructor().copy( this );
  28534. };
  28535. /**
  28536. * @author WestLangley / http://github.com/WestLangley
  28537. */
  28538. function Box3Helper( box, color ) {
  28539. this.type = 'Box3Helper';
  28540. this.box = box;
  28541. color = color || 0xffff00;
  28542. var 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 ] );
  28543. var 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 ];
  28544. var geometry = new BufferGeometry();
  28545. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28546. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28547. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28548. this.type = 'Box3Helper';
  28549. this.geometry.computeBoundingSphere();
  28550. }
  28551. Box3Helper.prototype = Object.create( LineSegments.prototype );
  28552. Box3Helper.prototype.constructor = Box3Helper;
  28553. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  28554. var box = this.box;
  28555. if ( box.isEmpty() ) return;
  28556. box.getCenter( this.position );
  28557. box.getSize( this.scale );
  28558. this.scale.multiplyScalar( 0.5 );
  28559. Object3D.prototype.updateMatrixWorld.call( this, force );
  28560. };
  28561. /**
  28562. * @author WestLangley / http://github.com/WestLangley
  28563. */
  28564. function PlaneHelper( plane, size, hex ) {
  28565. this.plane = plane;
  28566. this.size = ( size === undefined ) ? 1 : size;
  28567. var color = ( hex !== undefined ) ? hex : 0xffff00;
  28568. var 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 ];
  28569. var geometry = new BufferGeometry();
  28570. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28571. geometry.computeBoundingSphere();
  28572. Line.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28573. this.type = 'PlaneHelper';
  28574. //
  28575. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28576. var geometry2 = new BufferGeometry();
  28577. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28578. geometry2.computeBoundingSphere();
  28579. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  28580. }
  28581. PlaneHelper.prototype = Object.create( Line.prototype );
  28582. PlaneHelper.prototype.constructor = PlaneHelper;
  28583. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  28584. var scale = - this.plane.constant;
  28585. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28586. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28587. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28588. this.lookAt( this.plane.normal );
  28589. Object3D.prototype.updateMatrixWorld.call( this, force );
  28590. };
  28591. /**
  28592. * @author WestLangley / http://github.com/WestLangley
  28593. * @author zz85 / http://github.com/zz85
  28594. * @author bhouston / http://clara.io
  28595. *
  28596. * Creates an arrow for visualizing directions
  28597. *
  28598. * Parameters:
  28599. * dir - Vector3
  28600. * origin - Vector3
  28601. * length - Number
  28602. * color - color in hex value
  28603. * headLength - Number
  28604. * headWidth - Number
  28605. */
  28606. var _axis = new Vector3();
  28607. var _lineGeometry, _coneGeometry;
  28608. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  28609. // dir is assumed to be normalized
  28610. Object3D.call( this );
  28611. this.type = 'ArrowHelper';
  28612. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28613. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28614. if ( length === undefined ) length = 1;
  28615. if ( color === undefined ) color = 0xffff00;
  28616. if ( headLength === undefined ) headLength = 0.2 * length;
  28617. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28618. if ( _lineGeometry === undefined ) {
  28619. _lineGeometry = new BufferGeometry();
  28620. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28621. _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28622. _coneGeometry.translate( 0, - 0.5, 0 );
  28623. }
  28624. this.position.copy( origin );
  28625. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28626. this.line.matrixAutoUpdate = false;
  28627. this.add( this.line );
  28628. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  28629. this.cone.matrixAutoUpdate = false;
  28630. this.add( this.cone );
  28631. this.setDirection( dir );
  28632. this.setLength( length, headLength, headWidth );
  28633. }
  28634. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28635. ArrowHelper.prototype.constructor = ArrowHelper;
  28636. ArrowHelper.prototype.setDirection = function ( dir ) {
  28637. // dir is assumed to be normalized
  28638. if ( dir.y > 0.99999 ) {
  28639. this.quaternion.set( 0, 0, 0, 1 );
  28640. } else if ( dir.y < - 0.99999 ) {
  28641. this.quaternion.set( 1, 0, 0, 0 );
  28642. } else {
  28643. _axis.set( dir.z, 0, - dir.x ).normalize();
  28644. var radians = Math.acos( dir.y );
  28645. this.quaternion.setFromAxisAngle( _axis, radians );
  28646. }
  28647. };
  28648. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28649. if ( headLength === undefined ) headLength = 0.2 * length;
  28650. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28651. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  28652. this.line.updateMatrix();
  28653. this.cone.scale.set( headWidth, headLength, headWidth );
  28654. this.cone.position.y = length;
  28655. this.cone.updateMatrix();
  28656. };
  28657. ArrowHelper.prototype.setColor = function ( color ) {
  28658. this.line.material.color.set( color );
  28659. this.cone.material.color.set( color );
  28660. };
  28661. ArrowHelper.prototype.copy = function ( source ) {
  28662. Object3D.prototype.copy.call( this, source, false );
  28663. this.line.copy( source.line );
  28664. this.cone.copy( source.cone );
  28665. return this;
  28666. };
  28667. ArrowHelper.prototype.clone = function () {
  28668. return new this.constructor().copy( this );
  28669. };
  28670. /**
  28671. * @author sroucheray / http://sroucheray.org/
  28672. * @author mrdoob / http://mrdoob.com/
  28673. */
  28674. function AxesHelper( size ) {
  28675. size = size || 1;
  28676. var vertices = [
  28677. 0, 0, 0, size, 0, 0,
  28678. 0, 0, 0, 0, size, 0,
  28679. 0, 0, 0, 0, 0, size
  28680. ];
  28681. var colors = [
  28682. 1, 0, 0, 1, 0.6, 0,
  28683. 0, 1, 0, 0.6, 1, 0,
  28684. 0, 0, 1, 0, 0.6, 1
  28685. ];
  28686. var geometry = new BufferGeometry();
  28687. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28688. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28689. var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28690. LineSegments.call( this, geometry, material );
  28691. this.type = 'AxesHelper';
  28692. }
  28693. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28694. AxesHelper.prototype.constructor = AxesHelper;
  28695. /**
  28696. * @author Emmett Lalish / elalish
  28697. *
  28698. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28699. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28700. * blur to be quickly accessed based on material roughness. It is packed into a
  28701. * special CubeUV format that allows us to perform custom interpolation so that
  28702. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28703. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28704. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28705. * higher roughness levels. In this way we maintain resolution to smoothly
  28706. * interpolate diffuse lighting while limiting sampling computation.
  28707. */
  28708. var LOD_MIN = 4;
  28709. var LOD_MAX = 8;
  28710. var SIZE_MAX = Math.pow( 2, LOD_MAX );
  28711. // The standard deviations (radians) associated with the extra mips. These are
  28712. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28713. // geometric shadowing function. These sigma values squared must match the
  28714. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28715. var EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
  28716. var TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
  28717. // The maximum length of the blur for loop. Smaller sigmas will use fewer
  28718. // samples and exit early, but not recompile the shader.
  28719. var MAX_SAMPLES = 20;
  28720. var ENCODINGS = {
  28721. [ LinearEncoding ]: 0,
  28722. [ sRGBEncoding ]: 1,
  28723. [ RGBEEncoding ]: 2,
  28724. [ RGBM7Encoding ]: 3,
  28725. [ RGBM16Encoding ]: 4,
  28726. [ RGBDEncoding ]: 5,
  28727. [ GammaEncoding ]: 6
  28728. };
  28729. var _flatCamera = new OrthographicCamera();
  28730. var { _lodPlanes, _sizeLods, _sigmas } = _createPlanes();
  28731. var _oldTarget = null;
  28732. // Golden Ratio
  28733. var PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
  28734. var INV_PHI = 1 / PHI;
  28735. // Vertices of a dodecahedron (except the opposites, which represent the
  28736. // same axis), used as axis directions evenly spread on a sphere.
  28737. var _axisDirections = [
  28738. new Vector3( 1, 1, 1 ),
  28739. new Vector3( - 1, 1, 1 ),
  28740. new Vector3( 1, 1, - 1 ),
  28741. new Vector3( - 1, 1, - 1 ),
  28742. new Vector3( 0, PHI, INV_PHI ),
  28743. new Vector3( 0, PHI, - INV_PHI ),
  28744. new Vector3( INV_PHI, 0, PHI ),
  28745. new Vector3( - INV_PHI, 0, PHI ),
  28746. new Vector3( PHI, INV_PHI, 0 ),
  28747. new Vector3( - PHI, INV_PHI, 0 ) ];
  28748. function PMREMGenerator( renderer ) {
  28749. this._renderer = renderer;
  28750. this._pingPongRenderTarget = null;
  28751. this._blurMaterial = _getBlurShader( MAX_SAMPLES );
  28752. this._equirectShader = null;
  28753. this._cubemapShader = null;
  28754. this._compileMaterial( this._blurMaterial );
  28755. }
  28756. PMREMGenerator.prototype = {
  28757. constructor: PMREMGenerator,
  28758. /**
  28759. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28760. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28761. * in radians to be applied to the scene before PMREM generation. Optional near
  28762. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28763. * is placed at the origin).
  28764. */
  28765. fromScene: function ( scene, sigma = 0, near = 0.1, far = 100 ) {
  28766. _oldTarget = this._renderer.getRenderTarget();
  28767. var cubeUVRenderTarget = this._allocateTargets();
  28768. this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
  28769. if ( sigma > 0 ) {
  28770. this._blur( cubeUVRenderTarget, 0, 0, sigma );
  28771. }
  28772. this._applyPMREM( cubeUVRenderTarget );
  28773. this._cleanup( cubeUVRenderTarget );
  28774. return cubeUVRenderTarget;
  28775. },
  28776. /**
  28777. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28778. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28779. * as this matches best with the 256 x 256 cubemap output.
  28780. */
  28781. fromEquirectangular: function ( equirectangular ) {
  28782. equirectangular.magFilter = NearestFilter;
  28783. equirectangular.minFilter = NearestFilter;
  28784. equirectangular.generateMipmaps = false;
  28785. return this.fromCubemap( equirectangular );
  28786. },
  28787. /**
  28788. * Generates a PMREM from an cubemap texture, which can be either LDR
  28789. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28790. * as this matches best with the 256 x 256 cubemap output.
  28791. */
  28792. fromCubemap: function ( cubemap ) {
  28793. _oldTarget = this._renderer.getRenderTarget();
  28794. var cubeUVRenderTarget = this._allocateTargets( cubemap );
  28795. this._textureToCubeUV( cubemap, cubeUVRenderTarget );
  28796. this._applyPMREM( cubeUVRenderTarget );
  28797. this._cleanup( cubeUVRenderTarget );
  28798. return cubeUVRenderTarget;
  28799. },
  28800. /**
  28801. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28802. * your texture's network fetch for increased concurrency.
  28803. */
  28804. compileCubemapShader: function () {
  28805. if ( this._cubemapShader === null ) {
  28806. this._cubemapShader = _getCubemapShader();
  28807. this._compileMaterial( this._cubemapShader );
  28808. }
  28809. },
  28810. /**
  28811. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28812. * your texture's network fetch for increased concurrency.
  28813. */
  28814. compileEquirectangularShader: function () {
  28815. if ( this._equirectShader === null ) {
  28816. this._equirectShader = _getEquirectShader();
  28817. this._compileMaterial( this._equirectShader );
  28818. }
  28819. },
  28820. /**
  28821. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28822. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28823. * one of them will cause any others to also become unusable.
  28824. */
  28825. dispose: function () {
  28826. this._blurMaterial.dispose();
  28827. if ( this._cubemapShader !== null ) this._cubemapShader.dispose();
  28828. if ( this._equirectShader !== null ) this._equirectShader.dispose();
  28829. for ( var i = 0; i < _lodPlanes.length; i ++ ) {
  28830. _lodPlanes[ i ].dispose();
  28831. }
  28832. },
  28833. // private interface
  28834. _cleanup: function ( outputTarget ) {
  28835. this._pingPongRenderTarget.dispose();
  28836. this._renderer.setRenderTarget( _oldTarget );
  28837. outputTarget.scissorTest = false;
  28838. // reset viewport and scissor
  28839. outputTarget.setSize( outputTarget.width, outputTarget.height );
  28840. },
  28841. _allocateTargets: function ( equirectangular ) {
  28842. var params = {
  28843. magFilter: NearestFilter,
  28844. minFilter: NearestFilter,
  28845. generateMipmaps: false,
  28846. type: UnsignedByteType,
  28847. format: RGBEFormat,
  28848. encoding: _isLDR( equirectangular ) ? equirectangular.encoding : RGBEEncoding,
  28849. depthBuffer: false,
  28850. stencilBuffer: false
  28851. };
  28852. var cubeUVRenderTarget = _createRenderTarget( params );
  28853. cubeUVRenderTarget.depthBuffer = equirectangular ? false : true;
  28854. this._pingPongRenderTarget = _createRenderTarget( params );
  28855. return cubeUVRenderTarget;
  28856. },
  28857. _compileMaterial: function ( material ) {
  28858. var tmpMesh = new Mesh( _lodPlanes[ 0 ], material );
  28859. this._renderer.compile( tmpMesh, _flatCamera );
  28860. },
  28861. _sceneToCubeUV: function ( scene, near, far, cubeUVRenderTarget ) {
  28862. var fov = 90;
  28863. var aspect = 1;
  28864. var cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
  28865. var upSign = [ 1, - 1, 1, 1, 1, 1 ];
  28866. var forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
  28867. var renderer = this._renderer;
  28868. var outputEncoding = renderer.outputEncoding;
  28869. var toneMapping = renderer.toneMapping;
  28870. var toneMappingExposure = renderer.toneMappingExposure;
  28871. var clearColor = renderer.getClearColor();
  28872. var clearAlpha = renderer.getClearAlpha();
  28873. renderer.toneMapping = LinearToneMapping;
  28874. renderer.toneMappingExposure = 1.0;
  28875. renderer.outputEncoding = LinearEncoding;
  28876. var background = scene.background;
  28877. if ( background && background.isColor ) {
  28878. background.convertSRGBToLinear();
  28879. // Convert linear to RGBE
  28880. var maxComponent = Math.max( background.r, background.g, background.b );
  28881. var fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
  28882. background = background.multiplyScalar( Math.pow( 2.0, - fExp ) );
  28883. var alpha = ( fExp + 128.0 ) / 255.0;
  28884. renderer.setClearColor( background, alpha );
  28885. scene.background = null;
  28886. }
  28887. for ( var i = 0; i < 6; i ++ ) {
  28888. var col = i % 3;
  28889. if ( col == 0 ) {
  28890. cubeCamera.up.set( 0, upSign[ i ], 0 );
  28891. cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
  28892. } else if ( col == 1 ) {
  28893. cubeCamera.up.set( 0, 0, upSign[ i ] );
  28894. cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
  28895. } else {
  28896. cubeCamera.up.set( 0, upSign[ i ], 0 );
  28897. cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
  28898. }
  28899. _setViewport( cubeUVRenderTarget,
  28900. col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX );
  28901. renderer.setRenderTarget( cubeUVRenderTarget );
  28902. renderer.render( scene, cubeCamera );
  28903. }
  28904. renderer.toneMapping = toneMapping;
  28905. renderer.toneMappingExposure = toneMappingExposure;
  28906. renderer.outputEncoding = outputEncoding;
  28907. renderer.setClearColor( clearColor, clearAlpha );
  28908. },
  28909. _textureToCubeUV: function ( texture, cubeUVRenderTarget ) {
  28910. var renderer = this._renderer;
  28911. if ( texture.isCubeTexture ) {
  28912. if ( this._cubemapShader == null ) {
  28913. this._cubemapShader = _getCubemapShader();
  28914. }
  28915. } else {
  28916. if ( this._equirectShader == null ) {
  28917. this._equirectShader = _getEquirectShader();
  28918. }
  28919. }
  28920. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28921. var mesh = new Mesh( _lodPlanes[ 0 ], material );
  28922. var uniforms = material.uniforms;
  28923. uniforms[ 'envMap' ].value = texture;
  28924. if ( ! texture.isCubeTexture ) {
  28925. uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height );
  28926. }
  28927. uniforms[ 'inputEncoding' ].value = ENCODINGS[ texture.encoding ];
  28928. uniforms[ 'outputEncoding' ].value = ENCODINGS[ cubeUVRenderTarget.texture.encoding ];
  28929. _setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );
  28930. renderer.setRenderTarget( cubeUVRenderTarget );
  28931. renderer.render( mesh, _flatCamera );
  28932. },
  28933. _applyPMREM: function ( cubeUVRenderTarget ) {
  28934. var renderer = this._renderer;
  28935. var autoClear = renderer.autoClear;
  28936. renderer.autoClear = false;
  28937. for ( var i = 1; i < TOTAL_LODS; i ++ ) {
  28938. var sigma = Math.sqrt( _sigmas[ i ] * _sigmas[ i ] - _sigmas[ i - 1 ] * _sigmas[ i - 1 ] );
  28939. var poleAxis = _axisDirections[ ( i - 1 ) % _axisDirections.length ];
  28940. this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
  28941. }
  28942. renderer.autoClear = autoClear;
  28943. },
  28944. /**
  28945. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28946. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28947. * the blur latitudinally (around the poles), and then longitudinally (towards
  28948. * the poles) to approximate the orthogonally-separable blur. It is least
  28949. * accurate at the poles, but still does a decent job.
  28950. */
  28951. _blur: function ( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
  28952. var pingPongRenderTarget = this._pingPongRenderTarget;
  28953. this._halfBlur(
  28954. cubeUVRenderTarget,
  28955. pingPongRenderTarget,
  28956. lodIn,
  28957. lodOut,
  28958. sigma,
  28959. 'latitudinal',
  28960. poleAxis );
  28961. this._halfBlur(
  28962. pingPongRenderTarget,
  28963. cubeUVRenderTarget,
  28964. lodOut,
  28965. lodOut,
  28966. sigma,
  28967. 'longitudinal',
  28968. poleAxis );
  28969. },
  28970. _halfBlur: function ( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
  28971. var renderer = this._renderer;
  28972. var blurMaterial = this._blurMaterial;
  28973. if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
  28974. console.error(
  28975. 'blur direction must be either latitudinal or longitudinal!' );
  28976. }
  28977. // Number of standard deviations at which to cut off the discrete approximation.
  28978. var STANDARD_DEVIATIONS = 3;
  28979. var blurMesh = new Mesh( _lodPlanes[ lodOut ], blurMaterial );
  28980. var blurUniforms = blurMaterial.uniforms;
  28981. var pixels = _sizeLods[ lodIn ] - 1;
  28982. var radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
  28983. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28984. var samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
  28985. if ( samples > MAX_SAMPLES ) {
  28986. console.warn( `sigmaRadians, ${
  28987. sigmaRadians}, is too large and will clip, as it requested ${
  28988. samples} samples when the maximum is set to ${MAX_SAMPLES}` );
  28989. }
  28990. var weights = [];
  28991. var sum = 0;
  28992. for ( var i = 0; i < MAX_SAMPLES; ++ i ) {
  28993. var x = i / sigmaPixels;
  28994. var weight = Math.exp( - x * x / 2 );
  28995. weights.push( weight );
  28996. if ( i == 0 ) {
  28997. sum += weight;
  28998. } else if ( i < samples ) {
  28999. sum += 2 * weight;
  29000. }
  29001. }
  29002. for ( var i = 0; i < weights.length; i ++ ) {
  29003. weights[ i ] = weights[ i ] / sum;
  29004. }
  29005. blurUniforms[ 'envMap' ].value = targetIn.texture;
  29006. blurUniforms[ 'samples' ].value = samples;
  29007. blurUniforms[ 'weights' ].value = weights;
  29008. blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
  29009. if ( poleAxis ) {
  29010. blurUniforms[ 'poleAxis' ].value = poleAxis;
  29011. }
  29012. blurUniforms[ 'dTheta' ].value = radiansPerPixel;
  29013. blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;
  29014. blurUniforms[ 'inputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  29015. blurUniforms[ 'outputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  29016. var outputSize = _sizeLods[ lodOut ];
  29017. var x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
  29018. var y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
  29019. _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
  29020. renderer.setRenderTarget( targetOut );
  29021. renderer.render( blurMesh, _flatCamera );
  29022. }
  29023. };
  29024. function _isLDR( texture ) {
  29025. if ( texture === undefined || texture.type !== UnsignedByteType ) return false;
  29026. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29027. }
  29028. function _createPlanes() {
  29029. var _lodPlanes = [];
  29030. var _sizeLods = [];
  29031. var _sigmas = [];
  29032. var lod = LOD_MAX;
  29033. for ( var i = 0; i < TOTAL_LODS; i ++ ) {
  29034. var sizeLod = Math.pow( 2, lod );
  29035. _sizeLods.push( sizeLod );
  29036. var sigma = 1.0 / sizeLod;
  29037. if ( i > LOD_MAX - LOD_MIN ) {
  29038. sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ];
  29039. } else if ( i == 0 ) {
  29040. sigma = 0;
  29041. }
  29042. _sigmas.push( sigma );
  29043. var texelSize = 1.0 / ( sizeLod - 1 );
  29044. var min = - texelSize / 2;
  29045. var max = 1 + texelSize / 2;
  29046. var uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
  29047. var cubeFaces = 6;
  29048. var vertices = 6;
  29049. var positionSize = 3;
  29050. var uvSize = 2;
  29051. var faceIndexSize = 1;
  29052. var position = new Float32Array( positionSize * vertices * cubeFaces );
  29053. var uv = new Float32Array( uvSize * vertices * cubeFaces );
  29054. var faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
  29055. for ( var face = 0; face < cubeFaces; face ++ ) {
  29056. var x = ( face % 3 ) * 2 / 3 - 1;
  29057. var y = face > 2 ? 0 : - 1;
  29058. var coordinates = [
  29059. x, y, 0,
  29060. x + 2 / 3, y, 0,
  29061. x + 2 / 3, y + 1, 0,
  29062. x, y, 0,
  29063. x + 2 / 3, y + 1, 0,
  29064. x, y + 1, 0
  29065. ];
  29066. position.set( coordinates, positionSize * vertices * face );
  29067. uv.set( uv1, uvSize * vertices * face );
  29068. var fill = [ face, face, face, face, face, face ];
  29069. faceIndex.set( fill, faceIndexSize * vertices * face );
  29070. }
  29071. var planes = new BufferGeometry();
  29072. planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
  29073. planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
  29074. planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
  29075. _lodPlanes.push( planes );
  29076. if ( lod > LOD_MIN ) {
  29077. lod --;
  29078. }
  29079. }
  29080. return { _lodPlanes, _sizeLods, _sigmas };
  29081. }
  29082. function _createRenderTarget( params ) {
  29083. var cubeUVRenderTarget = new WebGLRenderTarget( 3 * SIZE_MAX, 3 * SIZE_MAX, params );
  29084. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29085. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29086. cubeUVRenderTarget.scissorTest = true;
  29087. return cubeUVRenderTarget;
  29088. }
  29089. function _setViewport( target, x, y, width, height ) {
  29090. target.viewport.set( x, y, width, height );
  29091. target.scissor.set( x, y, width, height );
  29092. }
  29093. function _getBlurShader( maxSamples ) {
  29094. var weights = new Float32Array( maxSamples );
  29095. var poleAxis = new Vector3( 0, 1, 0 );
  29096. var shaderMaterial = new RawShaderMaterial( {
  29097. defines: { 'n': maxSamples },
  29098. uniforms: {
  29099. 'envMap': { value: null },
  29100. 'samples': { value: 1 },
  29101. 'weights': { value: weights },
  29102. 'latitudinal': { value: false },
  29103. 'dTheta': { value: 0 },
  29104. 'mipInt': { value: 0 },
  29105. 'poleAxis': { value: poleAxis },
  29106. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29107. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29108. },
  29109. vertexShader: _getCommonVertexShader(),
  29110. fragmentShader: `
  29111. precision mediump float;
  29112. precision mediump int;
  29113. varying vec3 vOutputDirection;
  29114. uniform sampler2D envMap;
  29115. uniform int samples;
  29116. uniform float weights[n];
  29117. uniform bool latitudinal;
  29118. uniform float dTheta;
  29119. uniform float mipInt;
  29120. uniform vec3 poleAxis;
  29121. ${_getEncodings()}
  29122. #define ENVMAP_TYPE_CUBE_UV
  29123. #include <cube_uv_reflection_fragment>
  29124. vec3 getSample(float theta, vec3 axis) {
  29125. float cosTheta = cos(theta);
  29126. // Rodrigues' axis-angle rotation
  29127. vec3 sampleDirection = vOutputDirection * cosTheta
  29128. + cross(axis, vOutputDirection) * sin(theta)
  29129. + axis * dot(axis, vOutputDirection) * (1.0 - cosTheta);
  29130. return bilinearCubeUV(envMap, sampleDirection, mipInt);
  29131. }
  29132. void main() {
  29133. vec3 axis = latitudinal ? poleAxis : cross(poleAxis, vOutputDirection);
  29134. if (all(equal(axis, vec3(0.0))))
  29135. axis = vec3(vOutputDirection.z, 0.0, - vOutputDirection.x);
  29136. axis = normalize(axis);
  29137. gl_FragColor = vec4(0.0);
  29138. gl_FragColor.rgb += weights[0] * getSample(0.0, axis);
  29139. for (int i = 1; i < n; i++) {
  29140. if (i >= samples)
  29141. break;
  29142. float theta = dTheta * float(i);
  29143. gl_FragColor.rgb += weights[i] * getSample(-1.0 * theta, axis);
  29144. gl_FragColor.rgb += weights[i] * getSample(theta, axis);
  29145. }
  29146. gl_FragColor = linearToOutputTexel(gl_FragColor);
  29147. }
  29148. `,
  29149. blending: NoBlending,
  29150. depthTest: false,
  29151. depthWrite: false
  29152. } );
  29153. shaderMaterial.type = 'SphericalGaussianBlur';
  29154. return shaderMaterial;
  29155. }
  29156. function _getEquirectShader() {
  29157. var texelSize = new Vector2( 1, 1 );
  29158. var shaderMaterial = new RawShaderMaterial( {
  29159. uniforms: {
  29160. 'envMap': { value: null },
  29161. 'texelSize': { value: texelSize },
  29162. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29163. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29164. },
  29165. vertexShader: _getCommonVertexShader(),
  29166. fragmentShader: `
  29167. precision mediump float;
  29168. precision mediump int;
  29169. varying vec3 vOutputDirection;
  29170. uniform sampler2D envMap;
  29171. uniform vec2 texelSize;
  29172. ${_getEncodings()}
  29173. #include <common>
  29174. void main() {
  29175. gl_FragColor = vec4(0.0);
  29176. vec3 outputDirection = normalize(vOutputDirection);
  29177. vec2 uv = equirectUv( outputDirection );
  29178. vec2 f = fract(uv / texelSize - 0.5);
  29179. uv -= f * texelSize;
  29180. vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29181. uv.x += texelSize.x;
  29182. vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29183. uv.y += texelSize.y;
  29184. vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29185. uv.x -= texelSize.x;
  29186. vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29187. vec3 tm = mix(tl, tr, f.x);
  29188. vec3 bm = mix(bl, br, f.x);
  29189. gl_FragColor.rgb = mix(tm, bm, f.y);
  29190. gl_FragColor = linearToOutputTexel(gl_FragColor);
  29191. }
  29192. `,
  29193. blending: NoBlending,
  29194. depthTest: false,
  29195. depthWrite: false
  29196. } );
  29197. shaderMaterial.type = 'EquirectangularToCubeUV';
  29198. return shaderMaterial;
  29199. }
  29200. function _getCubemapShader() {
  29201. var shaderMaterial = new RawShaderMaterial( {
  29202. uniforms: {
  29203. 'envMap': { value: null },
  29204. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29205. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29206. },
  29207. vertexShader: _getCommonVertexShader(),
  29208. fragmentShader: `
  29209. precision mediump float;
  29210. precision mediump int;
  29211. varying vec3 vOutputDirection;
  29212. uniform samplerCube envMap;
  29213. ${_getEncodings()}
  29214. void main() {
  29215. gl_FragColor = vec4(0.0);
  29216. gl_FragColor.rgb = envMapTexelToLinear(textureCube(envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ))).rgb;
  29217. gl_FragColor = linearToOutputTexel(gl_FragColor);
  29218. }
  29219. `,
  29220. blending: NoBlending,
  29221. depthTest: false,
  29222. depthWrite: false
  29223. } );
  29224. shaderMaterial.type = 'CubemapToCubeUV';
  29225. return shaderMaterial;
  29226. }
  29227. function _getCommonVertexShader() {
  29228. return `
  29229. precision mediump float;
  29230. precision mediump int;
  29231. attribute vec3 position;
  29232. attribute vec2 uv;
  29233. attribute float faceIndex;
  29234. varying vec3 vOutputDirection;
  29235. // RH coordinate system; PMREM face-indexing convention
  29236. vec3 getDirection(vec2 uv, float face) {
  29237. uv = 2.0 * uv - 1.0;
  29238. vec3 direction = vec3(uv, 1.0);
  29239. if (face == 0.0) {
  29240. direction = direction.zyx; // ( 1, v, u ) pos x
  29241. } else if (face == 1.0) {
  29242. direction = direction.xzy;
  29243. direction.xz *= -1.0; // ( -u, 1, -v ) pos y
  29244. } else if (face == 2.0) {
  29245. direction.x *= -1.0; // ( -u, v, 1 ) pos z
  29246. } else if (face == 3.0) {
  29247. direction = direction.zyx;
  29248. direction.xz *= -1.0; // ( -1, v, -u ) neg x
  29249. } else if (face == 4.0) {
  29250. direction = direction.xzy;
  29251. direction.xy *= -1.0; // ( -u, -1, v ) neg y
  29252. } else if (face == 5.0) {
  29253. direction.z *= -1.0; // ( u, v, -1 ) neg z
  29254. }
  29255. return direction;
  29256. }
  29257. void main() {
  29258. vOutputDirection = getDirection(uv, faceIndex);
  29259. gl_Position = vec4( position, 1.0 );
  29260. }
  29261. `;
  29262. }
  29263. function _getEncodings() {
  29264. return `
  29265. uniform int inputEncoding;
  29266. uniform int outputEncoding;
  29267. #include <encodings_pars_fragment>
  29268. vec4 inputTexelToLinear(vec4 value){
  29269. if(inputEncoding == 0){
  29270. return value;
  29271. }else if(inputEncoding == 1){
  29272. return sRGBToLinear(value);
  29273. }else if(inputEncoding == 2){
  29274. return RGBEToLinear(value);
  29275. }else if(inputEncoding == 3){
  29276. return RGBMToLinear(value, 7.0);
  29277. }else if(inputEncoding == 4){
  29278. return RGBMToLinear(value, 16.0);
  29279. }else if(inputEncoding == 5){
  29280. return RGBDToLinear(value, 256.0);
  29281. }else{
  29282. return GammaToLinear(value, 2.2);
  29283. }
  29284. }
  29285. vec4 linearToOutputTexel(vec4 value){
  29286. if(outputEncoding == 0){
  29287. return value;
  29288. }else if(outputEncoding == 1){
  29289. return LinearTosRGB(value);
  29290. }else if(outputEncoding == 2){
  29291. return LinearToRGBE(value);
  29292. }else if(outputEncoding == 3){
  29293. return LinearToRGBM(value, 7.0);
  29294. }else if(outputEncoding == 4){
  29295. return LinearToRGBM(value, 16.0);
  29296. }else if(outputEncoding == 5){
  29297. return LinearToRGBD(value, 256.0);
  29298. }else{
  29299. return LinearToGamma(value, 2.2);
  29300. }
  29301. }
  29302. vec4 envMapTexelToLinear(vec4 color) {
  29303. return inputTexelToLinear(color);
  29304. }
  29305. `;
  29306. }
  29307. /**
  29308. * @author mrdoob / http://mrdoob.com/
  29309. */
  29310. function Face4( a, b, c, d, normal, color, materialIndex ) {
  29311. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  29312. return new Face3( a, b, c, normal, color, materialIndex );
  29313. }
  29314. var LineStrip = 0;
  29315. var LinePieces = 1;
  29316. var NoColors = 0;
  29317. var FaceColors = 1;
  29318. var VertexColors = 2;
  29319. function MeshFaceMaterial( materials ) {
  29320. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  29321. return materials;
  29322. }
  29323. function MultiMaterial( materials ) {
  29324. if ( materials === undefined ) materials = [];
  29325. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  29326. materials.isMultiMaterial = true;
  29327. materials.materials = materials;
  29328. materials.clone = function () {
  29329. return materials.slice();
  29330. };
  29331. return materials;
  29332. }
  29333. function PointCloud( geometry, material ) {
  29334. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  29335. return new Points( geometry, material );
  29336. }
  29337. function Particle( material ) {
  29338. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  29339. return new Sprite( material );
  29340. }
  29341. function ParticleSystem( geometry, material ) {
  29342. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  29343. return new Points( geometry, material );
  29344. }
  29345. function PointCloudMaterial( parameters ) {
  29346. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  29347. return new PointsMaterial( parameters );
  29348. }
  29349. function ParticleBasicMaterial( parameters ) {
  29350. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  29351. return new PointsMaterial( parameters );
  29352. }
  29353. function ParticleSystemMaterial( parameters ) {
  29354. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  29355. return new PointsMaterial( parameters );
  29356. }
  29357. function Vertex( x, y, z ) {
  29358. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  29359. return new Vector3( x, y, z );
  29360. }
  29361. //
  29362. function DynamicBufferAttribute( array, itemSize ) {
  29363. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.' );
  29364. return new BufferAttribute( array, itemSize ).setUsage( DynamicDrawUsage );
  29365. }
  29366. function Int8Attribute( array, itemSize ) {
  29367. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  29368. return new Int8BufferAttribute( array, itemSize );
  29369. }
  29370. function Uint8Attribute( array, itemSize ) {
  29371. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  29372. return new Uint8BufferAttribute( array, itemSize );
  29373. }
  29374. function Uint8ClampedAttribute( array, itemSize ) {
  29375. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  29376. return new Uint8ClampedBufferAttribute( array, itemSize );
  29377. }
  29378. function Int16Attribute( array, itemSize ) {
  29379. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  29380. return new Int16BufferAttribute( array, itemSize );
  29381. }
  29382. function Uint16Attribute( array, itemSize ) {
  29383. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  29384. return new Uint16BufferAttribute( array, itemSize );
  29385. }
  29386. function Int32Attribute( array, itemSize ) {
  29387. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  29388. return new Int32BufferAttribute( array, itemSize );
  29389. }
  29390. function Uint32Attribute( array, itemSize ) {
  29391. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  29392. return new Uint32BufferAttribute( array, itemSize );
  29393. }
  29394. function Float32Attribute( array, itemSize ) {
  29395. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  29396. return new Float32BufferAttribute( array, itemSize );
  29397. }
  29398. function Float64Attribute( array, itemSize ) {
  29399. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  29400. return new Float64BufferAttribute( array, itemSize );
  29401. }
  29402. //
  29403. Curve.create = function ( construct, getPoint ) {
  29404. console.log( 'THREE.Curve.create() has been deprecated' );
  29405. construct.prototype = Object.create( Curve.prototype );
  29406. construct.prototype.constructor = construct;
  29407. construct.prototype.getPoint = getPoint;
  29408. return construct;
  29409. };
  29410. //
  29411. Object.assign( CurvePath.prototype, {
  29412. createPointsGeometry: function ( divisions ) {
  29413. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29414. // generate geometry from path points (for Line or Points objects)
  29415. var pts = this.getPoints( divisions );
  29416. return this.createGeometry( pts );
  29417. },
  29418. createSpacedPointsGeometry: function ( divisions ) {
  29419. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29420. // generate geometry from equidistant sampling along the path
  29421. var pts = this.getSpacedPoints( divisions );
  29422. return this.createGeometry( pts );
  29423. },
  29424. createGeometry: function ( points ) {
  29425. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29426. var geometry = new Geometry();
  29427. for ( var i = 0, l = points.length; i < l; i ++ ) {
  29428. var point = points[ i ];
  29429. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  29430. }
  29431. return geometry;
  29432. }
  29433. } );
  29434. //
  29435. Object.assign( Path.prototype, {
  29436. fromPoints: function ( points ) {
  29437. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  29438. return this.setFromPoints( points );
  29439. }
  29440. } );
  29441. //
  29442. function ClosedSplineCurve3( points ) {
  29443. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29444. CatmullRomCurve3.call( this, points );
  29445. this.type = 'catmullrom';
  29446. this.closed = true;
  29447. }
  29448. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29449. //
  29450. function SplineCurve3( points ) {
  29451. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29452. CatmullRomCurve3.call( this, points );
  29453. this.type = 'catmullrom';
  29454. }
  29455. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29456. //
  29457. function Spline( points ) {
  29458. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  29459. CatmullRomCurve3.call( this, points );
  29460. this.type = 'catmullrom';
  29461. }
  29462. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  29463. Object.assign( Spline.prototype, {
  29464. initFromArray: function ( /* a */ ) {
  29465. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  29466. },
  29467. getControlPointsArray: function ( /* optionalTarget */ ) {
  29468. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  29469. },
  29470. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  29471. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  29472. }
  29473. } );
  29474. //
  29475. function AxisHelper( size ) {
  29476. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  29477. return new AxesHelper( size );
  29478. }
  29479. function BoundingBoxHelper( object, color ) {
  29480. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  29481. return new BoxHelper( object, color );
  29482. }
  29483. function EdgesHelper( object, hex ) {
  29484. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  29485. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29486. }
  29487. GridHelper.prototype.setColors = function () {
  29488. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  29489. };
  29490. SkeletonHelper.prototype.update = function () {
  29491. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  29492. };
  29493. function WireframeHelper( object, hex ) {
  29494. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  29495. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29496. }
  29497. //
  29498. Object.assign( Loader.prototype, {
  29499. extractUrlBase: function ( url ) {
  29500. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  29501. return LoaderUtils.extractUrlBase( url );
  29502. }
  29503. } );
  29504. Loader.Handlers = {
  29505. add: function ( /* regex, loader */ ) {
  29506. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  29507. },
  29508. get: function ( /* file */ ) {
  29509. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  29510. }
  29511. };
  29512. function XHRLoader( manager ) {
  29513. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  29514. return new FileLoader( manager );
  29515. }
  29516. function BinaryTextureLoader( manager ) {
  29517. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  29518. return new DataTextureLoader( manager );
  29519. }
  29520. Object.assign( ObjectLoader.prototype, {
  29521. setTexturePath: function ( value ) {
  29522. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  29523. return this.setResourcePath( value );
  29524. }
  29525. } );
  29526. //
  29527. Object.assign( Box2.prototype, {
  29528. center: function ( optionalTarget ) {
  29529. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  29530. return this.getCenter( optionalTarget );
  29531. },
  29532. empty: function () {
  29533. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  29534. return this.isEmpty();
  29535. },
  29536. isIntersectionBox: function ( box ) {
  29537. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29538. return this.intersectsBox( box );
  29539. },
  29540. size: function ( optionalTarget ) {
  29541. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  29542. return this.getSize( optionalTarget );
  29543. }
  29544. } );
  29545. Object.assign( Box3.prototype, {
  29546. center: function ( optionalTarget ) {
  29547. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  29548. return this.getCenter( optionalTarget );
  29549. },
  29550. empty: function () {
  29551. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  29552. return this.isEmpty();
  29553. },
  29554. isIntersectionBox: function ( box ) {
  29555. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29556. return this.intersectsBox( box );
  29557. },
  29558. isIntersectionSphere: function ( sphere ) {
  29559. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29560. return this.intersectsSphere( sphere );
  29561. },
  29562. size: function ( optionalTarget ) {
  29563. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  29564. return this.getSize( optionalTarget );
  29565. }
  29566. } );
  29567. Object.assign( Sphere.prototype, {
  29568. empty: function () {
  29569. console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
  29570. return this.isEmpty();
  29571. },
  29572. } );
  29573. Frustum.prototype.setFromMatrix = function ( m ) {
  29574. console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' );
  29575. return this.setFromProjectionMatrix( m );
  29576. };
  29577. Line3.prototype.center = function ( optionalTarget ) {
  29578. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  29579. return this.getCenter( optionalTarget );
  29580. };
  29581. Object.assign( MathUtils, {
  29582. random16: function () {
  29583. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  29584. return Math.random();
  29585. },
  29586. nearestPowerOfTwo: function ( value ) {
  29587. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  29588. return MathUtils.floorPowerOfTwo( value );
  29589. },
  29590. nextPowerOfTwo: function ( value ) {
  29591. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  29592. return MathUtils.ceilPowerOfTwo( value );
  29593. }
  29594. } );
  29595. Object.assign( Matrix3.prototype, {
  29596. flattenToArrayOffset: function ( array, offset ) {
  29597. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29598. return this.toArray( array, offset );
  29599. },
  29600. multiplyVector3: function ( vector ) {
  29601. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  29602. return vector.applyMatrix3( this );
  29603. },
  29604. multiplyVector3Array: function ( /* a */ ) {
  29605. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  29606. },
  29607. applyToBufferAttribute: function ( attribute ) {
  29608. console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' );
  29609. return attribute.applyMatrix3( this );
  29610. },
  29611. applyToVector3Array: function ( /* array, offset, length */ ) {
  29612. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  29613. }
  29614. } );
  29615. Object.assign( Matrix4.prototype, {
  29616. extractPosition: function ( m ) {
  29617. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  29618. return this.copyPosition( m );
  29619. },
  29620. flattenToArrayOffset: function ( array, offset ) {
  29621. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29622. return this.toArray( array, offset );
  29623. },
  29624. getPosition: function () {
  29625. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  29626. return new Vector3().setFromMatrixColumn( this, 3 );
  29627. },
  29628. setRotationFromQuaternion: function ( q ) {
  29629. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  29630. return this.makeRotationFromQuaternion( q );
  29631. },
  29632. multiplyToArray: function () {
  29633. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  29634. },
  29635. multiplyVector3: function ( vector ) {
  29636. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29637. return vector.applyMatrix4( this );
  29638. },
  29639. multiplyVector4: function ( vector ) {
  29640. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29641. return vector.applyMatrix4( this );
  29642. },
  29643. multiplyVector3Array: function ( /* a */ ) {
  29644. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  29645. },
  29646. rotateAxis: function ( v ) {
  29647. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  29648. v.transformDirection( this );
  29649. },
  29650. crossVector: function ( vector ) {
  29651. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29652. return vector.applyMatrix4( this );
  29653. },
  29654. translate: function () {
  29655. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  29656. },
  29657. rotateX: function () {
  29658. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  29659. },
  29660. rotateY: function () {
  29661. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  29662. },
  29663. rotateZ: function () {
  29664. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  29665. },
  29666. rotateByAxis: function () {
  29667. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  29668. },
  29669. applyToBufferAttribute: function ( attribute ) {
  29670. console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' );
  29671. return attribute.applyMatrix4( this );
  29672. },
  29673. applyToVector3Array: function ( /* array, offset, length */ ) {
  29674. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  29675. },
  29676. makeFrustum: function ( left, right, bottom, top, near, far ) {
  29677. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  29678. return this.makePerspective( left, right, top, bottom, near, far );
  29679. }
  29680. } );
  29681. Plane.prototype.isIntersectionLine = function ( line ) {
  29682. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  29683. return this.intersectsLine( line );
  29684. };
  29685. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  29686. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  29687. return vector.applyQuaternion( this );
  29688. };
  29689. Object.assign( Ray.prototype, {
  29690. isIntersectionBox: function ( box ) {
  29691. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29692. return this.intersectsBox( box );
  29693. },
  29694. isIntersectionPlane: function ( plane ) {
  29695. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  29696. return this.intersectsPlane( plane );
  29697. },
  29698. isIntersectionSphere: function ( sphere ) {
  29699. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29700. return this.intersectsSphere( sphere );
  29701. }
  29702. } );
  29703. Object.assign( Triangle.prototype, {
  29704. area: function () {
  29705. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  29706. return this.getArea();
  29707. },
  29708. barycoordFromPoint: function ( point, target ) {
  29709. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29710. return this.getBarycoord( point, target );
  29711. },
  29712. midpoint: function ( target ) {
  29713. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  29714. return this.getMidpoint( target );
  29715. },
  29716. normal: function ( target ) {
  29717. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29718. return this.getNormal( target );
  29719. },
  29720. plane: function ( target ) {
  29721. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  29722. return this.getPlane( target );
  29723. }
  29724. } );
  29725. Object.assign( Triangle, {
  29726. barycoordFromPoint: function ( point, a, b, c, target ) {
  29727. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29728. return Triangle.getBarycoord( point, a, b, c, target );
  29729. },
  29730. normal: function ( a, b, c, target ) {
  29731. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29732. return Triangle.getNormal( a, b, c, target );
  29733. }
  29734. } );
  29735. Object.assign( Shape.prototype, {
  29736. extractAllPoints: function ( divisions ) {
  29737. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  29738. return this.extractPoints( divisions );
  29739. },
  29740. extrude: function ( options ) {
  29741. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  29742. return new ExtrudeGeometry( this, options );
  29743. },
  29744. makeGeometry: function ( options ) {
  29745. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  29746. return new ShapeGeometry( this, options );
  29747. }
  29748. } );
  29749. Object.assign( Vector2.prototype, {
  29750. fromAttribute: function ( attribute, index, offset ) {
  29751. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29752. return this.fromBufferAttribute( attribute, index, offset );
  29753. },
  29754. distanceToManhattan: function ( v ) {
  29755. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29756. return this.manhattanDistanceTo( v );
  29757. },
  29758. lengthManhattan: function () {
  29759. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  29760. return this.manhattanLength();
  29761. }
  29762. } );
  29763. Object.assign( Vector3.prototype, {
  29764. setEulerFromRotationMatrix: function () {
  29765. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  29766. },
  29767. setEulerFromQuaternion: function () {
  29768. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  29769. },
  29770. getPositionFromMatrix: function ( m ) {
  29771. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  29772. return this.setFromMatrixPosition( m );
  29773. },
  29774. getScaleFromMatrix: function ( m ) {
  29775. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  29776. return this.setFromMatrixScale( m );
  29777. },
  29778. getColumnFromMatrix: function ( index, matrix ) {
  29779. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  29780. return this.setFromMatrixColumn( matrix, index );
  29781. },
  29782. applyProjection: function ( m ) {
  29783. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  29784. return this.applyMatrix4( m );
  29785. },
  29786. fromAttribute: function ( attribute, index, offset ) {
  29787. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29788. return this.fromBufferAttribute( attribute, index, offset );
  29789. },
  29790. distanceToManhattan: function ( v ) {
  29791. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29792. return this.manhattanDistanceTo( v );
  29793. },
  29794. lengthManhattan: function () {
  29795. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  29796. return this.manhattanLength();
  29797. }
  29798. } );
  29799. Object.assign( Vector4.prototype, {
  29800. fromAttribute: function ( attribute, index, offset ) {
  29801. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29802. return this.fromBufferAttribute( attribute, index, offset );
  29803. },
  29804. lengthManhattan: function () {
  29805. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  29806. return this.manhattanLength();
  29807. }
  29808. } );
  29809. //
  29810. Object.assign( Geometry.prototype, {
  29811. computeTangents: function () {
  29812. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  29813. },
  29814. computeLineDistances: function () {
  29815. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  29816. },
  29817. applyMatrix: function ( matrix ) {
  29818. console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  29819. return this.applyMatrix4( matrix );
  29820. }
  29821. } );
  29822. Object.assign( Object3D.prototype, {
  29823. getChildByName: function ( name ) {
  29824. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  29825. return this.getObjectByName( name );
  29826. },
  29827. renderDepth: function () {
  29828. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  29829. },
  29830. translate: function ( distance, axis ) {
  29831. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  29832. return this.translateOnAxis( axis, distance );
  29833. },
  29834. getWorldRotation: function () {
  29835. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  29836. },
  29837. applyMatrix: function ( matrix ) {
  29838. console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' );
  29839. return this.applyMatrix4( matrix );
  29840. }
  29841. } );
  29842. Object.defineProperties( Object3D.prototype, {
  29843. eulerOrder: {
  29844. get: function () {
  29845. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29846. return this.rotation.order;
  29847. },
  29848. set: function ( value ) {
  29849. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29850. this.rotation.order = value;
  29851. }
  29852. },
  29853. useQuaternion: {
  29854. get: function () {
  29855. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29856. },
  29857. set: function () {
  29858. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29859. }
  29860. }
  29861. } );
  29862. Object.assign( Mesh.prototype, {
  29863. setDrawMode: function () {
  29864. console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29865. },
  29866. } );
  29867. Object.defineProperties( Mesh.prototype, {
  29868. drawMode: {
  29869. get: function () {
  29870. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' );
  29871. return TrianglesDrawMode;
  29872. },
  29873. set: function () {
  29874. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29875. }
  29876. }
  29877. } );
  29878. Object.defineProperties( LOD.prototype, {
  29879. objects: {
  29880. get: function () {
  29881. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  29882. return this.levels;
  29883. }
  29884. }
  29885. } );
  29886. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  29887. get: function () {
  29888. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29889. },
  29890. set: function () {
  29891. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29892. }
  29893. } );
  29894. SkinnedMesh.prototype.initBones = function () {
  29895. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  29896. };
  29897. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  29898. get: function () {
  29899. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29900. return this.arcLengthDivisions;
  29901. },
  29902. set: function ( value ) {
  29903. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29904. this.arcLengthDivisions = value;
  29905. }
  29906. } );
  29907. //
  29908. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  29909. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  29910. "Use .setFocalLength and .filmGauge for a photographic setup." );
  29911. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  29912. this.setFocalLength( focalLength );
  29913. };
  29914. //
  29915. Object.defineProperties( Light.prototype, {
  29916. onlyShadow: {
  29917. set: function () {
  29918. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  29919. }
  29920. },
  29921. shadowCameraFov: {
  29922. set: function ( value ) {
  29923. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  29924. this.shadow.camera.fov = value;
  29925. }
  29926. },
  29927. shadowCameraLeft: {
  29928. set: function ( value ) {
  29929. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  29930. this.shadow.camera.left = value;
  29931. }
  29932. },
  29933. shadowCameraRight: {
  29934. set: function ( value ) {
  29935. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  29936. this.shadow.camera.right = value;
  29937. }
  29938. },
  29939. shadowCameraTop: {
  29940. set: function ( value ) {
  29941. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  29942. this.shadow.camera.top = value;
  29943. }
  29944. },
  29945. shadowCameraBottom: {
  29946. set: function ( value ) {
  29947. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  29948. this.shadow.camera.bottom = value;
  29949. }
  29950. },
  29951. shadowCameraNear: {
  29952. set: function ( value ) {
  29953. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  29954. this.shadow.camera.near = value;
  29955. }
  29956. },
  29957. shadowCameraFar: {
  29958. set: function ( value ) {
  29959. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  29960. this.shadow.camera.far = value;
  29961. }
  29962. },
  29963. shadowCameraVisible: {
  29964. set: function () {
  29965. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  29966. }
  29967. },
  29968. shadowBias: {
  29969. set: function ( value ) {
  29970. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  29971. this.shadow.bias = value;
  29972. }
  29973. },
  29974. shadowDarkness: {
  29975. set: function () {
  29976. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  29977. }
  29978. },
  29979. shadowMapWidth: {
  29980. set: function ( value ) {
  29981. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  29982. this.shadow.mapSize.width = value;
  29983. }
  29984. },
  29985. shadowMapHeight: {
  29986. set: function ( value ) {
  29987. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  29988. this.shadow.mapSize.height = value;
  29989. }
  29990. }
  29991. } );
  29992. //
  29993. Object.defineProperties( BufferAttribute.prototype, {
  29994. length: {
  29995. get: function () {
  29996. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  29997. return this.array.length;
  29998. }
  29999. },
  30000. dynamic: {
  30001. get: function () {
  30002. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  30003. return this.usage === DynamicDrawUsage;
  30004. },
  30005. set: function ( /* value */ ) {
  30006. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  30007. this.setUsage( DynamicDrawUsage );
  30008. }
  30009. }
  30010. } );
  30011. Object.assign( BufferAttribute.prototype, {
  30012. setDynamic: function ( value ) {
  30013. console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  30014. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  30015. return this;
  30016. },
  30017. copyIndicesArray: function ( /* indices */ ) {
  30018. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  30019. },
  30020. setArray: function ( /* array */ ) {
  30021. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  30022. }
  30023. } );
  30024. Object.assign( BufferGeometry.prototype, {
  30025. addIndex: function ( index ) {
  30026. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  30027. this.setIndex( index );
  30028. },
  30029. addAttribute: function ( name, attribute ) {
  30030. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  30031. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  30032. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  30033. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  30034. }
  30035. if ( name === 'index' ) {
  30036. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  30037. this.setIndex( attribute );
  30038. return this;
  30039. }
  30040. return this.setAttribute( name, attribute );
  30041. },
  30042. addDrawCall: function ( start, count, indexOffset ) {
  30043. if ( indexOffset !== undefined ) {
  30044. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  30045. }
  30046. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  30047. this.addGroup( start, count );
  30048. },
  30049. clearDrawCalls: function () {
  30050. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  30051. this.clearGroups();
  30052. },
  30053. computeTangents: function () {
  30054. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  30055. },
  30056. computeOffsets: function () {
  30057. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  30058. },
  30059. removeAttribute: function ( name ) {
  30060. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  30061. return this.deleteAttribute( name );
  30062. },
  30063. applyMatrix: function ( matrix ) {
  30064. console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  30065. return this.applyMatrix4( matrix );
  30066. }
  30067. } );
  30068. Object.defineProperties( BufferGeometry.prototype, {
  30069. drawcalls: {
  30070. get: function () {
  30071. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  30072. return this.groups;
  30073. }
  30074. },
  30075. offsets: {
  30076. get: function () {
  30077. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  30078. return this.groups;
  30079. }
  30080. }
  30081. } );
  30082. Object.defineProperties( InstancedBufferGeometry.prototype, {
  30083. maxInstancedCount: {
  30084. get: function () {
  30085. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30086. return this.instanceCount;
  30087. },
  30088. set: function ( value ) {
  30089. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30090. this.instanceCount = value;
  30091. }
  30092. }
  30093. } );
  30094. Object.defineProperties( Raycaster.prototype, {
  30095. linePrecision: {
  30096. get: function () {
  30097. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30098. return this.params.Line.threshold;
  30099. },
  30100. set: function ( value ) {
  30101. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30102. this.params.Line.threshold = value;
  30103. }
  30104. }
  30105. } );
  30106. Object.defineProperties( InterleavedBuffer.prototype, {
  30107. dynamic: {
  30108. get: function () {
  30109. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30110. return this.usage === DynamicDrawUsage;
  30111. },
  30112. set: function ( value ) {
  30113. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30114. this.setUsage( value );
  30115. }
  30116. }
  30117. } );
  30118. Object.assign( InterleavedBuffer.prototype, {
  30119. setDynamic: function ( value ) {
  30120. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  30121. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  30122. return this;
  30123. },
  30124. setArray: function ( /* array */ ) {
  30125. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  30126. }
  30127. } );
  30128. //
  30129. Object.assign( ExtrudeBufferGeometry.prototype, {
  30130. getArrays: function () {
  30131. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  30132. },
  30133. addShapeList: function () {
  30134. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  30135. },
  30136. addShape: function () {
  30137. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  30138. }
  30139. } );
  30140. //
  30141. Object.defineProperties( Uniform.prototype, {
  30142. dynamic: {
  30143. set: function () {
  30144. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  30145. }
  30146. },
  30147. onUpdate: {
  30148. value: function () {
  30149. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  30150. return this;
  30151. }
  30152. }
  30153. } );
  30154. //
  30155. Object.defineProperties( Material.prototype, {
  30156. wrapAround: {
  30157. get: function () {
  30158. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30159. },
  30160. set: function () {
  30161. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30162. }
  30163. },
  30164. overdraw: {
  30165. get: function () {
  30166. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30167. },
  30168. set: function () {
  30169. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30170. }
  30171. },
  30172. wrapRGB: {
  30173. get: function () {
  30174. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  30175. return new Color();
  30176. }
  30177. },
  30178. shading: {
  30179. get: function () {
  30180. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30181. },
  30182. set: function ( value ) {
  30183. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30184. this.flatShading = ( value === FlatShading );
  30185. }
  30186. },
  30187. stencilMask: {
  30188. get: function () {
  30189. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30190. return this.stencilFuncMask;
  30191. },
  30192. set: function ( value ) {
  30193. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30194. this.stencilFuncMask = value;
  30195. }
  30196. }
  30197. } );
  30198. Object.defineProperties( MeshPhongMaterial.prototype, {
  30199. metal: {
  30200. get: function () {
  30201. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  30202. return false;
  30203. },
  30204. set: function () {
  30205. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  30206. }
  30207. }
  30208. } );
  30209. Object.defineProperties( ShaderMaterial.prototype, {
  30210. derivatives: {
  30211. get: function () {
  30212. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30213. return this.extensions.derivatives;
  30214. },
  30215. set: function ( value ) {
  30216. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30217. this.extensions.derivatives = value;
  30218. }
  30219. }
  30220. } );
  30221. //
  30222. Object.assign( WebGLRenderer.prototype, {
  30223. clearTarget: function ( renderTarget, color, depth, stencil ) {
  30224. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  30225. this.setRenderTarget( renderTarget );
  30226. this.clear( color, depth, stencil );
  30227. },
  30228. animate: function ( callback ) {
  30229. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  30230. this.setAnimationLoop( callback );
  30231. },
  30232. getCurrentRenderTarget: function () {
  30233. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  30234. return this.getRenderTarget();
  30235. },
  30236. getMaxAnisotropy: function () {
  30237. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  30238. return this.capabilities.getMaxAnisotropy();
  30239. },
  30240. getPrecision: function () {
  30241. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  30242. return this.capabilities.precision;
  30243. },
  30244. resetGLState: function () {
  30245. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  30246. return this.state.reset();
  30247. },
  30248. supportsFloatTextures: function () {
  30249. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  30250. return this.extensions.get( 'OES_texture_float' );
  30251. },
  30252. supportsHalfFloatTextures: function () {
  30253. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  30254. return this.extensions.get( 'OES_texture_half_float' );
  30255. },
  30256. supportsStandardDerivatives: function () {
  30257. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  30258. return this.extensions.get( 'OES_standard_derivatives' );
  30259. },
  30260. supportsCompressedTextureS3TC: function () {
  30261. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  30262. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  30263. },
  30264. supportsCompressedTexturePVRTC: function () {
  30265. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  30266. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  30267. },
  30268. supportsBlendMinMax: function () {
  30269. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  30270. return this.extensions.get( 'EXT_blend_minmax' );
  30271. },
  30272. supportsVertexTextures: function () {
  30273. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  30274. return this.capabilities.vertexTextures;
  30275. },
  30276. supportsInstancedArrays: function () {
  30277. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  30278. return this.extensions.get( 'ANGLE_instanced_arrays' );
  30279. },
  30280. enableScissorTest: function ( boolean ) {
  30281. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  30282. this.setScissorTest( boolean );
  30283. },
  30284. initMaterial: function () {
  30285. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  30286. },
  30287. addPrePlugin: function () {
  30288. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  30289. },
  30290. addPostPlugin: function () {
  30291. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  30292. },
  30293. updateShadowMap: function () {
  30294. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  30295. },
  30296. setFaceCulling: function () {
  30297. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  30298. },
  30299. allocTextureUnit: function () {
  30300. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  30301. },
  30302. setTexture: function () {
  30303. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  30304. },
  30305. setTexture2D: function () {
  30306. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  30307. },
  30308. setTextureCube: function () {
  30309. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  30310. },
  30311. getActiveMipMapLevel: function () {
  30312. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  30313. return this.getActiveMipmapLevel();
  30314. }
  30315. } );
  30316. Object.defineProperties( WebGLRenderer.prototype, {
  30317. shadowMapEnabled: {
  30318. get: function () {
  30319. return this.shadowMap.enabled;
  30320. },
  30321. set: function ( value ) {
  30322. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  30323. this.shadowMap.enabled = value;
  30324. }
  30325. },
  30326. shadowMapType: {
  30327. get: function () {
  30328. return this.shadowMap.type;
  30329. },
  30330. set: function ( value ) {
  30331. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  30332. this.shadowMap.type = value;
  30333. }
  30334. },
  30335. shadowMapCullFace: {
  30336. get: function () {
  30337. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30338. return undefined;
  30339. },
  30340. set: function ( /* value */ ) {
  30341. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30342. }
  30343. },
  30344. context: {
  30345. get: function () {
  30346. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  30347. return this.getContext();
  30348. }
  30349. },
  30350. vr: {
  30351. get: function () {
  30352. console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' );
  30353. return this.xr;
  30354. }
  30355. },
  30356. gammaInput: {
  30357. get: function () {
  30358. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30359. return false;
  30360. },
  30361. set: function () {
  30362. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30363. }
  30364. },
  30365. gammaOutput: {
  30366. get: function () {
  30367. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30368. return false;
  30369. },
  30370. set: function ( value ) {
  30371. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30372. this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding;
  30373. }
  30374. }
  30375. } );
  30376. Object.defineProperties( WebGLShadowMap.prototype, {
  30377. cullFace: {
  30378. get: function () {
  30379. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30380. return undefined;
  30381. },
  30382. set: function ( /* cullFace */ ) {
  30383. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30384. }
  30385. },
  30386. renderReverseSided: {
  30387. get: function () {
  30388. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30389. return undefined;
  30390. },
  30391. set: function () {
  30392. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30393. }
  30394. },
  30395. renderSingleSided: {
  30396. get: function () {
  30397. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30398. return undefined;
  30399. },
  30400. set: function () {
  30401. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30402. }
  30403. }
  30404. } );
  30405. function WebGLRenderTargetCube( width, height, options ) {
  30406. console.warn( 'THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).' );
  30407. return new WebGLCubeRenderTarget( width, options );
  30408. }
  30409. //
  30410. Object.defineProperties( WebGLRenderTarget.prototype, {
  30411. wrapS: {
  30412. get: function () {
  30413. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30414. return this.texture.wrapS;
  30415. },
  30416. set: function ( value ) {
  30417. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30418. this.texture.wrapS = value;
  30419. }
  30420. },
  30421. wrapT: {
  30422. get: function () {
  30423. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30424. return this.texture.wrapT;
  30425. },
  30426. set: function ( value ) {
  30427. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30428. this.texture.wrapT = value;
  30429. }
  30430. },
  30431. magFilter: {
  30432. get: function () {
  30433. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30434. return this.texture.magFilter;
  30435. },
  30436. set: function ( value ) {
  30437. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30438. this.texture.magFilter = value;
  30439. }
  30440. },
  30441. minFilter: {
  30442. get: function () {
  30443. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30444. return this.texture.minFilter;
  30445. },
  30446. set: function ( value ) {
  30447. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30448. this.texture.minFilter = value;
  30449. }
  30450. },
  30451. anisotropy: {
  30452. get: function () {
  30453. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30454. return this.texture.anisotropy;
  30455. },
  30456. set: function ( value ) {
  30457. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30458. this.texture.anisotropy = value;
  30459. }
  30460. },
  30461. offset: {
  30462. get: function () {
  30463. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30464. return this.texture.offset;
  30465. },
  30466. set: function ( value ) {
  30467. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30468. this.texture.offset = value;
  30469. }
  30470. },
  30471. repeat: {
  30472. get: function () {
  30473. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30474. return this.texture.repeat;
  30475. },
  30476. set: function ( value ) {
  30477. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30478. this.texture.repeat = value;
  30479. }
  30480. },
  30481. format: {
  30482. get: function () {
  30483. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30484. return this.texture.format;
  30485. },
  30486. set: function ( value ) {
  30487. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30488. this.texture.format = value;
  30489. }
  30490. },
  30491. type: {
  30492. get: function () {
  30493. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30494. return this.texture.type;
  30495. },
  30496. set: function ( value ) {
  30497. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30498. this.texture.type = value;
  30499. }
  30500. },
  30501. generateMipmaps: {
  30502. get: function () {
  30503. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30504. return this.texture.generateMipmaps;
  30505. },
  30506. set: function ( value ) {
  30507. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30508. this.texture.generateMipmaps = value;
  30509. }
  30510. }
  30511. } );
  30512. //
  30513. Object.defineProperties( Audio.prototype, {
  30514. load: {
  30515. value: function ( file ) {
  30516. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  30517. var scope = this;
  30518. var audioLoader = new AudioLoader();
  30519. audioLoader.load( file, function ( buffer ) {
  30520. scope.setBuffer( buffer );
  30521. } );
  30522. return this;
  30523. }
  30524. },
  30525. startTime: {
  30526. set: function () {
  30527. console.warn( 'THREE.Audio: .startTime is now .play( delay ).' );
  30528. }
  30529. }
  30530. } );
  30531. AudioAnalyser.prototype.getData = function () {
  30532. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  30533. return this.getFrequencyData();
  30534. };
  30535. //
  30536. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  30537. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  30538. return this.update( renderer, scene );
  30539. };
  30540. //
  30541. var GeometryUtils = {
  30542. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  30543. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  30544. var matrix;
  30545. if ( geometry2.isMesh ) {
  30546. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30547. matrix = geometry2.matrix;
  30548. geometry2 = geometry2.geometry;
  30549. }
  30550. geometry1.merge( geometry2, matrix, materialIndexOffset );
  30551. },
  30552. center: function ( geometry ) {
  30553. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  30554. return geometry.center();
  30555. }
  30556. };
  30557. ImageUtils.crossOrigin = undefined;
  30558. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  30559. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  30560. var loader = new TextureLoader();
  30561. loader.setCrossOrigin( this.crossOrigin );
  30562. var texture = loader.load( url, onLoad, undefined, onError );
  30563. if ( mapping ) texture.mapping = mapping;
  30564. return texture;
  30565. };
  30566. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  30567. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  30568. var loader = new CubeTextureLoader();
  30569. loader.setCrossOrigin( this.crossOrigin );
  30570. var texture = loader.load( urls, onLoad, undefined, onError );
  30571. if ( mapping ) texture.mapping = mapping;
  30572. return texture;
  30573. };
  30574. ImageUtils.loadCompressedTexture = function () {
  30575. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  30576. };
  30577. ImageUtils.loadCompressedTextureCube = function () {
  30578. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  30579. };
  30580. //
  30581. function CanvasRenderer() {
  30582. console.error( 'THREE.CanvasRenderer has been removed' );
  30583. }
  30584. //
  30585. function JSONLoader() {
  30586. console.error( 'THREE.JSONLoader has been removed.' );
  30587. }
  30588. //
  30589. var SceneUtils = {
  30590. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  30591. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30592. },
  30593. detach: function ( /* child, parent, scene */ ) {
  30594. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30595. },
  30596. attach: function ( /* child, scene, parent */ ) {
  30597. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30598. }
  30599. };
  30600. //
  30601. function LensFlare() {
  30602. console.error( 'THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js' );
  30603. }
  30604. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  30605. /* eslint-disable no-undef */
  30606. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  30607. revision: REVISION,
  30608. } } ) );
  30609. /* eslint-enable no-undef */
  30610. }
  30611. 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, 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, SphericalReflectionMapping, 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, Uncharted2ToneMapping, Uniform, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, VectorKeyframeTrack, Vertex, VertexColors, VideoTexture, WebGLCubeRenderTarget, WebGLMultisampleRenderTarget, WebGLRenderTarget, WebGLRenderTargetCube, WebGLRenderer, WebGLUtils, WireframeGeometry, WireframeHelper, WrapAroundEnding, XHRLoader, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, sRGBEncoding };