three.module.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760
  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. var output = Object( target );
  36. for ( var index = 1; index < arguments.length; index ++ ) {
  37. var source = arguments[ index ];
  38. if ( source !== undefined && source !== null ) {
  39. for ( var 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. var REVISION = '111';
  50. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  51. var TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  52. var CullFaceNone = 0;
  53. var CullFaceBack = 1;
  54. var CullFaceFront = 2;
  55. var CullFaceFrontBack = 3;
  56. var FrontFaceDirectionCW = 0;
  57. var FrontFaceDirectionCCW = 1;
  58. var BasicShadowMap = 0;
  59. var PCFShadowMap = 1;
  60. var PCFSoftShadowMap = 2;
  61. var VSMShadowMap = 3;
  62. var FrontSide = 0;
  63. var BackSide = 1;
  64. var DoubleSide = 2;
  65. var FlatShading = 1;
  66. var SmoothShading = 2;
  67. var NoColors = 0;
  68. var FaceColors = 1;
  69. var VertexColors = 2;
  70. var NoBlending = 0;
  71. var NormalBlending = 1;
  72. var AdditiveBlending = 2;
  73. var SubtractiveBlending = 3;
  74. var MultiplyBlending = 4;
  75. var CustomBlending = 5;
  76. var AddEquation = 100;
  77. var SubtractEquation = 101;
  78. var ReverseSubtractEquation = 102;
  79. var MinEquation = 103;
  80. var MaxEquation = 104;
  81. var ZeroFactor = 200;
  82. var OneFactor = 201;
  83. var SrcColorFactor = 202;
  84. var OneMinusSrcColorFactor = 203;
  85. var SrcAlphaFactor = 204;
  86. var OneMinusSrcAlphaFactor = 205;
  87. var DstAlphaFactor = 206;
  88. var OneMinusDstAlphaFactor = 207;
  89. var DstColorFactor = 208;
  90. var OneMinusDstColorFactor = 209;
  91. var SrcAlphaSaturateFactor = 210;
  92. var NeverDepth = 0;
  93. var AlwaysDepth = 1;
  94. var LessDepth = 2;
  95. var LessEqualDepth = 3;
  96. var EqualDepth = 4;
  97. var GreaterEqualDepth = 5;
  98. var GreaterDepth = 6;
  99. var NotEqualDepth = 7;
  100. var MultiplyOperation = 0;
  101. var MixOperation = 1;
  102. var AddOperation = 2;
  103. var NoToneMapping = 0;
  104. var LinearToneMapping = 1;
  105. var ReinhardToneMapping = 2;
  106. var Uncharted2ToneMapping = 3;
  107. var CineonToneMapping = 4;
  108. var ACESFilmicToneMapping = 5;
  109. var UVMapping = 300;
  110. var CubeReflectionMapping = 301;
  111. var CubeRefractionMapping = 302;
  112. var EquirectangularReflectionMapping = 303;
  113. var EquirectangularRefractionMapping = 304;
  114. var SphericalReflectionMapping = 305;
  115. var CubeUVReflectionMapping = 306;
  116. var CubeUVRefractionMapping = 307;
  117. var RepeatWrapping = 1000;
  118. var ClampToEdgeWrapping = 1001;
  119. var MirroredRepeatWrapping = 1002;
  120. var NearestFilter = 1003;
  121. var NearestMipmapNearestFilter = 1004;
  122. var NearestMipMapNearestFilter = 1004;
  123. var NearestMipmapLinearFilter = 1005;
  124. var NearestMipMapLinearFilter = 1005;
  125. var LinearFilter = 1006;
  126. var LinearMipmapNearestFilter = 1007;
  127. var LinearMipMapNearestFilter = 1007;
  128. var LinearMipmapLinearFilter = 1008;
  129. var LinearMipMapLinearFilter = 1008;
  130. var UnsignedByteType = 1009;
  131. var ByteType = 1010;
  132. var ShortType = 1011;
  133. var UnsignedShortType = 1012;
  134. var IntType = 1013;
  135. var UnsignedIntType = 1014;
  136. var FloatType = 1015;
  137. var HalfFloatType = 1016;
  138. var UnsignedShort4444Type = 1017;
  139. var UnsignedShort5551Type = 1018;
  140. var UnsignedShort565Type = 1019;
  141. var UnsignedInt248Type = 1020;
  142. var AlphaFormat = 1021;
  143. var RGBFormat = 1022;
  144. var RGBAFormat = 1023;
  145. var LuminanceFormat = 1024;
  146. var LuminanceAlphaFormat = 1025;
  147. var RGBEFormat = RGBAFormat;
  148. var DepthFormat = 1026;
  149. var DepthStencilFormat = 1027;
  150. var RedFormat = 1028;
  151. var RGB_S3TC_DXT1_Format = 33776;
  152. var RGBA_S3TC_DXT1_Format = 33777;
  153. var RGBA_S3TC_DXT3_Format = 33778;
  154. var RGBA_S3TC_DXT5_Format = 33779;
  155. var RGB_PVRTC_4BPPV1_Format = 35840;
  156. var RGB_PVRTC_2BPPV1_Format = 35841;
  157. var RGBA_PVRTC_4BPPV1_Format = 35842;
  158. var RGBA_PVRTC_2BPPV1_Format = 35843;
  159. var RGB_ETC1_Format = 36196;
  160. var RGBA_ASTC_4x4_Format = 37808;
  161. var RGBA_ASTC_5x4_Format = 37809;
  162. var RGBA_ASTC_5x5_Format = 37810;
  163. var RGBA_ASTC_6x5_Format = 37811;
  164. var RGBA_ASTC_6x6_Format = 37812;
  165. var RGBA_ASTC_8x5_Format = 37813;
  166. var RGBA_ASTC_8x6_Format = 37814;
  167. var RGBA_ASTC_8x8_Format = 37815;
  168. var RGBA_ASTC_10x5_Format = 37816;
  169. var RGBA_ASTC_10x6_Format = 37817;
  170. var RGBA_ASTC_10x8_Format = 37818;
  171. var RGBA_ASTC_10x10_Format = 37819;
  172. var RGBA_ASTC_12x10_Format = 37820;
  173. var RGBA_ASTC_12x12_Format = 37821;
  174. var LoopOnce = 2200;
  175. var LoopRepeat = 2201;
  176. var LoopPingPong = 2202;
  177. var InterpolateDiscrete = 2300;
  178. var InterpolateLinear = 2301;
  179. var InterpolateSmooth = 2302;
  180. var ZeroCurvatureEnding = 2400;
  181. var ZeroSlopeEnding = 2401;
  182. var WrapAroundEnding = 2402;
  183. var TrianglesDrawMode = 0;
  184. var TriangleStripDrawMode = 1;
  185. var TriangleFanDrawMode = 2;
  186. var LinearEncoding = 3000;
  187. var sRGBEncoding = 3001;
  188. var GammaEncoding = 3007;
  189. var RGBEEncoding = 3002;
  190. var LogLuvEncoding = 3003;
  191. var RGBM7Encoding = 3004;
  192. var RGBM16Encoding = 3005;
  193. var RGBDEncoding = 3006;
  194. var BasicDepthPacking = 3200;
  195. var RGBADepthPacking = 3201;
  196. var TangentSpaceNormalMap = 0;
  197. var ObjectSpaceNormalMap = 1;
  198. var ZeroStencilOp = 0;
  199. var KeepStencilOp = 7680;
  200. var ReplaceStencilOp = 7681;
  201. var IncrementStencilOp = 7682;
  202. var DecrementStencilOp = 7683;
  203. var IncrementWrapStencilOp = 34055;
  204. var DecrementWrapStencilOp = 34056;
  205. var InvertStencilOp = 5386;
  206. var NeverStencilFunc = 512;
  207. var LessStencilFunc = 513;
  208. var EqualStencilFunc = 514;
  209. var LessEqualStencilFunc = 515;
  210. var GreaterStencilFunc = 516;
  211. var NotEqualStencilFunc = 517;
  212. var GreaterEqualStencilFunc = 518;
  213. var AlwaysStencilFunc = 519;
  214. var StaticDrawUsage = 35044;
  215. var DynamicDrawUsage = 35048;
  216. var StreamDrawUsage = 35040;
  217. var StaticReadUsage = 35045;
  218. var DynamicReadUsage = 35049;
  219. var StreamReadUsage = 35041;
  220. var StaticCopyUsage = 35046;
  221. var DynamicCopyUsage = 35050;
  222. var StreamCopyUsage = 35042;
  223. /**
  224. * https://github.com/mrdoob/eventdispatcher.js/
  225. */
  226. function EventDispatcher() {}
  227. Object.assign( EventDispatcher.prototype, {
  228. addEventListener: function ( type, listener ) {
  229. if ( this._listeners === undefined ) this._listeners = {};
  230. var listeners = this._listeners;
  231. if ( listeners[ type ] === undefined ) {
  232. listeners[ type ] = [];
  233. }
  234. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  235. listeners[ type ].push( listener );
  236. }
  237. },
  238. hasEventListener: function ( type, listener ) {
  239. if ( this._listeners === undefined ) return false;
  240. var listeners = this._listeners;
  241. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  242. },
  243. removeEventListener: function ( type, listener ) {
  244. if ( this._listeners === undefined ) return;
  245. var listeners = this._listeners;
  246. var listenerArray = listeners[ type ];
  247. if ( listenerArray !== undefined ) {
  248. var index = listenerArray.indexOf( listener );
  249. if ( index !== - 1 ) {
  250. listenerArray.splice( index, 1 );
  251. }
  252. }
  253. },
  254. dispatchEvent: function ( event ) {
  255. if ( this._listeners === undefined ) return;
  256. var listeners = this._listeners;
  257. var listenerArray = listeners[ event.type ];
  258. if ( listenerArray !== undefined ) {
  259. event.target = this;
  260. var array = listenerArray.slice( 0 );
  261. for ( var i = 0, l = array.length; i < l; i ++ ) {
  262. array[ i ].call( this, event );
  263. }
  264. }
  265. }
  266. } );
  267. /**
  268. * @author alteredq / http://alteredqualia.com/
  269. * @author mrdoob / http://mrdoob.com/
  270. */
  271. var _lut = [];
  272. for ( var i = 0; i < 256; i ++ ) {
  273. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  274. }
  275. var _Math = {
  276. DEG2RAD: Math.PI / 180,
  277. RAD2DEG: 180 / Math.PI,
  278. generateUUID: function () {
  279. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  280. var d0 = Math.random() * 0xffffffff | 0;
  281. var d1 = Math.random() * 0xffffffff | 0;
  282. var d2 = Math.random() * 0xffffffff | 0;
  283. var d3 = Math.random() * 0xffffffff | 0;
  284. var uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  285. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  286. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  287. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  288. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  289. return uuid.toUpperCase();
  290. },
  291. clamp: function ( value, min, max ) {
  292. return Math.max( min, Math.min( max, value ) );
  293. },
  294. // compute euclidian modulo of m % n
  295. // https://en.wikipedia.org/wiki/Modulo_operation
  296. euclideanModulo: function ( n, m ) {
  297. return ( ( n % m ) + m ) % m;
  298. },
  299. // Linear mapping from range <a1, a2> to range <b1, b2>
  300. mapLinear: function ( x, a1, a2, b1, b2 ) {
  301. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  302. },
  303. // https://en.wikipedia.org/wiki/Linear_interpolation
  304. lerp: function ( x, y, t ) {
  305. return ( 1 - t ) * x + t * y;
  306. },
  307. // http://en.wikipedia.org/wiki/Smoothstep
  308. smoothstep: function ( x, min, max ) {
  309. if ( x <= min ) return 0;
  310. if ( x >= max ) return 1;
  311. x = ( x - min ) / ( max - min );
  312. return x * x * ( 3 - 2 * x );
  313. },
  314. smootherstep: function ( x, min, max ) {
  315. if ( x <= min ) return 0;
  316. if ( x >= max ) return 1;
  317. x = ( x - min ) / ( max - min );
  318. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  319. },
  320. // Random integer from <low, high> interval
  321. randInt: function ( low, high ) {
  322. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  323. },
  324. // Random float from <low, high> interval
  325. randFloat: function ( low, high ) {
  326. return low + Math.random() * ( high - low );
  327. },
  328. // Random float from <-range/2, range/2> interval
  329. randFloatSpread: function ( range ) {
  330. return range * ( 0.5 - Math.random() );
  331. },
  332. degToRad: function ( degrees ) {
  333. return degrees * _Math.DEG2RAD;
  334. },
  335. radToDeg: function ( radians ) {
  336. return radians * _Math.RAD2DEG;
  337. },
  338. isPowerOfTwo: function ( value ) {
  339. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  340. },
  341. ceilPowerOfTwo: function ( value ) {
  342. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  343. },
  344. floorPowerOfTwo: function ( value ) {
  345. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  346. }
  347. };
  348. /**
  349. * @author mrdoob / http://mrdoob.com/
  350. * @author philogb / http://blog.thejit.org/
  351. * @author egraether / http://egraether.com/
  352. * @author zz85 / http://www.lab4games.net/zz85/blog
  353. */
  354. function Vector2( x, y ) {
  355. this.x = x || 0;
  356. this.y = y || 0;
  357. }
  358. Object.defineProperties( Vector2.prototype, {
  359. "width": {
  360. get: function () {
  361. return this.x;
  362. },
  363. set: function ( value ) {
  364. this.x = value;
  365. }
  366. },
  367. "height": {
  368. get: function () {
  369. return this.y;
  370. },
  371. set: function ( value ) {
  372. this.y = value;
  373. }
  374. }
  375. } );
  376. Object.assign( Vector2.prototype, {
  377. isVector2: true,
  378. set: function ( x, y ) {
  379. this.x = x;
  380. this.y = y;
  381. return this;
  382. },
  383. setScalar: function ( scalar ) {
  384. this.x = scalar;
  385. this.y = scalar;
  386. return this;
  387. },
  388. setX: function ( x ) {
  389. this.x = x;
  390. return this;
  391. },
  392. setY: function ( y ) {
  393. this.y = y;
  394. return this;
  395. },
  396. setComponent: function ( index, value ) {
  397. switch ( index ) {
  398. case 0: this.x = value; break;
  399. case 1: this.y = value; break;
  400. default: throw new Error( 'index is out of range: ' + index );
  401. }
  402. return this;
  403. },
  404. getComponent: function ( index ) {
  405. switch ( index ) {
  406. case 0: return this.x;
  407. case 1: return this.y;
  408. default: throw new Error( 'index is out of range: ' + index );
  409. }
  410. },
  411. clone: function () {
  412. return new this.constructor( this.x, this.y );
  413. },
  414. copy: function ( v ) {
  415. this.x = v.x;
  416. this.y = v.y;
  417. return this;
  418. },
  419. add: function ( v, w ) {
  420. if ( w !== undefined ) {
  421. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  422. return this.addVectors( v, w );
  423. }
  424. this.x += v.x;
  425. this.y += v.y;
  426. return this;
  427. },
  428. addScalar: function ( s ) {
  429. this.x += s;
  430. this.y += s;
  431. return this;
  432. },
  433. addVectors: function ( a, b ) {
  434. this.x = a.x + b.x;
  435. this.y = a.y + b.y;
  436. return this;
  437. },
  438. addScaledVector: function ( v, s ) {
  439. this.x += v.x * s;
  440. this.y += v.y * s;
  441. return this;
  442. },
  443. sub: function ( v, w ) {
  444. if ( w !== undefined ) {
  445. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  446. return this.subVectors( v, w );
  447. }
  448. this.x -= v.x;
  449. this.y -= v.y;
  450. return this;
  451. },
  452. subScalar: function ( s ) {
  453. this.x -= s;
  454. this.y -= s;
  455. return this;
  456. },
  457. subVectors: function ( a, b ) {
  458. this.x = a.x - b.x;
  459. this.y = a.y - b.y;
  460. return this;
  461. },
  462. multiply: function ( v ) {
  463. this.x *= v.x;
  464. this.y *= v.y;
  465. return this;
  466. },
  467. multiplyScalar: function ( scalar ) {
  468. this.x *= scalar;
  469. this.y *= scalar;
  470. return this;
  471. },
  472. divide: function ( v ) {
  473. this.x /= v.x;
  474. this.y /= v.y;
  475. return this;
  476. },
  477. divideScalar: function ( scalar ) {
  478. return this.multiplyScalar( 1 / scalar );
  479. },
  480. applyMatrix3: function ( m ) {
  481. var x = this.x, y = this.y;
  482. var e = m.elements;
  483. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  484. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  485. return this;
  486. },
  487. min: function ( v ) {
  488. this.x = Math.min( this.x, v.x );
  489. this.y = Math.min( this.y, v.y );
  490. return this;
  491. },
  492. max: function ( v ) {
  493. this.x = Math.max( this.x, v.x );
  494. this.y = Math.max( this.y, v.y );
  495. return this;
  496. },
  497. clamp: function ( min, max ) {
  498. // assumes min < max, componentwise
  499. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  500. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  501. return this;
  502. },
  503. clampScalar: function ( minVal, maxVal ) {
  504. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  505. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  506. return this;
  507. },
  508. clampLength: function ( min, max ) {
  509. var length = this.length();
  510. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  511. },
  512. floor: function () {
  513. this.x = Math.floor( this.x );
  514. this.y = Math.floor( this.y );
  515. return this;
  516. },
  517. ceil: function () {
  518. this.x = Math.ceil( this.x );
  519. this.y = Math.ceil( this.y );
  520. return this;
  521. },
  522. round: function () {
  523. this.x = Math.round( this.x );
  524. this.y = Math.round( this.y );
  525. return this;
  526. },
  527. roundToZero: function () {
  528. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  529. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  530. return this;
  531. },
  532. negate: function () {
  533. this.x = - this.x;
  534. this.y = - this.y;
  535. return this;
  536. },
  537. dot: function ( v ) {
  538. return this.x * v.x + this.y * v.y;
  539. },
  540. cross: function ( v ) {
  541. return this.x * v.y - this.y * v.x;
  542. },
  543. lengthSq: function () {
  544. return this.x * this.x + this.y * this.y;
  545. },
  546. length: function () {
  547. return Math.sqrt( this.x * this.x + this.y * this.y );
  548. },
  549. manhattanLength: function () {
  550. return Math.abs( this.x ) + Math.abs( this.y );
  551. },
  552. normalize: function () {
  553. return this.divideScalar( this.length() || 1 );
  554. },
  555. angle: function () {
  556. // computes the angle in radians with respect to the positive x-axis
  557. var angle = Math.atan2( this.y, this.x );
  558. if ( angle < 0 ) angle += 2 * Math.PI;
  559. return angle;
  560. },
  561. distanceTo: function ( v ) {
  562. return Math.sqrt( this.distanceToSquared( v ) );
  563. },
  564. distanceToSquared: function ( v ) {
  565. var dx = this.x - v.x, dy = this.y - v.y;
  566. return dx * dx + dy * dy;
  567. },
  568. manhattanDistanceTo: function ( v ) {
  569. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  570. },
  571. setLength: function ( length ) {
  572. return this.normalize().multiplyScalar( length );
  573. },
  574. lerp: function ( v, alpha ) {
  575. this.x += ( v.x - this.x ) * alpha;
  576. this.y += ( v.y - this.y ) * alpha;
  577. return this;
  578. },
  579. lerpVectors: function ( v1, v2, alpha ) {
  580. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  581. },
  582. equals: function ( v ) {
  583. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  584. },
  585. fromArray: function ( array, offset ) {
  586. if ( offset === undefined ) offset = 0;
  587. this.x = array[ offset ];
  588. this.y = array[ offset + 1 ];
  589. return this;
  590. },
  591. toArray: function ( array, offset ) {
  592. if ( array === undefined ) array = [];
  593. if ( offset === undefined ) offset = 0;
  594. array[ offset ] = this.x;
  595. array[ offset + 1 ] = this.y;
  596. return array;
  597. },
  598. fromBufferAttribute: function ( attribute, index, offset ) {
  599. if ( offset !== undefined ) {
  600. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  601. }
  602. this.x = attribute.getX( index );
  603. this.y = attribute.getY( index );
  604. return this;
  605. },
  606. rotateAround: function ( center, angle ) {
  607. var c = Math.cos( angle ), s = Math.sin( angle );
  608. var x = this.x - center.x;
  609. var y = this.y - center.y;
  610. this.x = x * c - y * s + center.x;
  611. this.y = x * s + y * c + center.y;
  612. return this;
  613. }
  614. } );
  615. /**
  616. * @author mikael emtinger / http://gomo.se/
  617. * @author alteredq / http://alteredqualia.com/
  618. * @author WestLangley / http://github.com/WestLangley
  619. * @author bhouston / http://clara.io
  620. */
  621. function Quaternion( x, y, z, w ) {
  622. this._x = x || 0;
  623. this._y = y || 0;
  624. this._z = z || 0;
  625. this._w = ( w !== undefined ) ? w : 1;
  626. }
  627. Object.assign( Quaternion, {
  628. slerp: function ( qa, qb, qm, t ) {
  629. return qm.copy( qa ).slerp( qb, t );
  630. },
  631. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  632. // fuzz-free, array-based Quaternion SLERP operation
  633. var x0 = src0[ srcOffset0 + 0 ],
  634. y0 = src0[ srcOffset0 + 1 ],
  635. z0 = src0[ srcOffset0 + 2 ],
  636. w0 = src0[ srcOffset0 + 3 ],
  637. x1 = src1[ srcOffset1 + 0 ],
  638. y1 = src1[ srcOffset1 + 1 ],
  639. z1 = src1[ srcOffset1 + 2 ],
  640. w1 = src1[ srcOffset1 + 3 ];
  641. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  642. var s = 1 - t,
  643. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  644. dir = ( cos >= 0 ? 1 : - 1 ),
  645. sqrSin = 1 - cos * cos;
  646. // Skip the Slerp for tiny steps to avoid numeric problems:
  647. if ( sqrSin > Number.EPSILON ) {
  648. var sin = Math.sqrt( sqrSin ),
  649. len = Math.atan2( sin, cos * dir );
  650. s = Math.sin( s * len ) / sin;
  651. t = Math.sin( t * len ) / sin;
  652. }
  653. var tDir = t * dir;
  654. x0 = x0 * s + x1 * tDir;
  655. y0 = y0 * s + y1 * tDir;
  656. z0 = z0 * s + z1 * tDir;
  657. w0 = w0 * s + w1 * tDir;
  658. // Normalize in case we just did a lerp:
  659. if ( s === 1 - t ) {
  660. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  661. x0 *= f;
  662. y0 *= f;
  663. z0 *= f;
  664. w0 *= f;
  665. }
  666. }
  667. dst[ dstOffset ] = x0;
  668. dst[ dstOffset + 1 ] = y0;
  669. dst[ dstOffset + 2 ] = z0;
  670. dst[ dstOffset + 3 ] = w0;
  671. }
  672. } );
  673. Object.defineProperties( Quaternion.prototype, {
  674. x: {
  675. get: function () {
  676. return this._x;
  677. },
  678. set: function ( value ) {
  679. this._x = value;
  680. this._onChangeCallback();
  681. }
  682. },
  683. y: {
  684. get: function () {
  685. return this._y;
  686. },
  687. set: function ( value ) {
  688. this._y = value;
  689. this._onChangeCallback();
  690. }
  691. },
  692. z: {
  693. get: function () {
  694. return this._z;
  695. },
  696. set: function ( value ) {
  697. this._z = value;
  698. this._onChangeCallback();
  699. }
  700. },
  701. w: {
  702. get: function () {
  703. return this._w;
  704. },
  705. set: function ( value ) {
  706. this._w = value;
  707. this._onChangeCallback();
  708. }
  709. }
  710. } );
  711. Object.assign( Quaternion.prototype, {
  712. isQuaternion: true,
  713. set: function ( x, y, z, w ) {
  714. this._x = x;
  715. this._y = y;
  716. this._z = z;
  717. this._w = w;
  718. this._onChangeCallback();
  719. return this;
  720. },
  721. clone: function () {
  722. return new this.constructor( this._x, this._y, this._z, this._w );
  723. },
  724. copy: function ( quaternion ) {
  725. this._x = quaternion.x;
  726. this._y = quaternion.y;
  727. this._z = quaternion.z;
  728. this._w = quaternion.w;
  729. this._onChangeCallback();
  730. return this;
  731. },
  732. setFromEuler: function ( euler, update ) {
  733. if ( ! ( euler && euler.isEuler ) ) {
  734. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  735. }
  736. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  737. // http://www.mathworks.com/matlabcentral/fileexchange/
  738. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  739. // content/SpinCalc.m
  740. var cos = Math.cos;
  741. var sin = Math.sin;
  742. var c1 = cos( x / 2 );
  743. var c2 = cos( y / 2 );
  744. var c3 = cos( z / 2 );
  745. var s1 = sin( x / 2 );
  746. var s2 = sin( y / 2 );
  747. var s3 = sin( z / 2 );
  748. if ( order === 'XYZ' ) {
  749. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  750. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  751. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  752. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  753. } else if ( order === 'YXZ' ) {
  754. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  755. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  756. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  757. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  758. } else if ( order === 'ZXY' ) {
  759. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  760. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  761. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  762. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  763. } else if ( order === 'ZYX' ) {
  764. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  765. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  766. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  767. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  768. } else if ( order === 'YZX' ) {
  769. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  770. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  771. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  772. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  773. } else if ( order === 'XZY' ) {
  774. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  775. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  776. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  777. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  778. }
  779. if ( update !== false ) this._onChangeCallback();
  780. return this;
  781. },
  782. setFromAxisAngle: function ( axis, angle ) {
  783. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  784. // assumes axis is normalized
  785. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  786. this._x = axis.x * s;
  787. this._y = axis.y * s;
  788. this._z = axis.z * s;
  789. this._w = Math.cos( halfAngle );
  790. this._onChangeCallback();
  791. return this;
  792. },
  793. setFromRotationMatrix: function ( m ) {
  794. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  795. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  796. var te = m.elements,
  797. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  798. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  799. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  800. trace = m11 + m22 + m33,
  801. s;
  802. if ( trace > 0 ) {
  803. s = 0.5 / Math.sqrt( trace + 1.0 );
  804. this._w = 0.25 / s;
  805. this._x = ( m32 - m23 ) * s;
  806. this._y = ( m13 - m31 ) * s;
  807. this._z = ( m21 - m12 ) * s;
  808. } else if ( m11 > m22 && m11 > m33 ) {
  809. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  810. this._w = ( m32 - m23 ) / s;
  811. this._x = 0.25 * s;
  812. this._y = ( m12 + m21 ) / s;
  813. this._z = ( m13 + m31 ) / s;
  814. } else if ( m22 > m33 ) {
  815. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  816. this._w = ( m13 - m31 ) / s;
  817. this._x = ( m12 + m21 ) / s;
  818. this._y = 0.25 * s;
  819. this._z = ( m23 + m32 ) / s;
  820. } else {
  821. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  822. this._w = ( m21 - m12 ) / s;
  823. this._x = ( m13 + m31 ) / s;
  824. this._y = ( m23 + m32 ) / s;
  825. this._z = 0.25 * s;
  826. }
  827. this._onChangeCallback();
  828. return this;
  829. },
  830. setFromUnitVectors: function ( vFrom, vTo ) {
  831. // assumes direction vectors vFrom and vTo are normalized
  832. var EPS = 0.000001;
  833. var r = vFrom.dot( vTo ) + 1;
  834. if ( r < EPS ) {
  835. r = 0;
  836. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  837. this._x = - vFrom.y;
  838. this._y = vFrom.x;
  839. this._z = 0;
  840. this._w = r;
  841. } else {
  842. this._x = 0;
  843. this._y = - vFrom.z;
  844. this._z = vFrom.y;
  845. this._w = r;
  846. }
  847. } else {
  848. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  849. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  850. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  851. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  852. this._w = r;
  853. }
  854. return this.normalize();
  855. },
  856. angleTo: function ( q ) {
  857. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  858. },
  859. rotateTowards: function ( q, step ) {
  860. var angle = this.angleTo( q );
  861. if ( angle === 0 ) return this;
  862. var t = Math.min( 1, step / angle );
  863. this.slerp( q, t );
  864. return this;
  865. },
  866. inverse: function () {
  867. // quaternion is assumed to have unit length
  868. return this.conjugate();
  869. },
  870. conjugate: function () {
  871. this._x *= - 1;
  872. this._y *= - 1;
  873. this._z *= - 1;
  874. this._onChangeCallback();
  875. return this;
  876. },
  877. dot: function ( v ) {
  878. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  879. },
  880. lengthSq: function () {
  881. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  882. },
  883. length: function () {
  884. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  885. },
  886. normalize: function () {
  887. var l = this.length();
  888. if ( l === 0 ) {
  889. this._x = 0;
  890. this._y = 0;
  891. this._z = 0;
  892. this._w = 1;
  893. } else {
  894. l = 1 / l;
  895. this._x = this._x * l;
  896. this._y = this._y * l;
  897. this._z = this._z * l;
  898. this._w = this._w * l;
  899. }
  900. this._onChangeCallback();
  901. return this;
  902. },
  903. multiply: function ( q, p ) {
  904. if ( p !== undefined ) {
  905. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  906. return this.multiplyQuaternions( q, p );
  907. }
  908. return this.multiplyQuaternions( this, q );
  909. },
  910. premultiply: function ( q ) {
  911. return this.multiplyQuaternions( q, this );
  912. },
  913. multiplyQuaternions: function ( a, b ) {
  914. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  915. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  916. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  917. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  918. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  919. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  920. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  921. this._onChangeCallback();
  922. return this;
  923. },
  924. slerp: function ( qb, t ) {
  925. if ( t === 0 ) return this;
  926. if ( t === 1 ) return this.copy( qb );
  927. var x = this._x, y = this._y, z = this._z, w = this._w;
  928. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  929. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  930. if ( cosHalfTheta < 0 ) {
  931. this._w = - qb._w;
  932. this._x = - qb._x;
  933. this._y = - qb._y;
  934. this._z = - qb._z;
  935. cosHalfTheta = - cosHalfTheta;
  936. } else {
  937. this.copy( qb );
  938. }
  939. if ( cosHalfTheta >= 1.0 ) {
  940. this._w = w;
  941. this._x = x;
  942. this._y = y;
  943. this._z = z;
  944. return this;
  945. }
  946. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  947. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  948. var s = 1 - t;
  949. this._w = s * w + t * this._w;
  950. this._x = s * x + t * this._x;
  951. this._y = s * y + t * this._y;
  952. this._z = s * z + t * this._z;
  953. this.normalize();
  954. this._onChangeCallback();
  955. return this;
  956. }
  957. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  958. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  959. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  960. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  961. this._w = ( w * ratioA + this._w * ratioB );
  962. this._x = ( x * ratioA + this._x * ratioB );
  963. this._y = ( y * ratioA + this._y * ratioB );
  964. this._z = ( z * ratioA + this._z * ratioB );
  965. this._onChangeCallback();
  966. return this;
  967. },
  968. equals: function ( quaternion ) {
  969. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  970. },
  971. fromArray: function ( array, offset ) {
  972. if ( offset === undefined ) offset = 0;
  973. this._x = array[ offset ];
  974. this._y = array[ offset + 1 ];
  975. this._z = array[ offset + 2 ];
  976. this._w = array[ offset + 3 ];
  977. this._onChangeCallback();
  978. return this;
  979. },
  980. toArray: function ( array, offset ) {
  981. if ( array === undefined ) array = [];
  982. if ( offset === undefined ) offset = 0;
  983. array[ offset ] = this._x;
  984. array[ offset + 1 ] = this._y;
  985. array[ offset + 2 ] = this._z;
  986. array[ offset + 3 ] = this._w;
  987. return array;
  988. },
  989. _onChange: function ( callback ) {
  990. this._onChangeCallback = callback;
  991. return this;
  992. },
  993. _onChangeCallback: function () {}
  994. } );
  995. /**
  996. * @author mrdoob / http://mrdoob.com/
  997. * @author kile / http://kile.stravaganza.org/
  998. * @author philogb / http://blog.thejit.org/
  999. * @author mikael emtinger / http://gomo.se/
  1000. * @author egraether / http://egraether.com/
  1001. * @author WestLangley / http://github.com/WestLangley
  1002. */
  1003. var _vector = new Vector3();
  1004. var _quaternion = new Quaternion();
  1005. function Vector3( x, y, z ) {
  1006. this.x = x || 0;
  1007. this.y = y || 0;
  1008. this.z = z || 0;
  1009. }
  1010. Object.assign( Vector3.prototype, {
  1011. isVector3: true,
  1012. set: function ( x, y, z ) {
  1013. this.x = x;
  1014. this.y = y;
  1015. this.z = z;
  1016. return this;
  1017. },
  1018. setScalar: function ( scalar ) {
  1019. this.x = scalar;
  1020. this.y = scalar;
  1021. this.z = scalar;
  1022. return this;
  1023. },
  1024. setX: function ( x ) {
  1025. this.x = x;
  1026. return this;
  1027. },
  1028. setY: function ( y ) {
  1029. this.y = y;
  1030. return this;
  1031. },
  1032. setZ: function ( z ) {
  1033. this.z = z;
  1034. return this;
  1035. },
  1036. setComponent: function ( index, value ) {
  1037. switch ( index ) {
  1038. case 0: this.x = value; break;
  1039. case 1: this.y = value; break;
  1040. case 2: this.z = value; break;
  1041. default: throw new Error( 'index is out of range: ' + index );
  1042. }
  1043. return this;
  1044. },
  1045. getComponent: function ( index ) {
  1046. switch ( index ) {
  1047. case 0: return this.x;
  1048. case 1: return this.y;
  1049. case 2: return this.z;
  1050. default: throw new Error( 'index is out of range: ' + index );
  1051. }
  1052. },
  1053. clone: function () {
  1054. return new this.constructor( this.x, this.y, this.z );
  1055. },
  1056. copy: function ( v ) {
  1057. this.x = v.x;
  1058. this.y = v.y;
  1059. this.z = v.z;
  1060. return this;
  1061. },
  1062. add: function ( v, w ) {
  1063. if ( w !== undefined ) {
  1064. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1065. return this.addVectors( v, w );
  1066. }
  1067. this.x += v.x;
  1068. this.y += v.y;
  1069. this.z += v.z;
  1070. return this;
  1071. },
  1072. addScalar: function ( s ) {
  1073. this.x += s;
  1074. this.y += s;
  1075. this.z += s;
  1076. return this;
  1077. },
  1078. addVectors: function ( a, b ) {
  1079. this.x = a.x + b.x;
  1080. this.y = a.y + b.y;
  1081. this.z = a.z + b.z;
  1082. return this;
  1083. },
  1084. addScaledVector: function ( v, s ) {
  1085. this.x += v.x * s;
  1086. this.y += v.y * s;
  1087. this.z += v.z * s;
  1088. return this;
  1089. },
  1090. sub: function ( v, w ) {
  1091. if ( w !== undefined ) {
  1092. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1093. return this.subVectors( v, w );
  1094. }
  1095. this.x -= v.x;
  1096. this.y -= v.y;
  1097. this.z -= v.z;
  1098. return this;
  1099. },
  1100. subScalar: function ( s ) {
  1101. this.x -= s;
  1102. this.y -= s;
  1103. this.z -= s;
  1104. return this;
  1105. },
  1106. subVectors: function ( a, b ) {
  1107. this.x = a.x - b.x;
  1108. this.y = a.y - b.y;
  1109. this.z = a.z - b.z;
  1110. return this;
  1111. },
  1112. multiply: function ( v, w ) {
  1113. if ( w !== undefined ) {
  1114. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1115. return this.multiplyVectors( v, w );
  1116. }
  1117. this.x *= v.x;
  1118. this.y *= v.y;
  1119. this.z *= v.z;
  1120. return this;
  1121. },
  1122. multiplyScalar: function ( scalar ) {
  1123. this.x *= scalar;
  1124. this.y *= scalar;
  1125. this.z *= scalar;
  1126. return this;
  1127. },
  1128. multiplyVectors: function ( a, b ) {
  1129. this.x = a.x * b.x;
  1130. this.y = a.y * b.y;
  1131. this.z = a.z * b.z;
  1132. return this;
  1133. },
  1134. applyEuler: function ( euler ) {
  1135. if ( ! ( euler && euler.isEuler ) ) {
  1136. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1137. }
  1138. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  1139. },
  1140. applyAxisAngle: function ( axis, angle ) {
  1141. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  1142. },
  1143. applyMatrix3: function ( m ) {
  1144. var x = this.x, y = this.y, z = this.z;
  1145. var e = m.elements;
  1146. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1147. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1148. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1149. return this;
  1150. },
  1151. applyNormalMatrix: function ( m ) {
  1152. return this.applyMatrix3( m ).normalize();
  1153. },
  1154. applyMatrix4: function ( m ) {
  1155. var x = this.x, y = this.y, z = this.z;
  1156. var e = m.elements;
  1157. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1158. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1159. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1160. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1161. return this;
  1162. },
  1163. applyQuaternion: function ( q ) {
  1164. var x = this.x, y = this.y, z = this.z;
  1165. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1166. // calculate quat * vector
  1167. var ix = qw * x + qy * z - qz * y;
  1168. var iy = qw * y + qz * x - qx * z;
  1169. var iz = qw * z + qx * y - qy * x;
  1170. var iw = - qx * x - qy * y - qz * z;
  1171. // calculate result * inverse quat
  1172. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1173. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1174. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1175. return this;
  1176. },
  1177. project: function ( camera ) {
  1178. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1179. },
  1180. unproject: function ( camera ) {
  1181. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1182. },
  1183. transformDirection: function ( m ) {
  1184. // input: THREE.Matrix4 affine matrix
  1185. // vector interpreted as a direction
  1186. var x = this.x, y = this.y, z = this.z;
  1187. var e = m.elements;
  1188. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1189. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1190. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1191. return this.normalize();
  1192. },
  1193. divide: function ( v ) {
  1194. this.x /= v.x;
  1195. this.y /= v.y;
  1196. this.z /= v.z;
  1197. return this;
  1198. },
  1199. divideScalar: function ( scalar ) {
  1200. return this.multiplyScalar( 1 / scalar );
  1201. },
  1202. min: function ( v ) {
  1203. this.x = Math.min( this.x, v.x );
  1204. this.y = Math.min( this.y, v.y );
  1205. this.z = Math.min( this.z, v.z );
  1206. return this;
  1207. },
  1208. max: function ( v ) {
  1209. this.x = Math.max( this.x, v.x );
  1210. this.y = Math.max( this.y, v.y );
  1211. this.z = Math.max( this.z, v.z );
  1212. return this;
  1213. },
  1214. clamp: function ( min, max ) {
  1215. // assumes min < max, componentwise
  1216. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1217. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1218. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1219. return this;
  1220. },
  1221. clampScalar: function ( minVal, maxVal ) {
  1222. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1223. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1224. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1225. return this;
  1226. },
  1227. clampLength: function ( min, max ) {
  1228. var length = this.length();
  1229. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1230. },
  1231. floor: function () {
  1232. this.x = Math.floor( this.x );
  1233. this.y = Math.floor( this.y );
  1234. this.z = Math.floor( this.z );
  1235. return this;
  1236. },
  1237. ceil: function () {
  1238. this.x = Math.ceil( this.x );
  1239. this.y = Math.ceil( this.y );
  1240. this.z = Math.ceil( this.z );
  1241. return this;
  1242. },
  1243. round: function () {
  1244. this.x = Math.round( this.x );
  1245. this.y = Math.round( this.y );
  1246. this.z = Math.round( this.z );
  1247. return this;
  1248. },
  1249. roundToZero: function () {
  1250. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1251. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1252. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1253. return this;
  1254. },
  1255. negate: function () {
  1256. this.x = - this.x;
  1257. this.y = - this.y;
  1258. this.z = - this.z;
  1259. return this;
  1260. },
  1261. dot: function ( v ) {
  1262. return this.x * v.x + this.y * v.y + this.z * v.z;
  1263. },
  1264. // TODO lengthSquared?
  1265. lengthSq: function () {
  1266. return this.x * this.x + this.y * this.y + this.z * this.z;
  1267. },
  1268. length: function () {
  1269. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1270. },
  1271. manhattanLength: function () {
  1272. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1273. },
  1274. normalize: function () {
  1275. return this.divideScalar( this.length() || 1 );
  1276. },
  1277. setLength: function ( length ) {
  1278. return this.normalize().multiplyScalar( length );
  1279. },
  1280. lerp: function ( v, alpha ) {
  1281. this.x += ( v.x - this.x ) * alpha;
  1282. this.y += ( v.y - this.y ) * alpha;
  1283. this.z += ( v.z - this.z ) * alpha;
  1284. return this;
  1285. },
  1286. lerpVectors: function ( v1, v2, alpha ) {
  1287. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1288. },
  1289. cross: function ( v, w ) {
  1290. if ( w !== undefined ) {
  1291. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1292. return this.crossVectors( v, w );
  1293. }
  1294. return this.crossVectors( this, v );
  1295. },
  1296. crossVectors: function ( a, b ) {
  1297. var ax = a.x, ay = a.y, az = a.z;
  1298. var bx = b.x, by = b.y, bz = b.z;
  1299. this.x = ay * bz - az * by;
  1300. this.y = az * bx - ax * bz;
  1301. this.z = ax * by - ay * bx;
  1302. return this;
  1303. },
  1304. projectOnVector: function ( v ) {
  1305. // v cannot be the zero v
  1306. var scalar = v.dot( this ) / v.lengthSq();
  1307. return this.copy( v ).multiplyScalar( scalar );
  1308. },
  1309. projectOnPlane: function ( planeNormal ) {
  1310. _vector.copy( this ).projectOnVector( planeNormal );
  1311. return this.sub( _vector );
  1312. },
  1313. reflect: function ( normal ) {
  1314. // reflect incident vector off plane orthogonal to normal
  1315. // normal is assumed to have unit length
  1316. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1317. },
  1318. angleTo: function ( v ) {
  1319. var denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  1320. if ( denominator === 0 ) console.error( 'THREE.Vector3: angleTo() can\'t handle zero length vectors.' );
  1321. var theta = this.dot( v ) / denominator;
  1322. // clamp, to handle numerical problems
  1323. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1324. },
  1325. distanceTo: function ( v ) {
  1326. return Math.sqrt( this.distanceToSquared( v ) );
  1327. },
  1328. distanceToSquared: function ( v ) {
  1329. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1330. return dx * dx + dy * dy + dz * dz;
  1331. },
  1332. manhattanDistanceTo: function ( v ) {
  1333. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1334. },
  1335. setFromSpherical: function ( s ) {
  1336. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1337. },
  1338. setFromSphericalCoords: function ( radius, phi, theta ) {
  1339. var sinPhiRadius = Math.sin( phi ) * radius;
  1340. this.x = sinPhiRadius * Math.sin( theta );
  1341. this.y = Math.cos( phi ) * radius;
  1342. this.z = sinPhiRadius * Math.cos( theta );
  1343. return this;
  1344. },
  1345. setFromCylindrical: function ( c ) {
  1346. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1347. },
  1348. setFromCylindricalCoords: function ( radius, theta, y ) {
  1349. this.x = radius * Math.sin( theta );
  1350. this.y = y;
  1351. this.z = radius * Math.cos( theta );
  1352. return this;
  1353. },
  1354. setFromMatrixPosition: function ( m ) {
  1355. var e = m.elements;
  1356. this.x = e[ 12 ];
  1357. this.y = e[ 13 ];
  1358. this.z = e[ 14 ];
  1359. return this;
  1360. },
  1361. setFromMatrixScale: function ( m ) {
  1362. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1363. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1364. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1365. this.x = sx;
  1366. this.y = sy;
  1367. this.z = sz;
  1368. return this;
  1369. },
  1370. setFromMatrixColumn: function ( m, index ) {
  1371. return this.fromArray( m.elements, index * 4 );
  1372. },
  1373. equals: function ( v ) {
  1374. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1375. },
  1376. fromArray: function ( array, offset ) {
  1377. if ( offset === undefined ) offset = 0;
  1378. this.x = array[ offset ];
  1379. this.y = array[ offset + 1 ];
  1380. this.z = array[ offset + 2 ];
  1381. return this;
  1382. },
  1383. toArray: function ( array, offset ) {
  1384. if ( array === undefined ) array = [];
  1385. if ( offset === undefined ) offset = 0;
  1386. array[ offset ] = this.x;
  1387. array[ offset + 1 ] = this.y;
  1388. array[ offset + 2 ] = this.z;
  1389. return array;
  1390. },
  1391. fromBufferAttribute: function ( attribute, index, offset ) {
  1392. if ( offset !== undefined ) {
  1393. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1394. }
  1395. this.x = attribute.getX( index );
  1396. this.y = attribute.getY( index );
  1397. this.z = attribute.getZ( index );
  1398. return this;
  1399. }
  1400. } );
  1401. /**
  1402. * @author alteredq / http://alteredqualia.com/
  1403. * @author WestLangley / http://github.com/WestLangley
  1404. * @author bhouston / http://clara.io
  1405. * @author tschw
  1406. */
  1407. var _vector$1 = new Vector3();
  1408. function Matrix3() {
  1409. this.elements = [
  1410. 1, 0, 0,
  1411. 0, 1, 0,
  1412. 0, 0, 1
  1413. ];
  1414. if ( arguments.length > 0 ) {
  1415. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1416. }
  1417. }
  1418. Object.assign( Matrix3.prototype, {
  1419. isMatrix3: true,
  1420. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1421. var te = this.elements;
  1422. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1423. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1424. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1425. return this;
  1426. },
  1427. identity: function () {
  1428. this.set(
  1429. 1, 0, 0,
  1430. 0, 1, 0,
  1431. 0, 0, 1
  1432. );
  1433. return this;
  1434. },
  1435. clone: function () {
  1436. return new this.constructor().fromArray( this.elements );
  1437. },
  1438. copy: function ( m ) {
  1439. var te = this.elements;
  1440. var me = m.elements;
  1441. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1442. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1443. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1444. return this;
  1445. },
  1446. setFromMatrix4: function ( m ) {
  1447. var me = m.elements;
  1448. this.set(
  1449. me[ 0 ], me[ 4 ], me[ 8 ],
  1450. me[ 1 ], me[ 5 ], me[ 9 ],
  1451. me[ 2 ], me[ 6 ], me[ 10 ]
  1452. );
  1453. return this;
  1454. },
  1455. applyToBufferAttribute: function ( attribute ) {
  1456. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1457. _vector$1.x = attribute.getX( i );
  1458. _vector$1.y = attribute.getY( i );
  1459. _vector$1.z = attribute.getZ( i );
  1460. _vector$1.applyMatrix3( this );
  1461. attribute.setXYZ( i, _vector$1.x, _vector$1.y, _vector$1.z );
  1462. }
  1463. return attribute;
  1464. },
  1465. multiply: function ( m ) {
  1466. return this.multiplyMatrices( this, m );
  1467. },
  1468. premultiply: function ( m ) {
  1469. return this.multiplyMatrices( m, this );
  1470. },
  1471. multiplyMatrices: function ( a, b ) {
  1472. var ae = a.elements;
  1473. var be = b.elements;
  1474. var te = this.elements;
  1475. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1476. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1477. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1478. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1479. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1480. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1481. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1482. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1483. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1484. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1485. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1486. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1487. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1488. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1489. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1490. return this;
  1491. },
  1492. multiplyScalar: function ( s ) {
  1493. var te = this.elements;
  1494. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1495. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1496. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1497. return this;
  1498. },
  1499. determinant: function () {
  1500. var te = this.elements;
  1501. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1502. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1503. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1504. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1505. },
  1506. getInverse: function ( matrix, throwOnDegenerate ) {
  1507. if ( matrix && matrix.isMatrix4 ) {
  1508. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1509. }
  1510. var me = matrix.elements,
  1511. te = this.elements,
  1512. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1513. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1514. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1515. t11 = n33 * n22 - n32 * n23,
  1516. t12 = n32 * n13 - n33 * n12,
  1517. t13 = n23 * n12 - n22 * n13,
  1518. det = n11 * t11 + n21 * t12 + n31 * t13;
  1519. if ( det === 0 ) {
  1520. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1521. if ( throwOnDegenerate === true ) {
  1522. throw new Error( msg );
  1523. } else {
  1524. console.warn( msg );
  1525. }
  1526. return this.identity();
  1527. }
  1528. var detInv = 1 / det;
  1529. te[ 0 ] = t11 * detInv;
  1530. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1531. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1532. te[ 3 ] = t12 * detInv;
  1533. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1534. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1535. te[ 6 ] = t13 * detInv;
  1536. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1537. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1538. return this;
  1539. },
  1540. transpose: function () {
  1541. var tmp, m = this.elements;
  1542. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1543. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1544. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1545. return this;
  1546. },
  1547. getNormalMatrix: function ( matrix4 ) {
  1548. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1549. },
  1550. transposeIntoArray: function ( r ) {
  1551. var m = this.elements;
  1552. r[ 0 ] = m[ 0 ];
  1553. r[ 1 ] = m[ 3 ];
  1554. r[ 2 ] = m[ 6 ];
  1555. r[ 3 ] = m[ 1 ];
  1556. r[ 4 ] = m[ 4 ];
  1557. r[ 5 ] = m[ 7 ];
  1558. r[ 6 ] = m[ 2 ];
  1559. r[ 7 ] = m[ 5 ];
  1560. r[ 8 ] = m[ 8 ];
  1561. return this;
  1562. },
  1563. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1564. var c = Math.cos( rotation );
  1565. var s = Math.sin( rotation );
  1566. this.set(
  1567. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1568. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1569. 0, 0, 1
  1570. );
  1571. },
  1572. scale: function ( sx, sy ) {
  1573. var te = this.elements;
  1574. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1575. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1576. return this;
  1577. },
  1578. rotate: function ( theta ) {
  1579. var c = Math.cos( theta );
  1580. var s = Math.sin( theta );
  1581. var te = this.elements;
  1582. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1583. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1584. te[ 0 ] = c * a11 + s * a21;
  1585. te[ 3 ] = c * a12 + s * a22;
  1586. te[ 6 ] = c * a13 + s * a23;
  1587. te[ 1 ] = - s * a11 + c * a21;
  1588. te[ 4 ] = - s * a12 + c * a22;
  1589. te[ 7 ] = - s * a13 + c * a23;
  1590. return this;
  1591. },
  1592. translate: function ( tx, ty ) {
  1593. var te = this.elements;
  1594. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1595. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1596. return this;
  1597. },
  1598. equals: function ( matrix ) {
  1599. var te = this.elements;
  1600. var me = matrix.elements;
  1601. for ( var i = 0; i < 9; i ++ ) {
  1602. if ( te[ i ] !== me[ i ] ) return false;
  1603. }
  1604. return true;
  1605. },
  1606. fromArray: function ( array, offset ) {
  1607. if ( offset === undefined ) offset = 0;
  1608. for ( var i = 0; i < 9; i ++ ) {
  1609. this.elements[ i ] = array[ i + offset ];
  1610. }
  1611. return this;
  1612. },
  1613. toArray: function ( array, offset ) {
  1614. if ( array === undefined ) array = [];
  1615. if ( offset === undefined ) offset = 0;
  1616. var te = this.elements;
  1617. array[ offset ] = te[ 0 ];
  1618. array[ offset + 1 ] = te[ 1 ];
  1619. array[ offset + 2 ] = te[ 2 ];
  1620. array[ offset + 3 ] = te[ 3 ];
  1621. array[ offset + 4 ] = te[ 4 ];
  1622. array[ offset + 5 ] = te[ 5 ];
  1623. array[ offset + 6 ] = te[ 6 ];
  1624. array[ offset + 7 ] = te[ 7 ];
  1625. array[ offset + 8 ] = te[ 8 ];
  1626. return array;
  1627. }
  1628. } );
  1629. /**
  1630. * @author mrdoob / http://mrdoob.com/
  1631. * @author alteredq / http://alteredqualia.com/
  1632. * @author szimek / https://github.com/szimek/
  1633. */
  1634. var _canvas;
  1635. var ImageUtils = {
  1636. getDataURL: function ( image ) {
  1637. var canvas;
  1638. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1639. return image.src;
  1640. } else if ( image instanceof HTMLCanvasElement ) {
  1641. canvas = image;
  1642. } else {
  1643. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1644. _canvas.width = image.width;
  1645. _canvas.height = image.height;
  1646. var context = _canvas.getContext( '2d' );
  1647. if ( image instanceof ImageData ) {
  1648. context.putImageData( image, 0, 0 );
  1649. } else {
  1650. context.drawImage( image, 0, 0, image.width, image.height );
  1651. }
  1652. canvas = _canvas;
  1653. }
  1654. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1655. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1656. } else {
  1657. return canvas.toDataURL( 'image/png' );
  1658. }
  1659. }
  1660. };
  1661. /**
  1662. * @author mrdoob / http://mrdoob.com/
  1663. * @author alteredq / http://alteredqualia.com/
  1664. * @author szimek / https://github.com/szimek/
  1665. */
  1666. var textureId = 0;
  1667. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1668. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1669. this.uuid = _Math.generateUUID();
  1670. this.name = '';
  1671. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1672. this.mipmaps = [];
  1673. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1674. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1675. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1676. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1677. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1678. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1679. this.format = format !== undefined ? format : RGBAFormat;
  1680. this.type = type !== undefined ? type : UnsignedByteType;
  1681. this.offset = new Vector2( 0, 0 );
  1682. this.repeat = new Vector2( 1, 1 );
  1683. this.center = new Vector2( 0, 0 );
  1684. this.rotation = 0;
  1685. this.matrixAutoUpdate = true;
  1686. this.matrix = new Matrix3();
  1687. this.generateMipmaps = true;
  1688. this.premultiplyAlpha = false;
  1689. this.flipY = true;
  1690. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1691. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1692. //
  1693. // Also changing the encoding after already used by a Material will not automatically make the Material
  1694. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1695. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1696. this.version = 0;
  1697. this.onUpdate = null;
  1698. }
  1699. Texture.DEFAULT_IMAGE = undefined;
  1700. Texture.DEFAULT_MAPPING = UVMapping;
  1701. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1702. constructor: Texture,
  1703. isTexture: true,
  1704. updateMatrix: function () {
  1705. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1706. },
  1707. clone: function () {
  1708. return new this.constructor().copy( this );
  1709. },
  1710. copy: function ( source ) {
  1711. this.name = source.name;
  1712. this.image = source.image;
  1713. this.mipmaps = source.mipmaps.slice( 0 );
  1714. this.mapping = source.mapping;
  1715. this.wrapS = source.wrapS;
  1716. this.wrapT = source.wrapT;
  1717. this.magFilter = source.magFilter;
  1718. this.minFilter = source.minFilter;
  1719. this.anisotropy = source.anisotropy;
  1720. this.format = source.format;
  1721. this.type = source.type;
  1722. this.offset.copy( source.offset );
  1723. this.repeat.copy( source.repeat );
  1724. this.center.copy( source.center );
  1725. this.rotation = source.rotation;
  1726. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1727. this.matrix.copy( source.matrix );
  1728. this.generateMipmaps = source.generateMipmaps;
  1729. this.premultiplyAlpha = source.premultiplyAlpha;
  1730. this.flipY = source.flipY;
  1731. this.unpackAlignment = source.unpackAlignment;
  1732. this.encoding = source.encoding;
  1733. return this;
  1734. },
  1735. toJSON: function ( meta ) {
  1736. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1737. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1738. return meta.textures[ this.uuid ];
  1739. }
  1740. var output = {
  1741. metadata: {
  1742. version: 4.5,
  1743. type: 'Texture',
  1744. generator: 'Texture.toJSON'
  1745. },
  1746. uuid: this.uuid,
  1747. name: this.name,
  1748. mapping: this.mapping,
  1749. repeat: [ this.repeat.x, this.repeat.y ],
  1750. offset: [ this.offset.x, this.offset.y ],
  1751. center: [ this.center.x, this.center.y ],
  1752. rotation: this.rotation,
  1753. wrap: [ this.wrapS, this.wrapT ],
  1754. format: this.format,
  1755. type: this.type,
  1756. encoding: this.encoding,
  1757. minFilter: this.minFilter,
  1758. magFilter: this.magFilter,
  1759. anisotropy: this.anisotropy,
  1760. flipY: this.flipY,
  1761. premultiplyAlpha: this.premultiplyAlpha,
  1762. unpackAlignment: this.unpackAlignment
  1763. };
  1764. if ( this.image !== undefined ) {
  1765. // TODO: Move to THREE.Image
  1766. var image = this.image;
  1767. if ( image.uuid === undefined ) {
  1768. image.uuid = _Math.generateUUID(); // UGH
  1769. }
  1770. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1771. var url;
  1772. if ( Array.isArray( image ) ) {
  1773. // process array of images e.g. CubeTexture
  1774. url = [];
  1775. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1776. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1777. }
  1778. } else {
  1779. // process single image
  1780. url = ImageUtils.getDataURL( image );
  1781. }
  1782. meta.images[ image.uuid ] = {
  1783. uuid: image.uuid,
  1784. url: url
  1785. };
  1786. }
  1787. output.image = image.uuid;
  1788. }
  1789. if ( ! isRootObject ) {
  1790. meta.textures[ this.uuid ] = output;
  1791. }
  1792. return output;
  1793. },
  1794. dispose: function () {
  1795. this.dispatchEvent( { type: 'dispose' } );
  1796. },
  1797. transformUv: function ( uv ) {
  1798. if ( this.mapping !== UVMapping ) return uv;
  1799. uv.applyMatrix3( this.matrix );
  1800. if ( uv.x < 0 || uv.x > 1 ) {
  1801. switch ( this.wrapS ) {
  1802. case RepeatWrapping:
  1803. uv.x = uv.x - Math.floor( uv.x );
  1804. break;
  1805. case ClampToEdgeWrapping:
  1806. uv.x = uv.x < 0 ? 0 : 1;
  1807. break;
  1808. case MirroredRepeatWrapping:
  1809. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1810. uv.x = Math.ceil( uv.x ) - uv.x;
  1811. } else {
  1812. uv.x = uv.x - Math.floor( uv.x );
  1813. }
  1814. break;
  1815. }
  1816. }
  1817. if ( uv.y < 0 || uv.y > 1 ) {
  1818. switch ( this.wrapT ) {
  1819. case RepeatWrapping:
  1820. uv.y = uv.y - Math.floor( uv.y );
  1821. break;
  1822. case ClampToEdgeWrapping:
  1823. uv.y = uv.y < 0 ? 0 : 1;
  1824. break;
  1825. case MirroredRepeatWrapping:
  1826. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1827. uv.y = Math.ceil( uv.y ) - uv.y;
  1828. } else {
  1829. uv.y = uv.y - Math.floor( uv.y );
  1830. }
  1831. break;
  1832. }
  1833. }
  1834. if ( this.flipY ) {
  1835. uv.y = 1 - uv.y;
  1836. }
  1837. return uv;
  1838. }
  1839. } );
  1840. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1841. set: function ( value ) {
  1842. if ( value === true ) this.version ++;
  1843. }
  1844. } );
  1845. /**
  1846. * @author supereggbert / http://www.paulbrunt.co.uk/
  1847. * @author philogb / http://blog.thejit.org/
  1848. * @author mikael emtinger / http://gomo.se/
  1849. * @author egraether / http://egraether.com/
  1850. * @author WestLangley / http://github.com/WestLangley
  1851. */
  1852. function Vector4( x, y, z, w ) {
  1853. this.x = x || 0;
  1854. this.y = y || 0;
  1855. this.z = z || 0;
  1856. this.w = ( w !== undefined ) ? w : 1;
  1857. }
  1858. Object.defineProperties( Vector4.prototype, {
  1859. "width": {
  1860. get: function () {
  1861. return this.z;
  1862. },
  1863. set: function ( value ) {
  1864. this.z = value;
  1865. }
  1866. },
  1867. "height": {
  1868. get: function () {
  1869. return this.w;
  1870. },
  1871. set: function ( value ) {
  1872. this.w = value;
  1873. }
  1874. }
  1875. } );
  1876. Object.assign( Vector4.prototype, {
  1877. isVector4: true,
  1878. set: function ( x, y, z, w ) {
  1879. this.x = x;
  1880. this.y = y;
  1881. this.z = z;
  1882. this.w = w;
  1883. return this;
  1884. },
  1885. setScalar: function ( scalar ) {
  1886. this.x = scalar;
  1887. this.y = scalar;
  1888. this.z = scalar;
  1889. this.w = scalar;
  1890. return this;
  1891. },
  1892. setX: function ( x ) {
  1893. this.x = x;
  1894. return this;
  1895. },
  1896. setY: function ( y ) {
  1897. this.y = y;
  1898. return this;
  1899. },
  1900. setZ: function ( z ) {
  1901. this.z = z;
  1902. return this;
  1903. },
  1904. setW: function ( w ) {
  1905. this.w = w;
  1906. return this;
  1907. },
  1908. setComponent: function ( index, value ) {
  1909. switch ( index ) {
  1910. case 0: this.x = value; break;
  1911. case 1: this.y = value; break;
  1912. case 2: this.z = value; break;
  1913. case 3: this.w = value; break;
  1914. default: throw new Error( 'index is out of range: ' + index );
  1915. }
  1916. return this;
  1917. },
  1918. getComponent: function ( index ) {
  1919. switch ( index ) {
  1920. case 0: return this.x;
  1921. case 1: return this.y;
  1922. case 2: return this.z;
  1923. case 3: return this.w;
  1924. default: throw new Error( 'index is out of range: ' + index );
  1925. }
  1926. },
  1927. clone: function () {
  1928. return new this.constructor( this.x, this.y, this.z, this.w );
  1929. },
  1930. copy: function ( v ) {
  1931. this.x = v.x;
  1932. this.y = v.y;
  1933. this.z = v.z;
  1934. this.w = ( v.w !== undefined ) ? v.w : 1;
  1935. return this;
  1936. },
  1937. add: function ( v, w ) {
  1938. if ( w !== undefined ) {
  1939. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1940. return this.addVectors( v, w );
  1941. }
  1942. this.x += v.x;
  1943. this.y += v.y;
  1944. this.z += v.z;
  1945. this.w += v.w;
  1946. return this;
  1947. },
  1948. addScalar: function ( s ) {
  1949. this.x += s;
  1950. this.y += s;
  1951. this.z += s;
  1952. this.w += s;
  1953. return this;
  1954. },
  1955. addVectors: function ( a, b ) {
  1956. this.x = a.x + b.x;
  1957. this.y = a.y + b.y;
  1958. this.z = a.z + b.z;
  1959. this.w = a.w + b.w;
  1960. return this;
  1961. },
  1962. addScaledVector: function ( v, s ) {
  1963. this.x += v.x * s;
  1964. this.y += v.y * s;
  1965. this.z += v.z * s;
  1966. this.w += v.w * s;
  1967. return this;
  1968. },
  1969. sub: function ( v, w ) {
  1970. if ( w !== undefined ) {
  1971. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1972. return this.subVectors( v, w );
  1973. }
  1974. this.x -= v.x;
  1975. this.y -= v.y;
  1976. this.z -= v.z;
  1977. this.w -= v.w;
  1978. return this;
  1979. },
  1980. subScalar: function ( s ) {
  1981. this.x -= s;
  1982. this.y -= s;
  1983. this.z -= s;
  1984. this.w -= s;
  1985. return this;
  1986. },
  1987. subVectors: function ( a, b ) {
  1988. this.x = a.x - b.x;
  1989. this.y = a.y - b.y;
  1990. this.z = a.z - b.z;
  1991. this.w = a.w - b.w;
  1992. return this;
  1993. },
  1994. multiplyScalar: function ( scalar ) {
  1995. this.x *= scalar;
  1996. this.y *= scalar;
  1997. this.z *= scalar;
  1998. this.w *= scalar;
  1999. return this;
  2000. },
  2001. applyMatrix4: function ( m ) {
  2002. var x = this.x, y = this.y, z = this.z, w = this.w;
  2003. var e = m.elements;
  2004. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2005. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2006. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2007. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2008. return this;
  2009. },
  2010. divideScalar: function ( scalar ) {
  2011. return this.multiplyScalar( 1 / scalar );
  2012. },
  2013. setAxisAngleFromQuaternion: function ( q ) {
  2014. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2015. // q is assumed to be normalized
  2016. this.w = 2 * Math.acos( q.w );
  2017. var s = Math.sqrt( 1 - q.w * q.w );
  2018. if ( s < 0.0001 ) {
  2019. this.x = 1;
  2020. this.y = 0;
  2021. this.z = 0;
  2022. } else {
  2023. this.x = q.x / s;
  2024. this.y = q.y / s;
  2025. this.z = q.z / s;
  2026. }
  2027. return this;
  2028. },
  2029. setAxisAngleFromRotationMatrix: function ( m ) {
  2030. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2031. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2032. var angle, x, y, z, // variables for result
  2033. epsilon = 0.01, // margin to allow for rounding errors
  2034. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2035. te = m.elements,
  2036. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2037. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2038. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2039. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2040. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2041. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2042. // singularity found
  2043. // first check for identity matrix which must have +1 for all terms
  2044. // in leading diagonal and zero in other terms
  2045. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2046. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2047. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2048. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2049. // this singularity is identity matrix so angle = 0
  2050. this.set( 1, 0, 0, 0 );
  2051. return this; // zero angle, arbitrary axis
  2052. }
  2053. // otherwise this singularity is angle = 180
  2054. angle = Math.PI;
  2055. var xx = ( m11 + 1 ) / 2;
  2056. var yy = ( m22 + 1 ) / 2;
  2057. var zz = ( m33 + 1 ) / 2;
  2058. var xy = ( m12 + m21 ) / 4;
  2059. var xz = ( m13 + m31 ) / 4;
  2060. var yz = ( m23 + m32 ) / 4;
  2061. if ( ( xx > yy ) && ( xx > zz ) ) {
  2062. // m11 is the largest diagonal term
  2063. if ( xx < epsilon ) {
  2064. x = 0;
  2065. y = 0.707106781;
  2066. z = 0.707106781;
  2067. } else {
  2068. x = Math.sqrt( xx );
  2069. y = xy / x;
  2070. z = xz / x;
  2071. }
  2072. } else if ( yy > zz ) {
  2073. // m22 is the largest diagonal term
  2074. if ( yy < epsilon ) {
  2075. x = 0.707106781;
  2076. y = 0;
  2077. z = 0.707106781;
  2078. } else {
  2079. y = Math.sqrt( yy );
  2080. x = xy / y;
  2081. z = yz / y;
  2082. }
  2083. } else {
  2084. // m33 is the largest diagonal term so base result on this
  2085. if ( zz < epsilon ) {
  2086. x = 0.707106781;
  2087. y = 0.707106781;
  2088. z = 0;
  2089. } else {
  2090. z = Math.sqrt( zz );
  2091. x = xz / z;
  2092. y = yz / z;
  2093. }
  2094. }
  2095. this.set( x, y, z, angle );
  2096. return this; // return 180 deg rotation
  2097. }
  2098. // as we have reached here there are no singularities so we can handle normally
  2099. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2100. ( m13 - m31 ) * ( m13 - m31 ) +
  2101. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2102. if ( Math.abs( s ) < 0.001 ) s = 1;
  2103. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2104. // caught by singularity test above, but I've left it in just in case
  2105. this.x = ( m32 - m23 ) / s;
  2106. this.y = ( m13 - m31 ) / s;
  2107. this.z = ( m21 - m12 ) / s;
  2108. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2109. return this;
  2110. },
  2111. min: function ( v ) {
  2112. this.x = Math.min( this.x, v.x );
  2113. this.y = Math.min( this.y, v.y );
  2114. this.z = Math.min( this.z, v.z );
  2115. this.w = Math.min( this.w, v.w );
  2116. return this;
  2117. },
  2118. max: function ( v ) {
  2119. this.x = Math.max( this.x, v.x );
  2120. this.y = Math.max( this.y, v.y );
  2121. this.z = Math.max( this.z, v.z );
  2122. this.w = Math.max( this.w, v.w );
  2123. return this;
  2124. },
  2125. clamp: function ( min, max ) {
  2126. // assumes min < max, componentwise
  2127. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2128. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2129. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2130. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2131. return this;
  2132. },
  2133. clampScalar: function ( minVal, maxVal ) {
  2134. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2135. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2136. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2137. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  2138. return this;
  2139. },
  2140. clampLength: function ( min, max ) {
  2141. var length = this.length();
  2142. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2143. },
  2144. floor: function () {
  2145. this.x = Math.floor( this.x );
  2146. this.y = Math.floor( this.y );
  2147. this.z = Math.floor( this.z );
  2148. this.w = Math.floor( this.w );
  2149. return this;
  2150. },
  2151. ceil: function () {
  2152. this.x = Math.ceil( this.x );
  2153. this.y = Math.ceil( this.y );
  2154. this.z = Math.ceil( this.z );
  2155. this.w = Math.ceil( this.w );
  2156. return this;
  2157. },
  2158. round: function () {
  2159. this.x = Math.round( this.x );
  2160. this.y = Math.round( this.y );
  2161. this.z = Math.round( this.z );
  2162. this.w = Math.round( this.w );
  2163. return this;
  2164. },
  2165. roundToZero: function () {
  2166. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2167. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2168. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2169. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2170. return this;
  2171. },
  2172. negate: function () {
  2173. this.x = - this.x;
  2174. this.y = - this.y;
  2175. this.z = - this.z;
  2176. this.w = - this.w;
  2177. return this;
  2178. },
  2179. dot: function ( v ) {
  2180. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2181. },
  2182. lengthSq: function () {
  2183. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2184. },
  2185. length: function () {
  2186. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2187. },
  2188. manhattanLength: function () {
  2189. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2190. },
  2191. normalize: function () {
  2192. return this.divideScalar( this.length() || 1 );
  2193. },
  2194. setLength: function ( length ) {
  2195. return this.normalize().multiplyScalar( length );
  2196. },
  2197. lerp: function ( v, alpha ) {
  2198. this.x += ( v.x - this.x ) * alpha;
  2199. this.y += ( v.y - this.y ) * alpha;
  2200. this.z += ( v.z - this.z ) * alpha;
  2201. this.w += ( v.w - this.w ) * alpha;
  2202. return this;
  2203. },
  2204. lerpVectors: function ( v1, v2, alpha ) {
  2205. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2206. },
  2207. equals: function ( v ) {
  2208. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2209. },
  2210. fromArray: function ( array, offset ) {
  2211. if ( offset === undefined ) offset = 0;
  2212. this.x = array[ offset ];
  2213. this.y = array[ offset + 1 ];
  2214. this.z = array[ offset + 2 ];
  2215. this.w = array[ offset + 3 ];
  2216. return this;
  2217. },
  2218. toArray: function ( array, offset ) {
  2219. if ( array === undefined ) array = [];
  2220. if ( offset === undefined ) offset = 0;
  2221. array[ offset ] = this.x;
  2222. array[ offset + 1 ] = this.y;
  2223. array[ offset + 2 ] = this.z;
  2224. array[ offset + 3 ] = this.w;
  2225. return array;
  2226. },
  2227. fromBufferAttribute: function ( attribute, index, offset ) {
  2228. if ( offset !== undefined ) {
  2229. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2230. }
  2231. this.x = attribute.getX( index );
  2232. this.y = attribute.getY( index );
  2233. this.z = attribute.getZ( index );
  2234. this.w = attribute.getW( index );
  2235. return this;
  2236. }
  2237. } );
  2238. /**
  2239. * @author szimek / https://github.com/szimek/
  2240. * @author alteredq / http://alteredqualia.com/
  2241. * @author Marius Kintel / https://github.com/kintel
  2242. */
  2243. /*
  2244. In options, we can specify:
  2245. * Texture parameters for an auto-generated target texture
  2246. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2247. */
  2248. function WebGLRenderTarget( width, height, options ) {
  2249. this.width = width;
  2250. this.height = height;
  2251. this.scissor = new Vector4( 0, 0, width, height );
  2252. this.scissorTest = false;
  2253. this.viewport = new Vector4( 0, 0, width, height );
  2254. options = options || {};
  2255. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2256. this.texture.image = {};
  2257. this.texture.image.width = width;
  2258. this.texture.image.height = height;
  2259. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2260. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2261. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2262. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2263. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2264. }
  2265. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2266. constructor: WebGLRenderTarget,
  2267. isWebGLRenderTarget: true,
  2268. setSize: function ( width, height ) {
  2269. if ( this.width !== width || this.height !== height ) {
  2270. this.width = width;
  2271. this.height = height;
  2272. this.texture.image.width = width;
  2273. this.texture.image.height = height;
  2274. this.dispose();
  2275. }
  2276. this.viewport.set( 0, 0, width, height );
  2277. this.scissor.set( 0, 0, width, height );
  2278. },
  2279. clone: function () {
  2280. return new this.constructor().copy( this );
  2281. },
  2282. copy: function ( source ) {
  2283. this.width = source.width;
  2284. this.height = source.height;
  2285. this.viewport.copy( source.viewport );
  2286. this.texture = source.texture.clone();
  2287. this.depthBuffer = source.depthBuffer;
  2288. this.stencilBuffer = source.stencilBuffer;
  2289. this.depthTexture = source.depthTexture;
  2290. return this;
  2291. },
  2292. dispose: function () {
  2293. this.dispatchEvent( { type: 'dispose' } );
  2294. }
  2295. } );
  2296. /**
  2297. * @author Mugen87 / https://github.com/Mugen87
  2298. * @author Matt DesLauriers / @mattdesl
  2299. */
  2300. function WebGLMultisampleRenderTarget( width, height, options ) {
  2301. WebGLRenderTarget.call( this, width, height, options );
  2302. this.samples = 4;
  2303. }
  2304. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2305. constructor: WebGLMultisampleRenderTarget,
  2306. isWebGLMultisampleRenderTarget: true,
  2307. copy: function ( source ) {
  2308. WebGLRenderTarget.prototype.copy.call( this, source );
  2309. this.samples = source.samples;
  2310. return this;
  2311. }
  2312. } );
  2313. var _v1 = new Vector3();
  2314. var _m1 = new Matrix4();
  2315. var _zero = new Vector3( 0, 0, 0 );
  2316. var _one = new Vector3( 1, 1, 1 );
  2317. var _x = new Vector3();
  2318. var _y = new Vector3();
  2319. var _z = new Vector3();
  2320. /**
  2321. * @author mrdoob / http://mrdoob.com/
  2322. * @author supereggbert / http://www.paulbrunt.co.uk/
  2323. * @author philogb / http://blog.thejit.org/
  2324. * @author jordi_ros / http://plattsoft.com
  2325. * @author D1plo1d / http://github.com/D1plo1d
  2326. * @author alteredq / http://alteredqualia.com/
  2327. * @author mikael emtinger / http://gomo.se/
  2328. * @author timknip / http://www.floorplanner.com/
  2329. * @author bhouston / http://clara.io
  2330. * @author WestLangley / http://github.com/WestLangley
  2331. */
  2332. function Matrix4() {
  2333. this.elements = [
  2334. 1, 0, 0, 0,
  2335. 0, 1, 0, 0,
  2336. 0, 0, 1, 0,
  2337. 0, 0, 0, 1
  2338. ];
  2339. if ( arguments.length > 0 ) {
  2340. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2341. }
  2342. }
  2343. Object.assign( Matrix4.prototype, {
  2344. isMatrix4: true,
  2345. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2346. var te = this.elements;
  2347. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2348. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2349. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2350. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2351. return this;
  2352. },
  2353. identity: function () {
  2354. this.set(
  2355. 1, 0, 0, 0,
  2356. 0, 1, 0, 0,
  2357. 0, 0, 1, 0,
  2358. 0, 0, 0, 1
  2359. );
  2360. return this;
  2361. },
  2362. clone: function () {
  2363. return new Matrix4().fromArray( this.elements );
  2364. },
  2365. copy: function ( m ) {
  2366. var te = this.elements;
  2367. var me = m.elements;
  2368. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2369. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2370. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2371. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2372. return this;
  2373. },
  2374. copyPosition: function ( m ) {
  2375. var te = this.elements, me = m.elements;
  2376. te[ 12 ] = me[ 12 ];
  2377. te[ 13 ] = me[ 13 ];
  2378. te[ 14 ] = me[ 14 ];
  2379. return this;
  2380. },
  2381. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2382. xAxis.setFromMatrixColumn( this, 0 );
  2383. yAxis.setFromMatrixColumn( this, 1 );
  2384. zAxis.setFromMatrixColumn( this, 2 );
  2385. return this;
  2386. },
  2387. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2388. this.set(
  2389. xAxis.x, yAxis.x, zAxis.x, 0,
  2390. xAxis.y, yAxis.y, zAxis.y, 0,
  2391. xAxis.z, yAxis.z, zAxis.z, 0,
  2392. 0, 0, 0, 1
  2393. );
  2394. return this;
  2395. },
  2396. extractRotation: function ( m ) {
  2397. // this method does not support reflection matrices
  2398. var te = this.elements;
  2399. var me = m.elements;
  2400. var scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length();
  2401. var scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length();
  2402. var scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length();
  2403. te[ 0 ] = me[ 0 ] * scaleX;
  2404. te[ 1 ] = me[ 1 ] * scaleX;
  2405. te[ 2 ] = me[ 2 ] * scaleX;
  2406. te[ 3 ] = 0;
  2407. te[ 4 ] = me[ 4 ] * scaleY;
  2408. te[ 5 ] = me[ 5 ] * scaleY;
  2409. te[ 6 ] = me[ 6 ] * scaleY;
  2410. te[ 7 ] = 0;
  2411. te[ 8 ] = me[ 8 ] * scaleZ;
  2412. te[ 9 ] = me[ 9 ] * scaleZ;
  2413. te[ 10 ] = me[ 10 ] * scaleZ;
  2414. te[ 11 ] = 0;
  2415. te[ 12 ] = 0;
  2416. te[ 13 ] = 0;
  2417. te[ 14 ] = 0;
  2418. te[ 15 ] = 1;
  2419. return this;
  2420. },
  2421. makeRotationFromEuler: function ( euler ) {
  2422. if ( ! ( euler && euler.isEuler ) ) {
  2423. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2424. }
  2425. var te = this.elements;
  2426. var x = euler.x, y = euler.y, z = euler.z;
  2427. var a = Math.cos( x ), b = Math.sin( x );
  2428. var c = Math.cos( y ), d = Math.sin( y );
  2429. var e = Math.cos( z ), f = Math.sin( z );
  2430. if ( euler.order === 'XYZ' ) {
  2431. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2432. te[ 0 ] = c * e;
  2433. te[ 4 ] = - c * f;
  2434. te[ 8 ] = d;
  2435. te[ 1 ] = af + be * d;
  2436. te[ 5 ] = ae - bf * d;
  2437. te[ 9 ] = - b * c;
  2438. te[ 2 ] = bf - ae * d;
  2439. te[ 6 ] = be + af * d;
  2440. te[ 10 ] = a * c;
  2441. } else if ( euler.order === 'YXZ' ) {
  2442. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2443. te[ 0 ] = ce + df * b;
  2444. te[ 4 ] = de * b - cf;
  2445. te[ 8 ] = a * d;
  2446. te[ 1 ] = a * f;
  2447. te[ 5 ] = a * e;
  2448. te[ 9 ] = - b;
  2449. te[ 2 ] = cf * b - de;
  2450. te[ 6 ] = df + ce * b;
  2451. te[ 10 ] = a * c;
  2452. } else if ( euler.order === 'ZXY' ) {
  2453. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2454. te[ 0 ] = ce - df * b;
  2455. te[ 4 ] = - a * f;
  2456. te[ 8 ] = de + cf * b;
  2457. te[ 1 ] = cf + de * b;
  2458. te[ 5 ] = a * e;
  2459. te[ 9 ] = df - ce * b;
  2460. te[ 2 ] = - a * d;
  2461. te[ 6 ] = b;
  2462. te[ 10 ] = a * c;
  2463. } else if ( euler.order === 'ZYX' ) {
  2464. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2465. te[ 0 ] = c * e;
  2466. te[ 4 ] = be * d - af;
  2467. te[ 8 ] = ae * d + bf;
  2468. te[ 1 ] = c * f;
  2469. te[ 5 ] = bf * d + ae;
  2470. te[ 9 ] = af * d - be;
  2471. te[ 2 ] = - d;
  2472. te[ 6 ] = b * c;
  2473. te[ 10 ] = a * c;
  2474. } else if ( euler.order === 'YZX' ) {
  2475. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2476. te[ 0 ] = c * e;
  2477. te[ 4 ] = bd - ac * f;
  2478. te[ 8 ] = bc * f + ad;
  2479. te[ 1 ] = f;
  2480. te[ 5 ] = a * e;
  2481. te[ 9 ] = - b * e;
  2482. te[ 2 ] = - d * e;
  2483. te[ 6 ] = ad * f + bc;
  2484. te[ 10 ] = ac - bd * f;
  2485. } else if ( euler.order === 'XZY' ) {
  2486. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2487. te[ 0 ] = c * e;
  2488. te[ 4 ] = - f;
  2489. te[ 8 ] = d * e;
  2490. te[ 1 ] = ac * f + bd;
  2491. te[ 5 ] = a * e;
  2492. te[ 9 ] = ad * f - bc;
  2493. te[ 2 ] = bc * f - ad;
  2494. te[ 6 ] = b * e;
  2495. te[ 10 ] = bd * f + ac;
  2496. }
  2497. // bottom row
  2498. te[ 3 ] = 0;
  2499. te[ 7 ] = 0;
  2500. te[ 11 ] = 0;
  2501. // last column
  2502. te[ 12 ] = 0;
  2503. te[ 13 ] = 0;
  2504. te[ 14 ] = 0;
  2505. te[ 15 ] = 1;
  2506. return this;
  2507. },
  2508. makeRotationFromQuaternion: function ( q ) {
  2509. return this.compose( _zero, q, _one );
  2510. },
  2511. lookAt: function ( eye, target, up ) {
  2512. var te = this.elements;
  2513. _z.subVectors( eye, target );
  2514. if ( _z.lengthSq() === 0 ) {
  2515. // eye and target are in the same position
  2516. _z.z = 1;
  2517. }
  2518. _z.normalize();
  2519. _x.crossVectors( up, _z );
  2520. if ( _x.lengthSq() === 0 ) {
  2521. // up and z are parallel
  2522. if ( Math.abs( up.z ) === 1 ) {
  2523. _z.x += 0.0001;
  2524. } else {
  2525. _z.z += 0.0001;
  2526. }
  2527. _z.normalize();
  2528. _x.crossVectors( up, _z );
  2529. }
  2530. _x.normalize();
  2531. _y.crossVectors( _z, _x );
  2532. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  2533. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  2534. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  2535. return this;
  2536. },
  2537. multiply: function ( m, n ) {
  2538. if ( n !== undefined ) {
  2539. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2540. return this.multiplyMatrices( m, n );
  2541. }
  2542. return this.multiplyMatrices( this, m );
  2543. },
  2544. premultiply: function ( m ) {
  2545. return this.multiplyMatrices( m, this );
  2546. },
  2547. multiplyMatrices: function ( a, b ) {
  2548. var ae = a.elements;
  2549. var be = b.elements;
  2550. var te = this.elements;
  2551. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2552. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2553. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2554. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2555. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2556. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2557. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2558. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2559. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2560. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2561. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2562. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2563. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2564. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2565. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2566. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2567. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2568. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2569. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2570. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2571. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2572. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2573. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2574. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2575. return this;
  2576. },
  2577. multiplyScalar: function ( s ) {
  2578. var te = this.elements;
  2579. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2580. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2581. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2582. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2583. return this;
  2584. },
  2585. applyToBufferAttribute: function ( attribute ) {
  2586. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2587. _v1.x = attribute.getX( i );
  2588. _v1.y = attribute.getY( i );
  2589. _v1.z = attribute.getZ( i );
  2590. _v1.applyMatrix4( this );
  2591. attribute.setXYZ( i, _v1.x, _v1.y, _v1.z );
  2592. }
  2593. return attribute;
  2594. },
  2595. determinant: function () {
  2596. var te = this.elements;
  2597. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2598. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2599. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2600. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2601. //TODO: make this more efficient
  2602. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2603. return (
  2604. n41 * (
  2605. + n14 * n23 * n32
  2606. - n13 * n24 * n32
  2607. - n14 * n22 * n33
  2608. + n12 * n24 * n33
  2609. + n13 * n22 * n34
  2610. - n12 * n23 * n34
  2611. ) +
  2612. n42 * (
  2613. + n11 * n23 * n34
  2614. - n11 * n24 * n33
  2615. + n14 * n21 * n33
  2616. - n13 * n21 * n34
  2617. + n13 * n24 * n31
  2618. - n14 * n23 * n31
  2619. ) +
  2620. n43 * (
  2621. + n11 * n24 * n32
  2622. - n11 * n22 * n34
  2623. - n14 * n21 * n32
  2624. + n12 * n21 * n34
  2625. + n14 * n22 * n31
  2626. - n12 * n24 * n31
  2627. ) +
  2628. n44 * (
  2629. - n13 * n22 * n31
  2630. - n11 * n23 * n32
  2631. + n11 * n22 * n33
  2632. + n13 * n21 * n32
  2633. - n12 * n21 * n33
  2634. + n12 * n23 * n31
  2635. )
  2636. );
  2637. },
  2638. transpose: function () {
  2639. var te = this.elements;
  2640. var tmp;
  2641. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2642. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2643. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2644. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2645. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2646. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2647. return this;
  2648. },
  2649. setPosition: function ( x, y, z ) {
  2650. var te = this.elements;
  2651. if ( x.isVector3 ) {
  2652. te[ 12 ] = x.x;
  2653. te[ 13 ] = x.y;
  2654. te[ 14 ] = x.z;
  2655. } else {
  2656. te[ 12 ] = x;
  2657. te[ 13 ] = y;
  2658. te[ 14 ] = z;
  2659. }
  2660. return this;
  2661. },
  2662. getInverse: function ( m, throwOnDegenerate ) {
  2663. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2664. var te = this.elements,
  2665. me = m.elements,
  2666. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2667. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2668. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2669. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2670. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2671. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2672. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2673. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2674. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2675. if ( det === 0 ) {
  2676. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  2677. if ( throwOnDegenerate === true ) {
  2678. throw new Error( msg );
  2679. } else {
  2680. console.warn( msg );
  2681. }
  2682. return this.identity();
  2683. }
  2684. var detInv = 1 / det;
  2685. te[ 0 ] = t11 * detInv;
  2686. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2687. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2688. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2689. te[ 4 ] = t12 * detInv;
  2690. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2691. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2692. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2693. te[ 8 ] = t13 * detInv;
  2694. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2695. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2696. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2697. te[ 12 ] = t14 * detInv;
  2698. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2699. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2700. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2701. return this;
  2702. },
  2703. scale: function ( v ) {
  2704. var te = this.elements;
  2705. var x = v.x, y = v.y, z = v.z;
  2706. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2707. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2708. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2709. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2710. return this;
  2711. },
  2712. getMaxScaleOnAxis: function () {
  2713. var te = this.elements;
  2714. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2715. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2716. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2717. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2718. },
  2719. makeTranslation: function ( x, y, z ) {
  2720. this.set(
  2721. 1, 0, 0, x,
  2722. 0, 1, 0, y,
  2723. 0, 0, 1, z,
  2724. 0, 0, 0, 1
  2725. );
  2726. return this;
  2727. },
  2728. makeRotationX: function ( theta ) {
  2729. var c = Math.cos( theta ), s = Math.sin( theta );
  2730. this.set(
  2731. 1, 0, 0, 0,
  2732. 0, c, - s, 0,
  2733. 0, s, c, 0,
  2734. 0, 0, 0, 1
  2735. );
  2736. return this;
  2737. },
  2738. makeRotationY: function ( theta ) {
  2739. var c = Math.cos( theta ), s = Math.sin( theta );
  2740. this.set(
  2741. c, 0, s, 0,
  2742. 0, 1, 0, 0,
  2743. - s, 0, c, 0,
  2744. 0, 0, 0, 1
  2745. );
  2746. return this;
  2747. },
  2748. makeRotationZ: function ( theta ) {
  2749. var c = Math.cos( theta ), s = Math.sin( theta );
  2750. this.set(
  2751. c, - s, 0, 0,
  2752. s, c, 0, 0,
  2753. 0, 0, 1, 0,
  2754. 0, 0, 0, 1
  2755. );
  2756. return this;
  2757. },
  2758. makeRotationAxis: function ( axis, angle ) {
  2759. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2760. var c = Math.cos( angle );
  2761. var s = Math.sin( angle );
  2762. var t = 1 - c;
  2763. var x = axis.x, y = axis.y, z = axis.z;
  2764. var tx = t * x, ty = t * y;
  2765. this.set(
  2766. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2767. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2768. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2769. 0, 0, 0, 1
  2770. );
  2771. return this;
  2772. },
  2773. makeScale: function ( x, y, z ) {
  2774. this.set(
  2775. x, 0, 0, 0,
  2776. 0, y, 0, 0,
  2777. 0, 0, z, 0,
  2778. 0, 0, 0, 1
  2779. );
  2780. return this;
  2781. },
  2782. makeShear: function ( x, y, z ) {
  2783. this.set(
  2784. 1, y, z, 0,
  2785. x, 1, z, 0,
  2786. x, y, 1, 0,
  2787. 0, 0, 0, 1
  2788. );
  2789. return this;
  2790. },
  2791. compose: function ( position, quaternion, scale ) {
  2792. var te = this.elements;
  2793. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2794. var x2 = x + x, y2 = y + y, z2 = z + z;
  2795. var xx = x * x2, xy = x * y2, xz = x * z2;
  2796. var yy = y * y2, yz = y * z2, zz = z * z2;
  2797. var wx = w * x2, wy = w * y2, wz = w * z2;
  2798. var sx = scale.x, sy = scale.y, sz = scale.z;
  2799. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2800. te[ 1 ] = ( xy + wz ) * sx;
  2801. te[ 2 ] = ( xz - wy ) * sx;
  2802. te[ 3 ] = 0;
  2803. te[ 4 ] = ( xy - wz ) * sy;
  2804. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2805. te[ 6 ] = ( yz + wx ) * sy;
  2806. te[ 7 ] = 0;
  2807. te[ 8 ] = ( xz + wy ) * sz;
  2808. te[ 9 ] = ( yz - wx ) * sz;
  2809. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2810. te[ 11 ] = 0;
  2811. te[ 12 ] = position.x;
  2812. te[ 13 ] = position.y;
  2813. te[ 14 ] = position.z;
  2814. te[ 15 ] = 1;
  2815. return this;
  2816. },
  2817. decompose: function ( position, quaternion, scale ) {
  2818. var te = this.elements;
  2819. var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2820. var sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2821. var sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2822. // if determine is negative, we need to invert one scale
  2823. var det = this.determinant();
  2824. if ( det < 0 ) sx = - sx;
  2825. position.x = te[ 12 ];
  2826. position.y = te[ 13 ];
  2827. position.z = te[ 14 ];
  2828. // scale the rotation part
  2829. _m1.copy( this );
  2830. var invSX = 1 / sx;
  2831. var invSY = 1 / sy;
  2832. var invSZ = 1 / sz;
  2833. _m1.elements[ 0 ] *= invSX;
  2834. _m1.elements[ 1 ] *= invSX;
  2835. _m1.elements[ 2 ] *= invSX;
  2836. _m1.elements[ 4 ] *= invSY;
  2837. _m1.elements[ 5 ] *= invSY;
  2838. _m1.elements[ 6 ] *= invSY;
  2839. _m1.elements[ 8 ] *= invSZ;
  2840. _m1.elements[ 9 ] *= invSZ;
  2841. _m1.elements[ 10 ] *= invSZ;
  2842. quaternion.setFromRotationMatrix( _m1 );
  2843. scale.x = sx;
  2844. scale.y = sy;
  2845. scale.z = sz;
  2846. return this;
  2847. },
  2848. makePerspective: function ( left, right, top, bottom, near, far ) {
  2849. if ( far === undefined ) {
  2850. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2851. }
  2852. var te = this.elements;
  2853. var x = 2 * near / ( right - left );
  2854. var y = 2 * near / ( top - bottom );
  2855. var a = ( right + left ) / ( right - left );
  2856. var b = ( top + bottom ) / ( top - bottom );
  2857. var c = - ( far + near ) / ( far - near );
  2858. var d = - 2 * far * near / ( far - near );
  2859. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2860. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2861. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2862. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2863. return this;
  2864. },
  2865. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2866. var te = this.elements;
  2867. var w = 1.0 / ( right - left );
  2868. var h = 1.0 / ( top - bottom );
  2869. var p = 1.0 / ( far - near );
  2870. var x = ( right + left ) * w;
  2871. var y = ( top + bottom ) * h;
  2872. var z = ( far + near ) * p;
  2873. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2874. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2875. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2876. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2877. return this;
  2878. },
  2879. equals: function ( matrix ) {
  2880. var te = this.elements;
  2881. var me = matrix.elements;
  2882. for ( var i = 0; i < 16; i ++ ) {
  2883. if ( te[ i ] !== me[ i ] ) return false;
  2884. }
  2885. return true;
  2886. },
  2887. fromArray: function ( array, offset ) {
  2888. if ( offset === undefined ) offset = 0;
  2889. for ( var i = 0; i < 16; i ++ ) {
  2890. this.elements[ i ] = array[ i + offset ];
  2891. }
  2892. return this;
  2893. },
  2894. toArray: function ( array, offset ) {
  2895. if ( array === undefined ) array = [];
  2896. if ( offset === undefined ) offset = 0;
  2897. var te = this.elements;
  2898. array[ offset ] = te[ 0 ];
  2899. array[ offset + 1 ] = te[ 1 ];
  2900. array[ offset + 2 ] = te[ 2 ];
  2901. array[ offset + 3 ] = te[ 3 ];
  2902. array[ offset + 4 ] = te[ 4 ];
  2903. array[ offset + 5 ] = te[ 5 ];
  2904. array[ offset + 6 ] = te[ 6 ];
  2905. array[ offset + 7 ] = te[ 7 ];
  2906. array[ offset + 8 ] = te[ 8 ];
  2907. array[ offset + 9 ] = te[ 9 ];
  2908. array[ offset + 10 ] = te[ 10 ];
  2909. array[ offset + 11 ] = te[ 11 ];
  2910. array[ offset + 12 ] = te[ 12 ];
  2911. array[ offset + 13 ] = te[ 13 ];
  2912. array[ offset + 14 ] = te[ 14 ];
  2913. array[ offset + 15 ] = te[ 15 ];
  2914. return array;
  2915. }
  2916. } );
  2917. /**
  2918. * @author mrdoob / http://mrdoob.com/
  2919. * @author WestLangley / http://github.com/WestLangley
  2920. * @author bhouston / http://clara.io
  2921. */
  2922. var _matrix = new Matrix4();
  2923. var _quaternion$1 = new Quaternion();
  2924. function Euler( x, y, z, order ) {
  2925. this._x = x || 0;
  2926. this._y = y || 0;
  2927. this._z = z || 0;
  2928. this._order = order || Euler.DefaultOrder;
  2929. }
  2930. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2931. Euler.DefaultOrder = 'XYZ';
  2932. Object.defineProperties( Euler.prototype, {
  2933. x: {
  2934. get: function () {
  2935. return this._x;
  2936. },
  2937. set: function ( value ) {
  2938. this._x = value;
  2939. this._onChangeCallback();
  2940. }
  2941. },
  2942. y: {
  2943. get: function () {
  2944. return this._y;
  2945. },
  2946. set: function ( value ) {
  2947. this._y = value;
  2948. this._onChangeCallback();
  2949. }
  2950. },
  2951. z: {
  2952. get: function () {
  2953. return this._z;
  2954. },
  2955. set: function ( value ) {
  2956. this._z = value;
  2957. this._onChangeCallback();
  2958. }
  2959. },
  2960. order: {
  2961. get: function () {
  2962. return this._order;
  2963. },
  2964. set: function ( value ) {
  2965. this._order = value;
  2966. this._onChangeCallback();
  2967. }
  2968. }
  2969. } );
  2970. Object.assign( Euler.prototype, {
  2971. isEuler: true,
  2972. set: function ( x, y, z, order ) {
  2973. this._x = x;
  2974. this._y = y;
  2975. this._z = z;
  2976. this._order = order || this._order;
  2977. this._onChangeCallback();
  2978. return this;
  2979. },
  2980. clone: function () {
  2981. return new this.constructor( this._x, this._y, this._z, this._order );
  2982. },
  2983. copy: function ( euler ) {
  2984. this._x = euler._x;
  2985. this._y = euler._y;
  2986. this._z = euler._z;
  2987. this._order = euler._order;
  2988. this._onChangeCallback();
  2989. return this;
  2990. },
  2991. setFromRotationMatrix: function ( m, order, update ) {
  2992. var clamp = _Math.clamp;
  2993. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2994. var te = m.elements;
  2995. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2996. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2997. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2998. order = order || this._order;
  2999. if ( order === 'XYZ' ) {
  3000. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3001. if ( Math.abs( m13 ) < 0.9999999 ) {
  3002. this._x = Math.atan2( - m23, m33 );
  3003. this._z = Math.atan2( - m12, m11 );
  3004. } else {
  3005. this._x = Math.atan2( m32, m22 );
  3006. this._z = 0;
  3007. }
  3008. } else if ( order === 'YXZ' ) {
  3009. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3010. if ( Math.abs( m23 ) < 0.9999999 ) {
  3011. this._y = Math.atan2( m13, m33 );
  3012. this._z = Math.atan2( m21, m22 );
  3013. } else {
  3014. this._y = Math.atan2( - m31, m11 );
  3015. this._z = 0;
  3016. }
  3017. } else if ( order === 'ZXY' ) {
  3018. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3019. if ( Math.abs( m32 ) < 0.9999999 ) {
  3020. this._y = Math.atan2( - m31, m33 );
  3021. this._z = Math.atan2( - m12, m22 );
  3022. } else {
  3023. this._y = 0;
  3024. this._z = Math.atan2( m21, m11 );
  3025. }
  3026. } else if ( order === 'ZYX' ) {
  3027. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3028. if ( Math.abs( m31 ) < 0.9999999 ) {
  3029. this._x = Math.atan2( m32, m33 );
  3030. this._z = Math.atan2( m21, m11 );
  3031. } else {
  3032. this._x = 0;
  3033. this._z = Math.atan2( - m12, m22 );
  3034. }
  3035. } else if ( order === 'YZX' ) {
  3036. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3037. if ( Math.abs( m21 ) < 0.9999999 ) {
  3038. this._x = Math.atan2( - m23, m22 );
  3039. this._y = Math.atan2( - m31, m11 );
  3040. } else {
  3041. this._x = 0;
  3042. this._y = Math.atan2( m13, m33 );
  3043. }
  3044. } else if ( order === 'XZY' ) {
  3045. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3046. if ( Math.abs( m12 ) < 0.9999999 ) {
  3047. this._x = Math.atan2( m32, m22 );
  3048. this._y = Math.atan2( m13, m11 );
  3049. } else {
  3050. this._x = Math.atan2( - m23, m33 );
  3051. this._y = 0;
  3052. }
  3053. } else {
  3054. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  3055. }
  3056. this._order = order;
  3057. if ( update !== false ) this._onChangeCallback();
  3058. return this;
  3059. },
  3060. setFromQuaternion: function ( q, order, update ) {
  3061. _matrix.makeRotationFromQuaternion( q );
  3062. return this.setFromRotationMatrix( _matrix, order, update );
  3063. },
  3064. setFromVector3: function ( v, order ) {
  3065. return this.set( v.x, v.y, v.z, order || this._order );
  3066. },
  3067. reorder: function ( newOrder ) {
  3068. // WARNING: this discards revolution information -bhouston
  3069. _quaternion$1.setFromEuler( this );
  3070. return this.setFromQuaternion( _quaternion$1, newOrder );
  3071. },
  3072. equals: function ( euler ) {
  3073. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3074. },
  3075. fromArray: function ( array ) {
  3076. this._x = array[ 0 ];
  3077. this._y = array[ 1 ];
  3078. this._z = array[ 2 ];
  3079. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3080. this._onChangeCallback();
  3081. return this;
  3082. },
  3083. toArray: function ( array, offset ) {
  3084. if ( array === undefined ) array = [];
  3085. if ( offset === undefined ) offset = 0;
  3086. array[ offset ] = this._x;
  3087. array[ offset + 1 ] = this._y;
  3088. array[ offset + 2 ] = this._z;
  3089. array[ offset + 3 ] = this._order;
  3090. return array;
  3091. },
  3092. toVector3: function ( optionalResult ) {
  3093. if ( optionalResult ) {
  3094. return optionalResult.set( this._x, this._y, this._z );
  3095. } else {
  3096. return new Vector3( this._x, this._y, this._z );
  3097. }
  3098. },
  3099. _onChange: function ( callback ) {
  3100. this._onChangeCallback = callback;
  3101. return this;
  3102. },
  3103. _onChangeCallback: function () {}
  3104. } );
  3105. /**
  3106. * @author mrdoob / http://mrdoob.com/
  3107. */
  3108. function Layers() {
  3109. this.mask = 1 | 0;
  3110. }
  3111. Object.assign( Layers.prototype, {
  3112. set: function ( channel ) {
  3113. this.mask = 1 << channel | 0;
  3114. },
  3115. enable: function ( channel ) {
  3116. this.mask |= 1 << channel | 0;
  3117. },
  3118. enableAll: function () {
  3119. this.mask = 0xffffffff | 0;
  3120. },
  3121. toggle: function ( channel ) {
  3122. this.mask ^= 1 << channel | 0;
  3123. },
  3124. disable: function ( channel ) {
  3125. this.mask &= ~ ( 1 << channel | 0 );
  3126. },
  3127. disableAll: function () {
  3128. this.mask = 0;
  3129. },
  3130. test: function ( layers ) {
  3131. return ( this.mask & layers.mask ) !== 0;
  3132. }
  3133. } );
  3134. var _object3DId = 0;
  3135. var _v1$1 = new Vector3();
  3136. var _q1 = new Quaternion();
  3137. var _m1$1 = new Matrix4();
  3138. var _target = new Vector3();
  3139. var _position = new Vector3();
  3140. var _scale = new Vector3();
  3141. var _quaternion$2 = new Quaternion();
  3142. var _xAxis = new Vector3( 1, 0, 0 );
  3143. var _yAxis = new Vector3( 0, 1, 0 );
  3144. var _zAxis = new Vector3( 0, 0, 1 );
  3145. var _addedEvent = { type: 'added' };
  3146. var _removedEvent = { type: 'removed' };
  3147. /**
  3148. * @author mrdoob / http://mrdoob.com/
  3149. * @author mikael emtinger / http://gomo.se/
  3150. * @author alteredq / http://alteredqualia.com/
  3151. * @author WestLangley / http://github.com/WestLangley
  3152. * @author elephantatwork / www.elephantatwork.ch
  3153. */
  3154. function Object3D() {
  3155. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3156. this.uuid = _Math.generateUUID();
  3157. this.name = '';
  3158. this.type = 'Object3D';
  3159. this.parent = null;
  3160. this.children = [];
  3161. this.up = Object3D.DefaultUp.clone();
  3162. var position = new Vector3();
  3163. var rotation = new Euler();
  3164. var quaternion = new Quaternion();
  3165. var scale = new Vector3( 1, 1, 1 );
  3166. function onRotationChange() {
  3167. quaternion.setFromEuler( rotation, false );
  3168. }
  3169. function onQuaternionChange() {
  3170. rotation.setFromQuaternion( quaternion, undefined, false );
  3171. }
  3172. rotation._onChange( onRotationChange );
  3173. quaternion._onChange( onQuaternionChange );
  3174. Object.defineProperties( this, {
  3175. position: {
  3176. configurable: true,
  3177. enumerable: true,
  3178. value: position
  3179. },
  3180. rotation: {
  3181. configurable: true,
  3182. enumerable: true,
  3183. value: rotation
  3184. },
  3185. quaternion: {
  3186. configurable: true,
  3187. enumerable: true,
  3188. value: quaternion
  3189. },
  3190. scale: {
  3191. configurable: true,
  3192. enumerable: true,
  3193. value: scale
  3194. },
  3195. modelViewMatrix: {
  3196. value: new Matrix4()
  3197. },
  3198. normalMatrix: {
  3199. value: new Matrix3()
  3200. }
  3201. } );
  3202. this.matrix = new Matrix4();
  3203. this.matrixWorld = new Matrix4();
  3204. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3205. this.matrixWorldNeedsUpdate = false;
  3206. this.layers = new Layers();
  3207. this.visible = true;
  3208. this.castShadow = false;
  3209. this.receiveShadow = false;
  3210. this.frustumCulled = true;
  3211. this.renderOrder = 0;
  3212. this.userData = {};
  3213. }
  3214. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3215. Object3D.DefaultMatrixAutoUpdate = true;
  3216. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3217. constructor: Object3D,
  3218. isObject3D: true,
  3219. onBeforeRender: function () {},
  3220. onAfterRender: function () {},
  3221. applyMatrix: function ( matrix ) {
  3222. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3223. this.matrix.premultiply( matrix );
  3224. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3225. },
  3226. applyQuaternion: function ( q ) {
  3227. this.quaternion.premultiply( q );
  3228. return this;
  3229. },
  3230. setRotationFromAxisAngle: function ( axis, angle ) {
  3231. // assumes axis is normalized
  3232. this.quaternion.setFromAxisAngle( axis, angle );
  3233. },
  3234. setRotationFromEuler: function ( euler ) {
  3235. this.quaternion.setFromEuler( euler, true );
  3236. },
  3237. setRotationFromMatrix: function ( m ) {
  3238. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3239. this.quaternion.setFromRotationMatrix( m );
  3240. },
  3241. setRotationFromQuaternion: function ( q ) {
  3242. // assumes q is normalized
  3243. this.quaternion.copy( q );
  3244. },
  3245. rotateOnAxis: function ( axis, angle ) {
  3246. // rotate object on axis in object space
  3247. // axis is assumed to be normalized
  3248. _q1.setFromAxisAngle( axis, angle );
  3249. this.quaternion.multiply( _q1 );
  3250. return this;
  3251. },
  3252. rotateOnWorldAxis: function ( axis, angle ) {
  3253. // rotate object on axis in world space
  3254. // axis is assumed to be normalized
  3255. // method assumes no rotated parent
  3256. _q1.setFromAxisAngle( axis, angle );
  3257. this.quaternion.premultiply( _q1 );
  3258. return this;
  3259. },
  3260. rotateX: function ( angle ) {
  3261. return this.rotateOnAxis( _xAxis, angle );
  3262. },
  3263. rotateY: function ( angle ) {
  3264. return this.rotateOnAxis( _yAxis, angle );
  3265. },
  3266. rotateZ: function ( angle ) {
  3267. return this.rotateOnAxis( _zAxis, angle );
  3268. },
  3269. translateOnAxis: function ( axis, distance ) {
  3270. // translate object by distance along axis in object space
  3271. // axis is assumed to be normalized
  3272. _v1$1.copy( axis ).applyQuaternion( this.quaternion );
  3273. this.position.add( _v1$1.multiplyScalar( distance ) );
  3274. return this;
  3275. },
  3276. translateX: function ( distance ) {
  3277. return this.translateOnAxis( _xAxis, distance );
  3278. },
  3279. translateY: function ( distance ) {
  3280. return this.translateOnAxis( _yAxis, distance );
  3281. },
  3282. translateZ: function ( distance ) {
  3283. return this.translateOnAxis( _zAxis, distance );
  3284. },
  3285. localToWorld: function ( vector ) {
  3286. return vector.applyMatrix4( this.matrixWorld );
  3287. },
  3288. worldToLocal: function ( vector ) {
  3289. return vector.applyMatrix4( _m1$1.getInverse( this.matrixWorld ) );
  3290. },
  3291. lookAt: function ( x, y, z ) {
  3292. // This method does not support objects having non-uniformly-scaled parent(s)
  3293. if ( x.isVector3 ) {
  3294. _target.copy( x );
  3295. } else {
  3296. _target.set( x, y, z );
  3297. }
  3298. var parent = this.parent;
  3299. this.updateWorldMatrix( true, false );
  3300. _position.setFromMatrixPosition( this.matrixWorld );
  3301. if ( this.isCamera || this.isLight ) {
  3302. _m1$1.lookAt( _position, _target, this.up );
  3303. } else {
  3304. _m1$1.lookAt( _target, _position, this.up );
  3305. }
  3306. this.quaternion.setFromRotationMatrix( _m1$1 );
  3307. if ( parent ) {
  3308. _m1$1.extractRotation( parent.matrixWorld );
  3309. _q1.setFromRotationMatrix( _m1$1 );
  3310. this.quaternion.premultiply( _q1.inverse() );
  3311. }
  3312. },
  3313. add: function ( object ) {
  3314. if ( arguments.length > 1 ) {
  3315. for ( var i = 0; i < arguments.length; i ++ ) {
  3316. this.add( arguments[ i ] );
  3317. }
  3318. return this;
  3319. }
  3320. if ( object === this ) {
  3321. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3322. return this;
  3323. }
  3324. if ( ( object && object.isObject3D ) ) {
  3325. if ( object.parent !== null ) {
  3326. object.parent.remove( object );
  3327. }
  3328. object.parent = this;
  3329. this.children.push( object );
  3330. object.dispatchEvent( _addedEvent );
  3331. } else {
  3332. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3333. }
  3334. return this;
  3335. },
  3336. remove: function ( object ) {
  3337. if ( arguments.length > 1 ) {
  3338. for ( var i = 0; i < arguments.length; i ++ ) {
  3339. this.remove( arguments[ i ] );
  3340. }
  3341. return this;
  3342. }
  3343. var index = this.children.indexOf( object );
  3344. if ( index !== - 1 ) {
  3345. object.parent = null;
  3346. this.children.splice( index, 1 );
  3347. object.dispatchEvent( _removedEvent );
  3348. }
  3349. return this;
  3350. },
  3351. attach: function ( object ) {
  3352. // adds object as a child of this, while maintaining the object's world transform
  3353. this.updateWorldMatrix( true, false );
  3354. _m1$1.getInverse( this.matrixWorld );
  3355. if ( object.parent !== null ) {
  3356. object.parent.updateWorldMatrix( true, false );
  3357. _m1$1.multiply( object.parent.matrixWorld );
  3358. }
  3359. object.applyMatrix( _m1$1 );
  3360. object.updateWorldMatrix( false, false );
  3361. this.add( object );
  3362. return this;
  3363. },
  3364. getObjectById: function ( id ) {
  3365. return this.getObjectByProperty( 'id', id );
  3366. },
  3367. getObjectByName: function ( name ) {
  3368. return this.getObjectByProperty( 'name', name );
  3369. },
  3370. getObjectByProperty: function ( name, value ) {
  3371. if ( this[ name ] === value ) return this;
  3372. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3373. var child = this.children[ i ];
  3374. var object = child.getObjectByProperty( name, value );
  3375. if ( object !== undefined ) {
  3376. return object;
  3377. }
  3378. }
  3379. return undefined;
  3380. },
  3381. getWorldPosition: function ( target ) {
  3382. if ( target === undefined ) {
  3383. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3384. target = new Vector3();
  3385. }
  3386. this.updateMatrixWorld( true );
  3387. return target.setFromMatrixPosition( this.matrixWorld );
  3388. },
  3389. getWorldQuaternion: function ( target ) {
  3390. if ( target === undefined ) {
  3391. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3392. target = new Quaternion();
  3393. }
  3394. this.updateMatrixWorld( true );
  3395. this.matrixWorld.decompose( _position, target, _scale );
  3396. return target;
  3397. },
  3398. getWorldScale: function ( target ) {
  3399. if ( target === undefined ) {
  3400. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3401. target = new Vector3();
  3402. }
  3403. this.updateMatrixWorld( true );
  3404. this.matrixWorld.decompose( _position, _quaternion$2, target );
  3405. return target;
  3406. },
  3407. getWorldDirection: function ( target ) {
  3408. if ( target === undefined ) {
  3409. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3410. target = new Vector3();
  3411. }
  3412. this.updateMatrixWorld( true );
  3413. var e = this.matrixWorld.elements;
  3414. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3415. },
  3416. raycast: function () {},
  3417. traverse: function ( callback ) {
  3418. callback( this );
  3419. var children = this.children;
  3420. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3421. children[ i ].traverse( callback );
  3422. }
  3423. },
  3424. traverseVisible: function ( callback ) {
  3425. if ( this.visible === false ) return;
  3426. callback( this );
  3427. var children = this.children;
  3428. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3429. children[ i ].traverseVisible( callback );
  3430. }
  3431. },
  3432. traverseAncestors: function ( callback ) {
  3433. var parent = this.parent;
  3434. if ( parent !== null ) {
  3435. callback( parent );
  3436. parent.traverseAncestors( callback );
  3437. }
  3438. },
  3439. updateMatrix: function () {
  3440. this.matrix.compose( this.position, this.quaternion, this.scale );
  3441. this.matrixWorldNeedsUpdate = true;
  3442. },
  3443. updateMatrixWorld: function ( force ) {
  3444. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3445. if ( this.matrixWorldNeedsUpdate || force ) {
  3446. if ( this.parent === null ) {
  3447. this.matrixWorld.copy( this.matrix );
  3448. } else {
  3449. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3450. }
  3451. this.matrixWorldNeedsUpdate = false;
  3452. force = true;
  3453. }
  3454. // update children
  3455. var children = this.children;
  3456. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3457. children[ i ].updateMatrixWorld( force );
  3458. }
  3459. },
  3460. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3461. var parent = this.parent;
  3462. if ( updateParents === true && parent !== null ) {
  3463. parent.updateWorldMatrix( true, false );
  3464. }
  3465. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3466. if ( this.parent === null ) {
  3467. this.matrixWorld.copy( this.matrix );
  3468. } else {
  3469. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3470. }
  3471. // update children
  3472. if ( updateChildren === true ) {
  3473. var children = this.children;
  3474. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3475. children[ i ].updateWorldMatrix( false, true );
  3476. }
  3477. }
  3478. },
  3479. toJSON: function ( meta ) {
  3480. // meta is a string when called from JSON.stringify
  3481. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3482. var output = {};
  3483. // meta is a hash used to collect geometries, materials.
  3484. // not providing it implies that this is the root object
  3485. // being serialized.
  3486. if ( isRootObject ) {
  3487. // initialize meta obj
  3488. meta = {
  3489. geometries: {},
  3490. materials: {},
  3491. textures: {},
  3492. images: {},
  3493. shapes: {}
  3494. };
  3495. output.metadata = {
  3496. version: 4.5,
  3497. type: 'Object',
  3498. generator: 'Object3D.toJSON'
  3499. };
  3500. }
  3501. // standard Object3D serialization
  3502. var object = {};
  3503. object.uuid = this.uuid;
  3504. object.type = this.type;
  3505. if ( this.name !== '' ) object.name = this.name;
  3506. if ( this.castShadow === true ) object.castShadow = true;
  3507. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3508. if ( this.visible === false ) object.visible = false;
  3509. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3510. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3511. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3512. object.layers = this.layers.mask;
  3513. object.matrix = this.matrix.toArray();
  3514. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3515. // object specific properties
  3516. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  3517. if ( this.isInstancedMesh ) {
  3518. object.type = 'InstancedMesh';
  3519. object.count = this.count;
  3520. object.instanceMatrix = this.instanceMatrix.toJSON();
  3521. }
  3522. //
  3523. function serialize( library, element ) {
  3524. if ( library[ element.uuid ] === undefined ) {
  3525. library[ element.uuid ] = element.toJSON( meta );
  3526. }
  3527. return element.uuid;
  3528. }
  3529. if ( this.isMesh || this.isLine || this.isPoints ) {
  3530. object.geometry = serialize( meta.geometries, this.geometry );
  3531. var parameters = this.geometry.parameters;
  3532. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3533. var shapes = parameters.shapes;
  3534. if ( Array.isArray( shapes ) ) {
  3535. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3536. var shape = shapes[ i ];
  3537. serialize( meta.shapes, shape );
  3538. }
  3539. } else {
  3540. serialize( meta.shapes, shapes );
  3541. }
  3542. }
  3543. }
  3544. if ( this.material !== undefined ) {
  3545. if ( Array.isArray( this.material ) ) {
  3546. var uuids = [];
  3547. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  3548. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3549. }
  3550. object.material = uuids;
  3551. } else {
  3552. object.material = serialize( meta.materials, this.material );
  3553. }
  3554. }
  3555. //
  3556. if ( this.children.length > 0 ) {
  3557. object.children = [];
  3558. for ( var i = 0; i < this.children.length; i ++ ) {
  3559. object.children.push( this.children[ i ].toJSON( meta ).object );
  3560. }
  3561. }
  3562. if ( isRootObject ) {
  3563. var geometries = extractFromCache( meta.geometries );
  3564. var materials = extractFromCache( meta.materials );
  3565. var textures = extractFromCache( meta.textures );
  3566. var images = extractFromCache( meta.images );
  3567. var shapes = extractFromCache( meta.shapes );
  3568. if ( geometries.length > 0 ) output.geometries = geometries;
  3569. if ( materials.length > 0 ) output.materials = materials;
  3570. if ( textures.length > 0 ) output.textures = textures;
  3571. if ( images.length > 0 ) output.images = images;
  3572. if ( shapes.length > 0 ) output.shapes = shapes;
  3573. }
  3574. output.object = object;
  3575. return output;
  3576. // extract data from the cache hash
  3577. // remove metadata on each item
  3578. // and return as array
  3579. function extractFromCache( cache ) {
  3580. var values = [];
  3581. for ( var key in cache ) {
  3582. var data = cache[ key ];
  3583. delete data.metadata;
  3584. values.push( data );
  3585. }
  3586. return values;
  3587. }
  3588. },
  3589. clone: function ( recursive ) {
  3590. return new this.constructor().copy( this, recursive );
  3591. },
  3592. copy: function ( source, recursive ) {
  3593. if ( recursive === undefined ) recursive = true;
  3594. this.name = source.name;
  3595. this.up.copy( source.up );
  3596. this.position.copy( source.position );
  3597. this.quaternion.copy( source.quaternion );
  3598. this.scale.copy( source.scale );
  3599. this.matrix.copy( source.matrix );
  3600. this.matrixWorld.copy( source.matrixWorld );
  3601. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3602. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3603. this.layers.mask = source.layers.mask;
  3604. this.visible = source.visible;
  3605. this.castShadow = source.castShadow;
  3606. this.receiveShadow = source.receiveShadow;
  3607. this.frustumCulled = source.frustumCulled;
  3608. this.renderOrder = source.renderOrder;
  3609. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3610. if ( recursive === true ) {
  3611. for ( var i = 0; i < source.children.length; i ++ ) {
  3612. var child = source.children[ i ];
  3613. this.add( child.clone() );
  3614. }
  3615. }
  3616. return this;
  3617. }
  3618. } );
  3619. /**
  3620. * @author mrdoob / http://mrdoob.com/
  3621. */
  3622. function Scene() {
  3623. Object3D.call( this );
  3624. this.type = 'Scene';
  3625. this.background = null;
  3626. this.fog = null;
  3627. this.overrideMaterial = null;
  3628. this.autoUpdate = true; // checked by the renderer
  3629. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3630. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3631. }
  3632. }
  3633. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3634. constructor: Scene,
  3635. isScene: true,
  3636. copy: function ( source, recursive ) {
  3637. Object3D.prototype.copy.call( this, source, recursive );
  3638. if ( source.background !== null ) this.background = source.background.clone();
  3639. if ( source.fog !== null ) this.fog = source.fog.clone();
  3640. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3641. this.autoUpdate = source.autoUpdate;
  3642. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3643. return this;
  3644. },
  3645. toJSON: function ( meta ) {
  3646. var data = Object3D.prototype.toJSON.call( this, meta );
  3647. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3648. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3649. return data;
  3650. },
  3651. dispose: function () {
  3652. this.dispatchEvent( { type: 'dispose' } );
  3653. }
  3654. } );
  3655. var _points = [
  3656. new Vector3(),
  3657. new Vector3(),
  3658. new Vector3(),
  3659. new Vector3(),
  3660. new Vector3(),
  3661. new Vector3(),
  3662. new Vector3(),
  3663. new Vector3()
  3664. ];
  3665. var _vector$2 = new Vector3();
  3666. var _box = new Box3();
  3667. // triangle centered vertices
  3668. var _v0 = new Vector3();
  3669. var _v1$2 = new Vector3();
  3670. var _v2 = new Vector3();
  3671. // triangle edge vectors
  3672. var _f0 = new Vector3();
  3673. var _f1 = new Vector3();
  3674. var _f2 = new Vector3();
  3675. var _center = new Vector3();
  3676. var _extents = new Vector3();
  3677. var _triangleNormal = new Vector3();
  3678. var _testAxis = new Vector3();
  3679. /**
  3680. * @author bhouston / http://clara.io
  3681. * @author WestLangley / http://github.com/WestLangley
  3682. */
  3683. function Box3( min, max ) {
  3684. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3685. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3686. }
  3687. Object.assign( Box3.prototype, {
  3688. isBox3: true,
  3689. set: function ( min, max ) {
  3690. this.min.copy( min );
  3691. this.max.copy( max );
  3692. return this;
  3693. },
  3694. setFromArray: function ( array ) {
  3695. var minX = + Infinity;
  3696. var minY = + Infinity;
  3697. var minZ = + Infinity;
  3698. var maxX = - Infinity;
  3699. var maxY = - Infinity;
  3700. var maxZ = - Infinity;
  3701. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3702. var x = array[ i ];
  3703. var y = array[ i + 1 ];
  3704. var z = array[ i + 2 ];
  3705. if ( x < minX ) minX = x;
  3706. if ( y < minY ) minY = y;
  3707. if ( z < minZ ) minZ = z;
  3708. if ( x > maxX ) maxX = x;
  3709. if ( y > maxY ) maxY = y;
  3710. if ( z > maxZ ) maxZ = z;
  3711. }
  3712. this.min.set( minX, minY, minZ );
  3713. this.max.set( maxX, maxY, maxZ );
  3714. return this;
  3715. },
  3716. setFromBufferAttribute: function ( attribute ) {
  3717. var minX = + Infinity;
  3718. var minY = + Infinity;
  3719. var minZ = + Infinity;
  3720. var maxX = - Infinity;
  3721. var maxY = - Infinity;
  3722. var maxZ = - Infinity;
  3723. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3724. var x = attribute.getX( i );
  3725. var y = attribute.getY( i );
  3726. var z = attribute.getZ( i );
  3727. if ( x < minX ) minX = x;
  3728. if ( y < minY ) minY = y;
  3729. if ( z < minZ ) minZ = z;
  3730. if ( x > maxX ) maxX = x;
  3731. if ( y > maxY ) maxY = y;
  3732. if ( z > maxZ ) maxZ = z;
  3733. }
  3734. this.min.set( minX, minY, minZ );
  3735. this.max.set( maxX, maxY, maxZ );
  3736. return this;
  3737. },
  3738. setFromPoints: function ( points ) {
  3739. this.makeEmpty();
  3740. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3741. this.expandByPoint( points[ i ] );
  3742. }
  3743. return this;
  3744. },
  3745. setFromCenterAndSize: function ( center, size ) {
  3746. var halfSize = _vector$2.copy( size ).multiplyScalar( 0.5 );
  3747. this.min.copy( center ).sub( halfSize );
  3748. this.max.copy( center ).add( halfSize );
  3749. return this;
  3750. },
  3751. setFromObject: function ( object ) {
  3752. this.makeEmpty();
  3753. return this.expandByObject( object );
  3754. },
  3755. clone: function () {
  3756. return new this.constructor().copy( this );
  3757. },
  3758. copy: function ( box ) {
  3759. this.min.copy( box.min );
  3760. this.max.copy( box.max );
  3761. return this;
  3762. },
  3763. makeEmpty: function () {
  3764. this.min.x = this.min.y = this.min.z = + Infinity;
  3765. this.max.x = this.max.y = this.max.z = - Infinity;
  3766. return this;
  3767. },
  3768. isEmpty: function () {
  3769. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3770. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3771. },
  3772. getCenter: function ( target ) {
  3773. if ( target === undefined ) {
  3774. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3775. target = new Vector3();
  3776. }
  3777. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3778. },
  3779. getSize: function ( target ) {
  3780. if ( target === undefined ) {
  3781. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3782. target = new Vector3();
  3783. }
  3784. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3785. },
  3786. expandByPoint: function ( point ) {
  3787. this.min.min( point );
  3788. this.max.max( point );
  3789. return this;
  3790. },
  3791. expandByVector: function ( vector ) {
  3792. this.min.sub( vector );
  3793. this.max.add( vector );
  3794. return this;
  3795. },
  3796. expandByScalar: function ( scalar ) {
  3797. this.min.addScalar( - scalar );
  3798. this.max.addScalar( scalar );
  3799. return this;
  3800. },
  3801. expandByObject: function ( object ) {
  3802. // Computes the world-axis-aligned bounding box of an object (including its children),
  3803. // accounting for both the object's, and children's, world transforms
  3804. object.updateWorldMatrix( false, false );
  3805. var geometry = object.geometry;
  3806. if ( geometry !== undefined ) {
  3807. if ( geometry.boundingBox === null ) {
  3808. geometry.computeBoundingBox();
  3809. }
  3810. _box.copy( geometry.boundingBox );
  3811. _box.applyMatrix4( object.matrixWorld );
  3812. this.expandByPoint( _box.min );
  3813. this.expandByPoint( _box.max );
  3814. }
  3815. var children = object.children;
  3816. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3817. this.expandByObject( children[ i ] );
  3818. }
  3819. return this;
  3820. },
  3821. containsPoint: function ( point ) {
  3822. return point.x < this.min.x || point.x > this.max.x ||
  3823. point.y < this.min.y || point.y > this.max.y ||
  3824. point.z < this.min.z || point.z > this.max.z ? false : true;
  3825. },
  3826. containsBox: function ( box ) {
  3827. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3828. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3829. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3830. },
  3831. getParameter: function ( point, target ) {
  3832. // This can potentially have a divide by zero if the box
  3833. // has a size dimension of 0.
  3834. if ( target === undefined ) {
  3835. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3836. target = new Vector3();
  3837. }
  3838. return target.set(
  3839. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3840. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3841. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3842. );
  3843. },
  3844. intersectsBox: function ( box ) {
  3845. // using 6 splitting planes to rule out intersections.
  3846. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3847. box.max.y < this.min.y || box.min.y > this.max.y ||
  3848. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3849. },
  3850. intersectsSphere: function ( sphere ) {
  3851. // Find the point on the AABB closest to the sphere center.
  3852. this.clampPoint( sphere.center, _vector$2 );
  3853. // If that point is inside the sphere, the AABB and sphere intersect.
  3854. return _vector$2.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3855. },
  3856. intersectsPlane: function ( plane ) {
  3857. // We compute the minimum and maximum dot product values. If those values
  3858. // are on the same side (back or front) of the plane, then there is no intersection.
  3859. var min, max;
  3860. if ( plane.normal.x > 0 ) {
  3861. min = plane.normal.x * this.min.x;
  3862. max = plane.normal.x * this.max.x;
  3863. } else {
  3864. min = plane.normal.x * this.max.x;
  3865. max = plane.normal.x * this.min.x;
  3866. }
  3867. if ( plane.normal.y > 0 ) {
  3868. min += plane.normal.y * this.min.y;
  3869. max += plane.normal.y * this.max.y;
  3870. } else {
  3871. min += plane.normal.y * this.max.y;
  3872. max += plane.normal.y * this.min.y;
  3873. }
  3874. if ( plane.normal.z > 0 ) {
  3875. min += plane.normal.z * this.min.z;
  3876. max += plane.normal.z * this.max.z;
  3877. } else {
  3878. min += plane.normal.z * this.max.z;
  3879. max += plane.normal.z * this.min.z;
  3880. }
  3881. return ( min <= - plane.constant && max >= - plane.constant );
  3882. },
  3883. intersectsTriangle: function ( triangle ) {
  3884. if ( this.isEmpty() ) {
  3885. return false;
  3886. }
  3887. // compute box center and extents
  3888. this.getCenter( _center );
  3889. _extents.subVectors( this.max, _center );
  3890. // translate triangle to aabb origin
  3891. _v0.subVectors( triangle.a, _center );
  3892. _v1$2.subVectors( triangle.b, _center );
  3893. _v2.subVectors( triangle.c, _center );
  3894. // compute edge vectors for triangle
  3895. _f0.subVectors( _v1$2, _v0 );
  3896. _f1.subVectors( _v2, _v1$2 );
  3897. _f2.subVectors( _v0, _v2 );
  3898. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3899. // 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
  3900. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3901. var axes = [
  3902. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  3903. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  3904. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  3905. ];
  3906. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  3907. return false;
  3908. }
  3909. // test 3 face normals from the aabb
  3910. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3911. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  3912. return false;
  3913. }
  3914. // finally testing the face normal of the triangle
  3915. // use already existing triangle edge vectors here
  3916. _triangleNormal.crossVectors( _f0, _f1 );
  3917. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  3918. return satForAxes( axes, _v0, _v1$2, _v2, _extents );
  3919. },
  3920. clampPoint: function ( point, target ) {
  3921. if ( target === undefined ) {
  3922. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3923. target = new Vector3();
  3924. }
  3925. return target.copy( point ).clamp( this.min, this.max );
  3926. },
  3927. distanceToPoint: function ( point ) {
  3928. var clampedPoint = _vector$2.copy( point ).clamp( this.min, this.max );
  3929. return clampedPoint.sub( point ).length();
  3930. },
  3931. getBoundingSphere: function ( target ) {
  3932. if ( target === undefined ) {
  3933. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3934. //target = new Sphere(); // removed to avoid cyclic dependency
  3935. }
  3936. this.getCenter( target.center );
  3937. target.radius = this.getSize( _vector$2 ).length() * 0.5;
  3938. return target;
  3939. },
  3940. intersect: function ( box ) {
  3941. this.min.max( box.min );
  3942. this.max.min( box.max );
  3943. // 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.
  3944. if ( this.isEmpty() ) this.makeEmpty();
  3945. return this;
  3946. },
  3947. union: function ( box ) {
  3948. this.min.min( box.min );
  3949. this.max.max( box.max );
  3950. return this;
  3951. },
  3952. applyMatrix4: function ( matrix ) {
  3953. // transform of empty box is an empty box.
  3954. if ( this.isEmpty() ) return this;
  3955. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3956. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3957. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3958. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3959. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3960. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3961. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3962. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3963. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3964. this.setFromPoints( _points );
  3965. return this;
  3966. },
  3967. translate: function ( offset ) {
  3968. this.min.add( offset );
  3969. this.max.add( offset );
  3970. return this;
  3971. },
  3972. equals: function ( box ) {
  3973. return box.min.equals( this.min ) && box.max.equals( this.max );
  3974. }
  3975. } );
  3976. function satForAxes( axes, v0, v1, v2, extents ) {
  3977. var i, j;
  3978. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3979. _testAxis.fromArray( axes, i );
  3980. // project the aabb onto the seperating axis
  3981. var r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  3982. // project all 3 vertices of the triangle onto the seperating axis
  3983. var p0 = v0.dot( _testAxis );
  3984. var p1 = v1.dot( _testAxis );
  3985. var p2 = v2.dot( _testAxis );
  3986. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3987. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3988. // points of the projected triangle are outside the projected half-length of the aabb
  3989. // the axis is seperating and we can exit
  3990. return false;
  3991. }
  3992. }
  3993. return true;
  3994. }
  3995. var _box$1 = new Box3();
  3996. /**
  3997. * @author bhouston / http://clara.io
  3998. * @author mrdoob / http://mrdoob.com/
  3999. */
  4000. function Sphere( center, radius ) {
  4001. this.center = ( center !== undefined ) ? center : new Vector3();
  4002. this.radius = ( radius !== undefined ) ? radius : 0;
  4003. }
  4004. Object.assign( Sphere.prototype, {
  4005. set: function ( center, radius ) {
  4006. this.center.copy( center );
  4007. this.radius = radius;
  4008. return this;
  4009. },
  4010. setFromPoints: function ( points, optionalCenter ) {
  4011. var center = this.center;
  4012. if ( optionalCenter !== undefined ) {
  4013. center.copy( optionalCenter );
  4014. } else {
  4015. _box$1.setFromPoints( points ).getCenter( center );
  4016. }
  4017. var maxRadiusSq = 0;
  4018. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4019. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4020. }
  4021. this.radius = Math.sqrt( maxRadiusSq );
  4022. return this;
  4023. },
  4024. clone: function () {
  4025. return new this.constructor().copy( this );
  4026. },
  4027. copy: function ( sphere ) {
  4028. this.center.copy( sphere.center );
  4029. this.radius = sphere.radius;
  4030. return this;
  4031. },
  4032. empty: function () {
  4033. return ( this.radius <= 0 );
  4034. },
  4035. containsPoint: function ( point ) {
  4036. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4037. },
  4038. distanceToPoint: function ( point ) {
  4039. return ( point.distanceTo( this.center ) - this.radius );
  4040. },
  4041. intersectsSphere: function ( sphere ) {
  4042. var radiusSum = this.radius + sphere.radius;
  4043. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4044. },
  4045. intersectsBox: function ( box ) {
  4046. return box.intersectsSphere( this );
  4047. },
  4048. intersectsPlane: function ( plane ) {
  4049. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4050. },
  4051. clampPoint: function ( point, target ) {
  4052. var deltaLengthSq = this.center.distanceToSquared( point );
  4053. if ( target === undefined ) {
  4054. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4055. target = new Vector3();
  4056. }
  4057. target.copy( point );
  4058. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4059. target.sub( this.center ).normalize();
  4060. target.multiplyScalar( this.radius ).add( this.center );
  4061. }
  4062. return target;
  4063. },
  4064. getBoundingBox: function ( target ) {
  4065. if ( target === undefined ) {
  4066. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4067. target = new Box3();
  4068. }
  4069. target.set( this.center, this.center );
  4070. target.expandByScalar( this.radius );
  4071. return target;
  4072. },
  4073. applyMatrix4: function ( matrix ) {
  4074. this.center.applyMatrix4( matrix );
  4075. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4076. return this;
  4077. },
  4078. translate: function ( offset ) {
  4079. this.center.add( offset );
  4080. return this;
  4081. },
  4082. equals: function ( sphere ) {
  4083. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4084. }
  4085. } );
  4086. var _vector$3 = new Vector3();
  4087. var _segCenter = new Vector3();
  4088. var _segDir = new Vector3();
  4089. var _diff = new Vector3();
  4090. var _edge1 = new Vector3();
  4091. var _edge2 = new Vector3();
  4092. var _normal = new Vector3();
  4093. /**
  4094. * @author bhouston / http://clara.io
  4095. */
  4096. function Ray( origin, direction ) {
  4097. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4098. this.direction = ( direction !== undefined ) ? direction : new Vector3( 0, 0, - 1 );
  4099. }
  4100. Object.assign( Ray.prototype, {
  4101. set: function ( origin, direction ) {
  4102. this.origin.copy( origin );
  4103. this.direction.copy( direction );
  4104. return this;
  4105. },
  4106. clone: function () {
  4107. return new this.constructor().copy( this );
  4108. },
  4109. copy: function ( ray ) {
  4110. this.origin.copy( ray.origin );
  4111. this.direction.copy( ray.direction );
  4112. return this;
  4113. },
  4114. at: function ( t, target ) {
  4115. if ( target === undefined ) {
  4116. console.warn( 'THREE.Ray: .at() target is now required' );
  4117. target = new Vector3();
  4118. }
  4119. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4120. },
  4121. lookAt: function ( v ) {
  4122. this.direction.copy( v ).sub( this.origin ).normalize();
  4123. return this;
  4124. },
  4125. recast: function ( t ) {
  4126. this.origin.copy( this.at( t, _vector$3 ) );
  4127. return this;
  4128. },
  4129. closestPointToPoint: function ( point, target ) {
  4130. if ( target === undefined ) {
  4131. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4132. target = new Vector3();
  4133. }
  4134. target.subVectors( point, this.origin );
  4135. var directionDistance = target.dot( this.direction );
  4136. if ( directionDistance < 0 ) {
  4137. return target.copy( this.origin );
  4138. }
  4139. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4140. },
  4141. distanceToPoint: function ( point ) {
  4142. return Math.sqrt( this.distanceSqToPoint( point ) );
  4143. },
  4144. distanceSqToPoint: function ( point ) {
  4145. var directionDistance = _vector$3.subVectors( point, this.origin ).dot( this.direction );
  4146. // point behind the ray
  4147. if ( directionDistance < 0 ) {
  4148. return this.origin.distanceToSquared( point );
  4149. }
  4150. _vector$3.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4151. return _vector$3.distanceToSquared( point );
  4152. },
  4153. distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4154. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4155. // It returns the min distance between the ray and the segment
  4156. // defined by v0 and v1
  4157. // It can also set two optional targets :
  4158. // - The closest point on the ray
  4159. // - The closest point on the segment
  4160. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4161. _segDir.copy( v1 ).sub( v0 ).normalize();
  4162. _diff.copy( this.origin ).sub( _segCenter );
  4163. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4164. var a01 = - this.direction.dot( _segDir );
  4165. var b0 = _diff.dot( this.direction );
  4166. var b1 = - _diff.dot( _segDir );
  4167. var c = _diff.lengthSq();
  4168. var det = Math.abs( 1 - a01 * a01 );
  4169. var s0, s1, sqrDist, extDet;
  4170. if ( det > 0 ) {
  4171. // The ray and segment are not parallel.
  4172. s0 = a01 * b1 - b0;
  4173. s1 = a01 * b0 - b1;
  4174. extDet = segExtent * det;
  4175. if ( s0 >= 0 ) {
  4176. if ( s1 >= - extDet ) {
  4177. if ( s1 <= extDet ) {
  4178. // region 0
  4179. // Minimum at interior points of ray and segment.
  4180. var invDet = 1 / det;
  4181. s0 *= invDet;
  4182. s1 *= invDet;
  4183. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4184. } else {
  4185. // region 1
  4186. s1 = segExtent;
  4187. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4188. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4189. }
  4190. } else {
  4191. // region 5
  4192. s1 = - segExtent;
  4193. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4194. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4195. }
  4196. } else {
  4197. if ( s1 <= - extDet ) {
  4198. // region 4
  4199. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4200. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4201. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4202. } else if ( s1 <= extDet ) {
  4203. // region 3
  4204. s0 = 0;
  4205. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4206. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4207. } else {
  4208. // region 2
  4209. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4210. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4211. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4212. }
  4213. }
  4214. } else {
  4215. // Ray and segment are parallel.
  4216. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4217. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4218. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4219. }
  4220. if ( optionalPointOnRay ) {
  4221. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4222. }
  4223. if ( optionalPointOnSegment ) {
  4224. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  4225. }
  4226. return sqrDist;
  4227. },
  4228. intersectSphere: function ( sphere, target ) {
  4229. _vector$3.subVectors( sphere.center, this.origin );
  4230. var tca = _vector$3.dot( this.direction );
  4231. var d2 = _vector$3.dot( _vector$3 ) - tca * tca;
  4232. var radius2 = sphere.radius * sphere.radius;
  4233. if ( d2 > radius2 ) return null;
  4234. var thc = Math.sqrt( radius2 - d2 );
  4235. // t0 = first intersect point - entrance on front of sphere
  4236. var t0 = tca - thc;
  4237. // t1 = second intersect point - exit point on back of sphere
  4238. var t1 = tca + thc;
  4239. // test to see if both t0 and t1 are behind the ray - if so, return null
  4240. if ( t0 < 0 && t1 < 0 ) return null;
  4241. // test to see if t0 is behind the ray:
  4242. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4243. // in order to always return an intersect point that is in front of the ray.
  4244. if ( t0 < 0 ) return this.at( t1, target );
  4245. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4246. return this.at( t0, target );
  4247. },
  4248. intersectsSphere: function ( sphere ) {
  4249. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4250. },
  4251. distanceToPlane: function ( plane ) {
  4252. var denominator = plane.normal.dot( this.direction );
  4253. if ( denominator === 0 ) {
  4254. // line is coplanar, return origin
  4255. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4256. return 0;
  4257. }
  4258. // Null is preferable to undefined since undefined means.... it is undefined
  4259. return null;
  4260. }
  4261. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4262. // Return if the ray never intersects the plane
  4263. return t >= 0 ? t : null;
  4264. },
  4265. intersectPlane: function ( plane, target ) {
  4266. var t = this.distanceToPlane( plane );
  4267. if ( t === null ) {
  4268. return null;
  4269. }
  4270. return this.at( t, target );
  4271. },
  4272. intersectsPlane: function ( plane ) {
  4273. // check if the ray lies on the plane first
  4274. var distToPoint = plane.distanceToPoint( this.origin );
  4275. if ( distToPoint === 0 ) {
  4276. return true;
  4277. }
  4278. var denominator = plane.normal.dot( this.direction );
  4279. if ( denominator * distToPoint < 0 ) {
  4280. return true;
  4281. }
  4282. // ray origin is behind the plane (and is pointing behind it)
  4283. return false;
  4284. },
  4285. intersectBox: function ( box, target ) {
  4286. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4287. var invdirx = 1 / this.direction.x,
  4288. invdiry = 1 / this.direction.y,
  4289. invdirz = 1 / this.direction.z;
  4290. var origin = this.origin;
  4291. if ( invdirx >= 0 ) {
  4292. tmin = ( box.min.x - origin.x ) * invdirx;
  4293. tmax = ( box.max.x - origin.x ) * invdirx;
  4294. } else {
  4295. tmin = ( box.max.x - origin.x ) * invdirx;
  4296. tmax = ( box.min.x - origin.x ) * invdirx;
  4297. }
  4298. if ( invdiry >= 0 ) {
  4299. tymin = ( box.min.y - origin.y ) * invdiry;
  4300. tymax = ( box.max.y - origin.y ) * invdiry;
  4301. } else {
  4302. tymin = ( box.max.y - origin.y ) * invdiry;
  4303. tymax = ( box.min.y - origin.y ) * invdiry;
  4304. }
  4305. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4306. // These lines also handle the case where tmin or tmax is NaN
  4307. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4308. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4309. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4310. if ( invdirz >= 0 ) {
  4311. tzmin = ( box.min.z - origin.z ) * invdirz;
  4312. tzmax = ( box.max.z - origin.z ) * invdirz;
  4313. } else {
  4314. tzmin = ( box.max.z - origin.z ) * invdirz;
  4315. tzmax = ( box.min.z - origin.z ) * invdirz;
  4316. }
  4317. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4318. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4319. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4320. //return point closest to the ray (positive side)
  4321. if ( tmax < 0 ) return null;
  4322. return this.at( tmin >= 0 ? tmin : tmax, target );
  4323. },
  4324. intersectsBox: function ( box ) {
  4325. return this.intersectBox( box, _vector$3 ) !== null;
  4326. },
  4327. intersectTriangle: function ( a, b, c, backfaceCulling, target ) {
  4328. // Compute the offset origin, edges, and normal.
  4329. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4330. _edge1.subVectors( b, a );
  4331. _edge2.subVectors( c, a );
  4332. _normal.crossVectors( _edge1, _edge2 );
  4333. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4334. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4335. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4336. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4337. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4338. var DdN = this.direction.dot( _normal );
  4339. var sign;
  4340. if ( DdN > 0 ) {
  4341. if ( backfaceCulling ) return null;
  4342. sign = 1;
  4343. } else if ( DdN < 0 ) {
  4344. sign = - 1;
  4345. DdN = - DdN;
  4346. } else {
  4347. return null;
  4348. }
  4349. _diff.subVectors( this.origin, a );
  4350. var DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  4351. // b1 < 0, no intersection
  4352. if ( DdQxE2 < 0 ) {
  4353. return null;
  4354. }
  4355. var DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  4356. // b2 < 0, no intersection
  4357. if ( DdE1xQ < 0 ) {
  4358. return null;
  4359. }
  4360. // b1+b2 > 1, no intersection
  4361. if ( DdQxE2 + DdE1xQ > DdN ) {
  4362. return null;
  4363. }
  4364. // Line intersects triangle, check if ray does.
  4365. var QdN = - sign * _diff.dot( _normal );
  4366. // t < 0, no intersection
  4367. if ( QdN < 0 ) {
  4368. return null;
  4369. }
  4370. // Ray intersects triangle.
  4371. return this.at( QdN / DdN, target );
  4372. },
  4373. applyMatrix4: function ( matrix4 ) {
  4374. this.origin.applyMatrix4( matrix4 );
  4375. this.direction.transformDirection( matrix4 );
  4376. return this;
  4377. },
  4378. equals: function ( ray ) {
  4379. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4380. }
  4381. } );
  4382. /**
  4383. * @author bhouston / http://clara.io
  4384. */
  4385. var _vector1 = new Vector3();
  4386. var _vector2 = new Vector3();
  4387. var _normalMatrix = new Matrix3();
  4388. function Plane( normal, constant ) {
  4389. // normal is assumed to be normalized
  4390. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  4391. this.constant = ( constant !== undefined ) ? constant : 0;
  4392. }
  4393. Object.assign( Plane.prototype, {
  4394. isPlane: true,
  4395. set: function ( normal, constant ) {
  4396. this.normal.copy( normal );
  4397. this.constant = constant;
  4398. return this;
  4399. },
  4400. setComponents: function ( x, y, z, w ) {
  4401. this.normal.set( x, y, z );
  4402. this.constant = w;
  4403. return this;
  4404. },
  4405. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  4406. this.normal.copy( normal );
  4407. this.constant = - point.dot( this.normal );
  4408. return this;
  4409. },
  4410. setFromCoplanarPoints: function ( a, b, c ) {
  4411. var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  4412. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4413. this.setFromNormalAndCoplanarPoint( normal, a );
  4414. return this;
  4415. },
  4416. clone: function () {
  4417. return new this.constructor().copy( this );
  4418. },
  4419. copy: function ( plane ) {
  4420. this.normal.copy( plane.normal );
  4421. this.constant = plane.constant;
  4422. return this;
  4423. },
  4424. normalize: function () {
  4425. // Note: will lead to a divide by zero if the plane is invalid.
  4426. var inverseNormalLength = 1.0 / this.normal.length();
  4427. this.normal.multiplyScalar( inverseNormalLength );
  4428. this.constant *= inverseNormalLength;
  4429. return this;
  4430. },
  4431. negate: function () {
  4432. this.constant *= - 1;
  4433. this.normal.negate();
  4434. return this;
  4435. },
  4436. distanceToPoint: function ( point ) {
  4437. return this.normal.dot( point ) + this.constant;
  4438. },
  4439. distanceToSphere: function ( sphere ) {
  4440. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4441. },
  4442. projectPoint: function ( point, target ) {
  4443. if ( target === undefined ) {
  4444. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  4445. target = new Vector3();
  4446. }
  4447. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  4448. },
  4449. intersectLine: function ( line, target ) {
  4450. if ( target === undefined ) {
  4451. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  4452. target = new Vector3();
  4453. }
  4454. var direction = line.delta( _vector1 );
  4455. var denominator = this.normal.dot( direction );
  4456. if ( denominator === 0 ) {
  4457. // line is coplanar, return origin
  4458. if ( this.distanceToPoint( line.start ) === 0 ) {
  4459. return target.copy( line.start );
  4460. }
  4461. // Unsure if this is the correct method to handle this case.
  4462. return undefined;
  4463. }
  4464. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4465. if ( t < 0 || t > 1 ) {
  4466. return undefined;
  4467. }
  4468. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  4469. },
  4470. intersectsLine: function ( line ) {
  4471. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4472. var startSign = this.distanceToPoint( line.start );
  4473. var endSign = this.distanceToPoint( line.end );
  4474. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4475. },
  4476. intersectsBox: function ( box ) {
  4477. return box.intersectsPlane( this );
  4478. },
  4479. intersectsSphere: function ( sphere ) {
  4480. return sphere.intersectsPlane( this );
  4481. },
  4482. coplanarPoint: function ( target ) {
  4483. if ( target === undefined ) {
  4484. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  4485. target = new Vector3();
  4486. }
  4487. return target.copy( this.normal ).multiplyScalar( - this.constant );
  4488. },
  4489. applyMatrix4: function ( matrix, optionalNormalMatrix ) {
  4490. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  4491. var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  4492. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4493. this.constant = - referencePoint.dot( normal );
  4494. return this;
  4495. },
  4496. translate: function ( offset ) {
  4497. this.constant -= offset.dot( this.normal );
  4498. return this;
  4499. },
  4500. equals: function ( plane ) {
  4501. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4502. }
  4503. } );
  4504. /**
  4505. * @author bhouston / http://clara.io
  4506. * @author mrdoob / http://mrdoob.com/
  4507. */
  4508. var _v0$1 = new Vector3();
  4509. var _v1$3 = new Vector3();
  4510. var _v2$1 = new Vector3();
  4511. var _v3 = new Vector3();
  4512. var _vab = new Vector3();
  4513. var _vac = new Vector3();
  4514. var _vbc = new Vector3();
  4515. var _vap = new Vector3();
  4516. var _vbp = new Vector3();
  4517. var _vcp = new Vector3();
  4518. function Triangle( a, b, c ) {
  4519. this.a = ( a !== undefined ) ? a : new Vector3();
  4520. this.b = ( b !== undefined ) ? b : new Vector3();
  4521. this.c = ( c !== undefined ) ? c : new Vector3();
  4522. }
  4523. Object.assign( Triangle, {
  4524. getNormal: function ( a, b, c, target ) {
  4525. if ( target === undefined ) {
  4526. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4527. target = new Vector3();
  4528. }
  4529. target.subVectors( c, b );
  4530. _v0$1.subVectors( a, b );
  4531. target.cross( _v0$1 );
  4532. var targetLengthSq = target.lengthSq();
  4533. if ( targetLengthSq > 0 ) {
  4534. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4535. }
  4536. return target.set( 0, 0, 0 );
  4537. },
  4538. // static/instance method to calculate barycentric coordinates
  4539. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4540. getBarycoord: function ( point, a, b, c, target ) {
  4541. _v0$1.subVectors( c, a );
  4542. _v1$3.subVectors( b, a );
  4543. _v2$1.subVectors( point, a );
  4544. var dot00 = _v0$1.dot( _v0$1 );
  4545. var dot01 = _v0$1.dot( _v1$3 );
  4546. var dot02 = _v0$1.dot( _v2$1 );
  4547. var dot11 = _v1$3.dot( _v1$3 );
  4548. var dot12 = _v1$3.dot( _v2$1 );
  4549. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4550. if ( target === undefined ) {
  4551. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4552. target = new Vector3();
  4553. }
  4554. // collinear or singular triangle
  4555. if ( denom === 0 ) {
  4556. // arbitrary location outside of triangle?
  4557. // not sure if this is the best idea, maybe should be returning undefined
  4558. return target.set( - 2, - 1, - 1 );
  4559. }
  4560. var invDenom = 1 / denom;
  4561. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4562. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4563. // barycentric coordinates must always sum to 1
  4564. return target.set( 1 - u - v, v, u );
  4565. },
  4566. containsPoint: function ( point, a, b, c ) {
  4567. Triangle.getBarycoord( point, a, b, c, _v3 );
  4568. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4569. },
  4570. getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4571. this.getBarycoord( point, p1, p2, p3, _v3 );
  4572. target.set( 0, 0 );
  4573. target.addScaledVector( uv1, _v3.x );
  4574. target.addScaledVector( uv2, _v3.y );
  4575. target.addScaledVector( uv3, _v3.z );
  4576. return target;
  4577. },
  4578. isFrontFacing: function ( a, b, c, direction ) {
  4579. _v0$1.subVectors( c, b );
  4580. _v1$3.subVectors( a, b );
  4581. // strictly front facing
  4582. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4583. }
  4584. } );
  4585. Object.assign( Triangle.prototype, {
  4586. set: function ( a, b, c ) {
  4587. this.a.copy( a );
  4588. this.b.copy( b );
  4589. this.c.copy( c );
  4590. return this;
  4591. },
  4592. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4593. this.a.copy( points[ i0 ] );
  4594. this.b.copy( points[ i1 ] );
  4595. this.c.copy( points[ i2 ] );
  4596. return this;
  4597. },
  4598. clone: function () {
  4599. return new this.constructor().copy( this );
  4600. },
  4601. copy: function ( triangle ) {
  4602. this.a.copy( triangle.a );
  4603. this.b.copy( triangle.b );
  4604. this.c.copy( triangle.c );
  4605. return this;
  4606. },
  4607. getArea: function () {
  4608. _v0$1.subVectors( this.c, this.b );
  4609. _v1$3.subVectors( this.a, this.b );
  4610. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4611. },
  4612. getMidpoint: function ( target ) {
  4613. if ( target === undefined ) {
  4614. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4615. target = new Vector3();
  4616. }
  4617. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4618. },
  4619. getNormal: function ( target ) {
  4620. return Triangle.getNormal( this.a, this.b, this.c, target );
  4621. },
  4622. getPlane: function ( target ) {
  4623. if ( target === undefined ) {
  4624. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4625. target = new Plane();
  4626. }
  4627. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4628. },
  4629. getBarycoord: function ( point, target ) {
  4630. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4631. },
  4632. getUV: function ( point, uv1, uv2, uv3, target ) {
  4633. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4634. },
  4635. containsPoint: function ( point ) {
  4636. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4637. },
  4638. isFrontFacing: function ( direction ) {
  4639. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4640. },
  4641. intersectsBox: function ( box ) {
  4642. return box.intersectsTriangle( this );
  4643. },
  4644. closestPointToPoint: function ( p, target ) {
  4645. if ( target === undefined ) {
  4646. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4647. target = new Vector3();
  4648. }
  4649. var a = this.a, b = this.b, c = this.c;
  4650. var v, w;
  4651. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4652. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4653. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4654. // basically, we're distinguishing which of the voronoi regions of the triangle
  4655. // the point lies in with the minimum amount of redundant computation.
  4656. _vab.subVectors( b, a );
  4657. _vac.subVectors( c, a );
  4658. _vap.subVectors( p, a );
  4659. var d1 = _vab.dot( _vap );
  4660. var d2 = _vac.dot( _vap );
  4661. if ( d1 <= 0 && d2 <= 0 ) {
  4662. // vertex region of A; barycentric coords (1, 0, 0)
  4663. return target.copy( a );
  4664. }
  4665. _vbp.subVectors( p, b );
  4666. var d3 = _vab.dot( _vbp );
  4667. var d4 = _vac.dot( _vbp );
  4668. if ( d3 >= 0 && d4 <= d3 ) {
  4669. // vertex region of B; barycentric coords (0, 1, 0)
  4670. return target.copy( b );
  4671. }
  4672. var vc = d1 * d4 - d3 * d2;
  4673. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4674. v = d1 / ( d1 - d3 );
  4675. // edge region of AB; barycentric coords (1-v, v, 0)
  4676. return target.copy( a ).addScaledVector( _vab, v );
  4677. }
  4678. _vcp.subVectors( p, c );
  4679. var d5 = _vab.dot( _vcp );
  4680. var d6 = _vac.dot( _vcp );
  4681. if ( d6 >= 0 && d5 <= d6 ) {
  4682. // vertex region of C; barycentric coords (0, 0, 1)
  4683. return target.copy( c );
  4684. }
  4685. var vb = d5 * d2 - d1 * d6;
  4686. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4687. w = d2 / ( d2 - d6 );
  4688. // edge region of AC; barycentric coords (1-w, 0, w)
  4689. return target.copy( a ).addScaledVector( _vac, w );
  4690. }
  4691. var va = d3 * d6 - d5 * d4;
  4692. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4693. _vbc.subVectors( c, b );
  4694. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4695. // edge region of BC; barycentric coords (0, 1-w, w)
  4696. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4697. }
  4698. // face region
  4699. var denom = 1 / ( va + vb + vc );
  4700. // u = va * denom
  4701. v = vb * denom;
  4702. w = vc * denom;
  4703. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4704. },
  4705. equals: function ( triangle ) {
  4706. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4707. }
  4708. } );
  4709. /**
  4710. * @author mrdoob / http://mrdoob.com/
  4711. */
  4712. var _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4713. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4714. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4715. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4716. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4717. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4718. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4719. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4720. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4721. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4722. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4723. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4724. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4725. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4726. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4727. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4728. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4729. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4730. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4731. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4732. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4733. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4734. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4735. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4736. var _hslA = { h: 0, s: 0, l: 0 };
  4737. var _hslB = { h: 0, s: 0, l: 0 };
  4738. function Color( r, g, b ) {
  4739. if ( g === undefined && b === undefined ) {
  4740. // r is THREE.Color, hex or string
  4741. return this.set( r );
  4742. }
  4743. return this.setRGB( r, g, b );
  4744. }
  4745. function hue2rgb( p, q, t ) {
  4746. if ( t < 0 ) t += 1;
  4747. if ( t > 1 ) t -= 1;
  4748. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4749. if ( t < 1 / 2 ) return q;
  4750. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4751. return p;
  4752. }
  4753. function SRGBToLinear( c ) {
  4754. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4755. }
  4756. function LinearToSRGB( c ) {
  4757. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4758. }
  4759. Object.assign( Color.prototype, {
  4760. isColor: true,
  4761. r: 1, g: 1, b: 1,
  4762. set: function ( value ) {
  4763. if ( value && value.isColor ) {
  4764. this.copy( value );
  4765. } else if ( typeof value === 'number' ) {
  4766. this.setHex( value );
  4767. } else if ( typeof value === 'string' ) {
  4768. this.setStyle( value );
  4769. }
  4770. return this;
  4771. },
  4772. setScalar: function ( scalar ) {
  4773. this.r = scalar;
  4774. this.g = scalar;
  4775. this.b = scalar;
  4776. return this;
  4777. },
  4778. setHex: function ( hex ) {
  4779. hex = Math.floor( hex );
  4780. this.r = ( hex >> 16 & 255 ) / 255;
  4781. this.g = ( hex >> 8 & 255 ) / 255;
  4782. this.b = ( hex & 255 ) / 255;
  4783. return this;
  4784. },
  4785. setRGB: function ( r, g, b ) {
  4786. this.r = r;
  4787. this.g = g;
  4788. this.b = b;
  4789. return this;
  4790. },
  4791. setHSL: function ( h, s, l ) {
  4792. // h,s,l ranges are in 0.0 - 1.0
  4793. h = _Math.euclideanModulo( h, 1 );
  4794. s = _Math.clamp( s, 0, 1 );
  4795. l = _Math.clamp( l, 0, 1 );
  4796. if ( s === 0 ) {
  4797. this.r = this.g = this.b = l;
  4798. } else {
  4799. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4800. var q = ( 2 * l ) - p;
  4801. this.r = hue2rgb( q, p, h + 1 / 3 );
  4802. this.g = hue2rgb( q, p, h );
  4803. this.b = hue2rgb( q, p, h - 1 / 3 );
  4804. }
  4805. return this;
  4806. },
  4807. setStyle: function ( style ) {
  4808. function handleAlpha( string ) {
  4809. if ( string === undefined ) return;
  4810. if ( parseFloat( string ) < 1 ) {
  4811. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4812. }
  4813. }
  4814. var m;
  4815. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4816. // rgb / hsl
  4817. var color;
  4818. var name = m[ 1 ];
  4819. var components = m[ 2 ];
  4820. switch ( name ) {
  4821. case 'rgb':
  4822. case 'rgba':
  4823. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4824. // rgb(255,0,0) rgba(255,0,0,0.5)
  4825. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4826. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4827. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4828. handleAlpha( color[ 5 ] );
  4829. return this;
  4830. }
  4831. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4832. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4833. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4834. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4835. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4836. handleAlpha( color[ 5 ] );
  4837. return this;
  4838. }
  4839. break;
  4840. case 'hsl':
  4841. case 'hsla':
  4842. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4843. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4844. var h = parseFloat( color[ 1 ] ) / 360;
  4845. var s = parseInt( color[ 2 ], 10 ) / 100;
  4846. var l = parseInt( color[ 3 ], 10 ) / 100;
  4847. handleAlpha( color[ 5 ] );
  4848. return this.setHSL( h, s, l );
  4849. }
  4850. break;
  4851. }
  4852. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4853. // hex color
  4854. var hex = m[ 1 ];
  4855. var size = hex.length;
  4856. if ( size === 3 ) {
  4857. // #ff0
  4858. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4859. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4860. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4861. return this;
  4862. } else if ( size === 6 ) {
  4863. // #ff0000
  4864. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4865. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4866. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4867. return this;
  4868. }
  4869. }
  4870. if ( style && style.length > 0 ) {
  4871. return this.setColorName( style );
  4872. }
  4873. return this;
  4874. },
  4875. setColorName: function ( style ) {
  4876. // color keywords
  4877. var hex = _colorKeywords[ style ];
  4878. if ( hex !== undefined ) {
  4879. // red
  4880. this.setHex( hex );
  4881. } else {
  4882. // unknown color
  4883. console.warn( 'THREE.Color: Unknown color ' + style );
  4884. }
  4885. return this;
  4886. },
  4887. clone: function () {
  4888. return new this.constructor( this.r, this.g, this.b );
  4889. },
  4890. copy: function ( color ) {
  4891. this.r = color.r;
  4892. this.g = color.g;
  4893. this.b = color.b;
  4894. return this;
  4895. },
  4896. copyGammaToLinear: function ( color, gammaFactor ) {
  4897. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4898. this.r = Math.pow( color.r, gammaFactor );
  4899. this.g = Math.pow( color.g, gammaFactor );
  4900. this.b = Math.pow( color.b, gammaFactor );
  4901. return this;
  4902. },
  4903. copyLinearToGamma: function ( color, gammaFactor ) {
  4904. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4905. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4906. this.r = Math.pow( color.r, safeInverse );
  4907. this.g = Math.pow( color.g, safeInverse );
  4908. this.b = Math.pow( color.b, safeInverse );
  4909. return this;
  4910. },
  4911. convertGammaToLinear: function ( gammaFactor ) {
  4912. this.copyGammaToLinear( this, gammaFactor );
  4913. return this;
  4914. },
  4915. convertLinearToGamma: function ( gammaFactor ) {
  4916. this.copyLinearToGamma( this, gammaFactor );
  4917. return this;
  4918. },
  4919. copySRGBToLinear: function ( color ) {
  4920. this.r = SRGBToLinear( color.r );
  4921. this.g = SRGBToLinear( color.g );
  4922. this.b = SRGBToLinear( color.b );
  4923. return this;
  4924. },
  4925. copyLinearToSRGB: function ( color ) {
  4926. this.r = LinearToSRGB( color.r );
  4927. this.g = LinearToSRGB( color.g );
  4928. this.b = LinearToSRGB( color.b );
  4929. return this;
  4930. },
  4931. convertSRGBToLinear: function () {
  4932. this.copySRGBToLinear( this );
  4933. return this;
  4934. },
  4935. convertLinearToSRGB: function () {
  4936. this.copyLinearToSRGB( this );
  4937. return this;
  4938. },
  4939. getHex: function () {
  4940. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4941. },
  4942. getHexString: function () {
  4943. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4944. },
  4945. getHSL: function ( target ) {
  4946. // h,s,l ranges are in 0.0 - 1.0
  4947. if ( target === undefined ) {
  4948. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4949. target = { h: 0, s: 0, l: 0 };
  4950. }
  4951. var r = this.r, g = this.g, b = this.b;
  4952. var max = Math.max( r, g, b );
  4953. var min = Math.min( r, g, b );
  4954. var hue, saturation;
  4955. var lightness = ( min + max ) / 2.0;
  4956. if ( min === max ) {
  4957. hue = 0;
  4958. saturation = 0;
  4959. } else {
  4960. var delta = max - min;
  4961. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4962. switch ( max ) {
  4963. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4964. case g: hue = ( b - r ) / delta + 2; break;
  4965. case b: hue = ( r - g ) / delta + 4; break;
  4966. }
  4967. hue /= 6;
  4968. }
  4969. target.h = hue;
  4970. target.s = saturation;
  4971. target.l = lightness;
  4972. return target;
  4973. },
  4974. getStyle: function () {
  4975. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4976. },
  4977. offsetHSL: function ( h, s, l ) {
  4978. this.getHSL( _hslA );
  4979. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  4980. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  4981. return this;
  4982. },
  4983. add: function ( color ) {
  4984. this.r += color.r;
  4985. this.g += color.g;
  4986. this.b += color.b;
  4987. return this;
  4988. },
  4989. addColors: function ( color1, color2 ) {
  4990. this.r = color1.r + color2.r;
  4991. this.g = color1.g + color2.g;
  4992. this.b = color1.b + color2.b;
  4993. return this;
  4994. },
  4995. addScalar: function ( s ) {
  4996. this.r += s;
  4997. this.g += s;
  4998. this.b += s;
  4999. return this;
  5000. },
  5001. sub: function ( color ) {
  5002. this.r = Math.max( 0, this.r - color.r );
  5003. this.g = Math.max( 0, this.g - color.g );
  5004. this.b = Math.max( 0, this.b - color.b );
  5005. return this;
  5006. },
  5007. multiply: function ( color ) {
  5008. this.r *= color.r;
  5009. this.g *= color.g;
  5010. this.b *= color.b;
  5011. return this;
  5012. },
  5013. multiplyScalar: function ( s ) {
  5014. this.r *= s;
  5015. this.g *= s;
  5016. this.b *= s;
  5017. return this;
  5018. },
  5019. lerp: function ( color, alpha ) {
  5020. this.r += ( color.r - this.r ) * alpha;
  5021. this.g += ( color.g - this.g ) * alpha;
  5022. this.b += ( color.b - this.b ) * alpha;
  5023. return this;
  5024. },
  5025. lerpHSL: function ( color, alpha ) {
  5026. this.getHSL( _hslA );
  5027. color.getHSL( _hslB );
  5028. var h = _Math.lerp( _hslA.h, _hslB.h, alpha );
  5029. var s = _Math.lerp( _hslA.s, _hslB.s, alpha );
  5030. var l = _Math.lerp( _hslA.l, _hslB.l, alpha );
  5031. this.setHSL( h, s, l );
  5032. return this;
  5033. },
  5034. equals: function ( c ) {
  5035. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5036. },
  5037. fromArray: function ( array, offset ) {
  5038. if ( offset === undefined ) offset = 0;
  5039. this.r = array[ offset ];
  5040. this.g = array[ offset + 1 ];
  5041. this.b = array[ offset + 2 ];
  5042. return this;
  5043. },
  5044. toArray: function ( array, offset ) {
  5045. if ( array === undefined ) array = [];
  5046. if ( offset === undefined ) offset = 0;
  5047. array[ offset ] = this.r;
  5048. array[ offset + 1 ] = this.g;
  5049. array[ offset + 2 ] = this.b;
  5050. return array;
  5051. },
  5052. toJSON: function () {
  5053. return this.getHex();
  5054. }
  5055. } );
  5056. Color.NAMES = _colorKeywords;
  5057. /**
  5058. * @author mrdoob / http://mrdoob.com/
  5059. * @author alteredq / http://alteredqualia.com/
  5060. */
  5061. function Face3( a, b, c, normal, color, materialIndex ) {
  5062. this.a = a;
  5063. this.b = b;
  5064. this.c = c;
  5065. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5066. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5067. this.color = ( color && color.isColor ) ? color : new Color();
  5068. this.vertexColors = Array.isArray( color ) ? color : [];
  5069. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5070. }
  5071. Object.assign( Face3.prototype, {
  5072. clone: function () {
  5073. return new this.constructor().copy( this );
  5074. },
  5075. copy: function ( source ) {
  5076. this.a = source.a;
  5077. this.b = source.b;
  5078. this.c = source.c;
  5079. this.normal.copy( source.normal );
  5080. this.color.copy( source.color );
  5081. this.materialIndex = source.materialIndex;
  5082. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5083. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5084. }
  5085. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5086. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5087. }
  5088. return this;
  5089. }
  5090. } );
  5091. /**
  5092. * @author mrdoob / http://mrdoob.com/
  5093. * @author alteredq / http://alteredqualia.com/
  5094. */
  5095. var materialId = 0;
  5096. function Material() {
  5097. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5098. this.uuid = _Math.generateUUID();
  5099. this.name = '';
  5100. this.type = 'Material';
  5101. this.fog = true;
  5102. this.blending = NormalBlending;
  5103. this.side = FrontSide;
  5104. this.flatShading = false;
  5105. this.vertexTangents = false;
  5106. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  5107. this.opacity = 1;
  5108. this.transparent = false;
  5109. this.blendSrc = SrcAlphaFactor;
  5110. this.blendDst = OneMinusSrcAlphaFactor;
  5111. this.blendEquation = AddEquation;
  5112. this.blendSrcAlpha = null;
  5113. this.blendDstAlpha = null;
  5114. this.blendEquationAlpha = null;
  5115. this.depthFunc = LessEqualDepth;
  5116. this.depthTest = true;
  5117. this.depthWrite = true;
  5118. this.stencilWriteMask = 0xff;
  5119. this.stencilFunc = AlwaysStencilFunc;
  5120. this.stencilRef = 0;
  5121. this.stencilFuncMask = 0xff;
  5122. this.stencilFail = KeepStencilOp;
  5123. this.stencilZFail = KeepStencilOp;
  5124. this.stencilZPass = KeepStencilOp;
  5125. this.stencilWrite = false;
  5126. this.clippingPlanes = null;
  5127. this.clipIntersection = false;
  5128. this.clipShadows = false;
  5129. this.shadowSide = null;
  5130. this.colorWrite = true;
  5131. this.precision = null; // override the renderer's default precision for this material
  5132. this.polygonOffset = false;
  5133. this.polygonOffsetFactor = 0;
  5134. this.polygonOffsetUnits = 0;
  5135. this.dithering = false;
  5136. this.alphaTest = 0;
  5137. this.premultipliedAlpha = false;
  5138. this.visible = true;
  5139. this.toneMapped = true;
  5140. this.userData = {};
  5141. this.version = 0;
  5142. }
  5143. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5144. constructor: Material,
  5145. isMaterial: true,
  5146. onBeforeCompile: function () {},
  5147. setValues: function ( values ) {
  5148. if ( values === undefined ) return;
  5149. for ( var key in values ) {
  5150. var newValue = values[ key ];
  5151. if ( newValue === undefined ) {
  5152. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5153. continue;
  5154. }
  5155. // for backward compatability if shading is set in the constructor
  5156. if ( key === 'shading' ) {
  5157. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5158. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5159. continue;
  5160. }
  5161. var currentValue = this[ key ];
  5162. if ( currentValue === undefined ) {
  5163. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5164. continue;
  5165. }
  5166. if ( currentValue && currentValue.isColor ) {
  5167. currentValue.set( newValue );
  5168. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5169. currentValue.copy( newValue );
  5170. } else {
  5171. this[ key ] = newValue;
  5172. }
  5173. }
  5174. },
  5175. toJSON: function ( meta ) {
  5176. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5177. if ( isRoot ) {
  5178. meta = {
  5179. textures: {},
  5180. images: {}
  5181. };
  5182. }
  5183. var data = {
  5184. metadata: {
  5185. version: 4.5,
  5186. type: 'Material',
  5187. generator: 'Material.toJSON'
  5188. }
  5189. };
  5190. // standard Material serialization
  5191. data.uuid = this.uuid;
  5192. data.type = this.type;
  5193. if ( this.name !== '' ) data.name = this.name;
  5194. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5195. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5196. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5197. if ( this.sheen && this.sheen.isColor ) data.sheen = this.sheen.getHex();
  5198. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5199. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5200. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5201. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5202. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5203. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5204. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5205. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5206. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5207. }
  5208. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5209. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5210. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5211. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5212. if ( this.aoMap && this.aoMap.isTexture ) {
  5213. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5214. data.aoMapIntensity = this.aoMapIntensity;
  5215. }
  5216. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5217. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5218. data.bumpScale = this.bumpScale;
  5219. }
  5220. if ( this.normalMap && this.normalMap.isTexture ) {
  5221. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5222. data.normalMapType = this.normalMapType;
  5223. data.normalScale = this.normalScale.toArray();
  5224. }
  5225. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5226. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5227. data.displacementScale = this.displacementScale;
  5228. data.displacementBias = this.displacementBias;
  5229. }
  5230. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5231. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5232. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5233. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5234. if ( this.envMap && this.envMap.isTexture ) {
  5235. data.envMap = this.envMap.toJSON( meta ).uuid;
  5236. data.reflectivity = this.reflectivity; // Scale behind envMap
  5237. data.refractionRatio = this.refractionRatio;
  5238. if ( this.combine !== undefined ) data.combine = this.combine;
  5239. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5240. }
  5241. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5242. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5243. }
  5244. if ( this.size !== undefined ) data.size = this.size;
  5245. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5246. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5247. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5248. if ( this.side !== FrontSide ) data.side = this.side;
  5249. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  5250. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5251. if ( this.transparent === true ) data.transparent = this.transparent;
  5252. data.depthFunc = this.depthFunc;
  5253. data.depthTest = this.depthTest;
  5254. data.depthWrite = this.depthWrite;
  5255. data.stencilWrite = this.stencilWrite;
  5256. data.stencilWriteMask = this.stencilWriteMask;
  5257. data.stencilFunc = this.stencilFunc;
  5258. data.stencilRef = this.stencilRef;
  5259. data.stencilFuncMask = this.stencilFuncMask;
  5260. data.stencilFail = this.stencilFail;
  5261. data.stencilZFail = this.stencilZFail;
  5262. data.stencilZPass = this.stencilZPass;
  5263. // rotation (SpriteMaterial)
  5264. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5265. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5266. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5267. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5268. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5269. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5270. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5271. if ( this.scale !== undefined ) data.scale = this.scale;
  5272. if ( this.dithering === true ) data.dithering = true;
  5273. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5274. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5275. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5276. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5277. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5278. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5279. if ( this.morphTargets === true ) data.morphTargets = true;
  5280. if ( this.morphNormals === true ) data.morphNormals = true;
  5281. if ( this.skinning === true ) data.skinning = true;
  5282. if ( this.visible === false ) data.visible = false;
  5283. if ( this.toneMapped === false ) data.toneMapped = false;
  5284. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5285. // TODO: Copied from Object3D.toJSON
  5286. function extractFromCache( cache ) {
  5287. var values = [];
  5288. for ( var key in cache ) {
  5289. var data = cache[ key ];
  5290. delete data.metadata;
  5291. values.push( data );
  5292. }
  5293. return values;
  5294. }
  5295. if ( isRoot ) {
  5296. var textures = extractFromCache( meta.textures );
  5297. var images = extractFromCache( meta.images );
  5298. if ( textures.length > 0 ) data.textures = textures;
  5299. if ( images.length > 0 ) data.images = images;
  5300. }
  5301. return data;
  5302. },
  5303. clone: function () {
  5304. return new this.constructor().copy( this );
  5305. },
  5306. copy: function ( source ) {
  5307. this.name = source.name;
  5308. this.fog = source.fog;
  5309. this.blending = source.blending;
  5310. this.side = source.side;
  5311. this.flatShading = source.flatShading;
  5312. this.vertexTangents = source.vertexTangents;
  5313. this.vertexColors = source.vertexColors;
  5314. this.opacity = source.opacity;
  5315. this.transparent = source.transparent;
  5316. this.blendSrc = source.blendSrc;
  5317. this.blendDst = source.blendDst;
  5318. this.blendEquation = source.blendEquation;
  5319. this.blendSrcAlpha = source.blendSrcAlpha;
  5320. this.blendDstAlpha = source.blendDstAlpha;
  5321. this.blendEquationAlpha = source.blendEquationAlpha;
  5322. this.depthFunc = source.depthFunc;
  5323. this.depthTest = source.depthTest;
  5324. this.depthWrite = source.depthWrite;
  5325. this.stencilWriteMask = source.stencilWriteMask;
  5326. this.stencilFunc = source.stencilFunc;
  5327. this.stencilRef = source.stencilRef;
  5328. this.stencilFuncMask = source.stencilFuncMask;
  5329. this.stencilFail = source.stencilFail;
  5330. this.stencilZFail = source.stencilZFail;
  5331. this.stencilZPass = source.stencilZPass;
  5332. this.stencilWrite = source.stencilWrite;
  5333. var srcPlanes = source.clippingPlanes,
  5334. dstPlanes = null;
  5335. if ( srcPlanes !== null ) {
  5336. var n = srcPlanes.length;
  5337. dstPlanes = new Array( n );
  5338. for ( var i = 0; i !== n; ++ i )
  5339. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5340. }
  5341. this.clippingPlanes = dstPlanes;
  5342. this.clipIntersection = source.clipIntersection;
  5343. this.clipShadows = source.clipShadows;
  5344. this.shadowSide = source.shadowSide;
  5345. this.colorWrite = source.colorWrite;
  5346. this.precision = source.precision;
  5347. this.polygonOffset = source.polygonOffset;
  5348. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5349. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5350. this.dithering = source.dithering;
  5351. this.alphaTest = source.alphaTest;
  5352. this.premultipliedAlpha = source.premultipliedAlpha;
  5353. this.visible = source.visible;
  5354. this.toneMapped = source.toneMapped;
  5355. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5356. return this;
  5357. },
  5358. dispose: function () {
  5359. this.dispatchEvent( { type: 'dispose' } );
  5360. }
  5361. } );
  5362. Object.defineProperty( Material.prototype, 'needsUpdate', {
  5363. set: function ( value ) {
  5364. if ( value === true ) this.version ++;
  5365. }
  5366. } );
  5367. /**
  5368. * @author mrdoob / http://mrdoob.com/
  5369. * @author alteredq / http://alteredqualia.com/
  5370. *
  5371. * parameters = {
  5372. * color: <hex>,
  5373. * opacity: <float>,
  5374. * map: new THREE.Texture( <Image> ),
  5375. *
  5376. * lightMap: new THREE.Texture( <Image> ),
  5377. * lightMapIntensity: <float>
  5378. *
  5379. * aoMap: new THREE.Texture( <Image> ),
  5380. * aoMapIntensity: <float>
  5381. *
  5382. * specularMap: new THREE.Texture( <Image> ),
  5383. *
  5384. * alphaMap: new THREE.Texture( <Image> ),
  5385. *
  5386. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5387. * combine: THREE.Multiply,
  5388. * reflectivity: <float>,
  5389. * refractionRatio: <float>,
  5390. *
  5391. * depthTest: <bool>,
  5392. * depthWrite: <bool>,
  5393. *
  5394. * wireframe: <boolean>,
  5395. * wireframeLinewidth: <float>,
  5396. *
  5397. * skinning: <bool>,
  5398. * morphTargets: <bool>
  5399. * }
  5400. */
  5401. function MeshBasicMaterial( parameters ) {
  5402. Material.call( this );
  5403. this.type = 'MeshBasicMaterial';
  5404. this.color = new Color( 0xffffff ); // emissive
  5405. this.map = null;
  5406. this.lightMap = null;
  5407. this.lightMapIntensity = 1.0;
  5408. this.aoMap = null;
  5409. this.aoMapIntensity = 1.0;
  5410. this.specularMap = null;
  5411. this.alphaMap = null;
  5412. this.envMap = null;
  5413. this.combine = MultiplyOperation;
  5414. this.reflectivity = 1;
  5415. this.refractionRatio = 0.98;
  5416. this.wireframe = false;
  5417. this.wireframeLinewidth = 1;
  5418. this.wireframeLinecap = 'round';
  5419. this.wireframeLinejoin = 'round';
  5420. this.skinning = false;
  5421. this.morphTargets = false;
  5422. this.setValues( parameters );
  5423. }
  5424. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5425. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5426. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5427. MeshBasicMaterial.prototype.copy = function ( source ) {
  5428. Material.prototype.copy.call( this, source );
  5429. this.color.copy( source.color );
  5430. this.map = source.map;
  5431. this.lightMap = source.lightMap;
  5432. this.lightMapIntensity = source.lightMapIntensity;
  5433. this.aoMap = source.aoMap;
  5434. this.aoMapIntensity = source.aoMapIntensity;
  5435. this.specularMap = source.specularMap;
  5436. this.alphaMap = source.alphaMap;
  5437. this.envMap = source.envMap;
  5438. this.combine = source.combine;
  5439. this.reflectivity = source.reflectivity;
  5440. this.refractionRatio = source.refractionRatio;
  5441. this.wireframe = source.wireframe;
  5442. this.wireframeLinewidth = source.wireframeLinewidth;
  5443. this.wireframeLinecap = source.wireframeLinecap;
  5444. this.wireframeLinejoin = source.wireframeLinejoin;
  5445. this.skinning = source.skinning;
  5446. this.morphTargets = source.morphTargets;
  5447. return this;
  5448. };
  5449. /**
  5450. * @author mrdoob / http://mrdoob.com/
  5451. */
  5452. function BufferAttribute( array, itemSize, normalized ) {
  5453. if ( Array.isArray( array ) ) {
  5454. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5455. }
  5456. this.name = '';
  5457. this.array = array;
  5458. this.itemSize = itemSize;
  5459. this.count = array !== undefined ? array.length / itemSize : 0;
  5460. this.normalized = normalized === true;
  5461. this.usage = StaticDrawUsage;
  5462. this.updateRange = { offset: 0, count: - 1 };
  5463. this.version = 0;
  5464. }
  5465. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5466. set: function ( value ) {
  5467. if ( value === true ) this.version ++;
  5468. }
  5469. } );
  5470. Object.assign( BufferAttribute.prototype, {
  5471. isBufferAttribute: true,
  5472. onUploadCallback: function () {},
  5473. setUsage: function ( value ) {
  5474. this.usage = value;
  5475. return this;
  5476. },
  5477. copy: function ( source ) {
  5478. this.name = source.name;
  5479. this.array = new source.array.constructor( source.array );
  5480. this.itemSize = source.itemSize;
  5481. this.count = source.count;
  5482. this.normalized = source.normalized;
  5483. this.usage = source.usage;
  5484. return this;
  5485. },
  5486. copyAt: function ( index1, attribute, index2 ) {
  5487. index1 *= this.itemSize;
  5488. index2 *= attribute.itemSize;
  5489. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5490. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5491. }
  5492. return this;
  5493. },
  5494. copyArray: function ( array ) {
  5495. this.array.set( array );
  5496. return this;
  5497. },
  5498. copyColorsArray: function ( colors ) {
  5499. var array = this.array, offset = 0;
  5500. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5501. var color = colors[ i ];
  5502. if ( color === undefined ) {
  5503. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5504. color = new Color();
  5505. }
  5506. array[ offset ++ ] = color.r;
  5507. array[ offset ++ ] = color.g;
  5508. array[ offset ++ ] = color.b;
  5509. }
  5510. return this;
  5511. },
  5512. copyVector2sArray: function ( vectors ) {
  5513. var array = this.array, offset = 0;
  5514. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5515. var vector = vectors[ i ];
  5516. if ( vector === undefined ) {
  5517. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5518. vector = new Vector2();
  5519. }
  5520. array[ offset ++ ] = vector.x;
  5521. array[ offset ++ ] = vector.y;
  5522. }
  5523. return this;
  5524. },
  5525. copyVector3sArray: function ( vectors ) {
  5526. var array = this.array, offset = 0;
  5527. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5528. var vector = vectors[ i ];
  5529. if ( vector === undefined ) {
  5530. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5531. vector = new Vector3();
  5532. }
  5533. array[ offset ++ ] = vector.x;
  5534. array[ offset ++ ] = vector.y;
  5535. array[ offset ++ ] = vector.z;
  5536. }
  5537. return this;
  5538. },
  5539. copyVector4sArray: function ( vectors ) {
  5540. var array = this.array, offset = 0;
  5541. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5542. var vector = vectors[ i ];
  5543. if ( vector === undefined ) {
  5544. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5545. vector = new Vector4();
  5546. }
  5547. array[ offset ++ ] = vector.x;
  5548. array[ offset ++ ] = vector.y;
  5549. array[ offset ++ ] = vector.z;
  5550. array[ offset ++ ] = vector.w;
  5551. }
  5552. return this;
  5553. },
  5554. set: function ( value, offset ) {
  5555. if ( offset === undefined ) offset = 0;
  5556. this.array.set( value, offset );
  5557. return this;
  5558. },
  5559. getX: function ( index ) {
  5560. return this.array[ index * this.itemSize ];
  5561. },
  5562. setX: function ( index, x ) {
  5563. this.array[ index * this.itemSize ] = x;
  5564. return this;
  5565. },
  5566. getY: function ( index ) {
  5567. return this.array[ index * this.itemSize + 1 ];
  5568. },
  5569. setY: function ( index, y ) {
  5570. this.array[ index * this.itemSize + 1 ] = y;
  5571. return this;
  5572. },
  5573. getZ: function ( index ) {
  5574. return this.array[ index * this.itemSize + 2 ];
  5575. },
  5576. setZ: function ( index, z ) {
  5577. this.array[ index * this.itemSize + 2 ] = z;
  5578. return this;
  5579. },
  5580. getW: function ( index ) {
  5581. return this.array[ index * this.itemSize + 3 ];
  5582. },
  5583. setW: function ( index, w ) {
  5584. this.array[ index * this.itemSize + 3 ] = w;
  5585. return this;
  5586. },
  5587. setXY: function ( index, x, y ) {
  5588. index *= this.itemSize;
  5589. this.array[ index + 0 ] = x;
  5590. this.array[ index + 1 ] = y;
  5591. return this;
  5592. },
  5593. setXYZ: function ( index, x, y, z ) {
  5594. index *= this.itemSize;
  5595. this.array[ index + 0 ] = x;
  5596. this.array[ index + 1 ] = y;
  5597. this.array[ index + 2 ] = z;
  5598. return this;
  5599. },
  5600. setXYZW: function ( index, x, y, z, w ) {
  5601. index *= this.itemSize;
  5602. this.array[ index + 0 ] = x;
  5603. this.array[ index + 1 ] = y;
  5604. this.array[ index + 2 ] = z;
  5605. this.array[ index + 3 ] = w;
  5606. return this;
  5607. },
  5608. onUpload: function ( callback ) {
  5609. this.onUploadCallback = callback;
  5610. return this;
  5611. },
  5612. clone: function () {
  5613. return new this.constructor( this.array, this.itemSize ).copy( this );
  5614. },
  5615. toJSON: function () {
  5616. return {
  5617. itemSize: this.itemSize,
  5618. type: this.array.constructor.name,
  5619. array: Array.prototype.slice.call( this.array ),
  5620. normalized: this.normalized
  5621. };
  5622. }
  5623. } );
  5624. //
  5625. function Int8BufferAttribute( array, itemSize, normalized ) {
  5626. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5627. }
  5628. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5629. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5630. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5631. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5632. }
  5633. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5634. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5635. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5636. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5637. }
  5638. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5639. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5640. function Int16BufferAttribute( array, itemSize, normalized ) {
  5641. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5642. }
  5643. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5644. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5645. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5646. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5647. }
  5648. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5649. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5650. function Int32BufferAttribute( array, itemSize, normalized ) {
  5651. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5652. }
  5653. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5654. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5655. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5656. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5657. }
  5658. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5659. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5660. function Float32BufferAttribute( array, itemSize, normalized ) {
  5661. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5662. }
  5663. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5664. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5665. function Float64BufferAttribute( array, itemSize, normalized ) {
  5666. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5667. }
  5668. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5669. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5670. /**
  5671. * @author mrdoob / http://mrdoob.com/
  5672. */
  5673. function DirectGeometry() {
  5674. this.vertices = [];
  5675. this.normals = [];
  5676. this.colors = [];
  5677. this.uvs = [];
  5678. this.uvs2 = [];
  5679. this.groups = [];
  5680. this.morphTargets = {};
  5681. this.skinWeights = [];
  5682. this.skinIndices = [];
  5683. // this.lineDistances = [];
  5684. this.boundingBox = null;
  5685. this.boundingSphere = null;
  5686. // update flags
  5687. this.verticesNeedUpdate = false;
  5688. this.normalsNeedUpdate = false;
  5689. this.colorsNeedUpdate = false;
  5690. this.uvsNeedUpdate = false;
  5691. this.groupsNeedUpdate = false;
  5692. }
  5693. Object.assign( DirectGeometry.prototype, {
  5694. computeGroups: function ( geometry ) {
  5695. var group;
  5696. var groups = [];
  5697. var materialIndex = undefined;
  5698. var faces = geometry.faces;
  5699. for ( var i = 0; i < faces.length; i ++ ) {
  5700. var face = faces[ i ];
  5701. // materials
  5702. if ( face.materialIndex !== materialIndex ) {
  5703. materialIndex = face.materialIndex;
  5704. if ( group !== undefined ) {
  5705. group.count = ( i * 3 ) - group.start;
  5706. groups.push( group );
  5707. }
  5708. group = {
  5709. start: i * 3,
  5710. materialIndex: materialIndex
  5711. };
  5712. }
  5713. }
  5714. if ( group !== undefined ) {
  5715. group.count = ( i * 3 ) - group.start;
  5716. groups.push( group );
  5717. }
  5718. this.groups = groups;
  5719. },
  5720. fromGeometry: function ( geometry ) {
  5721. var faces = geometry.faces;
  5722. var vertices = geometry.vertices;
  5723. var faceVertexUvs = geometry.faceVertexUvs;
  5724. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5725. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5726. // morphs
  5727. var morphTargets = geometry.morphTargets;
  5728. var morphTargetsLength = morphTargets.length;
  5729. var morphTargetsPosition;
  5730. if ( morphTargetsLength > 0 ) {
  5731. morphTargetsPosition = [];
  5732. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5733. morphTargetsPosition[ i ] = {
  5734. name: morphTargets[ i ].name,
  5735. data: []
  5736. };
  5737. }
  5738. this.morphTargets.position = morphTargetsPosition;
  5739. }
  5740. var morphNormals = geometry.morphNormals;
  5741. var morphNormalsLength = morphNormals.length;
  5742. var morphTargetsNormal;
  5743. if ( morphNormalsLength > 0 ) {
  5744. morphTargetsNormal = [];
  5745. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5746. morphTargetsNormal[ i ] = {
  5747. name: morphNormals[ i ].name,
  5748. data: []
  5749. };
  5750. }
  5751. this.morphTargets.normal = morphTargetsNormal;
  5752. }
  5753. // skins
  5754. var skinIndices = geometry.skinIndices;
  5755. var skinWeights = geometry.skinWeights;
  5756. var hasSkinIndices = skinIndices.length === vertices.length;
  5757. var hasSkinWeights = skinWeights.length === vertices.length;
  5758. //
  5759. if ( vertices.length > 0 && faces.length === 0 ) {
  5760. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5761. }
  5762. for ( var i = 0; i < faces.length; i ++ ) {
  5763. var face = faces[ i ];
  5764. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5765. var vertexNormals = face.vertexNormals;
  5766. if ( vertexNormals.length === 3 ) {
  5767. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5768. } else {
  5769. var normal = face.normal;
  5770. this.normals.push( normal, normal, normal );
  5771. }
  5772. var vertexColors = face.vertexColors;
  5773. if ( vertexColors.length === 3 ) {
  5774. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5775. } else {
  5776. var color = face.color;
  5777. this.colors.push( color, color, color );
  5778. }
  5779. if ( hasFaceVertexUv === true ) {
  5780. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5781. if ( vertexUvs !== undefined ) {
  5782. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5783. } else {
  5784. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5785. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5786. }
  5787. }
  5788. if ( hasFaceVertexUv2 === true ) {
  5789. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5790. if ( vertexUvs !== undefined ) {
  5791. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5792. } else {
  5793. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5794. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5795. }
  5796. }
  5797. // morphs
  5798. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5799. var morphTarget = morphTargets[ j ].vertices;
  5800. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5801. }
  5802. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5803. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5804. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5805. }
  5806. // skins
  5807. if ( hasSkinIndices ) {
  5808. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5809. }
  5810. if ( hasSkinWeights ) {
  5811. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5812. }
  5813. }
  5814. this.computeGroups( geometry );
  5815. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5816. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5817. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5818. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5819. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5820. if ( geometry.boundingSphere !== null ) {
  5821. this.boundingSphere = geometry.boundingSphere.clone();
  5822. }
  5823. if ( geometry.boundingBox !== null ) {
  5824. this.boundingBox = geometry.boundingBox.clone();
  5825. }
  5826. return this;
  5827. }
  5828. } );
  5829. /**
  5830. * @author mrdoob / http://mrdoob.com/
  5831. */
  5832. function arrayMax( array ) {
  5833. if ( array.length === 0 ) return - Infinity;
  5834. var max = array[ 0 ];
  5835. for ( var i = 1, l = array.length; i < l; ++ i ) {
  5836. if ( array[ i ] > max ) max = array[ i ];
  5837. }
  5838. return max;
  5839. }
  5840. /**
  5841. * @author alteredq / http://alteredqualia.com/
  5842. * @author mrdoob / http://mrdoob.com/
  5843. */
  5844. var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5845. var _m1$2 = new Matrix4();
  5846. var _obj = new Object3D();
  5847. var _offset = new Vector3();
  5848. var _box$2 = new Box3();
  5849. var _boxMorphTargets = new Box3();
  5850. var _vector$4 = new Vector3();
  5851. function BufferGeometry() {
  5852. Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
  5853. this.uuid = _Math.generateUUID();
  5854. this.name = '';
  5855. this.type = 'BufferGeometry';
  5856. this.index = null;
  5857. this.attributes = {};
  5858. this.morphAttributes = {};
  5859. this.morphTargetsRelative = false;
  5860. this.groups = [];
  5861. this.boundingBox = null;
  5862. this.boundingSphere = null;
  5863. this.drawRange = { start: 0, count: Infinity };
  5864. this.userData = {};
  5865. }
  5866. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5867. constructor: BufferGeometry,
  5868. isBufferGeometry: true,
  5869. getIndex: function () {
  5870. return this.index;
  5871. },
  5872. setIndex: function ( index ) {
  5873. if ( Array.isArray( index ) ) {
  5874. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5875. } else {
  5876. this.index = index;
  5877. }
  5878. },
  5879. getAttribute: function ( name ) {
  5880. return this.attributes[ name ];
  5881. },
  5882. setAttribute: function ( name, attribute ) {
  5883. this.attributes[ name ] = attribute;
  5884. return this;
  5885. },
  5886. deleteAttribute: function ( name ) {
  5887. delete this.attributes[ name ];
  5888. return this;
  5889. },
  5890. addGroup: function ( start, count, materialIndex ) {
  5891. this.groups.push( {
  5892. start: start,
  5893. count: count,
  5894. materialIndex: materialIndex !== undefined ? materialIndex : 0
  5895. } );
  5896. },
  5897. clearGroups: function () {
  5898. this.groups = [];
  5899. },
  5900. setDrawRange: function ( start, count ) {
  5901. this.drawRange.start = start;
  5902. this.drawRange.count = count;
  5903. },
  5904. applyMatrix: function ( matrix ) {
  5905. var position = this.attributes.position;
  5906. if ( position !== undefined ) {
  5907. matrix.applyToBufferAttribute( position );
  5908. position.needsUpdate = true;
  5909. }
  5910. var normal = this.attributes.normal;
  5911. if ( normal !== undefined ) {
  5912. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5913. normalMatrix.applyToBufferAttribute( normal );
  5914. normal.needsUpdate = true;
  5915. }
  5916. var tangent = this.attributes.tangent;
  5917. if ( tangent !== undefined ) {
  5918. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5919. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  5920. normalMatrix.applyToBufferAttribute( tangent );
  5921. tangent.needsUpdate = true;
  5922. }
  5923. if ( this.boundingBox !== null ) {
  5924. this.computeBoundingBox();
  5925. }
  5926. if ( this.boundingSphere !== null ) {
  5927. this.computeBoundingSphere();
  5928. }
  5929. return this;
  5930. },
  5931. rotateX: function ( angle ) {
  5932. // rotate geometry around world x-axis
  5933. _m1$2.makeRotationX( angle );
  5934. this.applyMatrix( _m1$2 );
  5935. return this;
  5936. },
  5937. rotateY: function ( angle ) {
  5938. // rotate geometry around world y-axis
  5939. _m1$2.makeRotationY( angle );
  5940. this.applyMatrix( _m1$2 );
  5941. return this;
  5942. },
  5943. rotateZ: function ( angle ) {
  5944. // rotate geometry around world z-axis
  5945. _m1$2.makeRotationZ( angle );
  5946. this.applyMatrix( _m1$2 );
  5947. return this;
  5948. },
  5949. translate: function ( x, y, z ) {
  5950. // translate geometry
  5951. _m1$2.makeTranslation( x, y, z );
  5952. this.applyMatrix( _m1$2 );
  5953. return this;
  5954. },
  5955. scale: function ( x, y, z ) {
  5956. // scale geometry
  5957. _m1$2.makeScale( x, y, z );
  5958. this.applyMatrix( _m1$2 );
  5959. return this;
  5960. },
  5961. lookAt: function ( vector ) {
  5962. _obj.lookAt( vector );
  5963. _obj.updateMatrix();
  5964. this.applyMatrix( _obj.matrix );
  5965. return this;
  5966. },
  5967. center: function () {
  5968. this.computeBoundingBox();
  5969. this.boundingBox.getCenter( _offset ).negate();
  5970. this.translate( _offset.x, _offset.y, _offset.z );
  5971. return this;
  5972. },
  5973. setFromObject: function ( object ) {
  5974. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5975. var geometry = object.geometry;
  5976. if ( object.isPoints || object.isLine ) {
  5977. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5978. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  5979. this.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5980. this.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5981. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  5982. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  5983. this.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  5984. }
  5985. if ( geometry.boundingSphere !== null ) {
  5986. this.boundingSphere = geometry.boundingSphere.clone();
  5987. }
  5988. if ( geometry.boundingBox !== null ) {
  5989. this.boundingBox = geometry.boundingBox.clone();
  5990. }
  5991. } else if ( object.isMesh ) {
  5992. if ( geometry && geometry.isGeometry ) {
  5993. this.fromGeometry( geometry );
  5994. }
  5995. }
  5996. return this;
  5997. },
  5998. setFromPoints: function ( points ) {
  5999. var position = [];
  6000. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6001. var point = points[ i ];
  6002. position.push( point.x, point.y, point.z || 0 );
  6003. }
  6004. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6005. return this;
  6006. },
  6007. updateFromObject: function ( object ) {
  6008. var geometry = object.geometry;
  6009. if ( object.isMesh ) {
  6010. var direct = geometry.__directGeometry;
  6011. if ( geometry.elementsNeedUpdate === true ) {
  6012. direct = undefined;
  6013. geometry.elementsNeedUpdate = false;
  6014. }
  6015. if ( direct === undefined ) {
  6016. return this.fromGeometry( geometry );
  6017. }
  6018. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6019. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6020. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6021. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6022. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6023. geometry.verticesNeedUpdate = false;
  6024. geometry.normalsNeedUpdate = false;
  6025. geometry.colorsNeedUpdate = false;
  6026. geometry.uvsNeedUpdate = false;
  6027. geometry.groupsNeedUpdate = false;
  6028. geometry = direct;
  6029. }
  6030. var attribute;
  6031. if ( geometry.verticesNeedUpdate === true ) {
  6032. attribute = this.attributes.position;
  6033. if ( attribute !== undefined ) {
  6034. attribute.copyVector3sArray( geometry.vertices );
  6035. attribute.needsUpdate = true;
  6036. }
  6037. geometry.verticesNeedUpdate = false;
  6038. }
  6039. if ( geometry.normalsNeedUpdate === true ) {
  6040. attribute = this.attributes.normal;
  6041. if ( attribute !== undefined ) {
  6042. attribute.copyVector3sArray( geometry.normals );
  6043. attribute.needsUpdate = true;
  6044. }
  6045. geometry.normalsNeedUpdate = false;
  6046. }
  6047. if ( geometry.colorsNeedUpdate === true ) {
  6048. attribute = this.attributes.color;
  6049. if ( attribute !== undefined ) {
  6050. attribute.copyColorsArray( geometry.colors );
  6051. attribute.needsUpdate = true;
  6052. }
  6053. geometry.colorsNeedUpdate = false;
  6054. }
  6055. if ( geometry.uvsNeedUpdate ) {
  6056. attribute = this.attributes.uv;
  6057. if ( attribute !== undefined ) {
  6058. attribute.copyVector2sArray( geometry.uvs );
  6059. attribute.needsUpdate = true;
  6060. }
  6061. geometry.uvsNeedUpdate = false;
  6062. }
  6063. if ( geometry.lineDistancesNeedUpdate ) {
  6064. attribute = this.attributes.lineDistance;
  6065. if ( attribute !== undefined ) {
  6066. attribute.copyArray( geometry.lineDistances );
  6067. attribute.needsUpdate = true;
  6068. }
  6069. geometry.lineDistancesNeedUpdate = false;
  6070. }
  6071. if ( geometry.groupsNeedUpdate ) {
  6072. geometry.computeGroups( object.geometry );
  6073. this.groups = geometry.groups;
  6074. geometry.groupsNeedUpdate = false;
  6075. }
  6076. return this;
  6077. },
  6078. fromGeometry: function ( geometry ) {
  6079. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6080. return this.fromDirectGeometry( geometry.__directGeometry );
  6081. },
  6082. fromDirectGeometry: function ( geometry ) {
  6083. var positions = new Float32Array( geometry.vertices.length * 3 );
  6084. this.setAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6085. if ( geometry.normals.length > 0 ) {
  6086. var normals = new Float32Array( geometry.normals.length * 3 );
  6087. this.setAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6088. }
  6089. if ( geometry.colors.length > 0 ) {
  6090. var colors = new Float32Array( geometry.colors.length * 3 );
  6091. this.setAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6092. }
  6093. if ( geometry.uvs.length > 0 ) {
  6094. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6095. this.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6096. }
  6097. if ( geometry.uvs2.length > 0 ) {
  6098. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6099. this.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6100. }
  6101. // groups
  6102. this.groups = geometry.groups;
  6103. // morphs
  6104. for ( var name in geometry.morphTargets ) {
  6105. var array = [];
  6106. var morphTargets = geometry.morphTargets[ name ];
  6107. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6108. var morphTarget = morphTargets[ i ];
  6109. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6110. attribute.name = morphTarget.name;
  6111. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6112. }
  6113. this.morphAttributes[ name ] = array;
  6114. }
  6115. // skinning
  6116. if ( geometry.skinIndices.length > 0 ) {
  6117. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6118. this.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6119. }
  6120. if ( geometry.skinWeights.length > 0 ) {
  6121. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6122. this.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6123. }
  6124. //
  6125. if ( geometry.boundingSphere !== null ) {
  6126. this.boundingSphere = geometry.boundingSphere.clone();
  6127. }
  6128. if ( geometry.boundingBox !== null ) {
  6129. this.boundingBox = geometry.boundingBox.clone();
  6130. }
  6131. return this;
  6132. },
  6133. computeBoundingBox: function () {
  6134. if ( this.boundingBox === null ) {
  6135. this.boundingBox = new Box3();
  6136. }
  6137. var position = this.attributes.position;
  6138. var morphAttributesPosition = this.morphAttributes.position;
  6139. if ( position !== undefined ) {
  6140. this.boundingBox.setFromBufferAttribute( position );
  6141. // process morph attributes if present
  6142. if ( morphAttributesPosition ) {
  6143. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6144. var morphAttribute = morphAttributesPosition[ i ];
  6145. _box$2.setFromBufferAttribute( morphAttribute );
  6146. if ( this.morphTargetsRelative ) {
  6147. _vector$4.addVectors( this.boundingBox.min, _box$2.min );
  6148. this.boundingBox.expandByPoint( _vector$4 );
  6149. _vector$4.addVectors( this.boundingBox.max, _box$2.max );
  6150. this.boundingBox.expandByPoint( _vector$4 );
  6151. } else {
  6152. this.boundingBox.expandByPoint( _box$2.min );
  6153. this.boundingBox.expandByPoint( _box$2.max );
  6154. }
  6155. }
  6156. }
  6157. } else {
  6158. this.boundingBox.makeEmpty();
  6159. }
  6160. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6161. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6162. }
  6163. },
  6164. computeBoundingSphere: function () {
  6165. if ( this.boundingSphere === null ) {
  6166. this.boundingSphere = new Sphere();
  6167. }
  6168. var position = this.attributes.position;
  6169. var morphAttributesPosition = this.morphAttributes.position;
  6170. if ( position ) {
  6171. // first, find the center of the bounding sphere
  6172. var center = this.boundingSphere.center;
  6173. _box$2.setFromBufferAttribute( position );
  6174. // process morph attributes if present
  6175. if ( morphAttributesPosition ) {
  6176. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6177. var morphAttribute = morphAttributesPosition[ i ];
  6178. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6179. if ( this.morphTargetsRelative ) {
  6180. _vector$4.addVectors( _box$2.min, _boxMorphTargets.min );
  6181. _box$2.expandByPoint( _vector$4 );
  6182. _vector$4.addVectors( _box$2.max, _boxMorphTargets.max );
  6183. _box$2.expandByPoint( _vector$4 );
  6184. } else {
  6185. _box$2.expandByPoint( _boxMorphTargets.min );
  6186. _box$2.expandByPoint( _boxMorphTargets.max );
  6187. }
  6188. }
  6189. }
  6190. _box$2.getCenter( center );
  6191. // second, try to find a boundingSphere with a radius smaller than the
  6192. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6193. var maxRadiusSq = 0;
  6194. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6195. _vector$4.fromBufferAttribute( position, i );
  6196. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6197. }
  6198. // process morph attributes if present
  6199. if ( morphAttributesPosition ) {
  6200. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6201. var morphAttribute = morphAttributesPosition[ i ];
  6202. var morphTargetsRelative = this.morphTargetsRelative;
  6203. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6204. _vector$4.fromBufferAttribute( morphAttribute, j );
  6205. if ( morphTargetsRelative ) {
  6206. _offset.fromBufferAttribute( position, j );
  6207. _vector$4.add( _offset );
  6208. }
  6209. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6210. }
  6211. }
  6212. }
  6213. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6214. if ( isNaN( this.boundingSphere.radius ) ) {
  6215. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6216. }
  6217. }
  6218. },
  6219. computeFaceNormals: function () {
  6220. // backwards compatibility
  6221. },
  6222. computeVertexNormals: function () {
  6223. var index = this.index;
  6224. var attributes = this.attributes;
  6225. if ( attributes.position ) {
  6226. var positions = attributes.position.array;
  6227. if ( attributes.normal === undefined ) {
  6228. this.setAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6229. } else {
  6230. // reset existing normals to zero
  6231. var array = attributes.normal.array;
  6232. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6233. array[ i ] = 0;
  6234. }
  6235. }
  6236. var normals = attributes.normal.array;
  6237. var vA, vB, vC;
  6238. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6239. var cb = new Vector3(), ab = new Vector3();
  6240. // indexed elements
  6241. if ( index ) {
  6242. var indices = index.array;
  6243. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  6244. vA = indices[ i + 0 ] * 3;
  6245. vB = indices[ i + 1 ] * 3;
  6246. vC = indices[ i + 2 ] * 3;
  6247. pA.fromArray( positions, vA );
  6248. pB.fromArray( positions, vB );
  6249. pC.fromArray( positions, vC );
  6250. cb.subVectors( pC, pB );
  6251. ab.subVectors( pA, pB );
  6252. cb.cross( ab );
  6253. normals[ vA ] += cb.x;
  6254. normals[ vA + 1 ] += cb.y;
  6255. normals[ vA + 2 ] += cb.z;
  6256. normals[ vB ] += cb.x;
  6257. normals[ vB + 1 ] += cb.y;
  6258. normals[ vB + 2 ] += cb.z;
  6259. normals[ vC ] += cb.x;
  6260. normals[ vC + 1 ] += cb.y;
  6261. normals[ vC + 2 ] += cb.z;
  6262. }
  6263. } else {
  6264. // non-indexed elements (unconnected triangle soup)
  6265. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6266. pA.fromArray( positions, i );
  6267. pB.fromArray( positions, i + 3 );
  6268. pC.fromArray( positions, i + 6 );
  6269. cb.subVectors( pC, pB );
  6270. ab.subVectors( pA, pB );
  6271. cb.cross( ab );
  6272. normals[ i ] = cb.x;
  6273. normals[ i + 1 ] = cb.y;
  6274. normals[ i + 2 ] = cb.z;
  6275. normals[ i + 3 ] = cb.x;
  6276. normals[ i + 4 ] = cb.y;
  6277. normals[ i + 5 ] = cb.z;
  6278. normals[ i + 6 ] = cb.x;
  6279. normals[ i + 7 ] = cb.y;
  6280. normals[ i + 8 ] = cb.z;
  6281. }
  6282. }
  6283. this.normalizeNormals();
  6284. attributes.normal.needsUpdate = true;
  6285. }
  6286. },
  6287. merge: function ( geometry, offset ) {
  6288. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6289. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6290. return;
  6291. }
  6292. if ( offset === undefined ) {
  6293. offset = 0;
  6294. console.warn(
  6295. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6296. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6297. );
  6298. }
  6299. var attributes = this.attributes;
  6300. for ( var key in attributes ) {
  6301. if ( geometry.attributes[ key ] === undefined ) continue;
  6302. var attribute1 = attributes[ key ];
  6303. var attributeArray1 = attribute1.array;
  6304. var attribute2 = geometry.attributes[ key ];
  6305. var attributeArray2 = attribute2.array;
  6306. var attributeOffset = attribute2.itemSize * offset;
  6307. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6308. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6309. attributeArray1[ j ] = attributeArray2[ i ];
  6310. }
  6311. }
  6312. return this;
  6313. },
  6314. normalizeNormals: function () {
  6315. var normals = this.attributes.normal;
  6316. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6317. _vector$4.x = normals.getX( i );
  6318. _vector$4.y = normals.getY( i );
  6319. _vector$4.z = normals.getZ( i );
  6320. _vector$4.normalize();
  6321. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6322. }
  6323. },
  6324. toNonIndexed: function () {
  6325. function convertBufferAttribute( attribute, indices ) {
  6326. var array = attribute.array;
  6327. var itemSize = attribute.itemSize;
  6328. var array2 = new array.constructor( indices.length * itemSize );
  6329. var index = 0, index2 = 0;
  6330. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6331. index = indices[ i ] * itemSize;
  6332. for ( var j = 0; j < itemSize; j ++ ) {
  6333. array2[ index2 ++ ] = array[ index ++ ];
  6334. }
  6335. }
  6336. return new BufferAttribute( array2, itemSize );
  6337. }
  6338. //
  6339. if ( this.index === null ) {
  6340. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6341. return this;
  6342. }
  6343. var geometry2 = new BufferGeometry();
  6344. var indices = this.index.array;
  6345. var attributes = this.attributes;
  6346. // attributes
  6347. for ( var name in attributes ) {
  6348. var attribute = attributes[ name ];
  6349. var newAttribute = convertBufferAttribute( attribute, indices );
  6350. geometry2.setAttribute( name, newAttribute );
  6351. }
  6352. // morph attributes
  6353. var morphAttributes = this.morphAttributes;
  6354. for ( name in morphAttributes ) {
  6355. var morphArray = [];
  6356. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6357. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6358. var attribute = morphAttribute[ i ];
  6359. var newAttribute = convertBufferAttribute( attribute, indices );
  6360. morphArray.push( newAttribute );
  6361. }
  6362. geometry2.morphAttributes[ name ] = morphArray;
  6363. }
  6364. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6365. // groups
  6366. var groups = this.groups;
  6367. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6368. var group = groups[ i ];
  6369. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6370. }
  6371. return geometry2;
  6372. },
  6373. toJSON: function () {
  6374. var data = {
  6375. metadata: {
  6376. version: 4.5,
  6377. type: 'BufferGeometry',
  6378. generator: 'BufferGeometry.toJSON'
  6379. }
  6380. };
  6381. // standard BufferGeometry serialization
  6382. data.uuid = this.uuid;
  6383. data.type = this.type;
  6384. if ( this.name !== '' ) data.name = this.name;
  6385. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6386. if ( this.parameters !== undefined ) {
  6387. var parameters = this.parameters;
  6388. for ( var key in parameters ) {
  6389. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6390. }
  6391. return data;
  6392. }
  6393. data.data = { attributes: {} };
  6394. var index = this.index;
  6395. if ( index !== null ) {
  6396. data.data.index = {
  6397. type: index.array.constructor.name,
  6398. array: Array.prototype.slice.call( index.array )
  6399. };
  6400. }
  6401. var attributes = this.attributes;
  6402. for ( var key in attributes ) {
  6403. var attribute = attributes[ key ];
  6404. var attributeData = attribute.toJSON();
  6405. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6406. data.data.attributes[ key ] = attributeData;
  6407. }
  6408. var morphAttributes = {};
  6409. var hasMorphAttributes = false;
  6410. for ( var key in this.morphAttributes ) {
  6411. var attributeArray = this.morphAttributes[ key ];
  6412. var array = [];
  6413. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6414. var attribute = attributeArray[ i ];
  6415. var attributeData = attribute.toJSON();
  6416. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6417. array.push( attributeData );
  6418. }
  6419. if ( array.length > 0 ) {
  6420. morphAttributes[ key ] = array;
  6421. hasMorphAttributes = true;
  6422. }
  6423. }
  6424. if ( hasMorphAttributes ) {
  6425. data.data.morphAttributes = morphAttributes;
  6426. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6427. }
  6428. var groups = this.groups;
  6429. if ( groups.length > 0 ) {
  6430. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6431. }
  6432. var boundingSphere = this.boundingSphere;
  6433. if ( boundingSphere !== null ) {
  6434. data.data.boundingSphere = {
  6435. center: boundingSphere.center.toArray(),
  6436. radius: boundingSphere.radius
  6437. };
  6438. }
  6439. return data;
  6440. },
  6441. clone: function () {
  6442. /*
  6443. // Handle primitives
  6444. var parameters = this.parameters;
  6445. if ( parameters !== undefined ) {
  6446. var values = [];
  6447. for ( var key in parameters ) {
  6448. values.push( parameters[ key ] );
  6449. }
  6450. var geometry = Object.create( this.constructor.prototype );
  6451. this.constructor.apply( geometry, values );
  6452. return geometry;
  6453. }
  6454. return new this.constructor().copy( this );
  6455. */
  6456. return new BufferGeometry().copy( this );
  6457. },
  6458. copy: function ( source ) {
  6459. var name, i, l;
  6460. // reset
  6461. this.index = null;
  6462. this.attributes = {};
  6463. this.morphAttributes = {};
  6464. this.groups = [];
  6465. this.boundingBox = null;
  6466. this.boundingSphere = null;
  6467. // name
  6468. this.name = source.name;
  6469. // index
  6470. var index = source.index;
  6471. if ( index !== null ) {
  6472. this.setIndex( index.clone() );
  6473. }
  6474. // attributes
  6475. var attributes = source.attributes;
  6476. for ( name in attributes ) {
  6477. var attribute = attributes[ name ];
  6478. this.setAttribute( name, attribute.clone() );
  6479. }
  6480. // morph attributes
  6481. var morphAttributes = source.morphAttributes;
  6482. for ( name in morphAttributes ) {
  6483. var array = [];
  6484. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6485. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6486. array.push( morphAttribute[ i ].clone() );
  6487. }
  6488. this.morphAttributes[ name ] = array;
  6489. }
  6490. this.morphTargetsRelative = source.morphTargetsRelative;
  6491. // groups
  6492. var groups = source.groups;
  6493. for ( i = 0, l = groups.length; i < l; i ++ ) {
  6494. var group = groups[ i ];
  6495. this.addGroup( group.start, group.count, group.materialIndex );
  6496. }
  6497. // bounding box
  6498. var boundingBox = source.boundingBox;
  6499. if ( boundingBox !== null ) {
  6500. this.boundingBox = boundingBox.clone();
  6501. }
  6502. // bounding sphere
  6503. var boundingSphere = source.boundingSphere;
  6504. if ( boundingSphere !== null ) {
  6505. this.boundingSphere = boundingSphere.clone();
  6506. }
  6507. // draw range
  6508. this.drawRange.start = source.drawRange.start;
  6509. this.drawRange.count = source.drawRange.count;
  6510. // user data
  6511. this.userData = source.userData;
  6512. return this;
  6513. },
  6514. dispose: function () {
  6515. this.dispatchEvent( { type: 'dispose' } );
  6516. }
  6517. } );
  6518. /**
  6519. * @author mrdoob / http://mrdoob.com/
  6520. * @author alteredq / http://alteredqualia.com/
  6521. * @author mikael emtinger / http://gomo.se/
  6522. * @author jonobr1 / http://jonobr1.com/
  6523. */
  6524. var _inverseMatrix = new Matrix4();
  6525. var _ray = new Ray();
  6526. var _sphere = new Sphere();
  6527. var _vA = new Vector3();
  6528. var _vB = new Vector3();
  6529. var _vC = new Vector3();
  6530. var _tempA = new Vector3();
  6531. var _tempB = new Vector3();
  6532. var _tempC = new Vector3();
  6533. var _morphA = new Vector3();
  6534. var _morphB = new Vector3();
  6535. var _morphC = new Vector3();
  6536. var _uvA = new Vector2();
  6537. var _uvB = new Vector2();
  6538. var _uvC = new Vector2();
  6539. var _intersectionPoint = new Vector3();
  6540. var _intersectionPointWorld = new Vector3();
  6541. function Mesh( geometry, material ) {
  6542. Object3D.call( this );
  6543. this.type = 'Mesh';
  6544. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6545. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  6546. this.drawMode = TrianglesDrawMode;
  6547. this.updateMorphTargets();
  6548. }
  6549. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6550. constructor: Mesh,
  6551. isMesh: true,
  6552. setDrawMode: function ( value ) {
  6553. this.drawMode = value;
  6554. },
  6555. copy: function ( source ) {
  6556. Object3D.prototype.copy.call( this, source );
  6557. this.drawMode = source.drawMode;
  6558. if ( source.morphTargetInfluences !== undefined ) {
  6559. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6560. }
  6561. if ( source.morphTargetDictionary !== undefined ) {
  6562. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6563. }
  6564. return this;
  6565. },
  6566. updateMorphTargets: function () {
  6567. var geometry = this.geometry;
  6568. var m, ml, name;
  6569. if ( geometry.isBufferGeometry ) {
  6570. var morphAttributes = geometry.morphAttributes;
  6571. var keys = Object.keys( morphAttributes );
  6572. if ( keys.length > 0 ) {
  6573. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6574. if ( morphAttribute !== undefined ) {
  6575. this.morphTargetInfluences = [];
  6576. this.morphTargetDictionary = {};
  6577. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6578. name = morphAttribute[ m ].name || String( m );
  6579. this.morphTargetInfluences.push( 0 );
  6580. this.morphTargetDictionary[ name ] = m;
  6581. }
  6582. }
  6583. }
  6584. } else {
  6585. var morphTargets = geometry.morphTargets;
  6586. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6587. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6588. }
  6589. }
  6590. },
  6591. raycast: function ( raycaster, intersects ) {
  6592. var geometry = this.geometry;
  6593. var material = this.material;
  6594. var matrixWorld = this.matrixWorld;
  6595. if ( material === undefined ) return;
  6596. // Checking boundingSphere distance to ray
  6597. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6598. _sphere.copy( geometry.boundingSphere );
  6599. _sphere.applyMatrix4( matrixWorld );
  6600. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  6601. //
  6602. _inverseMatrix.getInverse( matrixWorld );
  6603. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6604. // Check boundingBox before continuing
  6605. if ( geometry.boundingBox !== null ) {
  6606. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6607. }
  6608. // check unsupported draw modes
  6609. if ( this.drawMode !== TrianglesDrawMode ) {
  6610. console.warn( 'THREE.Mesh: TriangleStripDrawMode and TriangleFanDrawMode are not supported by .raycast().' );
  6611. return;
  6612. }
  6613. var intersection;
  6614. if ( geometry.isBufferGeometry ) {
  6615. var a, b, c;
  6616. var index = geometry.index;
  6617. var position = geometry.attributes.position;
  6618. var morphPosition = geometry.morphAttributes.position;
  6619. var morphTargetsRelative = geometry.morphTargetsRelative;
  6620. var uv = geometry.attributes.uv;
  6621. var uv2 = geometry.attributes.uv2;
  6622. var groups = geometry.groups;
  6623. var drawRange = geometry.drawRange;
  6624. var i, j, il, jl;
  6625. var group, groupMaterial;
  6626. var start, end;
  6627. if ( index !== null ) {
  6628. // indexed buffer geometry
  6629. if ( Array.isArray( material ) ) {
  6630. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6631. group = groups[ i ];
  6632. groupMaterial = material[ group.materialIndex ];
  6633. start = Math.max( group.start, drawRange.start );
  6634. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6635. for ( j = start, jl = end; j < jl; j += 3 ) {
  6636. a = index.getX( j );
  6637. b = index.getX( j + 1 );
  6638. c = index.getX( j + 2 );
  6639. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6640. if ( intersection ) {
  6641. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6642. intersection.face.materialIndex = group.materialIndex;
  6643. intersects.push( intersection );
  6644. }
  6645. }
  6646. }
  6647. } else {
  6648. start = Math.max( 0, drawRange.start );
  6649. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6650. for ( i = start, il = end; i < il; i += 3 ) {
  6651. a = index.getX( i );
  6652. b = index.getX( i + 1 );
  6653. c = index.getX( i + 2 );
  6654. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6655. if ( intersection ) {
  6656. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6657. intersects.push( intersection );
  6658. }
  6659. }
  6660. }
  6661. } else if ( position !== undefined ) {
  6662. // non-indexed buffer geometry
  6663. if ( Array.isArray( material ) ) {
  6664. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6665. group = groups[ i ];
  6666. groupMaterial = material[ group.materialIndex ];
  6667. start = Math.max( group.start, drawRange.start );
  6668. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6669. for ( j = start, jl = end; j < jl; j += 3 ) {
  6670. a = j;
  6671. b = j + 1;
  6672. c = j + 2;
  6673. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6674. if ( intersection ) {
  6675. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6676. intersection.face.materialIndex = group.materialIndex;
  6677. intersects.push( intersection );
  6678. }
  6679. }
  6680. }
  6681. } else {
  6682. start = Math.max( 0, drawRange.start );
  6683. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6684. for ( i = start, il = end; i < il; i += 3 ) {
  6685. a = i;
  6686. b = i + 1;
  6687. c = i + 2;
  6688. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6689. if ( intersection ) {
  6690. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6691. intersects.push( intersection );
  6692. }
  6693. }
  6694. }
  6695. }
  6696. } else if ( geometry.isGeometry ) {
  6697. var fvA, fvB, fvC;
  6698. var isMultiMaterial = Array.isArray( material );
  6699. var vertices = geometry.vertices;
  6700. var faces = geometry.faces;
  6701. var uvs;
  6702. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6703. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6704. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6705. var face = faces[ f ];
  6706. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6707. if ( faceMaterial === undefined ) continue;
  6708. fvA = vertices[ face.a ];
  6709. fvB = vertices[ face.b ];
  6710. fvC = vertices[ face.c ];
  6711. intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
  6712. if ( intersection ) {
  6713. if ( uvs && uvs[ f ] ) {
  6714. var uvs_f = uvs[ f ];
  6715. _uvA.copy( uvs_f[ 0 ] );
  6716. _uvB.copy( uvs_f[ 1 ] );
  6717. _uvC.copy( uvs_f[ 2 ] );
  6718. intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
  6719. }
  6720. intersection.face = face;
  6721. intersection.faceIndex = f;
  6722. intersects.push( intersection );
  6723. }
  6724. }
  6725. }
  6726. },
  6727. clone: function () {
  6728. return new this.constructor( this.geometry, this.material ).copy( this );
  6729. }
  6730. } );
  6731. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6732. var intersect;
  6733. if ( material.side === BackSide ) {
  6734. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6735. } else {
  6736. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6737. }
  6738. if ( intersect === null ) return null;
  6739. _intersectionPointWorld.copy( point );
  6740. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6741. var distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6742. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6743. return {
  6744. distance: distance,
  6745. point: _intersectionPointWorld.clone(),
  6746. object: object
  6747. };
  6748. }
  6749. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6750. _vA.fromBufferAttribute( position, a );
  6751. _vB.fromBufferAttribute( position, b );
  6752. _vC.fromBufferAttribute( position, c );
  6753. var morphInfluences = object.morphTargetInfluences;
  6754. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6755. _morphA.set( 0, 0, 0 );
  6756. _morphB.set( 0, 0, 0 );
  6757. _morphC.set( 0, 0, 0 );
  6758. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6759. var influence = morphInfluences[ i ];
  6760. var morphAttribute = morphPosition[ i ];
  6761. if ( influence === 0 ) continue;
  6762. _tempA.fromBufferAttribute( morphAttribute, a );
  6763. _tempB.fromBufferAttribute( morphAttribute, b );
  6764. _tempC.fromBufferAttribute( morphAttribute, c );
  6765. if ( morphTargetsRelative ) {
  6766. _morphA.addScaledVector( _tempA, influence );
  6767. _morphB.addScaledVector( _tempB, influence );
  6768. _morphC.addScaledVector( _tempC, influence );
  6769. } else {
  6770. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6771. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6772. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6773. }
  6774. }
  6775. _vA.add( _morphA );
  6776. _vB.add( _morphB );
  6777. _vC.add( _morphC );
  6778. }
  6779. var intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6780. if ( intersection ) {
  6781. if ( uv ) {
  6782. _uvA.fromBufferAttribute( uv, a );
  6783. _uvB.fromBufferAttribute( uv, b );
  6784. _uvC.fromBufferAttribute( uv, c );
  6785. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6786. }
  6787. if ( uv2 ) {
  6788. _uvA.fromBufferAttribute( uv2, a );
  6789. _uvB.fromBufferAttribute( uv2, b );
  6790. _uvC.fromBufferAttribute( uv2, c );
  6791. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6792. }
  6793. var face = new Face3( a, b, c );
  6794. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6795. intersection.face = face;
  6796. }
  6797. return intersection;
  6798. }
  6799. /**
  6800. * @author mrdoob / http://mrdoob.com/
  6801. * @author kile / http://kile.stravaganza.org/
  6802. * @author alteredq / http://alteredqualia.com/
  6803. * @author mikael emtinger / http://gomo.se/
  6804. * @author zz85 / http://www.lab4games.net/zz85/blog
  6805. * @author bhouston / http://clara.io
  6806. */
  6807. var _geometryId = 0; // Geometry uses even numbers as Id
  6808. var _m1$3 = new Matrix4();
  6809. var _obj$1 = new Object3D();
  6810. var _offset$1 = new Vector3();
  6811. function Geometry() {
  6812. Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
  6813. this.uuid = _Math.generateUUID();
  6814. this.name = '';
  6815. this.type = 'Geometry';
  6816. this.vertices = [];
  6817. this.colors = [];
  6818. this.faces = [];
  6819. this.faceVertexUvs = [[]];
  6820. this.morphTargets = [];
  6821. this.morphNormals = [];
  6822. this.skinWeights = [];
  6823. this.skinIndices = [];
  6824. this.lineDistances = [];
  6825. this.boundingBox = null;
  6826. this.boundingSphere = null;
  6827. // update flags
  6828. this.elementsNeedUpdate = false;
  6829. this.verticesNeedUpdate = false;
  6830. this.uvsNeedUpdate = false;
  6831. this.normalsNeedUpdate = false;
  6832. this.colorsNeedUpdate = false;
  6833. this.lineDistancesNeedUpdate = false;
  6834. this.groupsNeedUpdate = false;
  6835. }
  6836. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6837. constructor: Geometry,
  6838. isGeometry: true,
  6839. applyMatrix: function ( matrix ) {
  6840. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6841. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6842. var vertex = this.vertices[ i ];
  6843. vertex.applyMatrix4( matrix );
  6844. }
  6845. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6846. var face = this.faces[ i ];
  6847. face.normal.applyMatrix3( normalMatrix ).normalize();
  6848. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6849. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6850. }
  6851. }
  6852. if ( this.boundingBox !== null ) {
  6853. this.computeBoundingBox();
  6854. }
  6855. if ( this.boundingSphere !== null ) {
  6856. this.computeBoundingSphere();
  6857. }
  6858. this.verticesNeedUpdate = true;
  6859. this.normalsNeedUpdate = true;
  6860. return this;
  6861. },
  6862. rotateX: function ( angle ) {
  6863. // rotate geometry around world x-axis
  6864. _m1$3.makeRotationX( angle );
  6865. this.applyMatrix( _m1$3 );
  6866. return this;
  6867. },
  6868. rotateY: function ( angle ) {
  6869. // rotate geometry around world y-axis
  6870. _m1$3.makeRotationY( angle );
  6871. this.applyMatrix( _m1$3 );
  6872. return this;
  6873. },
  6874. rotateZ: function ( angle ) {
  6875. // rotate geometry around world z-axis
  6876. _m1$3.makeRotationZ( angle );
  6877. this.applyMatrix( _m1$3 );
  6878. return this;
  6879. },
  6880. translate: function ( x, y, z ) {
  6881. // translate geometry
  6882. _m1$3.makeTranslation( x, y, z );
  6883. this.applyMatrix( _m1$3 );
  6884. return this;
  6885. },
  6886. scale: function ( x, y, z ) {
  6887. // scale geometry
  6888. _m1$3.makeScale( x, y, z );
  6889. this.applyMatrix( _m1$3 );
  6890. return this;
  6891. },
  6892. lookAt: function ( vector ) {
  6893. _obj$1.lookAt( vector );
  6894. _obj$1.updateMatrix();
  6895. this.applyMatrix( _obj$1.matrix );
  6896. return this;
  6897. },
  6898. fromBufferGeometry: function ( geometry ) {
  6899. var scope = this;
  6900. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6901. var attributes = geometry.attributes;
  6902. if ( attributes.position === undefined ) {
  6903. console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
  6904. return this;
  6905. }
  6906. var positions = attributes.position.array;
  6907. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6908. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6909. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6910. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6911. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6912. for ( var i = 0; i < positions.length; i += 3 ) {
  6913. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  6914. if ( colors !== undefined ) {
  6915. scope.colors.push( new Color().fromArray( colors, i ) );
  6916. }
  6917. }
  6918. function addFace( a, b, c, materialIndex ) {
  6919. var vertexColors = ( colors === undefined ) ? [] : [
  6920. scope.colors[ a ].clone(),
  6921. scope.colors[ b ].clone(),
  6922. scope.colors[ c ].clone() ];
  6923. var vertexNormals = ( normals === undefined ) ? [] : [
  6924. new Vector3().fromArray( normals, a * 3 ),
  6925. new Vector3().fromArray( normals, b * 3 ),
  6926. new Vector3().fromArray( normals, c * 3 )
  6927. ];
  6928. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6929. scope.faces.push( face );
  6930. if ( uvs !== undefined ) {
  6931. scope.faceVertexUvs[ 0 ].push( [
  6932. new Vector2().fromArray( uvs, a * 2 ),
  6933. new Vector2().fromArray( uvs, b * 2 ),
  6934. new Vector2().fromArray( uvs, c * 2 )
  6935. ] );
  6936. }
  6937. if ( uvs2 !== undefined ) {
  6938. scope.faceVertexUvs[ 1 ].push( [
  6939. new Vector2().fromArray( uvs2, a * 2 ),
  6940. new Vector2().fromArray( uvs2, b * 2 ),
  6941. new Vector2().fromArray( uvs2, c * 2 )
  6942. ] );
  6943. }
  6944. }
  6945. var groups = geometry.groups;
  6946. if ( groups.length > 0 ) {
  6947. for ( var i = 0; i < groups.length; i ++ ) {
  6948. var group = groups[ i ];
  6949. var start = group.start;
  6950. var count = group.count;
  6951. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6952. if ( indices !== undefined ) {
  6953. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6954. } else {
  6955. addFace( j, j + 1, j + 2, group.materialIndex );
  6956. }
  6957. }
  6958. }
  6959. } else {
  6960. if ( indices !== undefined ) {
  6961. for ( var i = 0; i < indices.length; i += 3 ) {
  6962. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6963. }
  6964. } else {
  6965. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6966. addFace( i, i + 1, i + 2 );
  6967. }
  6968. }
  6969. }
  6970. this.computeFaceNormals();
  6971. if ( geometry.boundingBox !== null ) {
  6972. this.boundingBox = geometry.boundingBox.clone();
  6973. }
  6974. if ( geometry.boundingSphere !== null ) {
  6975. this.boundingSphere = geometry.boundingSphere.clone();
  6976. }
  6977. return this;
  6978. },
  6979. center: function () {
  6980. this.computeBoundingBox();
  6981. this.boundingBox.getCenter( _offset$1 ).negate();
  6982. this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
  6983. return this;
  6984. },
  6985. normalize: function () {
  6986. this.computeBoundingSphere();
  6987. var center = this.boundingSphere.center;
  6988. var radius = this.boundingSphere.radius;
  6989. var s = radius === 0 ? 1 : 1.0 / radius;
  6990. var matrix = new Matrix4();
  6991. matrix.set(
  6992. s, 0, 0, - s * center.x,
  6993. 0, s, 0, - s * center.y,
  6994. 0, 0, s, - s * center.z,
  6995. 0, 0, 0, 1
  6996. );
  6997. this.applyMatrix( matrix );
  6998. return this;
  6999. },
  7000. computeFaceNormals: function () {
  7001. var cb = new Vector3(), ab = new Vector3();
  7002. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7003. var face = this.faces[ f ];
  7004. var vA = this.vertices[ face.a ];
  7005. var vB = this.vertices[ face.b ];
  7006. var vC = this.vertices[ face.c ];
  7007. cb.subVectors( vC, vB );
  7008. ab.subVectors( vA, vB );
  7009. cb.cross( ab );
  7010. cb.normalize();
  7011. face.normal.copy( cb );
  7012. }
  7013. },
  7014. computeVertexNormals: function ( areaWeighted ) {
  7015. if ( areaWeighted === undefined ) areaWeighted = true;
  7016. var v, vl, f, fl, face, vertices;
  7017. vertices = new Array( this.vertices.length );
  7018. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7019. vertices[ v ] = new Vector3();
  7020. }
  7021. if ( areaWeighted ) {
  7022. // vertex normals weighted by triangle areas
  7023. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7024. var vA, vB, vC;
  7025. var cb = new Vector3(), ab = new Vector3();
  7026. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7027. face = this.faces[ f ];
  7028. vA = this.vertices[ face.a ];
  7029. vB = this.vertices[ face.b ];
  7030. vC = this.vertices[ face.c ];
  7031. cb.subVectors( vC, vB );
  7032. ab.subVectors( vA, vB );
  7033. cb.cross( ab );
  7034. vertices[ face.a ].add( cb );
  7035. vertices[ face.b ].add( cb );
  7036. vertices[ face.c ].add( cb );
  7037. }
  7038. } else {
  7039. this.computeFaceNormals();
  7040. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7041. face = this.faces[ f ];
  7042. vertices[ face.a ].add( face.normal );
  7043. vertices[ face.b ].add( face.normal );
  7044. vertices[ face.c ].add( face.normal );
  7045. }
  7046. }
  7047. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7048. vertices[ v ].normalize();
  7049. }
  7050. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7051. face = this.faces[ f ];
  7052. var vertexNormals = face.vertexNormals;
  7053. if ( vertexNormals.length === 3 ) {
  7054. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7055. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7056. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7057. } else {
  7058. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7059. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7060. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7061. }
  7062. }
  7063. if ( this.faces.length > 0 ) {
  7064. this.normalsNeedUpdate = true;
  7065. }
  7066. },
  7067. computeFlatVertexNormals: function () {
  7068. var f, fl, face;
  7069. this.computeFaceNormals();
  7070. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7071. face = this.faces[ f ];
  7072. var vertexNormals = face.vertexNormals;
  7073. if ( vertexNormals.length === 3 ) {
  7074. vertexNormals[ 0 ].copy( face.normal );
  7075. vertexNormals[ 1 ].copy( face.normal );
  7076. vertexNormals[ 2 ].copy( face.normal );
  7077. } else {
  7078. vertexNormals[ 0 ] = face.normal.clone();
  7079. vertexNormals[ 1 ] = face.normal.clone();
  7080. vertexNormals[ 2 ] = face.normal.clone();
  7081. }
  7082. }
  7083. if ( this.faces.length > 0 ) {
  7084. this.normalsNeedUpdate = true;
  7085. }
  7086. },
  7087. computeMorphNormals: function () {
  7088. var i, il, f, fl, face;
  7089. // save original normals
  7090. // - create temp variables on first access
  7091. // otherwise just copy (for faster repeated calls)
  7092. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7093. face = this.faces[ f ];
  7094. if ( ! face.__originalFaceNormal ) {
  7095. face.__originalFaceNormal = face.normal.clone();
  7096. } else {
  7097. face.__originalFaceNormal.copy( face.normal );
  7098. }
  7099. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7100. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7101. if ( ! face.__originalVertexNormals[ i ] ) {
  7102. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7103. } else {
  7104. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7105. }
  7106. }
  7107. }
  7108. // use temp geometry to compute face and vertex normals for each morph
  7109. var tmpGeo = new Geometry();
  7110. tmpGeo.faces = this.faces;
  7111. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7112. // create on first access
  7113. if ( ! this.morphNormals[ i ] ) {
  7114. this.morphNormals[ i ] = {};
  7115. this.morphNormals[ i ].faceNormals = [];
  7116. this.morphNormals[ i ].vertexNormals = [];
  7117. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7118. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7119. var faceNormal, vertexNormals;
  7120. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7121. faceNormal = new Vector3();
  7122. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7123. dstNormalsFace.push( faceNormal );
  7124. dstNormalsVertex.push( vertexNormals );
  7125. }
  7126. }
  7127. var morphNormals = this.morphNormals[ i ];
  7128. // set vertices to morph target
  7129. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7130. // compute morph normals
  7131. tmpGeo.computeFaceNormals();
  7132. tmpGeo.computeVertexNormals();
  7133. // store morph normals
  7134. var faceNormal, vertexNormals;
  7135. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7136. face = this.faces[ f ];
  7137. faceNormal = morphNormals.faceNormals[ f ];
  7138. vertexNormals = morphNormals.vertexNormals[ f ];
  7139. faceNormal.copy( face.normal );
  7140. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7141. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7142. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7143. }
  7144. }
  7145. // restore original normals
  7146. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7147. face = this.faces[ f ];
  7148. face.normal = face.__originalFaceNormal;
  7149. face.vertexNormals = face.__originalVertexNormals;
  7150. }
  7151. },
  7152. computeBoundingBox: function () {
  7153. if ( this.boundingBox === null ) {
  7154. this.boundingBox = new Box3();
  7155. }
  7156. this.boundingBox.setFromPoints( this.vertices );
  7157. },
  7158. computeBoundingSphere: function () {
  7159. if ( this.boundingSphere === null ) {
  7160. this.boundingSphere = new Sphere();
  7161. }
  7162. this.boundingSphere.setFromPoints( this.vertices );
  7163. },
  7164. merge: function ( geometry, matrix, materialIndexOffset ) {
  7165. if ( ! ( geometry && geometry.isGeometry ) ) {
  7166. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7167. return;
  7168. }
  7169. var normalMatrix,
  7170. vertexOffset = this.vertices.length,
  7171. vertices1 = this.vertices,
  7172. vertices2 = geometry.vertices,
  7173. faces1 = this.faces,
  7174. faces2 = geometry.faces,
  7175. colors1 = this.colors,
  7176. colors2 = geometry.colors;
  7177. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7178. if ( matrix !== undefined ) {
  7179. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7180. }
  7181. // vertices
  7182. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7183. var vertex = vertices2[ i ];
  7184. var vertexCopy = vertex.clone();
  7185. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7186. vertices1.push( vertexCopy );
  7187. }
  7188. // colors
  7189. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7190. colors1.push( colors2[ i ].clone() );
  7191. }
  7192. // faces
  7193. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7194. var face = faces2[ i ], faceCopy, normal, color,
  7195. faceVertexNormals = face.vertexNormals,
  7196. faceVertexColors = face.vertexColors;
  7197. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7198. faceCopy.normal.copy( face.normal );
  7199. if ( normalMatrix !== undefined ) {
  7200. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7201. }
  7202. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7203. normal = faceVertexNormals[ j ].clone();
  7204. if ( normalMatrix !== undefined ) {
  7205. normal.applyMatrix3( normalMatrix ).normalize();
  7206. }
  7207. faceCopy.vertexNormals.push( normal );
  7208. }
  7209. faceCopy.color.copy( face.color );
  7210. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7211. color = faceVertexColors[ j ];
  7212. faceCopy.vertexColors.push( color.clone() );
  7213. }
  7214. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7215. faces1.push( faceCopy );
  7216. }
  7217. // uvs
  7218. for ( var i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7219. var faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7220. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7221. for ( var j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7222. var uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7223. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7224. uvsCopy.push( uvs2[ k ].clone() );
  7225. }
  7226. this.faceVertexUvs[ i ].push( uvsCopy );
  7227. }
  7228. }
  7229. },
  7230. mergeMesh: function ( mesh ) {
  7231. if ( ! ( mesh && mesh.isMesh ) ) {
  7232. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7233. return;
  7234. }
  7235. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7236. this.merge( mesh.geometry, mesh.matrix );
  7237. },
  7238. /*
  7239. * Checks for duplicate vertices with hashmap.
  7240. * Duplicated vertices are removed
  7241. * and faces' vertices are updated.
  7242. */
  7243. mergeVertices: function () {
  7244. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7245. var unique = [], changes = [];
  7246. var v, key;
  7247. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7248. var precision = Math.pow( 10, precisionPoints );
  7249. var i, il, face;
  7250. var indices, j, jl;
  7251. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7252. v = this.vertices[ i ];
  7253. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7254. if ( verticesMap[ key ] === undefined ) {
  7255. verticesMap[ key ] = i;
  7256. unique.push( this.vertices[ i ] );
  7257. changes[ i ] = unique.length - 1;
  7258. } else {
  7259. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7260. changes[ i ] = changes[ verticesMap[ key ] ];
  7261. }
  7262. }
  7263. // if faces are completely degenerate after merging vertices, we
  7264. // have to remove them from the geometry.
  7265. var faceIndicesToRemove = [];
  7266. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7267. face = this.faces[ i ];
  7268. face.a = changes[ face.a ];
  7269. face.b = changes[ face.b ];
  7270. face.c = changes[ face.c ];
  7271. indices = [ face.a, face.b, face.c ];
  7272. // if any duplicate vertices are found in a Face3
  7273. // we have to remove the face as nothing can be saved
  7274. for ( var n = 0; n < 3; n ++ ) {
  7275. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7276. faceIndicesToRemove.push( i );
  7277. break;
  7278. }
  7279. }
  7280. }
  7281. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7282. var idx = faceIndicesToRemove[ i ];
  7283. this.faces.splice( idx, 1 );
  7284. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7285. this.faceVertexUvs[ j ].splice( idx, 1 );
  7286. }
  7287. }
  7288. // Use unique set of vertices
  7289. var diff = this.vertices.length - unique.length;
  7290. this.vertices = unique;
  7291. return diff;
  7292. },
  7293. setFromPoints: function ( points ) {
  7294. this.vertices = [];
  7295. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7296. var point = points[ i ];
  7297. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7298. }
  7299. return this;
  7300. },
  7301. sortFacesByMaterialIndex: function () {
  7302. var faces = this.faces;
  7303. var length = faces.length;
  7304. // tag faces
  7305. for ( var i = 0; i < length; i ++ ) {
  7306. faces[ i ]._id = i;
  7307. }
  7308. // sort faces
  7309. function materialIndexSort( a, b ) {
  7310. return a.materialIndex - b.materialIndex;
  7311. }
  7312. faces.sort( materialIndexSort );
  7313. // sort uvs
  7314. var uvs1 = this.faceVertexUvs[ 0 ];
  7315. var uvs2 = this.faceVertexUvs[ 1 ];
  7316. var newUvs1, newUvs2;
  7317. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7318. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7319. for ( var i = 0; i < length; i ++ ) {
  7320. var id = faces[ i ]._id;
  7321. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7322. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7323. }
  7324. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7325. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7326. },
  7327. toJSON: function () {
  7328. var data = {
  7329. metadata: {
  7330. version: 4.5,
  7331. type: 'Geometry',
  7332. generator: 'Geometry.toJSON'
  7333. }
  7334. };
  7335. // standard Geometry serialization
  7336. data.uuid = this.uuid;
  7337. data.type = this.type;
  7338. if ( this.name !== '' ) data.name = this.name;
  7339. if ( this.parameters !== undefined ) {
  7340. var parameters = this.parameters;
  7341. for ( var key in parameters ) {
  7342. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7343. }
  7344. return data;
  7345. }
  7346. var vertices = [];
  7347. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7348. var vertex = this.vertices[ i ];
  7349. vertices.push( vertex.x, vertex.y, vertex.z );
  7350. }
  7351. var faces = [];
  7352. var normals = [];
  7353. var normalsHash = {};
  7354. var colors = [];
  7355. var colorsHash = {};
  7356. var uvs = [];
  7357. var uvsHash = {};
  7358. for ( var i = 0; i < this.faces.length; i ++ ) {
  7359. var face = this.faces[ i ];
  7360. var hasMaterial = true;
  7361. var hasFaceUv = false; // deprecated
  7362. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7363. var hasFaceNormal = face.normal.length() > 0;
  7364. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7365. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7366. var hasFaceVertexColor = face.vertexColors.length > 0;
  7367. var faceType = 0;
  7368. faceType = setBit( faceType, 0, 0 ); // isQuad
  7369. faceType = setBit( faceType, 1, hasMaterial );
  7370. faceType = setBit( faceType, 2, hasFaceUv );
  7371. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7372. faceType = setBit( faceType, 4, hasFaceNormal );
  7373. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7374. faceType = setBit( faceType, 6, hasFaceColor );
  7375. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7376. faces.push( faceType );
  7377. faces.push( face.a, face.b, face.c );
  7378. faces.push( face.materialIndex );
  7379. if ( hasFaceVertexUv ) {
  7380. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7381. faces.push(
  7382. getUvIndex( faceVertexUvs[ 0 ] ),
  7383. getUvIndex( faceVertexUvs[ 1 ] ),
  7384. getUvIndex( faceVertexUvs[ 2 ] )
  7385. );
  7386. }
  7387. if ( hasFaceNormal ) {
  7388. faces.push( getNormalIndex( face.normal ) );
  7389. }
  7390. if ( hasFaceVertexNormal ) {
  7391. var vertexNormals = face.vertexNormals;
  7392. faces.push(
  7393. getNormalIndex( vertexNormals[ 0 ] ),
  7394. getNormalIndex( vertexNormals[ 1 ] ),
  7395. getNormalIndex( vertexNormals[ 2 ] )
  7396. );
  7397. }
  7398. if ( hasFaceColor ) {
  7399. faces.push( getColorIndex( face.color ) );
  7400. }
  7401. if ( hasFaceVertexColor ) {
  7402. var vertexColors = face.vertexColors;
  7403. faces.push(
  7404. getColorIndex( vertexColors[ 0 ] ),
  7405. getColorIndex( vertexColors[ 1 ] ),
  7406. getColorIndex( vertexColors[ 2 ] )
  7407. );
  7408. }
  7409. }
  7410. function setBit( value, position, enabled ) {
  7411. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7412. }
  7413. function getNormalIndex( normal ) {
  7414. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7415. if ( normalsHash[ hash ] !== undefined ) {
  7416. return normalsHash[ hash ];
  7417. }
  7418. normalsHash[ hash ] = normals.length / 3;
  7419. normals.push( normal.x, normal.y, normal.z );
  7420. return normalsHash[ hash ];
  7421. }
  7422. function getColorIndex( color ) {
  7423. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7424. if ( colorsHash[ hash ] !== undefined ) {
  7425. return colorsHash[ hash ];
  7426. }
  7427. colorsHash[ hash ] = colors.length;
  7428. colors.push( color.getHex() );
  7429. return colorsHash[ hash ];
  7430. }
  7431. function getUvIndex( uv ) {
  7432. var hash = uv.x.toString() + uv.y.toString();
  7433. if ( uvsHash[ hash ] !== undefined ) {
  7434. return uvsHash[ hash ];
  7435. }
  7436. uvsHash[ hash ] = uvs.length / 2;
  7437. uvs.push( uv.x, uv.y );
  7438. return uvsHash[ hash ];
  7439. }
  7440. data.data = {};
  7441. data.data.vertices = vertices;
  7442. data.data.normals = normals;
  7443. if ( colors.length > 0 ) data.data.colors = colors;
  7444. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7445. data.data.faces = faces;
  7446. return data;
  7447. },
  7448. clone: function () {
  7449. /*
  7450. // Handle primitives
  7451. var parameters = this.parameters;
  7452. if ( parameters !== undefined ) {
  7453. var values = [];
  7454. for ( var key in parameters ) {
  7455. values.push( parameters[ key ] );
  7456. }
  7457. var geometry = Object.create( this.constructor.prototype );
  7458. this.constructor.apply( geometry, values );
  7459. return geometry;
  7460. }
  7461. return new this.constructor().copy( this );
  7462. */
  7463. return new Geometry().copy( this );
  7464. },
  7465. copy: function ( source ) {
  7466. var i, il, j, jl, k, kl;
  7467. // reset
  7468. this.vertices = [];
  7469. this.colors = [];
  7470. this.faces = [];
  7471. this.faceVertexUvs = [[]];
  7472. this.morphTargets = [];
  7473. this.morphNormals = [];
  7474. this.skinWeights = [];
  7475. this.skinIndices = [];
  7476. this.lineDistances = [];
  7477. this.boundingBox = null;
  7478. this.boundingSphere = null;
  7479. // name
  7480. this.name = source.name;
  7481. // vertices
  7482. var vertices = source.vertices;
  7483. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7484. this.vertices.push( vertices[ i ].clone() );
  7485. }
  7486. // colors
  7487. var colors = source.colors;
  7488. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7489. this.colors.push( colors[ i ].clone() );
  7490. }
  7491. // faces
  7492. var faces = source.faces;
  7493. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7494. this.faces.push( faces[ i ].clone() );
  7495. }
  7496. // face vertex uvs
  7497. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7498. var faceVertexUvs = source.faceVertexUvs[ i ];
  7499. if ( this.faceVertexUvs[ i ] === undefined ) {
  7500. this.faceVertexUvs[ i ] = [];
  7501. }
  7502. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7503. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7504. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7505. var uv = uvs[ k ];
  7506. uvsCopy.push( uv.clone() );
  7507. }
  7508. this.faceVertexUvs[ i ].push( uvsCopy );
  7509. }
  7510. }
  7511. // morph targets
  7512. var morphTargets = source.morphTargets;
  7513. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7514. var morphTarget = {};
  7515. morphTarget.name = morphTargets[ i ].name;
  7516. // vertices
  7517. if ( morphTargets[ i ].vertices !== undefined ) {
  7518. morphTarget.vertices = [];
  7519. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7520. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7521. }
  7522. }
  7523. // normals
  7524. if ( morphTargets[ i ].normals !== undefined ) {
  7525. morphTarget.normals = [];
  7526. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7527. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7528. }
  7529. }
  7530. this.morphTargets.push( morphTarget );
  7531. }
  7532. // morph normals
  7533. var morphNormals = source.morphNormals;
  7534. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7535. var morphNormal = {};
  7536. // vertex normals
  7537. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7538. morphNormal.vertexNormals = [];
  7539. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7540. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7541. var destVertexNormal = {};
  7542. destVertexNormal.a = srcVertexNormal.a.clone();
  7543. destVertexNormal.b = srcVertexNormal.b.clone();
  7544. destVertexNormal.c = srcVertexNormal.c.clone();
  7545. morphNormal.vertexNormals.push( destVertexNormal );
  7546. }
  7547. }
  7548. // face normals
  7549. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7550. morphNormal.faceNormals = [];
  7551. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7552. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7553. }
  7554. }
  7555. this.morphNormals.push( morphNormal );
  7556. }
  7557. // skin weights
  7558. var skinWeights = source.skinWeights;
  7559. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7560. this.skinWeights.push( skinWeights[ i ].clone() );
  7561. }
  7562. // skin indices
  7563. var skinIndices = source.skinIndices;
  7564. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7565. this.skinIndices.push( skinIndices[ i ].clone() );
  7566. }
  7567. // line distances
  7568. var lineDistances = source.lineDistances;
  7569. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7570. this.lineDistances.push( lineDistances[ i ] );
  7571. }
  7572. // bounding box
  7573. var boundingBox = source.boundingBox;
  7574. if ( boundingBox !== null ) {
  7575. this.boundingBox = boundingBox.clone();
  7576. }
  7577. // bounding sphere
  7578. var boundingSphere = source.boundingSphere;
  7579. if ( boundingSphere !== null ) {
  7580. this.boundingSphere = boundingSphere.clone();
  7581. }
  7582. // update flags
  7583. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7584. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7585. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7586. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7587. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7588. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7589. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7590. return this;
  7591. },
  7592. dispose: function () {
  7593. this.dispatchEvent( { type: 'dispose' } );
  7594. }
  7595. } );
  7596. /**
  7597. * @author mrdoob / http://mrdoob.com/
  7598. * @author Mugen87 / https://github.com/Mugen87
  7599. */
  7600. // BoxGeometry
  7601. class BoxGeometry extends Geometry {
  7602. constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7603. super();
  7604. this.type = 'BoxGeometry';
  7605. this.parameters = {
  7606. width: width,
  7607. height: height,
  7608. depth: depth,
  7609. widthSegments: widthSegments,
  7610. heightSegments: heightSegments,
  7611. depthSegments: depthSegments
  7612. };
  7613. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7614. this.mergeVertices();
  7615. }
  7616. }
  7617. // BoxBufferGeometry
  7618. class BoxBufferGeometry extends BufferGeometry {
  7619. constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7620. super();
  7621. this.type = 'BoxBufferGeometry';
  7622. this.parameters = {
  7623. width: width,
  7624. height: height,
  7625. depth: depth,
  7626. widthSegments: widthSegments,
  7627. heightSegments: heightSegments,
  7628. depthSegments: depthSegments
  7629. };
  7630. var scope = this;
  7631. width = width || 1;
  7632. height = height || 1;
  7633. depth = depth || 1;
  7634. // segments
  7635. widthSegments = Math.floor( widthSegments ) || 1;
  7636. heightSegments = Math.floor( heightSegments ) || 1;
  7637. depthSegments = Math.floor( depthSegments ) || 1;
  7638. // buffers
  7639. var indices = [];
  7640. var vertices = [];
  7641. var normals = [];
  7642. var uvs = [];
  7643. // helper variables
  7644. var numberOfVertices = 0;
  7645. var groupStart = 0;
  7646. // build each side of the box geometry
  7647. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7648. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7649. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7650. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7651. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7652. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7653. // build geometry
  7654. this.setIndex( indices );
  7655. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7656. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7657. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7658. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7659. var segmentWidth = width / gridX;
  7660. var segmentHeight = height / gridY;
  7661. var widthHalf = width / 2;
  7662. var heightHalf = height / 2;
  7663. var depthHalf = depth / 2;
  7664. var gridX1 = gridX + 1;
  7665. var gridY1 = gridY + 1;
  7666. var vertexCounter = 0;
  7667. var groupCount = 0;
  7668. var ix, iy;
  7669. var vector = new Vector3();
  7670. // generate vertices, normals and uvs
  7671. for ( iy = 0; iy < gridY1; iy ++ ) {
  7672. var y = iy * segmentHeight - heightHalf;
  7673. for ( ix = 0; ix < gridX1; ix ++ ) {
  7674. var x = ix * segmentWidth - widthHalf;
  7675. // set values to correct vector component
  7676. vector[ u ] = x * udir;
  7677. vector[ v ] = y * vdir;
  7678. vector[ w ] = depthHalf;
  7679. // now apply vector to vertex buffer
  7680. vertices.push( vector.x, vector.y, vector.z );
  7681. // set values to correct vector component
  7682. vector[ u ] = 0;
  7683. vector[ v ] = 0;
  7684. vector[ w ] = depth > 0 ? 1 : - 1;
  7685. // now apply vector to normal buffer
  7686. normals.push( vector.x, vector.y, vector.z );
  7687. // uvs
  7688. uvs.push( ix / gridX );
  7689. uvs.push( 1 - ( iy / gridY ) );
  7690. // counters
  7691. vertexCounter += 1;
  7692. }
  7693. }
  7694. // indices
  7695. // 1. you need three indices to draw a single face
  7696. // 2. a single segment consists of two faces
  7697. // 3. so we need to generate six (2*3) indices per segment
  7698. for ( iy = 0; iy < gridY; iy ++ ) {
  7699. for ( ix = 0; ix < gridX; ix ++ ) {
  7700. var a = numberOfVertices + ix + gridX1 * iy;
  7701. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7702. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7703. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7704. // faces
  7705. indices.push( a, b, d );
  7706. indices.push( b, c, d );
  7707. // increase counter
  7708. groupCount += 6;
  7709. }
  7710. }
  7711. // add a group to the geometry. this will ensure multi material support
  7712. scope.addGroup( groupStart, groupCount, materialIndex );
  7713. // calculate new start value for groups
  7714. groupStart += groupCount;
  7715. // update total number of vertices
  7716. numberOfVertices += vertexCounter;
  7717. }
  7718. }
  7719. }
  7720. /**
  7721. * Uniform Utilities
  7722. */
  7723. function cloneUniforms( src ) {
  7724. var dst = {};
  7725. for ( var u in src ) {
  7726. dst[ u ] = {};
  7727. for ( var p in src[ u ] ) {
  7728. var property = src[ u ][ p ];
  7729. if ( property && ( property.isColor ||
  7730. property.isMatrix3 || property.isMatrix4 ||
  7731. property.isVector2 || property.isVector3 || property.isVector4 ||
  7732. property.isTexture ) ) {
  7733. dst[ u ][ p ] = property.clone();
  7734. } else if ( Array.isArray( property ) ) {
  7735. dst[ u ][ p ] = property.slice();
  7736. } else {
  7737. dst[ u ][ p ] = property;
  7738. }
  7739. }
  7740. }
  7741. return dst;
  7742. }
  7743. function mergeUniforms( uniforms ) {
  7744. var merged = {};
  7745. for ( var u = 0; u < uniforms.length; u ++ ) {
  7746. var tmp = cloneUniforms( uniforms[ u ] );
  7747. for ( var p in tmp ) {
  7748. merged[ p ] = tmp[ p ];
  7749. }
  7750. }
  7751. return merged;
  7752. }
  7753. // Legacy
  7754. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7755. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7756. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7757. /**
  7758. * @author alteredq / http://alteredqualia.com/
  7759. *
  7760. * parameters = {
  7761. * defines: { "label" : "value" },
  7762. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7763. *
  7764. * fragmentShader: <string>,
  7765. * vertexShader: <string>,
  7766. *
  7767. * wireframe: <boolean>,
  7768. * wireframeLinewidth: <float>,
  7769. *
  7770. * lights: <bool>,
  7771. *
  7772. * skinning: <bool>,
  7773. * morphTargets: <bool>,
  7774. * morphNormals: <bool>
  7775. * }
  7776. */
  7777. function ShaderMaterial( parameters ) {
  7778. Material.call( this );
  7779. this.type = 'ShaderMaterial';
  7780. this.defines = {};
  7781. this.uniforms = {};
  7782. this.vertexShader = default_vertex;
  7783. this.fragmentShader = default_fragment;
  7784. this.linewidth = 1;
  7785. this.wireframe = false;
  7786. this.wireframeLinewidth = 1;
  7787. this.fog = false; // set to use scene fog
  7788. this.lights = false; // set to use scene lights
  7789. this.clipping = false; // set to use user-defined clipping planes
  7790. this.skinning = false; // set to use skinning attribute streams
  7791. this.morphTargets = false; // set to use morph targets
  7792. this.morphNormals = false; // set to use morph normals
  7793. this.extensions = {
  7794. derivatives: false, // set to use derivatives
  7795. fragDepth: false, // set to use fragment depth values
  7796. drawBuffers: false, // set to use draw buffers
  7797. shaderTextureLOD: false // set to use shader texture LOD
  7798. };
  7799. // When rendered geometry doesn't include these attributes but the material does,
  7800. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7801. this.defaultAttributeValues = {
  7802. 'color': [ 1, 1, 1 ],
  7803. 'uv': [ 0, 0 ],
  7804. 'uv2': [ 0, 0 ]
  7805. };
  7806. this.index0AttributeName = undefined;
  7807. this.uniformsNeedUpdate = false;
  7808. if ( parameters !== undefined ) {
  7809. if ( parameters.attributes !== undefined ) {
  7810. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7811. }
  7812. this.setValues( parameters );
  7813. }
  7814. }
  7815. ShaderMaterial.prototype = Object.create( Material.prototype );
  7816. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7817. ShaderMaterial.prototype.isShaderMaterial = true;
  7818. ShaderMaterial.prototype.copy = function ( source ) {
  7819. Material.prototype.copy.call( this, source );
  7820. this.fragmentShader = source.fragmentShader;
  7821. this.vertexShader = source.vertexShader;
  7822. this.uniforms = cloneUniforms( source.uniforms );
  7823. this.defines = Object.assign( {}, source.defines );
  7824. this.wireframe = source.wireframe;
  7825. this.wireframeLinewidth = source.wireframeLinewidth;
  7826. this.lights = source.lights;
  7827. this.clipping = source.clipping;
  7828. this.skinning = source.skinning;
  7829. this.morphTargets = source.morphTargets;
  7830. this.morphNormals = source.morphNormals;
  7831. this.extensions = source.extensions;
  7832. return this;
  7833. };
  7834. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7835. var data = Material.prototype.toJSON.call( this, meta );
  7836. data.uniforms = {};
  7837. for ( var name in this.uniforms ) {
  7838. var uniform = this.uniforms[ name ];
  7839. var value = uniform.value;
  7840. if ( value && value.isTexture ) {
  7841. data.uniforms[ name ] = {
  7842. type: 't',
  7843. value: value.toJSON( meta ).uuid
  7844. };
  7845. } else if ( value && value.isColor ) {
  7846. data.uniforms[ name ] = {
  7847. type: 'c',
  7848. value: value.getHex()
  7849. };
  7850. } else if ( value && value.isVector2 ) {
  7851. data.uniforms[ name ] = {
  7852. type: 'v2',
  7853. value: value.toArray()
  7854. };
  7855. } else if ( value && value.isVector3 ) {
  7856. data.uniforms[ name ] = {
  7857. type: 'v3',
  7858. value: value.toArray()
  7859. };
  7860. } else if ( value && value.isVector4 ) {
  7861. data.uniforms[ name ] = {
  7862. type: 'v4',
  7863. value: value.toArray()
  7864. };
  7865. } else if ( value && value.isMatrix3 ) {
  7866. data.uniforms[ name ] = {
  7867. type: 'm3',
  7868. value: value.toArray()
  7869. };
  7870. } else if ( value && value.isMatrix4 ) {
  7871. data.uniforms[ name ] = {
  7872. type: 'm4',
  7873. value: value.toArray()
  7874. };
  7875. } else {
  7876. data.uniforms[ name ] = {
  7877. value: value
  7878. };
  7879. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7880. }
  7881. }
  7882. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7883. data.vertexShader = this.vertexShader;
  7884. data.fragmentShader = this.fragmentShader;
  7885. var extensions = {};
  7886. for ( var key in this.extensions ) {
  7887. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7888. }
  7889. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7890. return data;
  7891. };
  7892. /**
  7893. * @author mrdoob / http://mrdoob.com/
  7894. * @author mikael emtinger / http://gomo.se/
  7895. * @author WestLangley / http://github.com/WestLangley
  7896. */
  7897. function Camera() {
  7898. Object3D.call( this );
  7899. this.type = 'Camera';
  7900. this.matrixWorldInverse = new Matrix4();
  7901. this.projectionMatrix = new Matrix4();
  7902. this.projectionMatrixInverse = new Matrix4();
  7903. }
  7904. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7905. constructor: Camera,
  7906. isCamera: true,
  7907. copy: function ( source, recursive ) {
  7908. Object3D.prototype.copy.call( this, source, recursive );
  7909. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7910. this.projectionMatrix.copy( source.projectionMatrix );
  7911. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7912. return this;
  7913. },
  7914. getWorldDirection: function ( target ) {
  7915. if ( target === undefined ) {
  7916. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7917. target = new Vector3();
  7918. }
  7919. this.updateMatrixWorld( true );
  7920. var e = this.matrixWorld.elements;
  7921. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7922. },
  7923. updateMatrixWorld: function ( force ) {
  7924. Object3D.prototype.updateMatrixWorld.call( this, force );
  7925. this.matrixWorldInverse.getInverse( this.matrixWorld );
  7926. },
  7927. clone: function () {
  7928. return new this.constructor().copy( this );
  7929. }
  7930. } );
  7931. /**
  7932. * @author mrdoob / http://mrdoob.com/
  7933. * @author greggman / http://games.greggman.com/
  7934. * @author zz85 / http://www.lab4games.net/zz85/blog
  7935. * @author tschw
  7936. */
  7937. function PerspectiveCamera( fov, aspect, near, far ) {
  7938. Camera.call( this );
  7939. this.type = 'PerspectiveCamera';
  7940. this.fov = fov !== undefined ? fov : 50;
  7941. this.zoom = 1;
  7942. this.near = near !== undefined ? near : 0.1;
  7943. this.far = far !== undefined ? far : 2000;
  7944. this.focus = 10;
  7945. this.aspect = aspect !== undefined ? aspect : 1;
  7946. this.view = null;
  7947. this.filmGauge = 35; // width of the film (default in millimeters)
  7948. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7949. this.updateProjectionMatrix();
  7950. }
  7951. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7952. constructor: PerspectiveCamera,
  7953. isPerspectiveCamera: true,
  7954. copy: function ( source, recursive ) {
  7955. Camera.prototype.copy.call( this, source, recursive );
  7956. this.fov = source.fov;
  7957. this.zoom = source.zoom;
  7958. this.near = source.near;
  7959. this.far = source.far;
  7960. this.focus = source.focus;
  7961. this.aspect = source.aspect;
  7962. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7963. this.filmGauge = source.filmGauge;
  7964. this.filmOffset = source.filmOffset;
  7965. return this;
  7966. },
  7967. /**
  7968. * Sets the FOV by focal length in respect to the current .filmGauge.
  7969. *
  7970. * The default film gauge is 35, so that the focal length can be specified for
  7971. * a 35mm (full frame) camera.
  7972. *
  7973. * Values for focal length and film gauge must have the same unit.
  7974. */
  7975. setFocalLength: function ( focalLength ) {
  7976. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7977. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7978. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7979. this.updateProjectionMatrix();
  7980. },
  7981. /**
  7982. * Calculates the focal length from the current .fov and .filmGauge.
  7983. */
  7984. getFocalLength: function () {
  7985. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  7986. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7987. },
  7988. getEffectiveFOV: function () {
  7989. return _Math.RAD2DEG * 2 * Math.atan(
  7990. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7991. },
  7992. getFilmWidth: function () {
  7993. // film not completely covered in portrait format (aspect < 1)
  7994. return this.filmGauge * Math.min( this.aspect, 1 );
  7995. },
  7996. getFilmHeight: function () {
  7997. // film not completely covered in landscape format (aspect > 1)
  7998. return this.filmGauge / Math.max( this.aspect, 1 );
  7999. },
  8000. /**
  8001. * Sets an offset in a larger frustum. This is useful for multi-window or
  8002. * multi-monitor/multi-machine setups.
  8003. *
  8004. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8005. * the monitors are in grid like this
  8006. *
  8007. * +---+---+---+
  8008. * | A | B | C |
  8009. * +---+---+---+
  8010. * | D | E | F |
  8011. * +---+---+---+
  8012. *
  8013. * then for each monitor you would call it like this
  8014. *
  8015. * var w = 1920;
  8016. * var h = 1080;
  8017. * var fullWidth = w * 3;
  8018. * var fullHeight = h * 2;
  8019. *
  8020. * --A--
  8021. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8022. * --B--
  8023. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8024. * --C--
  8025. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8026. * --D--
  8027. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8028. * --E--
  8029. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8030. * --F--
  8031. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8032. *
  8033. * Note there is no reason monitors have to be the same size or in a grid.
  8034. */
  8035. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  8036. this.aspect = fullWidth / fullHeight;
  8037. if ( this.view === null ) {
  8038. this.view = {
  8039. enabled: true,
  8040. fullWidth: 1,
  8041. fullHeight: 1,
  8042. offsetX: 0,
  8043. offsetY: 0,
  8044. width: 1,
  8045. height: 1
  8046. };
  8047. }
  8048. this.view.enabled = true;
  8049. this.view.fullWidth = fullWidth;
  8050. this.view.fullHeight = fullHeight;
  8051. this.view.offsetX = x;
  8052. this.view.offsetY = y;
  8053. this.view.width = width;
  8054. this.view.height = height;
  8055. this.updateProjectionMatrix();
  8056. },
  8057. clearViewOffset: function () {
  8058. if ( this.view !== null ) {
  8059. this.view.enabled = false;
  8060. }
  8061. this.updateProjectionMatrix();
  8062. },
  8063. updateProjectionMatrix: function () {
  8064. var near = this.near,
  8065. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8066. height = 2 * top,
  8067. width = this.aspect * height,
  8068. left = - 0.5 * width,
  8069. view = this.view;
  8070. if ( this.view !== null && this.view.enabled ) {
  8071. var fullWidth = view.fullWidth,
  8072. fullHeight = view.fullHeight;
  8073. left += view.offsetX * width / fullWidth;
  8074. top -= view.offsetY * height / fullHeight;
  8075. width *= view.width / fullWidth;
  8076. height *= view.height / fullHeight;
  8077. }
  8078. var skew = this.filmOffset;
  8079. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8080. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8081. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8082. },
  8083. toJSON: function ( meta ) {
  8084. var data = Object3D.prototype.toJSON.call( this, meta );
  8085. data.object.fov = this.fov;
  8086. data.object.zoom = this.zoom;
  8087. data.object.near = this.near;
  8088. data.object.far = this.far;
  8089. data.object.focus = this.focus;
  8090. data.object.aspect = this.aspect;
  8091. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8092. data.object.filmGauge = this.filmGauge;
  8093. data.object.filmOffset = this.filmOffset;
  8094. return data;
  8095. }
  8096. } );
  8097. /**
  8098. * Camera for rendering cube maps
  8099. * - renders scene into axis-aligned cube
  8100. *
  8101. * @author alteredq / http://alteredqualia.com/
  8102. */
  8103. var fov = 90, aspect = 1;
  8104. function CubeCamera( near, far, cubeResolution, options ) {
  8105. Object3D.call( this );
  8106. this.type = 'CubeCamera';
  8107. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8108. cameraPX.up.set( 0, - 1, 0 );
  8109. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8110. this.add( cameraPX );
  8111. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8112. cameraNX.up.set( 0, - 1, 0 );
  8113. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8114. this.add( cameraNX );
  8115. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8116. cameraPY.up.set( 0, 0, 1 );
  8117. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8118. this.add( cameraPY );
  8119. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8120. cameraNY.up.set( 0, 0, - 1 );
  8121. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8122. this.add( cameraNY );
  8123. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8124. cameraPZ.up.set( 0, - 1, 0 );
  8125. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8126. this.add( cameraPZ );
  8127. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8128. cameraNZ.up.set( 0, - 1, 0 );
  8129. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8130. this.add( cameraNZ );
  8131. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  8132. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  8133. this.renderTarget.texture.name = "CubeCamera";
  8134. this.update = function ( renderer, scene ) {
  8135. if ( this.parent === null ) this.updateMatrixWorld();
  8136. var currentRenderTarget = renderer.getRenderTarget();
  8137. var renderTarget = this.renderTarget;
  8138. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8139. renderTarget.texture.generateMipmaps = false;
  8140. renderer.setRenderTarget( renderTarget, 0 );
  8141. renderer.render( scene, cameraPX );
  8142. renderer.setRenderTarget( renderTarget, 1 );
  8143. renderer.render( scene, cameraNX );
  8144. renderer.setRenderTarget( renderTarget, 2 );
  8145. renderer.render( scene, cameraPY );
  8146. renderer.setRenderTarget( renderTarget, 3 );
  8147. renderer.render( scene, cameraNY );
  8148. renderer.setRenderTarget( renderTarget, 4 );
  8149. renderer.render( scene, cameraPZ );
  8150. renderTarget.texture.generateMipmaps = generateMipmaps;
  8151. renderer.setRenderTarget( renderTarget, 5 );
  8152. renderer.render( scene, cameraNZ );
  8153. renderer.setRenderTarget( currentRenderTarget );
  8154. };
  8155. this.clear = function ( renderer, color, depth, stencil ) {
  8156. var currentRenderTarget = renderer.getRenderTarget();
  8157. var renderTarget = this.renderTarget;
  8158. for ( var i = 0; i < 6; i ++ ) {
  8159. renderer.setRenderTarget( renderTarget, i );
  8160. renderer.clear( color, depth, stencil );
  8161. }
  8162. renderer.setRenderTarget( currentRenderTarget );
  8163. };
  8164. }
  8165. CubeCamera.prototype = Object.create( Object3D.prototype );
  8166. CubeCamera.prototype.constructor = CubeCamera;
  8167. /**
  8168. * @author alteredq / http://alteredqualia.com
  8169. * @author WestLangley / http://github.com/WestLangley
  8170. */
  8171. function WebGLRenderTargetCube( width, height, options ) {
  8172. WebGLRenderTarget.call( this, width, height, options );
  8173. }
  8174. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  8175. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  8176. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  8177. WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8178. this.texture.type = texture.type;
  8179. this.texture.format = texture.format;
  8180. this.texture.encoding = texture.encoding;
  8181. var scene = new Scene();
  8182. var shader = {
  8183. uniforms: {
  8184. tEquirect: { value: null },
  8185. },
  8186. vertexShader: [
  8187. "varying vec3 vWorldDirection;",
  8188. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8189. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8190. "}",
  8191. "void main() {",
  8192. " vWorldDirection = transformDirection( position, modelMatrix );",
  8193. " #include <begin_vertex>",
  8194. " #include <project_vertex>",
  8195. "}"
  8196. ].join( '\n' ),
  8197. fragmentShader: [
  8198. "uniform sampler2D tEquirect;",
  8199. "varying vec3 vWorldDirection;",
  8200. "#define RECIPROCAL_PI 0.31830988618",
  8201. "#define RECIPROCAL_PI2 0.15915494",
  8202. "void main() {",
  8203. " vec3 direction = normalize( vWorldDirection );",
  8204. " vec2 sampleUV;",
  8205. " sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
  8206. " sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  8207. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8208. "}"
  8209. ].join( '\n' ),
  8210. };
  8211. var material = new ShaderMaterial( {
  8212. type: 'CubemapFromEquirect',
  8213. uniforms: cloneUniforms( shader.uniforms ),
  8214. vertexShader: shader.vertexShader,
  8215. fragmentShader: shader.fragmentShader,
  8216. side: BackSide,
  8217. blending: NoBlending
  8218. } );
  8219. material.uniforms.tEquirect.value = texture;
  8220. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8221. scene.add( mesh );
  8222. var camera = new CubeCamera( 1, 10, 1 );
  8223. camera.renderTarget = this;
  8224. camera.renderTarget.texture.name = 'CubeCameraTexture';
  8225. camera.update( renderer, scene );
  8226. mesh.geometry.dispose();
  8227. mesh.material.dispose();
  8228. return this;
  8229. };
  8230. /**
  8231. * @author alteredq / http://alteredqualia.com/
  8232. */
  8233. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8234. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8235. this.image = { data: data || null, width: width || 1, height: height || 1 };
  8236. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8237. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8238. this.generateMipmaps = false;
  8239. this.flipY = false;
  8240. this.unpackAlignment = 1;
  8241. this.needsUpdate = true;
  8242. }
  8243. DataTexture.prototype = Object.create( Texture.prototype );
  8244. DataTexture.prototype.constructor = DataTexture;
  8245. DataTexture.prototype.isDataTexture = true;
  8246. /**
  8247. * @author mrdoob / http://mrdoob.com/
  8248. * @author alteredq / http://alteredqualia.com/
  8249. * @author bhouston / http://clara.io
  8250. */
  8251. var _sphere$1 = new Sphere();
  8252. var _vector$5 = new Vector3();
  8253. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8254. this.planes = [
  8255. ( p0 !== undefined ) ? p0 : new Plane(),
  8256. ( p1 !== undefined ) ? p1 : new Plane(),
  8257. ( p2 !== undefined ) ? p2 : new Plane(),
  8258. ( p3 !== undefined ) ? p3 : new Plane(),
  8259. ( p4 !== undefined ) ? p4 : new Plane(),
  8260. ( p5 !== undefined ) ? p5 : new Plane()
  8261. ];
  8262. }
  8263. Object.assign( Frustum.prototype, {
  8264. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8265. var planes = this.planes;
  8266. planes[ 0 ].copy( p0 );
  8267. planes[ 1 ].copy( p1 );
  8268. planes[ 2 ].copy( p2 );
  8269. planes[ 3 ].copy( p3 );
  8270. planes[ 4 ].copy( p4 );
  8271. planes[ 5 ].copy( p5 );
  8272. return this;
  8273. },
  8274. clone: function () {
  8275. return new this.constructor().copy( this );
  8276. },
  8277. copy: function ( frustum ) {
  8278. var planes = this.planes;
  8279. for ( var i = 0; i < 6; i ++ ) {
  8280. planes[ i ].copy( frustum.planes[ i ] );
  8281. }
  8282. return this;
  8283. },
  8284. setFromMatrix: function ( m ) {
  8285. var planes = this.planes;
  8286. var me = m.elements;
  8287. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8288. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8289. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8290. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8291. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8292. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8293. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8294. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8295. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8296. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8297. return this;
  8298. },
  8299. intersectsObject: function ( object ) {
  8300. var geometry = object.geometry;
  8301. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8302. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  8303. return this.intersectsSphere( _sphere$1 );
  8304. },
  8305. intersectsSprite: function ( sprite ) {
  8306. _sphere$1.center.set( 0, 0, 0 );
  8307. _sphere$1.radius = 0.7071067811865476;
  8308. _sphere$1.applyMatrix4( sprite.matrixWorld );
  8309. return this.intersectsSphere( _sphere$1 );
  8310. },
  8311. intersectsSphere: function ( sphere ) {
  8312. var planes = this.planes;
  8313. var center = sphere.center;
  8314. var negRadius = - sphere.radius;
  8315. for ( var i = 0; i < 6; i ++ ) {
  8316. var distance = planes[ i ].distanceToPoint( center );
  8317. if ( distance < negRadius ) {
  8318. return false;
  8319. }
  8320. }
  8321. return true;
  8322. },
  8323. intersectsBox: function ( box ) {
  8324. var planes = this.planes;
  8325. for ( var i = 0; i < 6; i ++ ) {
  8326. var plane = planes[ i ];
  8327. // corner at max distance
  8328. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8329. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8330. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8331. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  8332. return false;
  8333. }
  8334. }
  8335. return true;
  8336. },
  8337. containsPoint: function ( point ) {
  8338. var planes = this.planes;
  8339. for ( var i = 0; i < 6; i ++ ) {
  8340. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8341. return false;
  8342. }
  8343. }
  8344. return true;
  8345. }
  8346. } );
  8347. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8348. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8349. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8350. 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";
  8351. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8352. var begin_vertex = "vec3 transformed = vec3( position );";
  8353. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8354. 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";
  8355. 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";
  8356. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
  8357. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8358. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  8359. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  8360. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8361. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8362. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8363. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8364. 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}";
  8365. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV( sampler2D envMap, vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif";
  8366. var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\ttransformedNormal = mat3( instanceMatrix ) * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = normalMatrix * objectTangent;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  8367. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8368. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8369. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8370. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8371. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8372. 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 = min( floor( D ) / 255.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}";
  8373. 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_EQUIREC )\n\t\tvec2 sampleUV;\n\t\treflectVec = normalize( reflectVec );\n\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\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\tenvColor = envMapTexelToLinear( envColor );\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";
  8374. 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";
  8375. 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";
  8376. 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";
  8377. 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";
  8378. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8379. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8380. 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";
  8381. 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";
  8382. var gradientmap_pars_fragment = "#ifdef TOON\n\tuniform sampler2D gradientMap;\n\tvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\t\tfloat dotNL = dot( normal, lightDirection );\n\t\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t\t#ifdef USE_GRADIENTMAP\n\t\t\treturn texture2D( gradientMap, coord ).rgb;\n\t\t#else\n\t\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t\t#endif\n\t}\n#endif";
  8383. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  8384. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8385. 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;\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\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#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\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#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\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#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop\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#endif";
  8386. 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\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t\tfloat shadowCameraNear;\n\t\tfloat shadowCameraFar;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  8387. 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\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, queryVec, 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\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, queryReflectVec, roughness );\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\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";
  8388. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8389. 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\t#ifdef TOON\n\t\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#else\n\t\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\t\tvec3 irradiance = dotNL * directLight.color;\n\t#endif\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)";
  8390. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 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 = saturate( clearcoat );\tmaterial.clearcoatRoughness = clamp( clearcoatRoughness, 0.04, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheen;\n#endif";
  8391. 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}";
  8392. 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#pragma unroll_loop\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\tdirectLight.color *= all( bvec3( pointLight.shadow, directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#pragma unroll_loop\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\tdirectLight.color *= all( bvec3( spotLight.shadow, directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\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\tdirectLight.color *= all( bvec3( directionalLight.shadow, directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop\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#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\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
  8393. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * 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";
  8394. 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";
  8395. 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";
  8396. 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";
  8397. 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";
  8398. 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";
  8399. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8400. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8401. 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";
  8402. 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";
  8403. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8404. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8405. 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";
  8406. 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";
  8407. 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";
  8408. 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;";
  8409. 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";
  8410. 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";
  8411. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8412. 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";
  8413. var clearcoat_normalmap_pars_fragment = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";
  8414. 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 unpack2HalfToRGBA( 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}";
  8415. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8416. 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;";
  8417. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8418. 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";
  8419. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8420. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8421. 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 unpack2HalfToRGBA( 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 texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = ( floor( uv * size - 0.5 ) + 0.5 ) * texelSize;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\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 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\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\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";
  8422. 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";
  8423. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif";
  8424. 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\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= all( bvec2( directionalLight.shadow, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= all( bvec2( spotLight.shadow, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= all( bvec2( pointLight.shadow, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#endif\n\t#endif\n\treturn shadow;\n}";
  8425. 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";
  8426. 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";
  8427. 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";
  8428. 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";
  8429. 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";
  8430. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8431. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8432. 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}";
  8433. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8434. 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";
  8435. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8436. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8437. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  8438. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  8439. 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";
  8440. 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}";
  8441. 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}";
  8442. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8443. 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}";
  8444. 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>\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\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - gl_FragCoord.z ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n\t#endif\n}";
  8445. 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>\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}";
  8446. 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}";
  8447. 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}";
  8448. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV;\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8449. 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}";
  8450. 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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8451. 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 <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\tvLineDistance = scale * lineDistance;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  8452. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\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 <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\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * 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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8453. 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}";
  8454. 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 <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\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\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}";
  8455. 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}";
  8456. 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 <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 <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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8457. 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 <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 <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}";
  8458. 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 <gradientmap_pars_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}";
  8459. 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}";
  8460. 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_normalmap_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}";
  8461. 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}";
  8462. 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}";
  8463. 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}";
  8464. 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 <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8465. 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}";
  8466. 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 <fog_fragment>\n}";
  8467. 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}";
  8468. 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}";
  8469. 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}";
  8470. var ShaderChunk = {
  8471. alphamap_fragment: alphamap_fragment,
  8472. alphamap_pars_fragment: alphamap_pars_fragment,
  8473. alphatest_fragment: alphatest_fragment,
  8474. aomap_fragment: aomap_fragment,
  8475. aomap_pars_fragment: aomap_pars_fragment,
  8476. begin_vertex: begin_vertex,
  8477. beginnormal_vertex: beginnormal_vertex,
  8478. bsdfs: bsdfs,
  8479. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8480. clipping_planes_fragment: clipping_planes_fragment,
  8481. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8482. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8483. clipping_planes_vertex: clipping_planes_vertex,
  8484. color_fragment: color_fragment,
  8485. color_pars_fragment: color_pars_fragment,
  8486. color_pars_vertex: color_pars_vertex,
  8487. color_vertex: color_vertex,
  8488. common: common,
  8489. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8490. defaultnormal_vertex: defaultnormal_vertex,
  8491. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8492. displacementmap_vertex: displacementmap_vertex,
  8493. emissivemap_fragment: emissivemap_fragment,
  8494. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8495. encodings_fragment: encodings_fragment,
  8496. encodings_pars_fragment: encodings_pars_fragment,
  8497. envmap_fragment: envmap_fragment,
  8498. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8499. envmap_pars_fragment: envmap_pars_fragment,
  8500. envmap_pars_vertex: envmap_pars_vertex,
  8501. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8502. envmap_vertex: envmap_vertex,
  8503. fog_vertex: fog_vertex,
  8504. fog_pars_vertex: fog_pars_vertex,
  8505. fog_fragment: fog_fragment,
  8506. fog_pars_fragment: fog_pars_fragment,
  8507. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8508. lightmap_fragment: lightmap_fragment,
  8509. lightmap_pars_fragment: lightmap_pars_fragment,
  8510. lights_lambert_vertex: lights_lambert_vertex,
  8511. lights_pars_begin: lights_pars_begin,
  8512. lights_phong_fragment: lights_phong_fragment,
  8513. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8514. lights_physical_fragment: lights_physical_fragment,
  8515. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8516. lights_fragment_begin: lights_fragment_begin,
  8517. lights_fragment_maps: lights_fragment_maps,
  8518. lights_fragment_end: lights_fragment_end,
  8519. logdepthbuf_fragment: logdepthbuf_fragment,
  8520. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8521. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8522. logdepthbuf_vertex: logdepthbuf_vertex,
  8523. map_fragment: map_fragment,
  8524. map_pars_fragment: map_pars_fragment,
  8525. map_particle_fragment: map_particle_fragment,
  8526. map_particle_pars_fragment: map_particle_pars_fragment,
  8527. metalnessmap_fragment: metalnessmap_fragment,
  8528. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8529. morphnormal_vertex: morphnormal_vertex,
  8530. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8531. morphtarget_vertex: morphtarget_vertex,
  8532. normal_fragment_begin: normal_fragment_begin,
  8533. normal_fragment_maps: normal_fragment_maps,
  8534. normalmap_pars_fragment: normalmap_pars_fragment,
  8535. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8536. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8537. clearcoat_normalmap_pars_fragment: clearcoat_normalmap_pars_fragment,
  8538. packing: packing,
  8539. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8540. project_vertex: project_vertex,
  8541. dithering_fragment: dithering_fragment,
  8542. dithering_pars_fragment: dithering_pars_fragment,
  8543. roughnessmap_fragment: roughnessmap_fragment,
  8544. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8545. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8546. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8547. shadowmap_vertex: shadowmap_vertex,
  8548. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8549. skinbase_vertex: skinbase_vertex,
  8550. skinning_pars_vertex: skinning_pars_vertex,
  8551. skinning_vertex: skinning_vertex,
  8552. skinnormal_vertex: skinnormal_vertex,
  8553. specularmap_fragment: specularmap_fragment,
  8554. specularmap_pars_fragment: specularmap_pars_fragment,
  8555. tonemapping_fragment: tonemapping_fragment,
  8556. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8557. uv_pars_fragment: uv_pars_fragment,
  8558. uv_pars_vertex: uv_pars_vertex,
  8559. uv_vertex: uv_vertex,
  8560. uv2_pars_fragment: uv2_pars_fragment,
  8561. uv2_pars_vertex: uv2_pars_vertex,
  8562. uv2_vertex: uv2_vertex,
  8563. worldpos_vertex: worldpos_vertex,
  8564. background_frag: background_frag,
  8565. background_vert: background_vert,
  8566. cube_frag: cube_frag,
  8567. cube_vert: cube_vert,
  8568. depth_frag: depth_frag,
  8569. depth_vert: depth_vert,
  8570. distanceRGBA_frag: distanceRGBA_frag,
  8571. distanceRGBA_vert: distanceRGBA_vert,
  8572. equirect_frag: equirect_frag,
  8573. equirect_vert: equirect_vert,
  8574. linedashed_frag: linedashed_frag,
  8575. linedashed_vert: linedashed_vert,
  8576. meshbasic_frag: meshbasic_frag,
  8577. meshbasic_vert: meshbasic_vert,
  8578. meshlambert_frag: meshlambert_frag,
  8579. meshlambert_vert: meshlambert_vert,
  8580. meshmatcap_frag: meshmatcap_frag,
  8581. meshmatcap_vert: meshmatcap_vert,
  8582. meshphong_frag: meshphong_frag,
  8583. meshphong_vert: meshphong_vert,
  8584. meshphysical_frag: meshphysical_frag,
  8585. meshphysical_vert: meshphysical_vert,
  8586. normal_frag: normal_frag,
  8587. normal_vert: normal_vert,
  8588. points_frag: points_frag,
  8589. points_vert: points_vert,
  8590. shadow_frag: shadow_frag,
  8591. shadow_vert: shadow_vert,
  8592. sprite_frag: sprite_frag,
  8593. sprite_vert: sprite_vert
  8594. };
  8595. /**
  8596. * Uniforms library for shared webgl shaders
  8597. */
  8598. var UniformsLib = {
  8599. common: {
  8600. diffuse: { value: new Color( 0xeeeeee ) },
  8601. opacity: { value: 1.0 },
  8602. map: { value: null },
  8603. uvTransform: { value: new Matrix3() },
  8604. alphaMap: { value: null },
  8605. },
  8606. specularmap: {
  8607. specularMap: { value: null },
  8608. },
  8609. envmap: {
  8610. envMap: { value: null },
  8611. flipEnvMap: { value: - 1 },
  8612. reflectivity: { value: 1.0 },
  8613. refractionRatio: { value: 0.98 },
  8614. maxMipLevel: { value: 0 }
  8615. },
  8616. aomap: {
  8617. aoMap: { value: null },
  8618. aoMapIntensity: { value: 1 }
  8619. },
  8620. lightmap: {
  8621. lightMap: { value: null },
  8622. lightMapIntensity: { value: 1 }
  8623. },
  8624. emissivemap: {
  8625. emissiveMap: { value: null }
  8626. },
  8627. bumpmap: {
  8628. bumpMap: { value: null },
  8629. bumpScale: { value: 1 }
  8630. },
  8631. normalmap: {
  8632. normalMap: { value: null },
  8633. normalScale: { value: new Vector2( 1, 1 ) }
  8634. },
  8635. displacementmap: {
  8636. displacementMap: { value: null },
  8637. displacementScale: { value: 1 },
  8638. displacementBias: { value: 0 }
  8639. },
  8640. roughnessmap: {
  8641. roughnessMap: { value: null }
  8642. },
  8643. metalnessmap: {
  8644. metalnessMap: { value: null }
  8645. },
  8646. gradientmap: {
  8647. gradientMap: { value: null }
  8648. },
  8649. fog: {
  8650. fogDensity: { value: 0.00025 },
  8651. fogNear: { value: 1 },
  8652. fogFar: { value: 2000 },
  8653. fogColor: { value: new Color( 0xffffff ) }
  8654. },
  8655. lights: {
  8656. ambientLightColor: { value: [] },
  8657. lightProbe: { value: [] },
  8658. directionalLights: { value: [], properties: {
  8659. direction: {},
  8660. color: {},
  8661. shadow: {},
  8662. shadowBias: {},
  8663. shadowRadius: {},
  8664. shadowMapSize: {}
  8665. } },
  8666. directionalShadowMap: { value: [] },
  8667. directionalShadowMatrix: { value: [] },
  8668. spotLights: { value: [], properties: {
  8669. color: {},
  8670. position: {},
  8671. direction: {},
  8672. distance: {},
  8673. coneCos: {},
  8674. penumbraCos: {},
  8675. decay: {},
  8676. shadow: {},
  8677. shadowBias: {},
  8678. shadowRadius: {},
  8679. shadowMapSize: {}
  8680. } },
  8681. spotShadowMap: { value: [] },
  8682. spotShadowMatrix: { value: [] },
  8683. pointLights: { value: [], properties: {
  8684. color: {},
  8685. position: {},
  8686. decay: {},
  8687. distance: {},
  8688. shadow: {},
  8689. shadowBias: {},
  8690. shadowRadius: {},
  8691. shadowMapSize: {},
  8692. shadowCameraNear: {},
  8693. shadowCameraFar: {}
  8694. } },
  8695. pointShadowMap: { value: [] },
  8696. pointShadowMatrix: { value: [] },
  8697. hemisphereLights: { value: [], properties: {
  8698. direction: {},
  8699. skyColor: {},
  8700. groundColor: {}
  8701. } },
  8702. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8703. rectAreaLights: { value: [], properties: {
  8704. color: {},
  8705. position: {},
  8706. width: {},
  8707. height: {}
  8708. } }
  8709. },
  8710. points: {
  8711. diffuse: { value: new Color( 0xeeeeee ) },
  8712. opacity: { value: 1.0 },
  8713. size: { value: 1.0 },
  8714. scale: { value: 1.0 },
  8715. map: { value: null },
  8716. alphaMap: { value: null },
  8717. uvTransform: { value: new Matrix3() }
  8718. },
  8719. sprite: {
  8720. diffuse: { value: new Color( 0xeeeeee ) },
  8721. opacity: { value: 1.0 },
  8722. center: { value: new Vector2( 0.5, 0.5 ) },
  8723. rotation: { value: 0.0 },
  8724. map: { value: null },
  8725. alphaMap: { value: null },
  8726. uvTransform: { value: new Matrix3() }
  8727. }
  8728. };
  8729. /**
  8730. * @author alteredq / http://alteredqualia.com/
  8731. * @author mrdoob / http://mrdoob.com/
  8732. * @author mikael emtinger / http://gomo.se/
  8733. */
  8734. var ShaderLib = {
  8735. basic: {
  8736. uniforms: mergeUniforms( [
  8737. UniformsLib.common,
  8738. UniformsLib.specularmap,
  8739. UniformsLib.envmap,
  8740. UniformsLib.aomap,
  8741. UniformsLib.lightmap,
  8742. UniformsLib.fog
  8743. ] ),
  8744. vertexShader: ShaderChunk.meshbasic_vert,
  8745. fragmentShader: ShaderChunk.meshbasic_frag
  8746. },
  8747. lambert: {
  8748. uniforms: mergeUniforms( [
  8749. UniformsLib.common,
  8750. UniformsLib.specularmap,
  8751. UniformsLib.envmap,
  8752. UniformsLib.aomap,
  8753. UniformsLib.lightmap,
  8754. UniformsLib.emissivemap,
  8755. UniformsLib.fog,
  8756. UniformsLib.lights,
  8757. {
  8758. emissive: { value: new Color( 0x000000 ) }
  8759. }
  8760. ] ),
  8761. vertexShader: ShaderChunk.meshlambert_vert,
  8762. fragmentShader: ShaderChunk.meshlambert_frag
  8763. },
  8764. phong: {
  8765. uniforms: mergeUniforms( [
  8766. UniformsLib.common,
  8767. UniformsLib.specularmap,
  8768. UniformsLib.envmap,
  8769. UniformsLib.aomap,
  8770. UniformsLib.lightmap,
  8771. UniformsLib.emissivemap,
  8772. UniformsLib.bumpmap,
  8773. UniformsLib.normalmap,
  8774. UniformsLib.displacementmap,
  8775. UniformsLib.gradientmap,
  8776. UniformsLib.fog,
  8777. UniformsLib.lights,
  8778. {
  8779. emissive: { value: new Color( 0x000000 ) },
  8780. specular: { value: new Color( 0x111111 ) },
  8781. shininess: { value: 30 }
  8782. }
  8783. ] ),
  8784. vertexShader: ShaderChunk.meshphong_vert,
  8785. fragmentShader: ShaderChunk.meshphong_frag
  8786. },
  8787. standard: {
  8788. uniforms: mergeUniforms( [
  8789. UniformsLib.common,
  8790. UniformsLib.envmap,
  8791. UniformsLib.aomap,
  8792. UniformsLib.lightmap,
  8793. UniformsLib.emissivemap,
  8794. UniformsLib.bumpmap,
  8795. UniformsLib.normalmap,
  8796. UniformsLib.displacementmap,
  8797. UniformsLib.roughnessmap,
  8798. UniformsLib.metalnessmap,
  8799. UniformsLib.fog,
  8800. UniformsLib.lights,
  8801. {
  8802. emissive: { value: new Color( 0x000000 ) },
  8803. roughness: { value: 0.5 },
  8804. metalness: { value: 0.5 },
  8805. envMapIntensity: { value: 1 } // temporary
  8806. }
  8807. ] ),
  8808. vertexShader: ShaderChunk.meshphysical_vert,
  8809. fragmentShader: ShaderChunk.meshphysical_frag
  8810. },
  8811. matcap: {
  8812. uniforms: mergeUniforms( [
  8813. UniformsLib.common,
  8814. UniformsLib.bumpmap,
  8815. UniformsLib.normalmap,
  8816. UniformsLib.displacementmap,
  8817. UniformsLib.fog,
  8818. {
  8819. matcap: { value: null }
  8820. }
  8821. ] ),
  8822. vertexShader: ShaderChunk.meshmatcap_vert,
  8823. fragmentShader: ShaderChunk.meshmatcap_frag
  8824. },
  8825. points: {
  8826. uniforms: mergeUniforms( [
  8827. UniformsLib.points,
  8828. UniformsLib.fog
  8829. ] ),
  8830. vertexShader: ShaderChunk.points_vert,
  8831. fragmentShader: ShaderChunk.points_frag
  8832. },
  8833. dashed: {
  8834. uniforms: mergeUniforms( [
  8835. UniformsLib.common,
  8836. UniformsLib.fog,
  8837. {
  8838. scale: { value: 1 },
  8839. dashSize: { value: 1 },
  8840. totalSize: { value: 2 }
  8841. }
  8842. ] ),
  8843. vertexShader: ShaderChunk.linedashed_vert,
  8844. fragmentShader: ShaderChunk.linedashed_frag
  8845. },
  8846. depth: {
  8847. uniforms: mergeUniforms( [
  8848. UniformsLib.common,
  8849. UniformsLib.displacementmap
  8850. ] ),
  8851. vertexShader: ShaderChunk.depth_vert,
  8852. fragmentShader: ShaderChunk.depth_frag
  8853. },
  8854. normal: {
  8855. uniforms: mergeUniforms( [
  8856. UniformsLib.common,
  8857. UniformsLib.bumpmap,
  8858. UniformsLib.normalmap,
  8859. UniformsLib.displacementmap,
  8860. {
  8861. opacity: { value: 1.0 }
  8862. }
  8863. ] ),
  8864. vertexShader: ShaderChunk.normal_vert,
  8865. fragmentShader: ShaderChunk.normal_frag
  8866. },
  8867. sprite: {
  8868. uniforms: mergeUniforms( [
  8869. UniformsLib.sprite,
  8870. UniformsLib.fog
  8871. ] ),
  8872. vertexShader: ShaderChunk.sprite_vert,
  8873. fragmentShader: ShaderChunk.sprite_frag
  8874. },
  8875. background: {
  8876. uniforms: {
  8877. uvTransform: { value: new Matrix3() },
  8878. t2D: { value: null },
  8879. },
  8880. vertexShader: ShaderChunk.background_vert,
  8881. fragmentShader: ShaderChunk.background_frag
  8882. },
  8883. /* -------------------------------------------------------------------------
  8884. // Cube map shader
  8885. ------------------------------------------------------------------------- */
  8886. cube: {
  8887. uniforms: {
  8888. tCube: { value: null },
  8889. tFlip: { value: - 1 },
  8890. opacity: { value: 1.0 }
  8891. },
  8892. vertexShader: ShaderChunk.cube_vert,
  8893. fragmentShader: ShaderChunk.cube_frag
  8894. },
  8895. equirect: {
  8896. uniforms: {
  8897. tEquirect: { value: null },
  8898. },
  8899. vertexShader: ShaderChunk.equirect_vert,
  8900. fragmentShader: ShaderChunk.equirect_frag
  8901. },
  8902. distanceRGBA: {
  8903. uniforms: mergeUniforms( [
  8904. UniformsLib.common,
  8905. UniformsLib.displacementmap,
  8906. {
  8907. referencePosition: { value: new Vector3() },
  8908. nearDistance: { value: 1 },
  8909. farDistance: { value: 1000 }
  8910. }
  8911. ] ),
  8912. vertexShader: ShaderChunk.distanceRGBA_vert,
  8913. fragmentShader: ShaderChunk.distanceRGBA_frag
  8914. },
  8915. shadow: {
  8916. uniforms: mergeUniforms( [
  8917. UniformsLib.lights,
  8918. UniformsLib.fog,
  8919. {
  8920. color: { value: new Color( 0x00000 ) },
  8921. opacity: { value: 1.0 }
  8922. },
  8923. ] ),
  8924. vertexShader: ShaderChunk.shadow_vert,
  8925. fragmentShader: ShaderChunk.shadow_frag
  8926. }
  8927. };
  8928. ShaderLib.physical = {
  8929. uniforms: mergeUniforms( [
  8930. ShaderLib.standard.uniforms,
  8931. {
  8932. transparency: { value: 0 },
  8933. clearcoat: { value: 0 },
  8934. clearcoatRoughness: { value: 0 },
  8935. sheen: { value: new Color( 0x000000 ) },
  8936. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  8937. clearcoatNormalMap: { value: null },
  8938. }
  8939. ] ),
  8940. vertexShader: ShaderChunk.meshphysical_vert,
  8941. fragmentShader: ShaderChunk.meshphysical_frag
  8942. };
  8943. /**
  8944. * @author mrdoob / http://mrdoob.com/
  8945. */
  8946. function WebGLAnimation() {
  8947. var context = null;
  8948. var isAnimating = false;
  8949. var animationLoop = null;
  8950. function onAnimationFrame( time, frame ) {
  8951. if ( isAnimating === false ) return;
  8952. animationLoop( time, frame );
  8953. context.requestAnimationFrame( onAnimationFrame );
  8954. }
  8955. return {
  8956. start: function () {
  8957. if ( isAnimating === true ) return;
  8958. if ( animationLoop === null ) return;
  8959. context.requestAnimationFrame( onAnimationFrame );
  8960. isAnimating = true;
  8961. },
  8962. stop: function () {
  8963. isAnimating = false;
  8964. },
  8965. setAnimationLoop: function ( callback ) {
  8966. animationLoop = callback;
  8967. },
  8968. setContext: function ( value ) {
  8969. context = value;
  8970. }
  8971. };
  8972. }
  8973. /**
  8974. * @author mrdoob / http://mrdoob.com/
  8975. */
  8976. function WebGLAttributes( gl ) {
  8977. var buffers = new WeakMap();
  8978. function createBuffer( attribute, bufferType ) {
  8979. var array = attribute.array;
  8980. var usage = attribute.usage;
  8981. var buffer = gl.createBuffer();
  8982. gl.bindBuffer( bufferType, buffer );
  8983. gl.bufferData( bufferType, array, usage );
  8984. attribute.onUploadCallback();
  8985. var type = 5126;
  8986. if ( array instanceof Float32Array ) {
  8987. type = 5126;
  8988. } else if ( array instanceof Float64Array ) {
  8989. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  8990. } else if ( array instanceof Uint16Array ) {
  8991. type = 5123;
  8992. } else if ( array instanceof Int16Array ) {
  8993. type = 5122;
  8994. } else if ( array instanceof Uint32Array ) {
  8995. type = 5125;
  8996. } else if ( array instanceof Int32Array ) {
  8997. type = 5124;
  8998. } else if ( array instanceof Int8Array ) {
  8999. type = 5120;
  9000. } else if ( array instanceof Uint8Array ) {
  9001. type = 5121;
  9002. }
  9003. return {
  9004. buffer: buffer,
  9005. type: type,
  9006. bytesPerElement: array.BYTES_PER_ELEMENT,
  9007. version: attribute.version
  9008. };
  9009. }
  9010. function updateBuffer( buffer, attribute, bufferType ) {
  9011. var array = attribute.array;
  9012. var updateRange = attribute.updateRange;
  9013. gl.bindBuffer( bufferType, buffer );
  9014. if ( updateRange.count === - 1 ) {
  9015. // Not using update ranges
  9016. gl.bufferSubData( bufferType, 0, array );
  9017. } else {
  9018. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9019. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9020. updateRange.count = - 1; // reset range
  9021. }
  9022. }
  9023. //
  9024. function get( attribute ) {
  9025. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9026. return buffers.get( attribute );
  9027. }
  9028. function remove( attribute ) {
  9029. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9030. var data = buffers.get( attribute );
  9031. if ( data ) {
  9032. gl.deleteBuffer( data.buffer );
  9033. buffers.delete( attribute );
  9034. }
  9035. }
  9036. function update( attribute, bufferType ) {
  9037. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9038. var data = buffers.get( attribute );
  9039. if ( data === undefined ) {
  9040. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  9041. } else if ( data.version < attribute.version ) {
  9042. updateBuffer( data.buffer, attribute, bufferType );
  9043. data.version = attribute.version;
  9044. }
  9045. }
  9046. return {
  9047. get: get,
  9048. remove: remove,
  9049. update: update
  9050. };
  9051. }
  9052. /**
  9053. * @author mrdoob / http://mrdoob.com/
  9054. * @author Mugen87 / https://github.com/Mugen87
  9055. */
  9056. // PlaneGeometry
  9057. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  9058. Geometry.call( this );
  9059. this.type = 'PlaneGeometry';
  9060. this.parameters = {
  9061. width: width,
  9062. height: height,
  9063. widthSegments: widthSegments,
  9064. heightSegments: heightSegments
  9065. };
  9066. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  9067. this.mergeVertices();
  9068. }
  9069. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  9070. PlaneGeometry.prototype.constructor = PlaneGeometry;
  9071. // PlaneBufferGeometry
  9072. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  9073. BufferGeometry.call( this );
  9074. this.type = 'PlaneBufferGeometry';
  9075. this.parameters = {
  9076. width: width,
  9077. height: height,
  9078. widthSegments: widthSegments,
  9079. heightSegments: heightSegments
  9080. };
  9081. width = width || 1;
  9082. height = height || 1;
  9083. var width_half = width / 2;
  9084. var height_half = height / 2;
  9085. var gridX = Math.floor( widthSegments ) || 1;
  9086. var gridY = Math.floor( heightSegments ) || 1;
  9087. var gridX1 = gridX + 1;
  9088. var gridY1 = gridY + 1;
  9089. var segment_width = width / gridX;
  9090. var segment_height = height / gridY;
  9091. var ix, iy;
  9092. // buffers
  9093. var indices = [];
  9094. var vertices = [];
  9095. var normals = [];
  9096. var uvs = [];
  9097. // generate vertices, normals and uvs
  9098. for ( iy = 0; iy < gridY1; iy ++ ) {
  9099. var y = iy * segment_height - height_half;
  9100. for ( ix = 0; ix < gridX1; ix ++ ) {
  9101. var x = ix * segment_width - width_half;
  9102. vertices.push( x, - y, 0 );
  9103. normals.push( 0, 0, 1 );
  9104. uvs.push( ix / gridX );
  9105. uvs.push( 1 - ( iy / gridY ) );
  9106. }
  9107. }
  9108. // indices
  9109. for ( iy = 0; iy < gridY; iy ++ ) {
  9110. for ( ix = 0; ix < gridX; ix ++ ) {
  9111. var a = ix + gridX1 * iy;
  9112. var b = ix + gridX1 * ( iy + 1 );
  9113. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  9114. var d = ( ix + 1 ) + gridX1 * iy;
  9115. // faces
  9116. indices.push( a, b, d );
  9117. indices.push( b, c, d );
  9118. }
  9119. }
  9120. // build geometry
  9121. this.setIndex( indices );
  9122. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9123. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9124. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9125. }
  9126. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9127. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  9128. /**
  9129. * @author mrdoob / http://mrdoob.com/
  9130. */
  9131. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9132. var clearColor = new Color( 0x000000 );
  9133. var clearAlpha = 0;
  9134. var planeMesh;
  9135. var boxMesh;
  9136. // Store the current background texture and its `version`
  9137. // so we can recompile the material accordingly.
  9138. var currentBackground = null;
  9139. var currentBackgroundVersion = 0;
  9140. function render( renderList, scene, camera, forceClear ) {
  9141. var background = scene.background;
  9142. // Ignore background in AR
  9143. // TODO: Reconsider this.
  9144. var vr = renderer.vr;
  9145. var session = vr.getSession && vr.getSession();
  9146. if ( session && session.environmentBlendMode === 'additive' ) {
  9147. background = null;
  9148. }
  9149. if ( background === null ) {
  9150. setClear( clearColor, clearAlpha );
  9151. currentBackground = null;
  9152. currentBackgroundVersion = 0;
  9153. } else if ( background && background.isColor ) {
  9154. setClear( background, 1 );
  9155. forceClear = true;
  9156. currentBackground = null;
  9157. currentBackgroundVersion = 0;
  9158. }
  9159. if ( renderer.autoClear || forceClear ) {
  9160. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9161. }
  9162. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  9163. if ( boxMesh === undefined ) {
  9164. boxMesh = new Mesh(
  9165. new BoxBufferGeometry( 1, 1, 1 ),
  9166. new ShaderMaterial( {
  9167. type: 'BackgroundCubeMaterial',
  9168. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9169. vertexShader: ShaderLib.cube.vertexShader,
  9170. fragmentShader: ShaderLib.cube.fragmentShader,
  9171. side: BackSide,
  9172. depthTest: false,
  9173. depthWrite: false,
  9174. fog: false
  9175. } )
  9176. );
  9177. boxMesh.geometry.deleteAttribute( 'normal' );
  9178. boxMesh.geometry.deleteAttribute( 'uv' );
  9179. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9180. this.matrixWorld.copyPosition( camera.matrixWorld );
  9181. };
  9182. // enable code injection for non-built-in material
  9183. Object.defineProperty( boxMesh.material, 'map', {
  9184. get: function () {
  9185. return this.uniforms.tCube.value;
  9186. }
  9187. } );
  9188. objects.update( boxMesh );
  9189. }
  9190. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  9191. boxMesh.material.uniforms.tCube.value = texture;
  9192. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  9193. if ( currentBackground !== background ||
  9194. currentBackgroundVersion !== texture.version ) {
  9195. boxMesh.material.needsUpdate = true;
  9196. currentBackground = background;
  9197. currentBackgroundVersion = texture.version;
  9198. }
  9199. // push to the pre-sorted opaque render list
  9200. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9201. } else if ( background && background.isTexture ) {
  9202. if ( planeMesh === undefined ) {
  9203. planeMesh = new Mesh(
  9204. new PlaneBufferGeometry( 2, 2 ),
  9205. new ShaderMaterial( {
  9206. type: 'BackgroundMaterial',
  9207. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9208. vertexShader: ShaderLib.background.vertexShader,
  9209. fragmentShader: ShaderLib.background.fragmentShader,
  9210. side: FrontSide,
  9211. depthTest: false,
  9212. depthWrite: false,
  9213. fog: false
  9214. } )
  9215. );
  9216. planeMesh.geometry.deleteAttribute( 'normal' );
  9217. // enable code injection for non-built-in material
  9218. Object.defineProperty( planeMesh.material, 'map', {
  9219. get: function () {
  9220. return this.uniforms.t2D.value;
  9221. }
  9222. } );
  9223. objects.update( planeMesh );
  9224. }
  9225. planeMesh.material.uniforms.t2D.value = background;
  9226. if ( background.matrixAutoUpdate === true ) {
  9227. background.updateMatrix();
  9228. }
  9229. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9230. if ( currentBackground !== background ||
  9231. currentBackgroundVersion !== background.version ) {
  9232. planeMesh.material.needsUpdate = true;
  9233. currentBackground = background;
  9234. currentBackgroundVersion = background.version;
  9235. }
  9236. // push to the pre-sorted opaque render list
  9237. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9238. }
  9239. }
  9240. function setClear( color, alpha ) {
  9241. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9242. }
  9243. return {
  9244. getClearColor: function () {
  9245. return clearColor;
  9246. },
  9247. setClearColor: function ( color, alpha ) {
  9248. clearColor.set( color );
  9249. clearAlpha = alpha !== undefined ? alpha : 1;
  9250. setClear( clearColor, clearAlpha );
  9251. },
  9252. getClearAlpha: function () {
  9253. return clearAlpha;
  9254. },
  9255. setClearAlpha: function ( alpha ) {
  9256. clearAlpha = alpha;
  9257. setClear( clearColor, clearAlpha );
  9258. },
  9259. render: render
  9260. };
  9261. }
  9262. /**
  9263. * @author mrdoob / http://mrdoob.com/
  9264. */
  9265. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9266. var isWebGL2 = capabilities.isWebGL2;
  9267. var mode;
  9268. function setMode( value ) {
  9269. mode = value;
  9270. }
  9271. function render( start, count ) {
  9272. gl.drawArrays( mode, start, count );
  9273. info.update( count, mode );
  9274. }
  9275. function renderInstances( geometry, start, count, primcount ) {
  9276. if ( primcount === 0 ) return;
  9277. var extension, methodName;
  9278. if ( isWebGL2 ) {
  9279. extension = gl;
  9280. methodName = 'drawArraysInstanced';
  9281. } else {
  9282. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9283. methodName = 'drawArraysInstancedANGLE';
  9284. if ( extension === null ) {
  9285. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9286. return;
  9287. }
  9288. }
  9289. extension[ methodName ]( mode, start, count, primcount );
  9290. info.update( count, mode, primcount );
  9291. }
  9292. //
  9293. this.setMode = setMode;
  9294. this.render = render;
  9295. this.renderInstances = renderInstances;
  9296. }
  9297. /**
  9298. * @author mrdoob / http://mrdoob.com/
  9299. */
  9300. function WebGLCapabilities( gl, extensions, parameters ) {
  9301. var maxAnisotropy;
  9302. function getMaxAnisotropy() {
  9303. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  9304. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9305. if ( extension !== null ) {
  9306. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9307. } else {
  9308. maxAnisotropy = 0;
  9309. }
  9310. return maxAnisotropy;
  9311. }
  9312. function getMaxPrecision( precision ) {
  9313. if ( precision === 'highp' ) {
  9314. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9315. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9316. return 'highp';
  9317. }
  9318. precision = 'mediump';
  9319. }
  9320. if ( precision === 'mediump' ) {
  9321. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9322. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9323. return 'mediump';
  9324. }
  9325. }
  9326. return 'lowp';
  9327. }
  9328. /* eslint-disable no-undef */
  9329. var isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  9330. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  9331. /* eslint-enable no-undef */
  9332. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9333. var maxPrecision = getMaxPrecision( precision );
  9334. if ( maxPrecision !== precision ) {
  9335. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9336. precision = maxPrecision;
  9337. }
  9338. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9339. var maxTextures = gl.getParameter( 34930 );
  9340. var maxVertexTextures = gl.getParameter( 35660 );
  9341. var maxTextureSize = gl.getParameter( 3379 );
  9342. var maxCubemapSize = gl.getParameter( 34076 );
  9343. var maxAttributes = gl.getParameter( 34921 );
  9344. var maxVertexUniforms = gl.getParameter( 36347 );
  9345. var maxVaryings = gl.getParameter( 36348 );
  9346. var maxFragmentUniforms = gl.getParameter( 36349 );
  9347. var vertexTextures = maxVertexTextures > 0;
  9348. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9349. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9350. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9351. return {
  9352. isWebGL2: isWebGL2,
  9353. getMaxAnisotropy: getMaxAnisotropy,
  9354. getMaxPrecision: getMaxPrecision,
  9355. precision: precision,
  9356. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9357. maxTextures: maxTextures,
  9358. maxVertexTextures: maxVertexTextures,
  9359. maxTextureSize: maxTextureSize,
  9360. maxCubemapSize: maxCubemapSize,
  9361. maxAttributes: maxAttributes,
  9362. maxVertexUniforms: maxVertexUniforms,
  9363. maxVaryings: maxVaryings,
  9364. maxFragmentUniforms: maxFragmentUniforms,
  9365. vertexTextures: vertexTextures,
  9366. floatFragmentTextures: floatFragmentTextures,
  9367. floatVertexTextures: floatVertexTextures,
  9368. maxSamples: maxSamples
  9369. };
  9370. }
  9371. /**
  9372. * @author tschw
  9373. */
  9374. function WebGLClipping() {
  9375. var scope = this,
  9376. globalState = null,
  9377. numGlobalPlanes = 0,
  9378. localClippingEnabled = false,
  9379. renderingShadows = false,
  9380. plane = new Plane(),
  9381. viewNormalMatrix = new Matrix3(),
  9382. uniform = { value: null, needsUpdate: false };
  9383. this.uniform = uniform;
  9384. this.numPlanes = 0;
  9385. this.numIntersection = 0;
  9386. this.init = function ( planes, enableLocalClipping, camera ) {
  9387. var enabled =
  9388. planes.length !== 0 ||
  9389. enableLocalClipping ||
  9390. // enable state of previous frame - the clipping code has to
  9391. // run another frame in order to reset the state:
  9392. numGlobalPlanes !== 0 ||
  9393. localClippingEnabled;
  9394. localClippingEnabled = enableLocalClipping;
  9395. globalState = projectPlanes( planes, camera, 0 );
  9396. numGlobalPlanes = planes.length;
  9397. return enabled;
  9398. };
  9399. this.beginShadows = function () {
  9400. renderingShadows = true;
  9401. projectPlanes( null );
  9402. };
  9403. this.endShadows = function () {
  9404. renderingShadows = false;
  9405. resetGlobalState();
  9406. };
  9407. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9408. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9409. // there's no local clipping
  9410. if ( renderingShadows ) {
  9411. // there's no global clipping
  9412. projectPlanes( null );
  9413. } else {
  9414. resetGlobalState();
  9415. }
  9416. } else {
  9417. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9418. lGlobal = nGlobal * 4,
  9419. dstArray = cache.clippingState || null;
  9420. uniform.value = dstArray; // ensure unique state
  9421. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9422. for ( var i = 0; i !== lGlobal; ++ i ) {
  9423. dstArray[ i ] = globalState[ i ];
  9424. }
  9425. cache.clippingState = dstArray;
  9426. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9427. this.numPlanes += nGlobal;
  9428. }
  9429. };
  9430. function resetGlobalState() {
  9431. if ( uniform.value !== globalState ) {
  9432. uniform.value = globalState;
  9433. uniform.needsUpdate = numGlobalPlanes > 0;
  9434. }
  9435. scope.numPlanes = numGlobalPlanes;
  9436. scope.numIntersection = 0;
  9437. }
  9438. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9439. var nPlanes = planes !== null ? planes.length : 0,
  9440. dstArray = null;
  9441. if ( nPlanes !== 0 ) {
  9442. dstArray = uniform.value;
  9443. if ( skipTransform !== true || dstArray === null ) {
  9444. var flatSize = dstOffset + nPlanes * 4,
  9445. viewMatrix = camera.matrixWorldInverse;
  9446. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9447. if ( dstArray === null || dstArray.length < flatSize ) {
  9448. dstArray = new Float32Array( flatSize );
  9449. }
  9450. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9451. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9452. plane.normal.toArray( dstArray, i4 );
  9453. dstArray[ i4 + 3 ] = plane.constant;
  9454. }
  9455. }
  9456. uniform.value = dstArray;
  9457. uniform.needsUpdate = true;
  9458. }
  9459. scope.numPlanes = nPlanes;
  9460. return dstArray;
  9461. }
  9462. }
  9463. /**
  9464. * @author mrdoob / http://mrdoob.com/
  9465. */
  9466. function WebGLExtensions( gl ) {
  9467. var extensions = {};
  9468. return {
  9469. get: function ( name ) {
  9470. if ( extensions[ name ] !== undefined ) {
  9471. return extensions[ name ];
  9472. }
  9473. var extension;
  9474. switch ( name ) {
  9475. case 'WEBGL_depth_texture':
  9476. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9477. break;
  9478. case 'EXT_texture_filter_anisotropic':
  9479. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9480. break;
  9481. case 'WEBGL_compressed_texture_s3tc':
  9482. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9483. break;
  9484. case 'WEBGL_compressed_texture_pvrtc':
  9485. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9486. break;
  9487. default:
  9488. extension = gl.getExtension( name );
  9489. }
  9490. if ( extension === null ) {
  9491. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9492. }
  9493. extensions[ name ] = extension;
  9494. return extension;
  9495. }
  9496. };
  9497. }
  9498. /**
  9499. * @author mrdoob / http://mrdoob.com/
  9500. */
  9501. function WebGLGeometries( gl, attributes, info ) {
  9502. var geometries = new WeakMap();
  9503. var wireframeAttributes = new WeakMap();
  9504. function onGeometryDispose( event ) {
  9505. var geometry = event.target;
  9506. var buffergeometry = geometries.get( geometry );
  9507. if ( buffergeometry.index !== null ) {
  9508. attributes.remove( buffergeometry.index );
  9509. }
  9510. for ( var name in buffergeometry.attributes ) {
  9511. attributes.remove( buffergeometry.attributes[ name ] );
  9512. }
  9513. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9514. geometries.delete( geometry );
  9515. var attribute = wireframeAttributes.get( buffergeometry );
  9516. if ( attribute ) {
  9517. attributes.remove( attribute );
  9518. wireframeAttributes.delete( buffergeometry );
  9519. }
  9520. //
  9521. info.memory.geometries --;
  9522. }
  9523. function get( object, geometry ) {
  9524. var buffergeometry = geometries.get( geometry );
  9525. if ( buffergeometry ) return buffergeometry;
  9526. geometry.addEventListener( 'dispose', onGeometryDispose );
  9527. if ( geometry.isBufferGeometry ) {
  9528. buffergeometry = geometry;
  9529. } else if ( geometry.isGeometry ) {
  9530. if ( geometry._bufferGeometry === undefined ) {
  9531. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9532. }
  9533. buffergeometry = geometry._bufferGeometry;
  9534. }
  9535. geometries.set( geometry, buffergeometry );
  9536. info.memory.geometries ++;
  9537. return buffergeometry;
  9538. }
  9539. function update( geometry ) {
  9540. var index = geometry.index;
  9541. var geometryAttributes = geometry.attributes;
  9542. if ( index !== null ) {
  9543. attributes.update( index, 34963 );
  9544. }
  9545. for ( var name in geometryAttributes ) {
  9546. attributes.update( geometryAttributes[ name ], 34962 );
  9547. }
  9548. // morph targets
  9549. var morphAttributes = geometry.morphAttributes;
  9550. for ( var name in morphAttributes ) {
  9551. var array = morphAttributes[ name ];
  9552. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9553. attributes.update( array[ i ], 34962 );
  9554. }
  9555. }
  9556. }
  9557. function updateWireframeAttribute( geometry ) {
  9558. var indices = [];
  9559. var geometryIndex = geometry.index;
  9560. var geometryPosition = geometry.attributes.position;
  9561. var version = 0;
  9562. if ( geometryIndex !== null ) {
  9563. var array = geometryIndex.array;
  9564. version = geometryIndex.version;
  9565. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9566. var a = array[ i + 0 ];
  9567. var b = array[ i + 1 ];
  9568. var c = array[ i + 2 ];
  9569. indices.push( a, b, b, c, c, a );
  9570. }
  9571. } else {
  9572. var array = geometryPosition.array;
  9573. version = geometryPosition.version;
  9574. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9575. var a = i + 0;
  9576. var b = i + 1;
  9577. var c = i + 2;
  9578. indices.push( a, b, b, c, c, a );
  9579. }
  9580. }
  9581. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9582. attribute.version = version;
  9583. attributes.update( attribute, 34963 );
  9584. //
  9585. var previousAttribute = wireframeAttributes.get( geometry );
  9586. if ( previousAttribute ) attributes.remove( previousAttribute );
  9587. //
  9588. wireframeAttributes.set( geometry, attribute );
  9589. }
  9590. function getWireframeAttribute( geometry ) {
  9591. var currentAttribute = wireframeAttributes.get( geometry );
  9592. if ( currentAttribute ) {
  9593. var geometryIndex = geometry.index;
  9594. if ( geometryIndex !== null ) {
  9595. // if the attribute is obsolete, create a new one
  9596. if ( currentAttribute.version < geometryIndex.version ) {
  9597. updateWireframeAttribute( geometry );
  9598. }
  9599. }
  9600. } else {
  9601. updateWireframeAttribute( geometry );
  9602. }
  9603. return wireframeAttributes.get( geometry );
  9604. }
  9605. return {
  9606. get: get,
  9607. update: update,
  9608. getWireframeAttribute: getWireframeAttribute
  9609. };
  9610. }
  9611. /**
  9612. * @author mrdoob / http://mrdoob.com/
  9613. */
  9614. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9615. var isWebGL2 = capabilities.isWebGL2;
  9616. var mode;
  9617. function setMode( value ) {
  9618. mode = value;
  9619. }
  9620. var type, bytesPerElement;
  9621. function setIndex( value ) {
  9622. type = value.type;
  9623. bytesPerElement = value.bytesPerElement;
  9624. }
  9625. function render( start, count ) {
  9626. gl.drawElements( mode, count, type, start * bytesPerElement );
  9627. info.update( count, mode );
  9628. }
  9629. function renderInstances( geometry, start, count, primcount ) {
  9630. if ( primcount === 0 ) return;
  9631. var extension, methodName;
  9632. if ( isWebGL2 ) {
  9633. extension = gl;
  9634. methodName = 'drawElementsInstanced';
  9635. } else {
  9636. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9637. methodName = 'drawElementsInstancedANGLE';
  9638. if ( extension === null ) {
  9639. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9640. return;
  9641. }
  9642. }
  9643. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  9644. info.update( count, mode, primcount );
  9645. }
  9646. //
  9647. this.setMode = setMode;
  9648. this.setIndex = setIndex;
  9649. this.render = render;
  9650. this.renderInstances = renderInstances;
  9651. }
  9652. /**
  9653. * @author Mugen87 / https://github.com/Mugen87
  9654. */
  9655. function WebGLInfo( gl ) {
  9656. var memory = {
  9657. geometries: 0,
  9658. textures: 0
  9659. };
  9660. var render = {
  9661. frame: 0,
  9662. calls: 0,
  9663. triangles: 0,
  9664. points: 0,
  9665. lines: 0
  9666. };
  9667. function update( count, mode, instanceCount ) {
  9668. instanceCount = instanceCount || 1;
  9669. render.calls ++;
  9670. switch ( mode ) {
  9671. case 4:
  9672. render.triangles += instanceCount * ( count / 3 );
  9673. break;
  9674. case 5:
  9675. case 6:
  9676. render.triangles += instanceCount * ( count - 2 );
  9677. break;
  9678. case 1:
  9679. render.lines += instanceCount * ( count / 2 );
  9680. break;
  9681. case 3:
  9682. render.lines += instanceCount * ( count - 1 );
  9683. break;
  9684. case 2:
  9685. render.lines += instanceCount * count;
  9686. break;
  9687. case 0:
  9688. render.points += instanceCount * count;
  9689. break;
  9690. default:
  9691. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9692. break;
  9693. }
  9694. }
  9695. function reset() {
  9696. render.frame ++;
  9697. render.calls = 0;
  9698. render.triangles = 0;
  9699. render.points = 0;
  9700. render.lines = 0;
  9701. }
  9702. return {
  9703. memory: memory,
  9704. render: render,
  9705. programs: null,
  9706. autoReset: true,
  9707. reset: reset,
  9708. update: update
  9709. };
  9710. }
  9711. /**
  9712. * @author mrdoob / http://mrdoob.com/
  9713. */
  9714. function absNumericalSort( a, b ) {
  9715. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9716. }
  9717. function WebGLMorphtargets( gl ) {
  9718. var influencesList = {};
  9719. var morphInfluences = new Float32Array( 8 );
  9720. function update( object, geometry, material, program ) {
  9721. var objectInfluences = object.morphTargetInfluences;
  9722. var length = objectInfluences.length;
  9723. var influences = influencesList[ geometry.id ];
  9724. if ( influences === undefined ) {
  9725. // initialise list
  9726. influences = [];
  9727. for ( var i = 0; i < length; i ++ ) {
  9728. influences[ i ] = [ i, 0 ];
  9729. }
  9730. influencesList[ geometry.id ] = influences;
  9731. }
  9732. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9733. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9734. // Remove current morphAttributes
  9735. for ( var i = 0; i < length; i ++ ) {
  9736. var influence = influences[ i ];
  9737. if ( influence[ 1 ] !== 0 ) {
  9738. if ( morphTargets ) geometry.deleteAttribute( 'morphTarget' + i );
  9739. if ( morphNormals ) geometry.deleteAttribute( 'morphNormal' + i );
  9740. }
  9741. }
  9742. // Collect influences
  9743. for ( var i = 0; i < length; i ++ ) {
  9744. var influence = influences[ i ];
  9745. influence[ 0 ] = i;
  9746. influence[ 1 ] = objectInfluences[ i ];
  9747. }
  9748. influences.sort( absNumericalSort );
  9749. // Add morphAttributes
  9750. var morphInfluencesSum = 0;
  9751. for ( var i = 0; i < 8; i ++ ) {
  9752. var influence = influences[ i ];
  9753. if ( influence ) {
  9754. var index = influence[ 0 ];
  9755. var value = influence[ 1 ];
  9756. if ( value ) {
  9757. if ( morphTargets ) geometry.setAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9758. if ( morphNormals ) geometry.setAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9759. morphInfluences[ i ] = value;
  9760. morphInfluencesSum += value;
  9761. continue;
  9762. }
  9763. }
  9764. morphInfluences[ i ] = 0;
  9765. }
  9766. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9767. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9768. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9769. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9770. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  9771. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9772. }
  9773. return {
  9774. update: update
  9775. };
  9776. }
  9777. /**
  9778. * @author mrdoob / http://mrdoob.com/
  9779. */
  9780. function WebGLObjects( gl, geometries, attributes, info ) {
  9781. var updateList = {};
  9782. function update( object ) {
  9783. var frame = info.render.frame;
  9784. var geometry = object.geometry;
  9785. var buffergeometry = geometries.get( object, geometry );
  9786. // Update once per frame
  9787. if ( updateList[ buffergeometry.id ] !== frame ) {
  9788. if ( geometry.isGeometry ) {
  9789. buffergeometry.updateFromObject( object );
  9790. }
  9791. geometries.update( buffergeometry );
  9792. updateList[ buffergeometry.id ] = frame;
  9793. }
  9794. if ( object.isInstancedMesh ) {
  9795. attributes.update( object.instanceMatrix, 34962 );
  9796. }
  9797. return buffergeometry;
  9798. }
  9799. function dispose() {
  9800. updateList = {};
  9801. }
  9802. return {
  9803. update: update,
  9804. dispose: dispose
  9805. };
  9806. }
  9807. /**
  9808. * @author mrdoob / http://mrdoob.com/
  9809. */
  9810. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9811. images = images !== undefined ? images : [];
  9812. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9813. format = format !== undefined ? format : RGBFormat;
  9814. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9815. this.flipY = false;
  9816. }
  9817. CubeTexture.prototype = Object.create( Texture.prototype );
  9818. CubeTexture.prototype.constructor = CubeTexture;
  9819. CubeTexture.prototype.isCubeTexture = true;
  9820. Object.defineProperty( CubeTexture.prototype, 'images', {
  9821. get: function () {
  9822. return this.image;
  9823. },
  9824. set: function ( value ) {
  9825. this.image = value;
  9826. }
  9827. } );
  9828. /**
  9829. * @author Takahiro https://github.com/takahirox
  9830. */
  9831. function DataTexture2DArray( data, width, height, depth ) {
  9832. Texture.call( this, null );
  9833. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  9834. this.magFilter = NearestFilter;
  9835. this.minFilter = NearestFilter;
  9836. this.wrapR = ClampToEdgeWrapping;
  9837. this.generateMipmaps = false;
  9838. this.flipY = false;
  9839. this.needsUpdate = true;
  9840. }
  9841. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9842. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9843. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9844. /**
  9845. * @author Artur Trzesiok
  9846. */
  9847. function DataTexture3D( data, width, height, depth ) {
  9848. // We're going to add .setXXX() methods for setting properties later.
  9849. // Users can still set in DataTexture3D directly.
  9850. //
  9851. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9852. // texture.anisotropy = 16;
  9853. //
  9854. // See #14839
  9855. Texture.call( this, null );
  9856. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  9857. this.magFilter = NearestFilter;
  9858. this.minFilter = NearestFilter;
  9859. this.wrapR = ClampToEdgeWrapping;
  9860. this.generateMipmaps = false;
  9861. this.flipY = false;
  9862. this.needsUpdate = true;
  9863. }
  9864. DataTexture3D.prototype = Object.create( Texture.prototype );
  9865. DataTexture3D.prototype.constructor = DataTexture3D;
  9866. DataTexture3D.prototype.isDataTexture3D = true;
  9867. /**
  9868. * @author tschw
  9869. * @author Mugen87 / https://github.com/Mugen87
  9870. * @author mrdoob / http://mrdoob.com/
  9871. *
  9872. * Uniforms of a program.
  9873. * Those form a tree structure with a special top-level container for the root,
  9874. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9875. *
  9876. *
  9877. * Properties of inner nodes including the top-level container:
  9878. *
  9879. * .seq - array of nested uniforms
  9880. * .map - nested uniforms by name
  9881. *
  9882. *
  9883. * Methods of all nodes except the top-level container:
  9884. *
  9885. * .setValue( gl, value, [textures] )
  9886. *
  9887. * uploads a uniform value(s)
  9888. * the 'textures' parameter is needed for sampler uniforms
  9889. *
  9890. *
  9891. * Static methods of the top-level container (textures factorizations):
  9892. *
  9893. * .upload( gl, seq, values, textures )
  9894. *
  9895. * sets uniforms in 'seq' to 'values[id].value'
  9896. *
  9897. * .seqWithValue( seq, values ) : filteredSeq
  9898. *
  9899. * filters 'seq' entries with corresponding entry in values
  9900. *
  9901. *
  9902. * Methods of the top-level container (textures factorizations):
  9903. *
  9904. * .setValue( gl, name, value, textures )
  9905. *
  9906. * sets uniform with name 'name' to 'value'
  9907. *
  9908. * .setOptional( gl, obj, prop )
  9909. *
  9910. * like .set for an optional property of the object
  9911. *
  9912. */
  9913. var emptyTexture = new Texture();
  9914. var emptyTexture2dArray = new DataTexture2DArray();
  9915. var emptyTexture3d = new DataTexture3D();
  9916. var emptyCubeTexture = new CubeTexture();
  9917. // --- Utilities ---
  9918. // Array Caches (provide typed arrays for temporary by size)
  9919. var arrayCacheF32 = [];
  9920. var arrayCacheI32 = [];
  9921. // Float32Array caches used for uploading Matrix uniforms
  9922. var mat4array = new Float32Array( 16 );
  9923. var mat3array = new Float32Array( 9 );
  9924. var mat2array = new Float32Array( 4 );
  9925. // Flattening for arrays of vectors and matrices
  9926. function flatten( array, nBlocks, blockSize ) {
  9927. var firstElem = array[ 0 ];
  9928. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9929. // unoptimized: ! isNaN( firstElem )
  9930. // see http://jacksondunstan.com/articles/983
  9931. var n = nBlocks * blockSize,
  9932. r = arrayCacheF32[ n ];
  9933. if ( r === undefined ) {
  9934. r = new Float32Array( n );
  9935. arrayCacheF32[ n ] = r;
  9936. }
  9937. if ( nBlocks !== 0 ) {
  9938. firstElem.toArray( r, 0 );
  9939. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9940. offset += blockSize;
  9941. array[ i ].toArray( r, offset );
  9942. }
  9943. }
  9944. return r;
  9945. }
  9946. function arraysEqual( a, b ) {
  9947. if ( a.length !== b.length ) return false;
  9948. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9949. if ( a[ i ] !== b[ i ] ) return false;
  9950. }
  9951. return true;
  9952. }
  9953. function copyArray( a, b ) {
  9954. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9955. a[ i ] = b[ i ];
  9956. }
  9957. }
  9958. // Texture unit allocation
  9959. function allocTexUnits( textures, n ) {
  9960. var r = arrayCacheI32[ n ];
  9961. if ( r === undefined ) {
  9962. r = new Int32Array( n );
  9963. arrayCacheI32[ n ] = r;
  9964. }
  9965. for ( var i = 0; i !== n; ++ i )
  9966. r[ i ] = textures.allocateTextureUnit();
  9967. return r;
  9968. }
  9969. // --- Setters ---
  9970. // Note: Defining these methods externally, because they come in a bunch
  9971. // and this way their names minify.
  9972. // Single scalar
  9973. function setValueV1f( gl, v ) {
  9974. var cache = this.cache;
  9975. if ( cache[ 0 ] === v ) return;
  9976. gl.uniform1f( this.addr, v );
  9977. cache[ 0 ] = v;
  9978. }
  9979. // Single float vector (from flat array or THREE.VectorN)
  9980. function setValueV2f( gl, v ) {
  9981. var cache = this.cache;
  9982. if ( v.x !== undefined ) {
  9983. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9984. gl.uniform2f( this.addr, v.x, v.y );
  9985. cache[ 0 ] = v.x;
  9986. cache[ 1 ] = v.y;
  9987. }
  9988. } else {
  9989. if ( arraysEqual( cache, v ) ) return;
  9990. gl.uniform2fv( this.addr, v );
  9991. copyArray( cache, v );
  9992. }
  9993. }
  9994. function setValueV3f( gl, v ) {
  9995. var cache = this.cache;
  9996. if ( v.x !== undefined ) {
  9997. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9998. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9999. cache[ 0 ] = v.x;
  10000. cache[ 1 ] = v.y;
  10001. cache[ 2 ] = v.z;
  10002. }
  10003. } else if ( v.r !== undefined ) {
  10004. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10005. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10006. cache[ 0 ] = v.r;
  10007. cache[ 1 ] = v.g;
  10008. cache[ 2 ] = v.b;
  10009. }
  10010. } else {
  10011. if ( arraysEqual( cache, v ) ) return;
  10012. gl.uniform3fv( this.addr, v );
  10013. copyArray( cache, v );
  10014. }
  10015. }
  10016. function setValueV4f( gl, v ) {
  10017. var cache = this.cache;
  10018. if ( v.x !== undefined ) {
  10019. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10020. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10021. cache[ 0 ] = v.x;
  10022. cache[ 1 ] = v.y;
  10023. cache[ 2 ] = v.z;
  10024. cache[ 3 ] = v.w;
  10025. }
  10026. } else {
  10027. if ( arraysEqual( cache, v ) ) return;
  10028. gl.uniform4fv( this.addr, v );
  10029. copyArray( cache, v );
  10030. }
  10031. }
  10032. // Single matrix (from flat array or MatrixN)
  10033. function setValueM2( gl, v ) {
  10034. var cache = this.cache;
  10035. var elements = v.elements;
  10036. if ( elements === undefined ) {
  10037. if ( arraysEqual( cache, v ) ) return;
  10038. gl.uniformMatrix2fv( this.addr, false, v );
  10039. copyArray( cache, v );
  10040. } else {
  10041. if ( arraysEqual( cache, elements ) ) return;
  10042. mat2array.set( elements );
  10043. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10044. copyArray( cache, elements );
  10045. }
  10046. }
  10047. function setValueM3( gl, v ) {
  10048. var cache = this.cache;
  10049. var elements = v.elements;
  10050. if ( elements === undefined ) {
  10051. if ( arraysEqual( cache, v ) ) return;
  10052. gl.uniformMatrix3fv( this.addr, false, v );
  10053. copyArray( cache, v );
  10054. } else {
  10055. if ( arraysEqual( cache, elements ) ) return;
  10056. mat3array.set( elements );
  10057. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10058. copyArray( cache, elements );
  10059. }
  10060. }
  10061. function setValueM4( gl, v ) {
  10062. var cache = this.cache;
  10063. var elements = v.elements;
  10064. if ( elements === undefined ) {
  10065. if ( arraysEqual( cache, v ) ) return;
  10066. gl.uniformMatrix4fv( this.addr, false, v );
  10067. copyArray( cache, v );
  10068. } else {
  10069. if ( arraysEqual( cache, elements ) ) return;
  10070. mat4array.set( elements );
  10071. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10072. copyArray( cache, elements );
  10073. }
  10074. }
  10075. // Single texture (2D / Cube)
  10076. function setValueT1( gl, v, textures ) {
  10077. var cache = this.cache;
  10078. var unit = textures.allocateTextureUnit();
  10079. if ( cache[ 0 ] !== unit ) {
  10080. gl.uniform1i( this.addr, unit );
  10081. cache[ 0 ] = unit;
  10082. }
  10083. textures.safeSetTexture2D( v || emptyTexture, unit );
  10084. }
  10085. function setValueT2DArray1( gl, v, textures ) {
  10086. var cache = this.cache;
  10087. var unit = textures.allocateTextureUnit();
  10088. if ( cache[ 0 ] !== unit ) {
  10089. gl.uniform1i( this.addr, unit );
  10090. cache[ 0 ] = unit;
  10091. }
  10092. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10093. }
  10094. function setValueT3D1( gl, v, textures ) {
  10095. var cache = this.cache;
  10096. var unit = textures.allocateTextureUnit();
  10097. if ( cache[ 0 ] !== unit ) {
  10098. gl.uniform1i( this.addr, unit );
  10099. cache[ 0 ] = unit;
  10100. }
  10101. textures.setTexture3D( v || emptyTexture3d, unit );
  10102. }
  10103. function setValueT6( gl, v, textures ) {
  10104. var cache = this.cache;
  10105. var unit = textures.allocateTextureUnit();
  10106. if ( cache[ 0 ] !== unit ) {
  10107. gl.uniform1i( this.addr, unit );
  10108. cache[ 0 ] = unit;
  10109. }
  10110. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10111. }
  10112. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10113. function setValueV1i( gl, v ) {
  10114. var cache = this.cache;
  10115. if ( cache[ 0 ] === v ) return;
  10116. gl.uniform1i( this.addr, v );
  10117. cache[ 0 ] = v;
  10118. }
  10119. function setValueV2i( gl, v ) {
  10120. var cache = this.cache;
  10121. if ( arraysEqual( cache, v ) ) return;
  10122. gl.uniform2iv( this.addr, v );
  10123. copyArray( cache, v );
  10124. }
  10125. function setValueV3i( gl, v ) {
  10126. var cache = this.cache;
  10127. if ( arraysEqual( cache, v ) ) return;
  10128. gl.uniform3iv( this.addr, v );
  10129. copyArray( cache, v );
  10130. }
  10131. function setValueV4i( gl, v ) {
  10132. var cache = this.cache;
  10133. if ( arraysEqual( cache, v ) ) return;
  10134. gl.uniform4iv( this.addr, v );
  10135. copyArray( cache, v );
  10136. }
  10137. // Helper to pick the right setter for the singular case
  10138. function getSingularSetter( type ) {
  10139. switch ( type ) {
  10140. case 0x1406: return setValueV1f; // FLOAT
  10141. case 0x8b50: return setValueV2f; // _VEC2
  10142. case 0x8b51: return setValueV3f; // _VEC3
  10143. case 0x8b52: return setValueV4f; // _VEC4
  10144. case 0x8b5a: return setValueM2; // _MAT2
  10145. case 0x8b5b: return setValueM3; // _MAT3
  10146. case 0x8b5c: return setValueM4; // _MAT4
  10147. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  10148. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  10149. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  10150. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  10151. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10152. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10153. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10154. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10155. }
  10156. }
  10157. // Array of scalars
  10158. function setValueV1fArray( gl, v ) {
  10159. gl.uniform1fv( this.addr, v );
  10160. }
  10161. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10162. function setValueV1iArray( gl, v ) {
  10163. gl.uniform1iv( this.addr, v );
  10164. }
  10165. function setValueV2iArray( gl, v ) {
  10166. gl.uniform2iv( this.addr, v );
  10167. }
  10168. function setValueV3iArray( gl, v ) {
  10169. gl.uniform3iv( this.addr, v );
  10170. }
  10171. function setValueV4iArray( gl, v ) {
  10172. gl.uniform4iv( this.addr, v );
  10173. }
  10174. // Array of vectors (flat or from THREE classes)
  10175. function setValueV2fArray( gl, v ) {
  10176. var data = flatten( v, this.size, 2 );
  10177. gl.uniform2fv( this.addr, data );
  10178. }
  10179. function setValueV3fArray( gl, v ) {
  10180. var data = flatten( v, this.size, 3 );
  10181. gl.uniform3fv( this.addr, data );
  10182. }
  10183. function setValueV4fArray( gl, v ) {
  10184. var data = flatten( v, this.size, 4 );
  10185. gl.uniform4fv( this.addr, data );
  10186. }
  10187. // Array of matrices (flat or from THREE clases)
  10188. function setValueM2Array( gl, v ) {
  10189. var data = flatten( v, this.size, 4 );
  10190. gl.uniformMatrix2fv( this.addr, false, data );
  10191. }
  10192. function setValueM3Array( gl, v ) {
  10193. var data = flatten( v, this.size, 9 );
  10194. gl.uniformMatrix3fv( this.addr, false, data );
  10195. }
  10196. function setValueM4Array( gl, v ) {
  10197. var data = flatten( v, this.size, 16 );
  10198. gl.uniformMatrix4fv( this.addr, false, data );
  10199. }
  10200. // Array of textures (2D / Cube)
  10201. function setValueT1Array( gl, v, textures ) {
  10202. var n = v.length;
  10203. var units = allocTexUnits( textures, n );
  10204. gl.uniform1iv( this.addr, units );
  10205. for ( var i = 0; i !== n; ++ i ) {
  10206. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10207. }
  10208. }
  10209. function setValueT6Array( gl, v, textures ) {
  10210. var n = v.length;
  10211. var units = allocTexUnits( textures, n );
  10212. gl.uniform1iv( this.addr, units );
  10213. for ( var i = 0; i !== n; ++ i ) {
  10214. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10215. }
  10216. }
  10217. // Helper to pick the right setter for a pure (bottom-level) array
  10218. function getPureArraySetter( type ) {
  10219. switch ( type ) {
  10220. case 0x1406: return setValueV1fArray; // FLOAT
  10221. case 0x8b50: return setValueV2fArray; // _VEC2
  10222. case 0x8b51: return setValueV3fArray; // _VEC3
  10223. case 0x8b52: return setValueV4fArray; // _VEC4
  10224. case 0x8b5a: return setValueM2Array; // _MAT2
  10225. case 0x8b5b: return setValueM3Array; // _MAT3
  10226. case 0x8b5c: return setValueM4Array; // _MAT4
  10227. case 0x8b5e: return setValueT1Array; // SAMPLER_2D
  10228. case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
  10229. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10230. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10231. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10232. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10233. }
  10234. }
  10235. // --- Uniform Classes ---
  10236. function SingleUniform( id, activeInfo, addr ) {
  10237. this.id = id;
  10238. this.addr = addr;
  10239. this.cache = [];
  10240. this.setValue = getSingularSetter( activeInfo.type );
  10241. // this.path = activeInfo.name; // DEBUG
  10242. }
  10243. function PureArrayUniform( id, activeInfo, addr ) {
  10244. this.id = id;
  10245. this.addr = addr;
  10246. this.cache = [];
  10247. this.size = activeInfo.size;
  10248. this.setValue = getPureArraySetter( activeInfo.type );
  10249. // this.path = activeInfo.name; // DEBUG
  10250. }
  10251. PureArrayUniform.prototype.updateCache = function ( data ) {
  10252. var cache = this.cache;
  10253. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10254. this.cache = new Float32Array( data.length );
  10255. }
  10256. copyArray( cache, data );
  10257. };
  10258. function StructuredUniform( id ) {
  10259. this.id = id;
  10260. this.seq = [];
  10261. this.map = {};
  10262. }
  10263. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10264. var seq = this.seq;
  10265. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10266. var u = seq[ i ];
  10267. u.setValue( gl, value[ u.id ], textures );
  10268. }
  10269. };
  10270. // --- Top-level ---
  10271. // Parser - builds up the property tree from the path strings
  10272. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10273. // extracts
  10274. // - the identifier (member name or array index)
  10275. // - followed by an optional right bracket (found when array index)
  10276. // - followed by an optional left bracket or dot (type of subscript)
  10277. //
  10278. // Note: These portions can be read in a non-overlapping fashion and
  10279. // allow straightforward parsing of the hierarchy that WebGL encodes
  10280. // in the uniform names.
  10281. function addUniform( container, uniformObject ) {
  10282. container.seq.push( uniformObject );
  10283. container.map[ uniformObject.id ] = uniformObject;
  10284. }
  10285. function parseUniform( activeInfo, addr, container ) {
  10286. var path = activeInfo.name,
  10287. pathLength = path.length;
  10288. // reset RegExp object, because of the early exit of a previous run
  10289. RePathPart.lastIndex = 0;
  10290. while ( true ) {
  10291. var match = RePathPart.exec( path ),
  10292. matchEnd = RePathPart.lastIndex,
  10293. id = match[ 1 ],
  10294. idIsIndex = match[ 2 ] === ']',
  10295. subscript = match[ 3 ];
  10296. if ( idIsIndex ) id = id | 0; // convert to integer
  10297. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10298. // bare name or "pure" bottom-level array "[0]" suffix
  10299. addUniform( container, subscript === undefined ?
  10300. new SingleUniform( id, activeInfo, addr ) :
  10301. new PureArrayUniform( id, activeInfo, addr ) );
  10302. break;
  10303. } else {
  10304. // step into inner node / create it in case it doesn't exist
  10305. var map = container.map, next = map[ id ];
  10306. if ( next === undefined ) {
  10307. next = new StructuredUniform( id );
  10308. addUniform( container, next );
  10309. }
  10310. container = next;
  10311. }
  10312. }
  10313. }
  10314. // Root Container
  10315. function WebGLUniforms( gl, program ) {
  10316. this.seq = [];
  10317. this.map = {};
  10318. var n = gl.getProgramParameter( program, 35718 );
  10319. for ( var i = 0; i < n; ++ i ) {
  10320. var info = gl.getActiveUniform( program, i ),
  10321. addr = gl.getUniformLocation( program, info.name );
  10322. parseUniform( info, addr, this );
  10323. }
  10324. }
  10325. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10326. var u = this.map[ name ];
  10327. if ( u !== undefined ) u.setValue( gl, value, textures );
  10328. };
  10329. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10330. var v = object[ name ];
  10331. if ( v !== undefined ) this.setValue( gl, name, v );
  10332. };
  10333. // Static interface
  10334. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10335. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10336. var u = seq[ i ],
  10337. v = values[ u.id ];
  10338. if ( v.needsUpdate !== false ) {
  10339. // note: always updating when .needsUpdate is undefined
  10340. u.setValue( gl, v.value, textures );
  10341. }
  10342. }
  10343. };
  10344. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10345. var r = [];
  10346. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10347. var u = seq[ i ];
  10348. if ( u.id in values ) r.push( u );
  10349. }
  10350. return r;
  10351. };
  10352. /**
  10353. * @author mrdoob / http://mrdoob.com/
  10354. */
  10355. function WebGLShader( gl, type, string ) {
  10356. var shader = gl.createShader( type );
  10357. gl.shaderSource( shader, string );
  10358. gl.compileShader( shader );
  10359. return shader;
  10360. }
  10361. /**
  10362. * @author mrdoob / http://mrdoob.com/
  10363. */
  10364. var programIdCount = 0;
  10365. function addLineNumbers( string ) {
  10366. var lines = string.split( '\n' );
  10367. for ( var i = 0; i < lines.length; i ++ ) {
  10368. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10369. }
  10370. return lines.join( '\n' );
  10371. }
  10372. function getEncodingComponents( encoding ) {
  10373. switch ( encoding ) {
  10374. case LinearEncoding:
  10375. return [ 'Linear', '( value )' ];
  10376. case sRGBEncoding:
  10377. return [ 'sRGB', '( value )' ];
  10378. case RGBEEncoding:
  10379. return [ 'RGBE', '( value )' ];
  10380. case RGBM7Encoding:
  10381. return [ 'RGBM', '( value, 7.0 )' ];
  10382. case RGBM16Encoding:
  10383. return [ 'RGBM', '( value, 16.0 )' ];
  10384. case RGBDEncoding:
  10385. return [ 'RGBD', '( value, 256.0 )' ];
  10386. case GammaEncoding:
  10387. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10388. case LogLuvEncoding:
  10389. return [ 'LogLuv', '( value )' ];
  10390. default:
  10391. throw new Error( 'unsupported encoding: ' + encoding );
  10392. }
  10393. }
  10394. function getShaderErrors( gl, shader, type ) {
  10395. var status = gl.getShaderParameter( shader, 35713 );
  10396. var log = gl.getShaderInfoLog( shader ).trim();
  10397. if ( status && log === '' ) return '';
  10398. // --enable-privileged-webgl-extension
  10399. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10400. var source = gl.getShaderSource( shader );
  10401. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10402. }
  10403. function getTexelDecodingFunction( functionName, encoding ) {
  10404. var components = getEncodingComponents( encoding );
  10405. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10406. }
  10407. function getTexelEncodingFunction( functionName, encoding ) {
  10408. var components = getEncodingComponents( encoding );
  10409. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10410. }
  10411. function getToneMappingFunction( functionName, toneMapping ) {
  10412. var toneMappingName;
  10413. switch ( toneMapping ) {
  10414. case LinearToneMapping:
  10415. toneMappingName = 'Linear';
  10416. break;
  10417. case ReinhardToneMapping:
  10418. toneMappingName = 'Reinhard';
  10419. break;
  10420. case Uncharted2ToneMapping:
  10421. toneMappingName = 'Uncharted2';
  10422. break;
  10423. case CineonToneMapping:
  10424. toneMappingName = 'OptimizedCineon';
  10425. break;
  10426. case ACESFilmicToneMapping:
  10427. toneMappingName = 'ACESFilmic';
  10428. break;
  10429. default:
  10430. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10431. }
  10432. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10433. }
  10434. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10435. extensions = extensions || {};
  10436. var chunks = [
  10437. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10438. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10439. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10440. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10441. ];
  10442. return chunks.filter( filterEmptyLine ).join( '\n' );
  10443. }
  10444. function generateDefines( defines ) {
  10445. var chunks = [];
  10446. for ( var name in defines ) {
  10447. var value = defines[ name ];
  10448. if ( value === false ) continue;
  10449. chunks.push( '#define ' + name + ' ' + value );
  10450. }
  10451. return chunks.join( '\n' );
  10452. }
  10453. function fetchAttributeLocations( gl, program ) {
  10454. var attributes = {};
  10455. var n = gl.getProgramParameter( program, 35721 );
  10456. for ( var i = 0; i < n; i ++ ) {
  10457. var info = gl.getActiveAttrib( program, i );
  10458. var name = info.name;
  10459. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10460. attributes[ name ] = gl.getAttribLocation( program, name );
  10461. }
  10462. return attributes;
  10463. }
  10464. function filterEmptyLine( string ) {
  10465. return string !== '';
  10466. }
  10467. function replaceLightNums( string, parameters ) {
  10468. return string
  10469. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10470. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10471. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10472. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10473. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  10474. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  10475. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  10476. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  10477. }
  10478. function replaceClippingPlaneNums( string, parameters ) {
  10479. return string
  10480. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10481. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10482. }
  10483. // Resolve Includes
  10484. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10485. function resolveIncludes( string ) {
  10486. return string.replace( includePattern, includeReplacer );
  10487. }
  10488. function includeReplacer( match, include ) {
  10489. var string = ShaderChunk[ include ];
  10490. if ( string === undefined ) {
  10491. throw new Error( 'Can not resolve #include <' + include + '>' );
  10492. }
  10493. return resolveIncludes( string );
  10494. }
  10495. // Unroll Loops
  10496. var loopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10497. function unrollLoops( string ) {
  10498. return string.replace( loopPattern, loopReplacer );
  10499. }
  10500. function loopReplacer( match, start, end, snippet ) {
  10501. var string = '';
  10502. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10503. string += snippet
  10504. .replace( /\[ i \]/g, '[ ' + i + ' ]' )
  10505. .replace( /UNROLLED_LOOP_INDEX/g, i );
  10506. }
  10507. return string;
  10508. }
  10509. //
  10510. function generatePrecision( parameters ) {
  10511. var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  10512. if ( parameters.precision === "highp" ) {
  10513. precisionstring += "\n#define HIGH_PRECISION";
  10514. } else if ( parameters.precision === "mediump" ) {
  10515. precisionstring += "\n#define MEDIUM_PRECISION";
  10516. } else if ( parameters.precision === "lowp" ) {
  10517. precisionstring += "\n#define LOW_PRECISION";
  10518. }
  10519. return precisionstring;
  10520. }
  10521. function generateShadowMapTypeDefine( parameters ) {
  10522. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10523. if ( parameters.shadowMapType === PCFShadowMap ) {
  10524. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10525. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10526. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10527. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  10528. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10529. }
  10530. return shadowMapTypeDefine;
  10531. }
  10532. function generateEnvMapTypeDefine( parameters ) {
  10533. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10534. if ( parameters.envMap ) {
  10535. switch ( parameters.envMapMode ) {
  10536. case CubeReflectionMapping:
  10537. case CubeRefractionMapping:
  10538. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10539. break;
  10540. case CubeUVReflectionMapping:
  10541. case CubeUVRefractionMapping:
  10542. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10543. break;
  10544. case EquirectangularReflectionMapping:
  10545. case EquirectangularRefractionMapping:
  10546. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10547. break;
  10548. case SphericalReflectionMapping:
  10549. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10550. break;
  10551. }
  10552. }
  10553. return envMapTypeDefine;
  10554. }
  10555. function generateEnvMapModeDefine( parameters ) {
  10556. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10557. if ( parameters.envMap ) {
  10558. switch ( parameters.envMapMode ) {
  10559. case CubeRefractionMapping:
  10560. case EquirectangularRefractionMapping:
  10561. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10562. break;
  10563. }
  10564. }
  10565. return envMapModeDefine;
  10566. }
  10567. function generateEnvMapBlendingDefine( parameters ) {
  10568. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10569. if ( parameters.envMap ) {
  10570. switch ( parameters.combine ) {
  10571. case MultiplyOperation:
  10572. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10573. break;
  10574. case MixOperation:
  10575. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10576. break;
  10577. case AddOperation:
  10578. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10579. break;
  10580. }
  10581. }
  10582. return envMapBlendingDefine;
  10583. }
  10584. function WebGLProgram( renderer, extensions, cacheKey, material, shader, parameters ) {
  10585. var gl = renderer.getContext();
  10586. var defines = material.defines;
  10587. var vertexShader = shader.vertexShader;
  10588. var fragmentShader = shader.fragmentShader;
  10589. var shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  10590. var envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  10591. var envMapModeDefine = generateEnvMapModeDefine( parameters );
  10592. var envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  10593. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10594. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10595. var customDefines = generateDefines( defines );
  10596. var program = gl.createProgram();
  10597. var prefixVertex, prefixFragment;
  10598. var numMultiviewViews = parameters.numMultiviewViews;
  10599. if ( material.isRawShaderMaterial ) {
  10600. prefixVertex = [
  10601. customDefines
  10602. ].filter( filterEmptyLine ).join( '\n' );
  10603. if ( prefixVertex.length > 0 ) {
  10604. prefixVertex += '\n';
  10605. }
  10606. prefixFragment = [
  10607. customExtensions,
  10608. customDefines
  10609. ].filter( filterEmptyLine ).join( '\n' );
  10610. if ( prefixFragment.length > 0 ) {
  10611. prefixFragment += '\n';
  10612. }
  10613. } else {
  10614. prefixVertex = [
  10615. generatePrecision( parameters ),
  10616. '#define SHADER_NAME ' + shader.name,
  10617. customDefines,
  10618. parameters.instancing ? '#define USE_INSTANCING' : '',
  10619. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10620. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10621. '#define MAX_BONES ' + parameters.maxBones,
  10622. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10623. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10624. parameters.map ? '#define USE_MAP' : '',
  10625. parameters.envMap ? '#define USE_ENVMAP' : '',
  10626. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10627. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10628. parameters.aoMap ? '#define USE_AOMAP' : '',
  10629. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10630. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10631. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10632. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10633. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10634. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10635. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10636. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10637. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10638. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10639. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10640. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10641. parameters.vertexColors ? '#define USE_COLOR' : '',
  10642. parameters.vertexUvs ? '#define USE_UV' : '',
  10643. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10644. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10645. parameters.skinning ? '#define USE_SKINNING' : '',
  10646. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10647. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10648. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10649. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10650. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10651. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10652. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10653. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10654. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10655. parameters.logarithmicDepthBuffer && ( parameters.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10656. 'uniform mat4 modelMatrix;',
  10657. 'uniform mat4 modelViewMatrix;',
  10658. 'uniform mat4 projectionMatrix;',
  10659. 'uniform mat4 viewMatrix;',
  10660. 'uniform mat3 normalMatrix;',
  10661. 'uniform vec3 cameraPosition;',
  10662. 'uniform bool isOrthographic;',
  10663. '#ifdef USE_INSTANCING',
  10664. ' attribute mat4 instanceMatrix;',
  10665. '#endif',
  10666. 'attribute vec3 position;',
  10667. 'attribute vec3 normal;',
  10668. 'attribute vec2 uv;',
  10669. '#ifdef USE_TANGENT',
  10670. ' attribute vec4 tangent;',
  10671. '#endif',
  10672. '#ifdef USE_COLOR',
  10673. ' attribute vec3 color;',
  10674. '#endif',
  10675. '#ifdef USE_MORPHTARGETS',
  10676. ' attribute vec3 morphTarget0;',
  10677. ' attribute vec3 morphTarget1;',
  10678. ' attribute vec3 morphTarget2;',
  10679. ' attribute vec3 morphTarget3;',
  10680. ' #ifdef USE_MORPHNORMALS',
  10681. ' attribute vec3 morphNormal0;',
  10682. ' attribute vec3 morphNormal1;',
  10683. ' attribute vec3 morphNormal2;',
  10684. ' attribute vec3 morphNormal3;',
  10685. ' #else',
  10686. ' attribute vec3 morphTarget4;',
  10687. ' attribute vec3 morphTarget5;',
  10688. ' attribute vec3 morphTarget6;',
  10689. ' attribute vec3 morphTarget7;',
  10690. ' #endif',
  10691. '#endif',
  10692. '#ifdef USE_SKINNING',
  10693. ' attribute vec4 skinIndex;',
  10694. ' attribute vec4 skinWeight;',
  10695. '#endif',
  10696. '\n'
  10697. ].filter( filterEmptyLine ).join( '\n' );
  10698. prefixFragment = [
  10699. customExtensions,
  10700. generatePrecision( parameters ),
  10701. '#define SHADER_NAME ' + shader.name,
  10702. customDefines,
  10703. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10704. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10705. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10706. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10707. parameters.map ? '#define USE_MAP' : '',
  10708. parameters.matcap ? '#define USE_MATCAP' : '',
  10709. parameters.envMap ? '#define USE_ENVMAP' : '',
  10710. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10711. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10712. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10713. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10714. parameters.aoMap ? '#define USE_AOMAP' : '',
  10715. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10716. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10717. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10718. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10719. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10720. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10721. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10722. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10723. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10724. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10725. parameters.sheen ? '#define USE_SHEEN' : '',
  10726. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10727. parameters.vertexColors ? '#define USE_COLOR' : '',
  10728. parameters.vertexUvs ? '#define USE_UV' : '',
  10729. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10730. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10731. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10732. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10733. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10734. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10735. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10736. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10737. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10738. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10739. parameters.logarithmicDepthBuffer && ( parameters.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10740. ( ( material.extensions ? material.extensions.shaderTextureLOD : false ) || parameters.envMap ) && ( parameters.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10741. 'uniform mat4 viewMatrix;',
  10742. 'uniform vec3 cameraPosition;',
  10743. 'uniform bool isOrthographic;',
  10744. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10745. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10746. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10747. parameters.dithering ? '#define DITHERING' : '',
  10748. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10749. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10750. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10751. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10752. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10753. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10754. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10755. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10756. '\n'
  10757. ].filter( filterEmptyLine ).join( '\n' );
  10758. }
  10759. vertexShader = resolveIncludes( vertexShader );
  10760. vertexShader = replaceLightNums( vertexShader, parameters );
  10761. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10762. fragmentShader = resolveIncludes( fragmentShader );
  10763. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10764. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10765. vertexShader = unrollLoops( vertexShader );
  10766. fragmentShader = unrollLoops( fragmentShader );
  10767. if ( parameters.isWebGL2 && ! material.isRawShaderMaterial ) {
  10768. var isGLSL3ShaderMaterial = false;
  10769. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10770. if ( material.isShaderMaterial &&
  10771. vertexShader.match( versionRegex ) !== null &&
  10772. fragmentShader.match( versionRegex ) !== null ) {
  10773. isGLSL3ShaderMaterial = true;
  10774. vertexShader = vertexShader.replace( versionRegex, '' );
  10775. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10776. }
  10777. // GLSL 3.0 conversion
  10778. prefixVertex = [
  10779. '#version 300 es\n',
  10780. '#define attribute in',
  10781. '#define varying out',
  10782. '#define texture2D texture'
  10783. ].join( '\n' ) + '\n' + prefixVertex;
  10784. prefixFragment = [
  10785. '#version 300 es\n',
  10786. '#define varying in',
  10787. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10788. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10789. '#define gl_FragDepthEXT gl_FragDepth',
  10790. '#define texture2D texture',
  10791. '#define textureCube texture',
  10792. '#define texture2DProj textureProj',
  10793. '#define texture2DLodEXT textureLod',
  10794. '#define texture2DProjLodEXT textureProjLod',
  10795. '#define textureCubeLodEXT textureLod',
  10796. '#define texture2DGradEXT textureGrad',
  10797. '#define texture2DProjGradEXT textureProjGrad',
  10798. '#define textureCubeGradEXT textureGrad'
  10799. ].join( '\n' ) + '\n' + prefixFragment;
  10800. // Multiview
  10801. if ( numMultiviewViews > 0 ) {
  10802. prefixVertex = prefixVertex.replace(
  10803. '#version 300 es\n',
  10804. [
  10805. '#version 300 es\n',
  10806. '#extension GL_OVR_multiview2 : require',
  10807. 'layout(num_views = ' + numMultiviewViews + ') in;',
  10808. '#define VIEW_ID gl_ViewID_OVR'
  10809. ].join( '\n' )
  10810. );
  10811. prefixVertex = prefixVertex.replace(
  10812. [
  10813. 'uniform mat4 modelViewMatrix;',
  10814. 'uniform mat4 projectionMatrix;',
  10815. 'uniform mat4 viewMatrix;',
  10816. 'uniform mat3 normalMatrix;'
  10817. ].join( '\n' ),
  10818. [
  10819. 'uniform mat4 modelViewMatrices[' + numMultiviewViews + '];',
  10820. 'uniform mat4 projectionMatrices[' + numMultiviewViews + '];',
  10821. 'uniform mat4 viewMatrices[' + numMultiviewViews + '];',
  10822. 'uniform mat3 normalMatrices[' + numMultiviewViews + '];',
  10823. '#define modelViewMatrix modelViewMatrices[VIEW_ID]',
  10824. '#define projectionMatrix projectionMatrices[VIEW_ID]',
  10825. '#define viewMatrix viewMatrices[VIEW_ID]',
  10826. '#define normalMatrix normalMatrices[VIEW_ID]'
  10827. ].join( '\n' )
  10828. );
  10829. prefixFragment = prefixFragment.replace(
  10830. '#version 300 es\n',
  10831. [
  10832. '#version 300 es\n',
  10833. '#extension GL_OVR_multiview2 : require',
  10834. '#define VIEW_ID gl_ViewID_OVR'
  10835. ].join( '\n' )
  10836. );
  10837. prefixFragment = prefixFragment.replace(
  10838. 'uniform mat4 viewMatrix;',
  10839. [
  10840. 'uniform mat4 viewMatrices[' + numMultiviewViews + '];',
  10841. '#define viewMatrix viewMatrices[VIEW_ID]'
  10842. ].join( '\n' )
  10843. );
  10844. }
  10845. }
  10846. var vertexGlsl = prefixVertex + vertexShader;
  10847. var fragmentGlsl = prefixFragment + fragmentShader;
  10848. // console.log( '*VERTEX*', vertexGlsl );
  10849. // console.log( '*FRAGMENT*', fragmentGlsl );
  10850. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10851. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10852. gl.attachShader( program, glVertexShader );
  10853. gl.attachShader( program, glFragmentShader );
  10854. // Force a particular attribute to index 0.
  10855. if ( material.index0AttributeName !== undefined ) {
  10856. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10857. } else if ( parameters.morphTargets === true ) {
  10858. // programs with morphTargets displace position out of attribute 0
  10859. gl.bindAttribLocation( program, 0, 'position' );
  10860. }
  10861. gl.linkProgram( program );
  10862. // check for link errors
  10863. if ( renderer.debug.checkShaderErrors ) {
  10864. var programLog = gl.getProgramInfoLog( program ).trim();
  10865. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10866. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10867. var runnable = true;
  10868. var haveDiagnostics = true;
  10869. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10870. runnable = false;
  10871. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10872. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10873. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10874. } else if ( programLog !== '' ) {
  10875. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10876. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10877. haveDiagnostics = false;
  10878. }
  10879. if ( haveDiagnostics ) {
  10880. this.diagnostics = {
  10881. runnable: runnable,
  10882. material: material,
  10883. programLog: programLog,
  10884. vertexShader: {
  10885. log: vertexLog,
  10886. prefix: prefixVertex
  10887. },
  10888. fragmentShader: {
  10889. log: fragmentLog,
  10890. prefix: prefixFragment
  10891. }
  10892. };
  10893. }
  10894. }
  10895. // clean up
  10896. gl.deleteShader( glVertexShader );
  10897. gl.deleteShader( glFragmentShader );
  10898. // set up caching for uniform locations
  10899. var cachedUniforms;
  10900. this.getUniforms = function () {
  10901. if ( cachedUniforms === undefined ) {
  10902. cachedUniforms = new WebGLUniforms( gl, program );
  10903. }
  10904. return cachedUniforms;
  10905. };
  10906. // set up caching for attribute locations
  10907. var cachedAttributes;
  10908. this.getAttributes = function () {
  10909. if ( cachedAttributes === undefined ) {
  10910. cachedAttributes = fetchAttributeLocations( gl, program );
  10911. }
  10912. return cachedAttributes;
  10913. };
  10914. // free resource
  10915. this.destroy = function () {
  10916. gl.deleteProgram( program );
  10917. this.program = undefined;
  10918. };
  10919. //
  10920. this.name = shader.name;
  10921. this.id = programIdCount ++;
  10922. this.cacheKey = cacheKey;
  10923. this.usedTimes = 1;
  10924. this.program = program;
  10925. this.vertexShader = glVertexShader;
  10926. this.fragmentShader = glFragmentShader;
  10927. this.numMultiviewViews = numMultiviewViews;
  10928. return this;
  10929. }
  10930. /**
  10931. * @author mrdoob / http://mrdoob.com/
  10932. */
  10933. function WebGLPrograms( renderer, extensions, capabilities ) {
  10934. var programs = [];
  10935. var isWebGL2 = capabilities.isWebGL2;
  10936. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10937. var floatVertexTextures = capabilities.floatVertexTextures;
  10938. var precision = capabilities.precision;
  10939. var maxVertexUniforms = capabilities.maxVertexUniforms;
  10940. var vertexTextures = capabilities.vertexTextures;
  10941. var shaderIDs = {
  10942. MeshDepthMaterial: 'depth',
  10943. MeshDistanceMaterial: 'distanceRGBA',
  10944. MeshNormalMaterial: 'normal',
  10945. MeshBasicMaterial: 'basic',
  10946. MeshLambertMaterial: 'lambert',
  10947. MeshPhongMaterial: 'phong',
  10948. MeshToonMaterial: 'phong',
  10949. MeshStandardMaterial: 'physical',
  10950. MeshPhysicalMaterial: 'physical',
  10951. MeshMatcapMaterial: 'matcap',
  10952. LineBasicMaterial: 'basic',
  10953. LineDashedMaterial: 'dashed',
  10954. PointsMaterial: 'points',
  10955. ShadowMaterial: 'shadow',
  10956. SpriteMaterial: 'sprite'
  10957. };
  10958. var parameterNames = [
  10959. "precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing", "numMultiviewViews",
  10960. "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding", "envMapCubeUV",
  10961. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "tangentSpaceNormalMap", "clearcoatNormalMap", "displacementMap", "specularMap",
  10962. "roughnessMap", "metalnessMap", "gradientMap",
  10963. "alphaMap", "combine", "vertexColors", "vertexTangents", "vertexUvs", "uvsVertexOnly", "fog", "useFog", "fogExp2",
  10964. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10965. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10966. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10967. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10968. "numDirLightShadows", "numPointLightShadows", "numSpotLightShadows",
  10969. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10970. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering",
  10971. "sheen"
  10972. ];
  10973. function allocateBones( object ) {
  10974. var skeleton = object.skeleton;
  10975. var bones = skeleton.bones;
  10976. if ( floatVertexTextures ) {
  10977. return 1024;
  10978. } else {
  10979. // default for when object is not specified
  10980. // ( for example when prebuilding shader to be used with multiple objects )
  10981. //
  10982. // - leave some extra space for other uniforms
  10983. // - limit here is ANGLE's 254 max uniform vectors
  10984. // (up to 54 should be safe)
  10985. var nVertexUniforms = maxVertexUniforms;
  10986. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10987. var maxBones = Math.min( nVertexMatrices, bones.length );
  10988. if ( maxBones < bones.length ) {
  10989. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10990. return 0;
  10991. }
  10992. return maxBones;
  10993. }
  10994. }
  10995. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10996. var encoding;
  10997. if ( ! map ) {
  10998. encoding = LinearEncoding;
  10999. } else if ( map.isTexture ) {
  11000. encoding = map.encoding;
  11001. } else if ( map.isWebGLRenderTarget ) {
  11002. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  11003. encoding = map.texture.encoding;
  11004. }
  11005. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  11006. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  11007. encoding = GammaEncoding;
  11008. }
  11009. return encoding;
  11010. }
  11011. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  11012. var shaderID = shaderIDs[ material.type ];
  11013. // heuristics to create shader parameters according to lights in the scene
  11014. // (not to blow over maxLights budget)
  11015. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  11016. if ( material.precision !== null ) {
  11017. precision = capabilities.getMaxPrecision( material.precision );
  11018. if ( precision !== material.precision ) {
  11019. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11020. }
  11021. }
  11022. var currentRenderTarget = renderer.getRenderTarget();
  11023. var numMultiviewViews = currentRenderTarget && currentRenderTarget.isWebGLMultiviewRenderTarget ? currentRenderTarget.numViews : 0;
  11024. var parameters = {
  11025. isWebGL2: isWebGL2,
  11026. shaderID: shaderID,
  11027. precision: precision,
  11028. instancing: object.isInstancedMesh === true,
  11029. supportsVertexTextures: vertexTextures,
  11030. numMultiviewViews: numMultiviewViews,
  11031. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  11032. map: !! material.map,
  11033. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  11034. matcap: !! material.matcap,
  11035. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  11036. envMap: !! material.envMap,
  11037. envMapMode: material.envMap && material.envMap.mapping,
  11038. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  11039. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  11040. lightMap: !! material.lightMap,
  11041. aoMap: !! material.aoMap,
  11042. emissiveMap: !! material.emissiveMap,
  11043. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  11044. bumpMap: !! material.bumpMap,
  11045. normalMap: !! material.normalMap,
  11046. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11047. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11048. clearcoatNormalMap: !! material.clearcoatNormalMap,
  11049. displacementMap: !! material.displacementMap,
  11050. roughnessMap: !! material.roughnessMap,
  11051. metalnessMap: !! material.metalnessMap,
  11052. specularMap: !! material.specularMap,
  11053. alphaMap: !! material.alphaMap,
  11054. gradientMap: !! material.gradientMap,
  11055. sheen: !! material.sheen,
  11056. combine: material.combine,
  11057. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11058. vertexColors: material.vertexColors,
  11059. vertexUvs: !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap || !! material.displacementMap,
  11060. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap ) && !! material.displacementMap,
  11061. fog: !! fog,
  11062. useFog: material.fog,
  11063. fogExp2: ( fog && fog.isFogExp2 ),
  11064. flatShading: material.flatShading,
  11065. sizeAttenuation: material.sizeAttenuation,
  11066. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11067. skinning: material.skinning && maxBones > 0,
  11068. maxBones: maxBones,
  11069. useVertexTexture: floatVertexTextures,
  11070. morphTargets: material.morphTargets,
  11071. morphNormals: material.morphNormals,
  11072. maxMorphTargets: renderer.maxMorphTargets,
  11073. maxMorphNormals: renderer.maxMorphNormals,
  11074. numDirLights: lights.directional.length,
  11075. numPointLights: lights.point.length,
  11076. numSpotLights: lights.spot.length,
  11077. numRectAreaLights: lights.rectArea.length,
  11078. numHemiLights: lights.hemi.length,
  11079. numDirLightShadows: lights.directionalShadowMap.length,
  11080. numPointLightShadows: lights.pointShadowMap.length,
  11081. numSpotLightShadows: lights.spotShadowMap.length,
  11082. numClippingPlanes: nClipPlanes,
  11083. numClipIntersection: nClipIntersection,
  11084. dithering: material.dithering,
  11085. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11086. shadowMapType: renderer.shadowMap.type,
  11087. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11088. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11089. premultipliedAlpha: material.premultipliedAlpha,
  11090. alphaTest: material.alphaTest,
  11091. doubleSided: material.side === DoubleSide,
  11092. flipSided: material.side === BackSide,
  11093. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  11094. };
  11095. return parameters;
  11096. };
  11097. this.getProgramCacheKey = function ( material, parameters ) {
  11098. var array = [];
  11099. if ( parameters.shaderID ) {
  11100. array.push( parameters.shaderID );
  11101. } else {
  11102. array.push( material.fragmentShader );
  11103. array.push( material.vertexShader );
  11104. }
  11105. if ( material.defines !== undefined ) {
  11106. for ( var name in material.defines ) {
  11107. array.push( name );
  11108. array.push( material.defines[ name ] );
  11109. }
  11110. }
  11111. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11112. array.push( parameters[ parameterNames[ i ] ] );
  11113. }
  11114. array.push( material.onBeforeCompile.toString() );
  11115. array.push( renderer.gammaOutput );
  11116. array.push( renderer.gammaFactor );
  11117. return array.join();
  11118. };
  11119. this.acquireProgram = function ( material, shader, parameters, cacheKey ) {
  11120. var program;
  11121. // Check if code has been already compiled
  11122. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11123. var preexistingProgram = programs[ p ];
  11124. if ( preexistingProgram.cacheKey === cacheKey ) {
  11125. program = preexistingProgram;
  11126. ++ program.usedTimes;
  11127. break;
  11128. }
  11129. }
  11130. if ( program === undefined ) {
  11131. program = new WebGLProgram( renderer, extensions, cacheKey, material, shader, parameters );
  11132. programs.push( program );
  11133. }
  11134. return program;
  11135. };
  11136. this.releaseProgram = function ( program ) {
  11137. if ( -- program.usedTimes === 0 ) {
  11138. // Remove from unordered set
  11139. var i = programs.indexOf( program );
  11140. programs[ i ] = programs[ programs.length - 1 ];
  11141. programs.pop();
  11142. // Free WebGL resources
  11143. program.destroy();
  11144. }
  11145. };
  11146. // Exposed for resource monitoring & error feedback via renderer.info:
  11147. this.programs = programs;
  11148. }
  11149. /**
  11150. * @author fordacious / fordacious.github.io
  11151. */
  11152. function WebGLProperties() {
  11153. var properties = new WeakMap();
  11154. function get( object ) {
  11155. var map = properties.get( object );
  11156. if ( map === undefined ) {
  11157. map = {};
  11158. properties.set( object, map );
  11159. }
  11160. return map;
  11161. }
  11162. function remove( object ) {
  11163. properties.delete( object );
  11164. }
  11165. function update( object, key, value ) {
  11166. properties.get( object )[ key ] = value;
  11167. }
  11168. function dispose() {
  11169. properties = new WeakMap();
  11170. }
  11171. return {
  11172. get: get,
  11173. remove: remove,
  11174. update: update,
  11175. dispose: dispose
  11176. };
  11177. }
  11178. /**
  11179. * @author mrdoob / http://mrdoob.com/
  11180. */
  11181. function painterSortStable( a, b ) {
  11182. if ( a.groupOrder !== b.groupOrder ) {
  11183. return a.groupOrder - b.groupOrder;
  11184. } else if ( a.renderOrder !== b.renderOrder ) {
  11185. return a.renderOrder - b.renderOrder;
  11186. } else if ( a.program !== b.program ) {
  11187. return a.program.id - b.program.id;
  11188. } else if ( a.material.id !== b.material.id ) {
  11189. return a.material.id - b.material.id;
  11190. } else if ( a.z !== b.z ) {
  11191. return a.z - b.z;
  11192. } else {
  11193. return a.id - b.id;
  11194. }
  11195. }
  11196. function reversePainterSortStable( a, b ) {
  11197. if ( a.groupOrder !== b.groupOrder ) {
  11198. return a.groupOrder - b.groupOrder;
  11199. } else if ( a.renderOrder !== b.renderOrder ) {
  11200. return a.renderOrder - b.renderOrder;
  11201. } else if ( a.z !== b.z ) {
  11202. return b.z - a.z;
  11203. } else {
  11204. return a.id - b.id;
  11205. }
  11206. }
  11207. function WebGLRenderList() {
  11208. var renderItems = [];
  11209. var renderItemsIndex = 0;
  11210. var opaque = [];
  11211. var transparent = [];
  11212. var defaultProgram = { id: - 1 };
  11213. function init() {
  11214. renderItemsIndex = 0;
  11215. opaque.length = 0;
  11216. transparent.length = 0;
  11217. }
  11218. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11219. var renderItem = renderItems[ renderItemsIndex ];
  11220. if ( renderItem === undefined ) {
  11221. renderItem = {
  11222. id: object.id,
  11223. object: object,
  11224. geometry: geometry,
  11225. material: material,
  11226. program: material.program || defaultProgram,
  11227. groupOrder: groupOrder,
  11228. renderOrder: object.renderOrder,
  11229. z: z,
  11230. group: group
  11231. };
  11232. renderItems[ renderItemsIndex ] = renderItem;
  11233. } else {
  11234. renderItem.id = object.id;
  11235. renderItem.object = object;
  11236. renderItem.geometry = geometry;
  11237. renderItem.material = material;
  11238. renderItem.program = material.program || defaultProgram;
  11239. renderItem.groupOrder = groupOrder;
  11240. renderItem.renderOrder = object.renderOrder;
  11241. renderItem.z = z;
  11242. renderItem.group = group;
  11243. }
  11244. renderItemsIndex ++;
  11245. return renderItem;
  11246. }
  11247. function push( object, geometry, material, groupOrder, z, group ) {
  11248. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11249. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11250. }
  11251. function unshift( object, geometry, material, groupOrder, z, group ) {
  11252. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11253. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11254. }
  11255. function sort() {
  11256. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  11257. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  11258. }
  11259. return {
  11260. opaque: opaque,
  11261. transparent: transparent,
  11262. init: init,
  11263. push: push,
  11264. unshift: unshift,
  11265. sort: sort
  11266. };
  11267. }
  11268. function WebGLRenderLists() {
  11269. var lists = new WeakMap();
  11270. function onSceneDispose( event ) {
  11271. var scene = event.target;
  11272. scene.removeEventListener( 'dispose', onSceneDispose );
  11273. lists.delete( scene );
  11274. }
  11275. function get( scene, camera ) {
  11276. var cameras = lists.get( scene );
  11277. var list;
  11278. if ( cameras === undefined ) {
  11279. list = new WebGLRenderList();
  11280. lists.set( scene, new WeakMap() );
  11281. lists.get( scene ).set( camera, list );
  11282. scene.addEventListener( 'dispose', onSceneDispose );
  11283. } else {
  11284. list = cameras.get( camera );
  11285. if ( list === undefined ) {
  11286. list = new WebGLRenderList();
  11287. cameras.set( camera, list );
  11288. }
  11289. }
  11290. return list;
  11291. }
  11292. function dispose() {
  11293. lists = new WeakMap();
  11294. }
  11295. return {
  11296. get: get,
  11297. dispose: dispose
  11298. };
  11299. }
  11300. /**
  11301. * @author mrdoob / http://mrdoob.com/
  11302. */
  11303. function UniformsCache() {
  11304. var lights = {};
  11305. return {
  11306. get: function ( light ) {
  11307. if ( lights[ light.id ] !== undefined ) {
  11308. return lights[ light.id ];
  11309. }
  11310. var uniforms;
  11311. switch ( light.type ) {
  11312. case 'DirectionalLight':
  11313. uniforms = {
  11314. direction: new Vector3(),
  11315. color: new Color(),
  11316. shadow: false,
  11317. shadowBias: 0,
  11318. shadowRadius: 1,
  11319. shadowMapSize: new Vector2()
  11320. };
  11321. break;
  11322. case 'SpotLight':
  11323. uniforms = {
  11324. position: new Vector3(),
  11325. direction: new Vector3(),
  11326. color: new Color(),
  11327. distance: 0,
  11328. coneCos: 0,
  11329. penumbraCos: 0,
  11330. decay: 0,
  11331. shadow: false,
  11332. shadowBias: 0,
  11333. shadowRadius: 1,
  11334. shadowMapSize: new Vector2()
  11335. };
  11336. break;
  11337. case 'PointLight':
  11338. uniforms = {
  11339. position: new Vector3(),
  11340. color: new Color(),
  11341. distance: 0,
  11342. decay: 0,
  11343. shadow: false,
  11344. shadowBias: 0,
  11345. shadowRadius: 1,
  11346. shadowMapSize: new Vector2(),
  11347. shadowCameraNear: 1,
  11348. shadowCameraFar: 1000
  11349. };
  11350. break;
  11351. case 'HemisphereLight':
  11352. uniforms = {
  11353. direction: new Vector3(),
  11354. skyColor: new Color(),
  11355. groundColor: new Color()
  11356. };
  11357. break;
  11358. case 'RectAreaLight':
  11359. uniforms = {
  11360. color: new Color(),
  11361. position: new Vector3(),
  11362. halfWidth: new Vector3(),
  11363. halfHeight: new Vector3()
  11364. // TODO (abelnation): set RectAreaLight shadow uniforms
  11365. };
  11366. break;
  11367. }
  11368. lights[ light.id ] = uniforms;
  11369. return uniforms;
  11370. }
  11371. };
  11372. }
  11373. var nextVersion = 0;
  11374. function shadowCastingLightsFirst( lightA, lightB ) {
  11375. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  11376. }
  11377. function WebGLLights() {
  11378. var cache = new UniformsCache();
  11379. var state = {
  11380. version: 0,
  11381. hash: {
  11382. directionalLength: - 1,
  11383. pointLength: - 1,
  11384. spotLength: - 1,
  11385. rectAreaLength: - 1,
  11386. hemiLength: - 1,
  11387. numDirectionalShadows: - 1,
  11388. numPointShadows: - 1,
  11389. numSpotShadows: - 1,
  11390. },
  11391. ambient: [ 0, 0, 0 ],
  11392. probe: [],
  11393. directional: [],
  11394. directionalShadowMap: [],
  11395. directionalShadowMatrix: [],
  11396. spot: [],
  11397. spotShadowMap: [],
  11398. spotShadowMatrix: [],
  11399. rectArea: [],
  11400. point: [],
  11401. pointShadowMap: [],
  11402. pointShadowMatrix: [],
  11403. hemi: [],
  11404. numDirectionalShadows: - 1,
  11405. numPointShadows: - 1,
  11406. numSpotShadows: - 1
  11407. };
  11408. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11409. var vector3 = new Vector3();
  11410. var matrix4 = new Matrix4();
  11411. var matrix42 = new Matrix4();
  11412. function setup( lights, shadows, camera ) {
  11413. var r = 0, g = 0, b = 0;
  11414. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11415. var directionalLength = 0;
  11416. var pointLength = 0;
  11417. var spotLength = 0;
  11418. var rectAreaLength = 0;
  11419. var hemiLength = 0;
  11420. var numDirectionalShadows = 0;
  11421. var numPointShadows = 0;
  11422. var numSpotShadows = 0;
  11423. var viewMatrix = camera.matrixWorldInverse;
  11424. lights.sort( shadowCastingLightsFirst );
  11425. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  11426. var light = lights[ i ];
  11427. var color = light.color;
  11428. var intensity = light.intensity;
  11429. var distance = light.distance;
  11430. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11431. if ( light.isAmbientLight ) {
  11432. r += color.r * intensity;
  11433. g += color.g * intensity;
  11434. b += color.b * intensity;
  11435. } else if ( light.isLightProbe ) {
  11436. for ( var j = 0; j < 9; j ++ ) {
  11437. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11438. }
  11439. } else if ( light.isDirectionalLight ) {
  11440. var uniforms = cache.get( light );
  11441. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11442. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11443. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11444. uniforms.direction.sub( vector3 );
  11445. uniforms.direction.transformDirection( viewMatrix );
  11446. uniforms.shadow = light.castShadow;
  11447. if ( light.castShadow ) {
  11448. var shadow = light.shadow;
  11449. uniforms.shadowBias = shadow.bias;
  11450. uniforms.shadowRadius = shadow.radius;
  11451. uniforms.shadowMapSize = shadow.mapSize;
  11452. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11453. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11454. numDirectionalShadows ++;
  11455. }
  11456. state.directional[ directionalLength ] = uniforms;
  11457. directionalLength ++;
  11458. } else if ( light.isSpotLight ) {
  11459. var uniforms = cache.get( light );
  11460. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11461. uniforms.position.applyMatrix4( viewMatrix );
  11462. uniforms.color.copy( color ).multiplyScalar( intensity );
  11463. uniforms.distance = distance;
  11464. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11465. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11466. uniforms.direction.sub( vector3 );
  11467. uniforms.direction.transformDirection( viewMatrix );
  11468. uniforms.coneCos = Math.cos( light.angle );
  11469. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11470. uniforms.decay = light.decay;
  11471. uniforms.shadow = light.castShadow;
  11472. if ( light.castShadow ) {
  11473. var shadow = light.shadow;
  11474. uniforms.shadowBias = shadow.bias;
  11475. uniforms.shadowRadius = shadow.radius;
  11476. uniforms.shadowMapSize = shadow.mapSize;
  11477. state.spotShadowMap[ spotLength ] = shadowMap;
  11478. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11479. numSpotShadows ++;
  11480. }
  11481. state.spot[ spotLength ] = uniforms;
  11482. spotLength ++;
  11483. } else if ( light.isRectAreaLight ) {
  11484. var uniforms = cache.get( light );
  11485. // (a) intensity is the total visible light emitted
  11486. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11487. // (b) intensity is the brightness of the light
  11488. uniforms.color.copy( color ).multiplyScalar( intensity );
  11489. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11490. uniforms.position.applyMatrix4( viewMatrix );
  11491. // extract local rotation of light to derive width/height half vectors
  11492. matrix42.identity();
  11493. matrix4.copy( light.matrixWorld );
  11494. matrix4.premultiply( viewMatrix );
  11495. matrix42.extractRotation( matrix4 );
  11496. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11497. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11498. uniforms.halfWidth.applyMatrix4( matrix42 );
  11499. uniforms.halfHeight.applyMatrix4( matrix42 );
  11500. // TODO (abelnation): RectAreaLight distance?
  11501. // uniforms.distance = distance;
  11502. state.rectArea[ rectAreaLength ] = uniforms;
  11503. rectAreaLength ++;
  11504. } else if ( light.isPointLight ) {
  11505. var uniforms = cache.get( light );
  11506. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11507. uniforms.position.applyMatrix4( viewMatrix );
  11508. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11509. uniforms.distance = light.distance;
  11510. uniforms.decay = light.decay;
  11511. uniforms.shadow = light.castShadow;
  11512. if ( light.castShadow ) {
  11513. var shadow = light.shadow;
  11514. uniforms.shadowBias = shadow.bias;
  11515. uniforms.shadowRadius = shadow.radius;
  11516. uniforms.shadowMapSize = shadow.mapSize;
  11517. uniforms.shadowCameraNear = shadow.camera.near;
  11518. uniforms.shadowCameraFar = shadow.camera.far;
  11519. state.pointShadowMap[ pointLength ] = shadowMap;
  11520. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11521. numPointShadows ++;
  11522. }
  11523. state.point[ pointLength ] = uniforms;
  11524. pointLength ++;
  11525. } else if ( light.isHemisphereLight ) {
  11526. var uniforms = cache.get( light );
  11527. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11528. uniforms.direction.transformDirection( viewMatrix );
  11529. uniforms.direction.normalize();
  11530. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11531. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11532. state.hemi[ hemiLength ] = uniforms;
  11533. hemiLength ++;
  11534. }
  11535. }
  11536. state.ambient[ 0 ] = r;
  11537. state.ambient[ 1 ] = g;
  11538. state.ambient[ 2 ] = b;
  11539. var hash = state.hash;
  11540. if ( hash.directionalLength !== directionalLength ||
  11541. hash.pointLength !== pointLength ||
  11542. hash.spotLength !== spotLength ||
  11543. hash.rectAreaLength !== rectAreaLength ||
  11544. hash.hemiLength !== hemiLength ||
  11545. hash.numDirectionalShadows !== numDirectionalShadows ||
  11546. hash.numPointShadows !== numPointShadows ||
  11547. hash.numSpotShadows !== numSpotShadows ) {
  11548. state.directional.length = directionalLength;
  11549. state.spot.length = spotLength;
  11550. state.rectArea.length = rectAreaLength;
  11551. state.point.length = pointLength;
  11552. state.hemi.length = hemiLength;
  11553. state.directionalShadowMap.length = numDirectionalShadows;
  11554. state.pointShadowMap.length = numPointShadows;
  11555. state.spotShadowMap.length = numSpotShadows;
  11556. state.directionalShadowMatrix.length = numDirectionalShadows;
  11557. state.pointShadowMatrix.length = numPointShadows;
  11558. state.spotShadowMatrix.length = numSpotShadows;
  11559. hash.directionalLength = directionalLength;
  11560. hash.pointLength = pointLength;
  11561. hash.spotLength = spotLength;
  11562. hash.rectAreaLength = rectAreaLength;
  11563. hash.hemiLength = hemiLength;
  11564. hash.numDirectionalShadows = numDirectionalShadows;
  11565. hash.numPointShadows = numPointShadows;
  11566. hash.numSpotShadows = numSpotShadows;
  11567. state.version = nextVersion ++;
  11568. }
  11569. }
  11570. return {
  11571. setup: setup,
  11572. state: state
  11573. };
  11574. }
  11575. /**
  11576. * @author Mugen87 / https://github.com/Mugen87
  11577. */
  11578. function WebGLRenderState() {
  11579. var lights = new WebGLLights();
  11580. var lightsArray = [];
  11581. var shadowsArray = [];
  11582. function init() {
  11583. lightsArray.length = 0;
  11584. shadowsArray.length = 0;
  11585. }
  11586. function pushLight( light ) {
  11587. lightsArray.push( light );
  11588. }
  11589. function pushShadow( shadowLight ) {
  11590. shadowsArray.push( shadowLight );
  11591. }
  11592. function setupLights( camera ) {
  11593. lights.setup( lightsArray, shadowsArray, camera );
  11594. }
  11595. var state = {
  11596. lightsArray: lightsArray,
  11597. shadowsArray: shadowsArray,
  11598. lights: lights
  11599. };
  11600. return {
  11601. init: init,
  11602. state: state,
  11603. setupLights: setupLights,
  11604. pushLight: pushLight,
  11605. pushShadow: pushShadow
  11606. };
  11607. }
  11608. function WebGLRenderStates() {
  11609. var renderStates = new WeakMap();
  11610. function onSceneDispose( event ) {
  11611. var scene = event.target;
  11612. scene.removeEventListener( 'dispose', onSceneDispose );
  11613. renderStates.delete( scene );
  11614. }
  11615. function get( scene, camera ) {
  11616. var renderState;
  11617. if ( renderStates.has( scene ) === false ) {
  11618. renderState = new WebGLRenderState();
  11619. renderStates.set( scene, new WeakMap() );
  11620. renderStates.get( scene ).set( camera, renderState );
  11621. scene.addEventListener( 'dispose', onSceneDispose );
  11622. } else {
  11623. if ( renderStates.get( scene ).has( camera ) === false ) {
  11624. renderState = new WebGLRenderState();
  11625. renderStates.get( scene ).set( camera, renderState );
  11626. } else {
  11627. renderState = renderStates.get( scene ).get( camera );
  11628. }
  11629. }
  11630. return renderState;
  11631. }
  11632. function dispose() {
  11633. renderStates = new WeakMap();
  11634. }
  11635. return {
  11636. get: get,
  11637. dispose: dispose
  11638. };
  11639. }
  11640. /**
  11641. * @author mrdoob / http://mrdoob.com/
  11642. * @author alteredq / http://alteredqualia.com/
  11643. * @author bhouston / https://clara.io
  11644. * @author WestLangley / http://github.com/WestLangley
  11645. *
  11646. * parameters = {
  11647. *
  11648. * opacity: <float>,
  11649. *
  11650. * map: new THREE.Texture( <Image> ),
  11651. *
  11652. * alphaMap: new THREE.Texture( <Image> ),
  11653. *
  11654. * displacementMap: new THREE.Texture( <Image> ),
  11655. * displacementScale: <float>,
  11656. * displacementBias: <float>,
  11657. *
  11658. * wireframe: <boolean>,
  11659. * wireframeLinewidth: <float>
  11660. * }
  11661. */
  11662. function MeshDepthMaterial( parameters ) {
  11663. Material.call( this );
  11664. this.type = 'MeshDepthMaterial';
  11665. this.depthPacking = BasicDepthPacking;
  11666. this.skinning = false;
  11667. this.morphTargets = false;
  11668. this.map = null;
  11669. this.alphaMap = null;
  11670. this.displacementMap = null;
  11671. this.displacementScale = 1;
  11672. this.displacementBias = 0;
  11673. this.wireframe = false;
  11674. this.wireframeLinewidth = 1;
  11675. this.fog = false;
  11676. this.setValues( parameters );
  11677. }
  11678. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11679. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11680. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11681. MeshDepthMaterial.prototype.copy = function ( source ) {
  11682. Material.prototype.copy.call( this, source );
  11683. this.depthPacking = source.depthPacking;
  11684. this.skinning = source.skinning;
  11685. this.morphTargets = source.morphTargets;
  11686. this.map = source.map;
  11687. this.alphaMap = source.alphaMap;
  11688. this.displacementMap = source.displacementMap;
  11689. this.displacementScale = source.displacementScale;
  11690. this.displacementBias = source.displacementBias;
  11691. this.wireframe = source.wireframe;
  11692. this.wireframeLinewidth = source.wireframeLinewidth;
  11693. return this;
  11694. };
  11695. /**
  11696. * @author WestLangley / http://github.com/WestLangley
  11697. *
  11698. * parameters = {
  11699. *
  11700. * referencePosition: <float>,
  11701. * nearDistance: <float>,
  11702. * farDistance: <float>,
  11703. *
  11704. * skinning: <bool>,
  11705. * morphTargets: <bool>,
  11706. *
  11707. * map: new THREE.Texture( <Image> ),
  11708. *
  11709. * alphaMap: new THREE.Texture( <Image> ),
  11710. *
  11711. * displacementMap: new THREE.Texture( <Image> ),
  11712. * displacementScale: <float>,
  11713. * displacementBias: <float>
  11714. *
  11715. * }
  11716. */
  11717. function MeshDistanceMaterial( parameters ) {
  11718. Material.call( this );
  11719. this.type = 'MeshDistanceMaterial';
  11720. this.referencePosition = new Vector3();
  11721. this.nearDistance = 1;
  11722. this.farDistance = 1000;
  11723. this.skinning = false;
  11724. this.morphTargets = false;
  11725. this.map = null;
  11726. this.alphaMap = null;
  11727. this.displacementMap = null;
  11728. this.displacementScale = 1;
  11729. this.displacementBias = 0;
  11730. this.fog = false;
  11731. this.setValues( parameters );
  11732. }
  11733. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11734. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11735. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11736. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11737. Material.prototype.copy.call( this, source );
  11738. this.referencePosition.copy( source.referencePosition );
  11739. this.nearDistance = source.nearDistance;
  11740. this.farDistance = source.farDistance;
  11741. this.skinning = source.skinning;
  11742. this.morphTargets = source.morphTargets;
  11743. this.map = source.map;
  11744. this.alphaMap = source.alphaMap;
  11745. this.displacementMap = source.displacementMap;
  11746. this.displacementScale = source.displacementScale;
  11747. this.displacementBias = source.displacementBias;
  11748. return this;
  11749. };
  11750. 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 = unpack2HalfToRGBA ( 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}";
  11751. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11752. /**
  11753. * @author alteredq / http://alteredqualia.com/
  11754. * @author mrdoob / http://mrdoob.com/
  11755. */
  11756. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11757. var _frustum = new Frustum(),
  11758. _shadowMapSize = new Vector2(),
  11759. _viewportSize = new Vector2(),
  11760. _viewport = new Vector4(),
  11761. _depthMaterials = [],
  11762. _distanceMaterials = [],
  11763. _materialCache = {};
  11764. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11765. var shadowMaterialVertical = new ShaderMaterial( {
  11766. defines: {
  11767. SAMPLE_RATE: 2.0 / 8.0,
  11768. HALF_SAMPLE_RATE: 1.0 / 8.0
  11769. },
  11770. uniforms: {
  11771. shadow_pass: { value: null },
  11772. resolution: { value: new Vector2() },
  11773. radius: { value: 4.0 }
  11774. },
  11775. vertexShader: vsm_vert,
  11776. fragmentShader: vsm_frag
  11777. } );
  11778. var shadowMaterialHorizonal = shadowMaterialVertical.clone();
  11779. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  11780. var fullScreenTri = new BufferGeometry();
  11781. fullScreenTri.setAttribute(
  11782. "position",
  11783. new BufferAttribute(
  11784. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  11785. 3
  11786. )
  11787. );
  11788. var fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  11789. var scope = this;
  11790. this.enabled = false;
  11791. this.autoUpdate = true;
  11792. this.needsUpdate = false;
  11793. this.type = PCFShadowMap;
  11794. this.render = function ( lights, scene, camera ) {
  11795. if ( scope.enabled === false ) return;
  11796. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11797. if ( lights.length === 0 ) return;
  11798. var currentRenderTarget = _renderer.getRenderTarget();
  11799. var activeCubeFace = _renderer.getActiveCubeFace();
  11800. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11801. var _state = _renderer.state;
  11802. // Set GL state for depth map.
  11803. _state.setBlending( NoBlending );
  11804. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11805. _state.buffers.depth.setTest( true );
  11806. _state.setScissorTest( false );
  11807. // render depth map
  11808. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11809. var light = lights[ i ];
  11810. var shadow = light.shadow;
  11811. if ( shadow === undefined ) {
  11812. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11813. continue;
  11814. }
  11815. _shadowMapSize.copy( shadow.mapSize );
  11816. var shadowFrameExtents = shadow.getFrameExtents();
  11817. _shadowMapSize.multiply( shadowFrameExtents );
  11818. _viewportSize.copy( shadow.mapSize );
  11819. if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
  11820. console.warn( 'THREE.WebGLShadowMap:', light, 'has shadow exceeding max texture size, reducing' );
  11821. if ( _shadowMapSize.x > maxTextureSize ) {
  11822. _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
  11823. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11824. shadow.mapSize.x = _viewportSize.x;
  11825. }
  11826. if ( _shadowMapSize.y > maxTextureSize ) {
  11827. _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
  11828. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11829. shadow.mapSize.y = _viewportSize.y;
  11830. }
  11831. }
  11832. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11833. var pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  11834. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11835. shadow.map.texture.name = light.name + ".shadowMap";
  11836. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11837. shadow.camera.updateProjectionMatrix();
  11838. }
  11839. if ( shadow.map === null ) {
  11840. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11841. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11842. shadow.map.texture.name = light.name + ".shadowMap";
  11843. shadow.camera.updateProjectionMatrix();
  11844. }
  11845. _renderer.setRenderTarget( shadow.map );
  11846. _renderer.clear();
  11847. var viewportCount = shadow.getViewportCount();
  11848. for ( var vp = 0; vp < viewportCount; vp ++ ) {
  11849. var viewport = shadow.getViewport( vp );
  11850. _viewport.set(
  11851. _viewportSize.x * viewport.x,
  11852. _viewportSize.y * viewport.y,
  11853. _viewportSize.x * viewport.z,
  11854. _viewportSize.y * viewport.w
  11855. );
  11856. _state.viewport( _viewport );
  11857. shadow.updateMatrices( light, vp );
  11858. _frustum = shadow.getFrustum();
  11859. renderObject( scene, camera, shadow.camera, light, this.type );
  11860. }
  11861. // do blur pass for VSM
  11862. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11863. VSMPass( shadow, camera );
  11864. }
  11865. }
  11866. scope.needsUpdate = false;
  11867. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11868. };
  11869. function VSMPass( shadow, camera ) {
  11870. var geometry = _objects.update( fullScreenMesh );
  11871. // vertical pass
  11872. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11873. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11874. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11875. _renderer.setRenderTarget( shadow.mapPass );
  11876. _renderer.clear();
  11877. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  11878. // horizonal pass
  11879. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11880. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  11881. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  11882. _renderer.setRenderTarget( shadow.map );
  11883. _renderer.clear();
  11884. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null );
  11885. }
  11886. function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11887. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11888. var material = _depthMaterials[ index ];
  11889. if ( material === undefined ) {
  11890. material = new MeshDepthMaterial( {
  11891. depthPacking: RGBADepthPacking,
  11892. morphTargets: useMorphing,
  11893. skinning: useSkinning
  11894. } );
  11895. _depthMaterials[ index ] = material;
  11896. }
  11897. return material;
  11898. }
  11899. function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11900. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11901. var material = _distanceMaterials[ index ];
  11902. if ( material === undefined ) {
  11903. material = new MeshDistanceMaterial( {
  11904. morphTargets: useMorphing,
  11905. skinning: useSkinning
  11906. } );
  11907. _distanceMaterials[ index ] = material;
  11908. }
  11909. return material;
  11910. }
  11911. function getDepthMaterial( object, material, light, shadowCameraNear, shadowCameraFar, type ) {
  11912. var geometry = object.geometry;
  11913. var result = null;
  11914. var getMaterialVariant = getDepthMaterialVariant;
  11915. var customMaterial = object.customDepthMaterial;
  11916. if ( light.isPointLight === true ) {
  11917. getMaterialVariant = getDistanceMaterialVariant;
  11918. customMaterial = object.customDistanceMaterial;
  11919. }
  11920. if ( customMaterial === undefined ) {
  11921. var useMorphing = false;
  11922. if ( material.morphTargets === true ) {
  11923. if ( geometry.isBufferGeometry === true ) {
  11924. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11925. } else if ( geometry.isGeometry === true ) {
  11926. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11927. }
  11928. }
  11929. var useSkinning = false;
  11930. if ( object.isSkinnedMesh === true ) {
  11931. if ( material.skinning === true ) {
  11932. useSkinning = true;
  11933. } else {
  11934. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11935. }
  11936. }
  11937. var useInstancing = object.isInstancedMesh === true;
  11938. result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
  11939. } else {
  11940. result = customMaterial;
  11941. }
  11942. if ( _renderer.localClippingEnabled &&
  11943. material.clipShadows === true &&
  11944. material.clippingPlanes.length !== 0 ) {
  11945. // in this case we need a unique material instance reflecting the
  11946. // appropriate state
  11947. var keyA = result.uuid, keyB = material.uuid;
  11948. var materialsForVariant = _materialCache[ keyA ];
  11949. if ( materialsForVariant === undefined ) {
  11950. materialsForVariant = {};
  11951. _materialCache[ keyA ] = materialsForVariant;
  11952. }
  11953. var cachedMaterial = materialsForVariant[ keyB ];
  11954. if ( cachedMaterial === undefined ) {
  11955. cachedMaterial = result.clone();
  11956. materialsForVariant[ keyB ] = cachedMaterial;
  11957. }
  11958. result = cachedMaterial;
  11959. }
  11960. result.visible = material.visible;
  11961. result.wireframe = material.wireframe;
  11962. if ( type === VSMShadowMap ) {
  11963. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  11964. } else {
  11965. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  11966. }
  11967. result.clipShadows = material.clipShadows;
  11968. result.clippingPlanes = material.clippingPlanes;
  11969. result.clipIntersection = material.clipIntersection;
  11970. result.wireframeLinewidth = material.wireframeLinewidth;
  11971. result.linewidth = material.linewidth;
  11972. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  11973. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  11974. result.nearDistance = shadowCameraNear;
  11975. result.farDistance = shadowCameraFar;
  11976. }
  11977. return result;
  11978. }
  11979. function renderObject( object, camera, shadowCamera, light, type ) {
  11980. if ( object.visible === false ) return;
  11981. var visible = object.layers.test( camera.layers );
  11982. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11983. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11984. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11985. var geometry = _objects.update( object );
  11986. var material = object.material;
  11987. if ( Array.isArray( material ) ) {
  11988. var groups = geometry.groups;
  11989. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11990. var group = groups[ k ];
  11991. var groupMaterial = material[ group.materialIndex ];
  11992. if ( groupMaterial && groupMaterial.visible ) {
  11993. var depthMaterial = getDepthMaterial( object, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  11994. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11995. }
  11996. }
  11997. } else if ( material.visible ) {
  11998. var depthMaterial = getDepthMaterial( object, material, light, shadowCamera.near, shadowCamera.far, type );
  11999. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  12000. }
  12001. }
  12002. }
  12003. var children = object.children;
  12004. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12005. renderObject( children[ i ], camera, shadowCamera, light, type );
  12006. }
  12007. }
  12008. }
  12009. /**
  12010. * @author mrdoob / http://mrdoob.com/
  12011. */
  12012. function WebGLState( gl, extensions, capabilities ) {
  12013. var isWebGL2 = capabilities.isWebGL2;
  12014. function ColorBuffer() {
  12015. var locked = false;
  12016. var color = new Vector4();
  12017. var currentColorMask = null;
  12018. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  12019. return {
  12020. setMask: function ( colorMask ) {
  12021. if ( currentColorMask !== colorMask && ! locked ) {
  12022. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  12023. currentColorMask = colorMask;
  12024. }
  12025. },
  12026. setLocked: function ( lock ) {
  12027. locked = lock;
  12028. },
  12029. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  12030. if ( premultipliedAlpha === true ) {
  12031. r *= a; g *= a; b *= a;
  12032. }
  12033. color.set( r, g, b, a );
  12034. if ( currentColorClear.equals( color ) === false ) {
  12035. gl.clearColor( r, g, b, a );
  12036. currentColorClear.copy( color );
  12037. }
  12038. },
  12039. reset: function () {
  12040. locked = false;
  12041. currentColorMask = null;
  12042. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  12043. }
  12044. };
  12045. }
  12046. function DepthBuffer() {
  12047. var locked = false;
  12048. var currentDepthMask = null;
  12049. var currentDepthFunc = null;
  12050. var currentDepthClear = null;
  12051. return {
  12052. setTest: function ( depthTest ) {
  12053. if ( depthTest ) {
  12054. enable( 2929 );
  12055. } else {
  12056. disable( 2929 );
  12057. }
  12058. },
  12059. setMask: function ( depthMask ) {
  12060. if ( currentDepthMask !== depthMask && ! locked ) {
  12061. gl.depthMask( depthMask );
  12062. currentDepthMask = depthMask;
  12063. }
  12064. },
  12065. setFunc: function ( depthFunc ) {
  12066. if ( currentDepthFunc !== depthFunc ) {
  12067. if ( depthFunc ) {
  12068. switch ( depthFunc ) {
  12069. case NeverDepth:
  12070. gl.depthFunc( 512 );
  12071. break;
  12072. case AlwaysDepth:
  12073. gl.depthFunc( 519 );
  12074. break;
  12075. case LessDepth:
  12076. gl.depthFunc( 513 );
  12077. break;
  12078. case LessEqualDepth:
  12079. gl.depthFunc( 515 );
  12080. break;
  12081. case EqualDepth:
  12082. gl.depthFunc( 514 );
  12083. break;
  12084. case GreaterEqualDepth:
  12085. gl.depthFunc( 518 );
  12086. break;
  12087. case GreaterDepth:
  12088. gl.depthFunc( 516 );
  12089. break;
  12090. case NotEqualDepth:
  12091. gl.depthFunc( 517 );
  12092. break;
  12093. default:
  12094. gl.depthFunc( 515 );
  12095. }
  12096. } else {
  12097. gl.depthFunc( 515 );
  12098. }
  12099. currentDepthFunc = depthFunc;
  12100. }
  12101. },
  12102. setLocked: function ( lock ) {
  12103. locked = lock;
  12104. },
  12105. setClear: function ( depth ) {
  12106. if ( currentDepthClear !== depth ) {
  12107. gl.clearDepth( depth );
  12108. currentDepthClear = depth;
  12109. }
  12110. },
  12111. reset: function () {
  12112. locked = false;
  12113. currentDepthMask = null;
  12114. currentDepthFunc = null;
  12115. currentDepthClear = null;
  12116. }
  12117. };
  12118. }
  12119. function StencilBuffer() {
  12120. var locked = false;
  12121. var currentStencilMask = null;
  12122. var currentStencilFunc = null;
  12123. var currentStencilRef = null;
  12124. var currentStencilFuncMask = null;
  12125. var currentStencilFail = null;
  12126. var currentStencilZFail = null;
  12127. var currentStencilZPass = null;
  12128. var currentStencilClear = null;
  12129. return {
  12130. setTest: function ( stencilTest ) {
  12131. if ( ! locked ) {
  12132. if ( stencilTest ) {
  12133. enable( 2960 );
  12134. } else {
  12135. disable( 2960 );
  12136. }
  12137. }
  12138. },
  12139. setMask: function ( stencilMask ) {
  12140. if ( currentStencilMask !== stencilMask && ! locked ) {
  12141. gl.stencilMask( stencilMask );
  12142. currentStencilMask = stencilMask;
  12143. }
  12144. },
  12145. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12146. if ( currentStencilFunc !== stencilFunc ||
  12147. currentStencilRef !== stencilRef ||
  12148. currentStencilFuncMask !== stencilMask ) {
  12149. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12150. currentStencilFunc = stencilFunc;
  12151. currentStencilRef = stencilRef;
  12152. currentStencilFuncMask = stencilMask;
  12153. }
  12154. },
  12155. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12156. if ( currentStencilFail !== stencilFail ||
  12157. currentStencilZFail !== stencilZFail ||
  12158. currentStencilZPass !== stencilZPass ) {
  12159. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12160. currentStencilFail = stencilFail;
  12161. currentStencilZFail = stencilZFail;
  12162. currentStencilZPass = stencilZPass;
  12163. }
  12164. },
  12165. setLocked: function ( lock ) {
  12166. locked = lock;
  12167. },
  12168. setClear: function ( stencil ) {
  12169. if ( currentStencilClear !== stencil ) {
  12170. gl.clearStencil( stencil );
  12171. currentStencilClear = stencil;
  12172. }
  12173. },
  12174. reset: function () {
  12175. locked = false;
  12176. currentStencilMask = null;
  12177. currentStencilFunc = null;
  12178. currentStencilRef = null;
  12179. currentStencilFuncMask = null;
  12180. currentStencilFail = null;
  12181. currentStencilZFail = null;
  12182. currentStencilZPass = null;
  12183. currentStencilClear = null;
  12184. }
  12185. };
  12186. }
  12187. //
  12188. var colorBuffer = new ColorBuffer();
  12189. var depthBuffer = new DepthBuffer();
  12190. var stencilBuffer = new StencilBuffer();
  12191. var maxVertexAttributes = gl.getParameter( 34921 );
  12192. var newAttributes = new Uint8Array( maxVertexAttributes );
  12193. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  12194. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  12195. var enabledCapabilities = {};
  12196. var currentProgram = null;
  12197. var currentBlendingEnabled = null;
  12198. var currentBlending = null;
  12199. var currentBlendEquation = null;
  12200. var currentBlendSrc = null;
  12201. var currentBlendDst = null;
  12202. var currentBlendEquationAlpha = null;
  12203. var currentBlendSrcAlpha = null;
  12204. var currentBlendDstAlpha = null;
  12205. var currentPremultipledAlpha = false;
  12206. var currentFlipSided = null;
  12207. var currentCullFace = null;
  12208. var currentLineWidth = null;
  12209. var currentPolygonOffsetFactor = null;
  12210. var currentPolygonOffsetUnits = null;
  12211. var maxTextures = gl.getParameter( 35661 );
  12212. var lineWidthAvailable = false;
  12213. var version = 0;
  12214. var glVersion = gl.getParameter( 7938 );
  12215. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12216. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12217. lineWidthAvailable = ( version >= 1.0 );
  12218. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12219. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12220. lineWidthAvailable = ( version >= 2.0 );
  12221. }
  12222. var currentTextureSlot = null;
  12223. var currentBoundTextures = {};
  12224. var currentScissor = new Vector4();
  12225. var currentViewport = new Vector4();
  12226. function createTexture( type, target, count ) {
  12227. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12228. var texture = gl.createTexture();
  12229. gl.bindTexture( type, texture );
  12230. gl.texParameteri( type, 10241, 9728 );
  12231. gl.texParameteri( type, 10240, 9728 );
  12232. for ( var i = 0; i < count; i ++ ) {
  12233. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12234. }
  12235. return texture;
  12236. }
  12237. var emptyTextures = {};
  12238. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12239. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12240. // init
  12241. colorBuffer.setClear( 0, 0, 0, 1 );
  12242. depthBuffer.setClear( 1 );
  12243. stencilBuffer.setClear( 0 );
  12244. enable( 2929 );
  12245. depthBuffer.setFunc( LessEqualDepth );
  12246. setFlipSided( false );
  12247. setCullFace( CullFaceBack );
  12248. enable( 2884 );
  12249. setBlending( NoBlending );
  12250. //
  12251. function initAttributes() {
  12252. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  12253. newAttributes[ i ] = 0;
  12254. }
  12255. }
  12256. function enableAttribute( attribute ) {
  12257. enableAttributeAndDivisor( attribute, 0 );
  12258. }
  12259. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  12260. newAttributes[ attribute ] = 1;
  12261. if ( enabledAttributes[ attribute ] === 0 ) {
  12262. gl.enableVertexAttribArray( attribute );
  12263. enabledAttributes[ attribute ] = 1;
  12264. }
  12265. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  12266. var extension = isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  12267. extension[ isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  12268. attributeDivisors[ attribute ] = meshPerAttribute;
  12269. }
  12270. }
  12271. function disableUnusedAttributes() {
  12272. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  12273. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  12274. gl.disableVertexAttribArray( i );
  12275. enabledAttributes[ i ] = 0;
  12276. }
  12277. }
  12278. }
  12279. function enable( id ) {
  12280. if ( enabledCapabilities[ id ] !== true ) {
  12281. gl.enable( id );
  12282. enabledCapabilities[ id ] = true;
  12283. }
  12284. }
  12285. function disable( id ) {
  12286. if ( enabledCapabilities[ id ] !== false ) {
  12287. gl.disable( id );
  12288. enabledCapabilities[ id ] = false;
  12289. }
  12290. }
  12291. function useProgram( program ) {
  12292. if ( currentProgram !== program ) {
  12293. gl.useProgram( program );
  12294. currentProgram = program;
  12295. return true;
  12296. }
  12297. return false;
  12298. }
  12299. var equationToGL = {
  12300. [ AddEquation ]: 32774,
  12301. [ SubtractEquation ]: 32778,
  12302. [ ReverseSubtractEquation ]: 32779
  12303. };
  12304. if ( isWebGL2 ) {
  12305. equationToGL[ MinEquation ] = 32775;
  12306. equationToGL[ MaxEquation ] = 32776;
  12307. } else {
  12308. var extension = extensions.get( 'EXT_blend_minmax' );
  12309. if ( extension !== null ) {
  12310. equationToGL[ MinEquation ] = extension.MIN_EXT;
  12311. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  12312. }
  12313. }
  12314. var factorToGL = {
  12315. [ ZeroFactor ]: 0,
  12316. [ OneFactor ]: 1,
  12317. [ SrcColorFactor ]: 768,
  12318. [ SrcAlphaFactor ]: 770,
  12319. [ SrcAlphaSaturateFactor ]: 776,
  12320. [ DstColorFactor ]: 774,
  12321. [ DstAlphaFactor ]: 772,
  12322. [ OneMinusSrcColorFactor ]: 769,
  12323. [ OneMinusSrcAlphaFactor ]: 771,
  12324. [ OneMinusDstColorFactor ]: 775,
  12325. [ OneMinusDstAlphaFactor ]: 773
  12326. };
  12327. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12328. if ( blending === NoBlending ) {
  12329. if ( currentBlendingEnabled ) {
  12330. disable( 3042 );
  12331. currentBlendingEnabled = false;
  12332. }
  12333. return;
  12334. }
  12335. if ( ! currentBlendingEnabled ) {
  12336. enable( 3042 );
  12337. currentBlendingEnabled = true;
  12338. }
  12339. if ( blending !== CustomBlending ) {
  12340. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12341. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12342. gl.blendEquation( 32774 );
  12343. currentBlendEquation = AddEquation;
  12344. currentBlendEquationAlpha = AddEquation;
  12345. }
  12346. if ( premultipliedAlpha ) {
  12347. switch ( blending ) {
  12348. case NormalBlending:
  12349. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12350. break;
  12351. case AdditiveBlending:
  12352. gl.blendFunc( 1, 1 );
  12353. break;
  12354. case SubtractiveBlending:
  12355. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12356. break;
  12357. case MultiplyBlending:
  12358. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12359. break;
  12360. default:
  12361. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12362. break;
  12363. }
  12364. } else {
  12365. switch ( blending ) {
  12366. case NormalBlending:
  12367. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12368. break;
  12369. case AdditiveBlending:
  12370. gl.blendFunc( 770, 1 );
  12371. break;
  12372. case SubtractiveBlending:
  12373. gl.blendFunc( 0, 769 );
  12374. break;
  12375. case MultiplyBlending:
  12376. gl.blendFunc( 0, 768 );
  12377. break;
  12378. default:
  12379. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12380. break;
  12381. }
  12382. }
  12383. currentBlendSrc = null;
  12384. currentBlendDst = null;
  12385. currentBlendSrcAlpha = null;
  12386. currentBlendDstAlpha = null;
  12387. currentBlending = blending;
  12388. currentPremultipledAlpha = premultipliedAlpha;
  12389. }
  12390. return;
  12391. }
  12392. // custom blending
  12393. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12394. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12395. blendDstAlpha = blendDstAlpha || blendDst;
  12396. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12397. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  12398. currentBlendEquation = blendEquation;
  12399. currentBlendEquationAlpha = blendEquationAlpha;
  12400. }
  12401. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12402. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  12403. currentBlendSrc = blendSrc;
  12404. currentBlendDst = blendDst;
  12405. currentBlendSrcAlpha = blendSrcAlpha;
  12406. currentBlendDstAlpha = blendDstAlpha;
  12407. }
  12408. currentBlending = blending;
  12409. currentPremultipledAlpha = null;
  12410. }
  12411. function setMaterial( material, frontFaceCW ) {
  12412. material.side === DoubleSide
  12413. ? disable( 2884 )
  12414. : enable( 2884 );
  12415. var flipSided = ( material.side === BackSide );
  12416. if ( frontFaceCW ) flipSided = ! flipSided;
  12417. setFlipSided( flipSided );
  12418. ( material.blending === NormalBlending && material.transparent === false )
  12419. ? setBlending( NoBlending )
  12420. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12421. depthBuffer.setFunc( material.depthFunc );
  12422. depthBuffer.setTest( material.depthTest );
  12423. depthBuffer.setMask( material.depthWrite );
  12424. colorBuffer.setMask( material.colorWrite );
  12425. var stencilWrite = material.stencilWrite;
  12426. stencilBuffer.setTest( stencilWrite );
  12427. if ( stencilWrite ) {
  12428. stencilBuffer.setMask( material.stencilWriteMask );
  12429. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  12430. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12431. }
  12432. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12433. }
  12434. //
  12435. function setFlipSided( flipSided ) {
  12436. if ( currentFlipSided !== flipSided ) {
  12437. if ( flipSided ) {
  12438. gl.frontFace( 2304 );
  12439. } else {
  12440. gl.frontFace( 2305 );
  12441. }
  12442. currentFlipSided = flipSided;
  12443. }
  12444. }
  12445. function setCullFace( cullFace ) {
  12446. if ( cullFace !== CullFaceNone ) {
  12447. enable( 2884 );
  12448. if ( cullFace !== currentCullFace ) {
  12449. if ( cullFace === CullFaceBack ) {
  12450. gl.cullFace( 1029 );
  12451. } else if ( cullFace === CullFaceFront ) {
  12452. gl.cullFace( 1028 );
  12453. } else {
  12454. gl.cullFace( 1032 );
  12455. }
  12456. }
  12457. } else {
  12458. disable( 2884 );
  12459. }
  12460. currentCullFace = cullFace;
  12461. }
  12462. function setLineWidth( width ) {
  12463. if ( width !== currentLineWidth ) {
  12464. if ( lineWidthAvailable ) gl.lineWidth( width );
  12465. currentLineWidth = width;
  12466. }
  12467. }
  12468. function setPolygonOffset( polygonOffset, factor, units ) {
  12469. if ( polygonOffset ) {
  12470. enable( 32823 );
  12471. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12472. gl.polygonOffset( factor, units );
  12473. currentPolygonOffsetFactor = factor;
  12474. currentPolygonOffsetUnits = units;
  12475. }
  12476. } else {
  12477. disable( 32823 );
  12478. }
  12479. }
  12480. function setScissorTest( scissorTest ) {
  12481. if ( scissorTest ) {
  12482. enable( 3089 );
  12483. } else {
  12484. disable( 3089 );
  12485. }
  12486. }
  12487. // texture
  12488. function activeTexture( webglSlot ) {
  12489. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12490. if ( currentTextureSlot !== webglSlot ) {
  12491. gl.activeTexture( webglSlot );
  12492. currentTextureSlot = webglSlot;
  12493. }
  12494. }
  12495. function bindTexture( webglType, webglTexture ) {
  12496. if ( currentTextureSlot === null ) {
  12497. activeTexture();
  12498. }
  12499. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12500. if ( boundTexture === undefined ) {
  12501. boundTexture = { type: undefined, texture: undefined };
  12502. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12503. }
  12504. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12505. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12506. boundTexture.type = webglType;
  12507. boundTexture.texture = webglTexture;
  12508. }
  12509. }
  12510. function unbindTexture() {
  12511. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12512. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  12513. gl.bindTexture( boundTexture.type, null );
  12514. boundTexture.type = undefined;
  12515. boundTexture.texture = undefined;
  12516. }
  12517. }
  12518. function compressedTexImage2D() {
  12519. try {
  12520. gl.compressedTexImage2D.apply( gl, arguments );
  12521. } catch ( error ) {
  12522. console.error( 'THREE.WebGLState:', error );
  12523. }
  12524. }
  12525. function texImage2D() {
  12526. try {
  12527. gl.texImage2D.apply( gl, arguments );
  12528. } catch ( error ) {
  12529. console.error( 'THREE.WebGLState:', error );
  12530. }
  12531. }
  12532. function texImage3D() {
  12533. try {
  12534. gl.texImage3D.apply( gl, arguments );
  12535. } catch ( error ) {
  12536. console.error( 'THREE.WebGLState:', error );
  12537. }
  12538. }
  12539. //
  12540. function scissor( scissor ) {
  12541. if ( currentScissor.equals( scissor ) === false ) {
  12542. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12543. currentScissor.copy( scissor );
  12544. }
  12545. }
  12546. function viewport( viewport ) {
  12547. if ( currentViewport.equals( viewport ) === false ) {
  12548. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12549. currentViewport.copy( viewport );
  12550. }
  12551. }
  12552. //
  12553. function reset() {
  12554. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12555. if ( enabledAttributes[ i ] === 1 ) {
  12556. gl.disableVertexAttribArray( i );
  12557. enabledAttributes[ i ] = 0;
  12558. }
  12559. }
  12560. enabledCapabilities = {};
  12561. currentTextureSlot = null;
  12562. currentBoundTextures = {};
  12563. currentProgram = null;
  12564. currentBlending = null;
  12565. currentFlipSided = null;
  12566. currentCullFace = null;
  12567. colorBuffer.reset();
  12568. depthBuffer.reset();
  12569. stencilBuffer.reset();
  12570. }
  12571. return {
  12572. buffers: {
  12573. color: colorBuffer,
  12574. depth: depthBuffer,
  12575. stencil: stencilBuffer
  12576. },
  12577. initAttributes: initAttributes,
  12578. enableAttribute: enableAttribute,
  12579. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12580. disableUnusedAttributes: disableUnusedAttributes,
  12581. enable: enable,
  12582. disable: disable,
  12583. useProgram: useProgram,
  12584. setBlending: setBlending,
  12585. setMaterial: setMaterial,
  12586. setFlipSided: setFlipSided,
  12587. setCullFace: setCullFace,
  12588. setLineWidth: setLineWidth,
  12589. setPolygonOffset: setPolygonOffset,
  12590. setScissorTest: setScissorTest,
  12591. activeTexture: activeTexture,
  12592. bindTexture: bindTexture,
  12593. unbindTexture: unbindTexture,
  12594. compressedTexImage2D: compressedTexImage2D,
  12595. texImage2D: texImage2D,
  12596. texImage3D: texImage3D,
  12597. scissor: scissor,
  12598. viewport: viewport,
  12599. reset: reset
  12600. };
  12601. }
  12602. /**
  12603. * @author mrdoob / http://mrdoob.com/
  12604. */
  12605. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12606. var isWebGL2 = capabilities.isWebGL2;
  12607. var maxTextures = capabilities.maxTextures;
  12608. var maxCubemapSize = capabilities.maxCubemapSize;
  12609. var maxTextureSize = capabilities.maxTextureSize;
  12610. var maxSamples = capabilities.maxSamples;
  12611. var _videoTextures = new WeakMap();
  12612. var _canvas;
  12613. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12614. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12615. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  12616. && ( new OffscreenCanvas( 1, 1 ).getContext( "2d" ) ) !== null;
  12617. function createCanvas( width, height ) {
  12618. // Use OffscreenCanvas when available. Specially needed in web workers
  12619. return useOffscreenCanvas ?
  12620. new OffscreenCanvas( width, height ) :
  12621. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12622. }
  12623. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12624. var scale = 1;
  12625. // handle case if texture exceeds max size
  12626. if ( image.width > maxSize || image.height > maxSize ) {
  12627. scale = maxSize / Math.max( image.width, image.height );
  12628. }
  12629. // only perform resize if necessary
  12630. if ( scale < 1 || needsPowerOfTwo === true ) {
  12631. // only perform resize for certain image types
  12632. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12633. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12634. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12635. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12636. var width = floor( scale * image.width );
  12637. var height = floor( scale * image.height );
  12638. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12639. // cube textures can't reuse the same canvas
  12640. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12641. canvas.width = width;
  12642. canvas.height = height;
  12643. var context = canvas.getContext( '2d' );
  12644. context.drawImage( image, 0, 0, width, height );
  12645. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12646. return canvas;
  12647. } else {
  12648. if ( 'data' in image ) {
  12649. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12650. }
  12651. return image;
  12652. }
  12653. }
  12654. return image;
  12655. }
  12656. function isPowerOfTwo( image ) {
  12657. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12658. }
  12659. function textureNeedsPowerOfTwo( texture ) {
  12660. if ( isWebGL2 ) return false;
  12661. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12662. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12663. }
  12664. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12665. return texture.generateMipmaps && supportsMips &&
  12666. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12667. }
  12668. function generateMipmap( target, texture, width, height ) {
  12669. _gl.generateMipmap( target );
  12670. var textureProperties = properties.get( texture );
  12671. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12672. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12673. }
  12674. function getInternalFormat( glFormat, glType ) {
  12675. if ( isWebGL2 === false ) return glFormat;
  12676. var internalFormat = glFormat;
  12677. if ( glFormat === 6403 ) {
  12678. if ( glType === 5126 ) internalFormat = 33326;
  12679. if ( glType === 5131 ) internalFormat = 33325;
  12680. if ( glType === 5121 ) internalFormat = 33321;
  12681. }
  12682. if ( glFormat === 6407 ) {
  12683. if ( glType === 5126 ) internalFormat = 34837;
  12684. if ( glType === 5131 ) internalFormat = 34843;
  12685. if ( glType === 5121 ) internalFormat = 32849;
  12686. }
  12687. if ( glFormat === 6408 ) {
  12688. if ( glType === 5126 ) internalFormat = 34836;
  12689. if ( glType === 5131 ) internalFormat = 34842;
  12690. if ( glType === 5121 ) internalFormat = 32856;
  12691. }
  12692. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12693. internalFormat === 34842 || internalFormat === 34836 ) {
  12694. extensions.get( 'EXT_color_buffer_float' );
  12695. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12696. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12697. }
  12698. return internalFormat;
  12699. }
  12700. // Fallback filters for non-power-of-2 textures
  12701. function filterFallback( f ) {
  12702. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12703. return 9728;
  12704. }
  12705. return 9729;
  12706. }
  12707. //
  12708. function onTextureDispose( event ) {
  12709. var texture = event.target;
  12710. texture.removeEventListener( 'dispose', onTextureDispose );
  12711. deallocateTexture( texture );
  12712. if ( texture.isVideoTexture ) {
  12713. _videoTextures.delete( texture );
  12714. }
  12715. info.memory.textures --;
  12716. }
  12717. function onRenderTargetDispose( event ) {
  12718. var renderTarget = event.target;
  12719. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12720. deallocateRenderTarget( renderTarget );
  12721. info.memory.textures --;
  12722. }
  12723. //
  12724. function deallocateTexture( texture ) {
  12725. var textureProperties = properties.get( texture );
  12726. if ( textureProperties.__webglInit === undefined ) return;
  12727. _gl.deleteTexture( textureProperties.__webglTexture );
  12728. properties.remove( texture );
  12729. }
  12730. function deallocateRenderTarget( renderTarget ) {
  12731. var renderTargetProperties = properties.get( renderTarget );
  12732. var textureProperties = properties.get( renderTarget.texture );
  12733. if ( ! renderTarget ) return;
  12734. if ( textureProperties.__webglTexture !== undefined ) {
  12735. _gl.deleteTexture( textureProperties.__webglTexture );
  12736. }
  12737. if ( renderTarget.depthTexture ) {
  12738. renderTarget.depthTexture.dispose();
  12739. }
  12740. if ( renderTarget.isWebGLRenderTargetCube ) {
  12741. for ( var i = 0; i < 6; i ++ ) {
  12742. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12743. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12744. }
  12745. } else {
  12746. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12747. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12748. }
  12749. if ( renderTarget.isWebGLMultiviewRenderTarget ) {
  12750. _gl.deleteTexture( renderTargetProperties.__webglColorTexture );
  12751. _gl.deleteTexture( renderTargetProperties.__webglDepthStencilTexture );
  12752. info.memory.textures -= 2;
  12753. for ( var i = 0, il = renderTargetProperties.__webglViewFramebuffers.length; i < il; i ++ ) {
  12754. _gl.deleteFramebuffer( renderTargetProperties.__webglViewFramebuffers[ i ] );
  12755. }
  12756. }
  12757. properties.remove( renderTarget.texture );
  12758. properties.remove( renderTarget );
  12759. }
  12760. //
  12761. var textureUnits = 0;
  12762. function resetTextureUnits() {
  12763. textureUnits = 0;
  12764. }
  12765. function allocateTextureUnit() {
  12766. var textureUnit = textureUnits;
  12767. if ( textureUnit >= maxTextures ) {
  12768. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  12769. }
  12770. textureUnits += 1;
  12771. return textureUnit;
  12772. }
  12773. //
  12774. function setTexture2D( texture, slot ) {
  12775. var textureProperties = properties.get( texture );
  12776. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12777. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12778. var image = texture.image;
  12779. if ( image === undefined ) {
  12780. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12781. } else if ( image.complete === false ) {
  12782. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12783. } else {
  12784. uploadTexture( textureProperties, texture, slot );
  12785. return;
  12786. }
  12787. }
  12788. state.activeTexture( 33984 + slot );
  12789. state.bindTexture( 3553, textureProperties.__webglTexture );
  12790. }
  12791. function setTexture2DArray( texture, slot ) {
  12792. var textureProperties = properties.get( texture );
  12793. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12794. uploadTexture( textureProperties, texture, slot );
  12795. return;
  12796. }
  12797. state.activeTexture( 33984 + slot );
  12798. state.bindTexture( 35866, textureProperties.__webglTexture );
  12799. }
  12800. function setTexture3D( texture, slot ) {
  12801. var textureProperties = properties.get( texture );
  12802. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12803. uploadTexture( textureProperties, texture, slot );
  12804. return;
  12805. }
  12806. state.activeTexture( 33984 + slot );
  12807. state.bindTexture( 32879, textureProperties.__webglTexture );
  12808. }
  12809. function setTextureCube( texture, slot ) {
  12810. if ( texture.image.length !== 6 ) return;
  12811. var textureProperties = properties.get( texture );
  12812. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12813. initTexture( textureProperties, texture );
  12814. state.activeTexture( 33984 + slot );
  12815. state.bindTexture( 34067, textureProperties.__webglTexture );
  12816. _gl.pixelStorei( 37440, texture.flipY );
  12817. var isCompressed = ( texture && texture.isCompressedTexture );
  12818. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12819. var cubeImage = [];
  12820. for ( var i = 0; i < 6; i ++ ) {
  12821. if ( ! isCompressed && ! isDataTexture ) {
  12822. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  12823. } else {
  12824. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12825. }
  12826. }
  12827. var image = cubeImage[ 0 ],
  12828. supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12829. glFormat = utils.convert( texture.format ),
  12830. glType = utils.convert( texture.type ),
  12831. glInternalFormat = getInternalFormat( glFormat, glType );
  12832. setTextureParameters( 34067, texture, supportsMips );
  12833. var mipmaps;
  12834. if ( isCompressed ) {
  12835. for ( var i = 0; i < 6; i ++ ) {
  12836. mipmaps = cubeImage[ i ].mipmaps;
  12837. for ( var j = 0; j < mipmaps.length; j ++ ) {
  12838. var mipmap = mipmaps[ j ];
  12839. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12840. if ( glFormat !== null ) {
  12841. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12842. } else {
  12843. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12844. }
  12845. } else {
  12846. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12847. }
  12848. }
  12849. }
  12850. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12851. } else {
  12852. mipmaps = texture.mipmaps;
  12853. for ( var i = 0; i < 6; i ++ ) {
  12854. if ( isDataTexture ) {
  12855. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12856. for ( var j = 0; j < mipmaps.length; j ++ ) {
  12857. var mipmap = mipmaps[ j ];
  12858. var mipmapImage = mipmap.image[ i ].image;
  12859. state.texImage2D( 34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  12860. }
  12861. } else {
  12862. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12863. for ( var j = 0; j < mipmaps.length; j ++ ) {
  12864. var mipmap = mipmaps[ j ];
  12865. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  12866. }
  12867. }
  12868. }
  12869. textureProperties.__maxMipLevel = mipmaps.length;
  12870. }
  12871. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12872. // We assume images for cube map have the same size.
  12873. generateMipmap( 34067, texture, image.width, image.height );
  12874. }
  12875. textureProperties.__version = texture.version;
  12876. if ( texture.onUpdate ) texture.onUpdate( texture );
  12877. } else {
  12878. state.activeTexture( 33984 + slot );
  12879. state.bindTexture( 34067, textureProperties.__webglTexture );
  12880. }
  12881. }
  12882. function setTextureCubeDynamic( texture, slot ) {
  12883. state.activeTexture( 33984 + slot );
  12884. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12885. }
  12886. var wrappingToGL = {
  12887. [ RepeatWrapping ]: 10497,
  12888. [ ClampToEdgeWrapping ]: 33071,
  12889. [ MirroredRepeatWrapping ]: 33648
  12890. };
  12891. var filterToGL = {
  12892. [ NearestFilter ]: 9728,
  12893. [ NearestMipmapNearestFilter ]: 9984,
  12894. [ NearestMipmapLinearFilter ]: 9986,
  12895. [ LinearFilter ]: 9729,
  12896. [ LinearMipmapNearestFilter ]: 9985,
  12897. [ LinearMipmapLinearFilter ]: 9987
  12898. };
  12899. function setTextureParameters( textureType, texture, supportsMips ) {
  12900. if ( supportsMips ) {
  12901. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  12902. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  12903. if ( textureType === 32879 || textureType === 35866 ) {
  12904. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  12905. }
  12906. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  12907. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  12908. } else {
  12909. _gl.texParameteri( textureType, 10242, 33071 );
  12910. _gl.texParameteri( textureType, 10243, 33071 );
  12911. if ( textureType === 32879 || textureType === 35866 ) {
  12912. _gl.texParameteri( textureType, 32882, 33071 );
  12913. }
  12914. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12915. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12916. }
  12917. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12918. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12919. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12920. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12921. }
  12922. }
  12923. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12924. if ( extension ) {
  12925. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12926. if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12927. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12928. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12929. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12930. }
  12931. }
  12932. }
  12933. function initTexture( textureProperties, texture ) {
  12934. if ( textureProperties.__webglInit === undefined ) {
  12935. textureProperties.__webglInit = true;
  12936. texture.addEventListener( 'dispose', onTextureDispose );
  12937. textureProperties.__webglTexture = _gl.createTexture();
  12938. info.memory.textures ++;
  12939. }
  12940. }
  12941. function uploadTexture( textureProperties, texture, slot ) {
  12942. var textureType = 3553;
  12943. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12944. if ( texture.isDataTexture3D ) textureType = 32879;
  12945. initTexture( textureProperties, texture );
  12946. state.activeTexture( 33984 + slot );
  12947. state.bindTexture( textureType, textureProperties.__webglTexture );
  12948. _gl.pixelStorei( 37440, texture.flipY );
  12949. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12950. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12951. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12952. var image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  12953. var supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12954. glFormat = utils.convert( texture.format ),
  12955. glType = utils.convert( texture.type ),
  12956. glInternalFormat = getInternalFormat( glFormat, glType );
  12957. setTextureParameters( textureType, texture, supportsMips );
  12958. var mipmap, mipmaps = texture.mipmaps;
  12959. if ( texture.isDepthTexture ) {
  12960. // populate depth texture with dummy data
  12961. glInternalFormat = 6402;
  12962. if ( texture.type === FloatType ) {
  12963. if ( isWebGL2 === false ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12964. glInternalFormat = 36012;
  12965. } else if ( isWebGL2 ) {
  12966. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12967. glInternalFormat = 33189;
  12968. }
  12969. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12970. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12971. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12972. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12973. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12974. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12975. texture.type = UnsignedShortType;
  12976. glType = utils.convert( texture.type );
  12977. }
  12978. }
  12979. // Depth stencil textures need the DEPTH_STENCIL internal format
  12980. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12981. if ( texture.format === DepthStencilFormat ) {
  12982. glInternalFormat = 34041;
  12983. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12984. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12985. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12986. if ( texture.type !== UnsignedInt248Type ) {
  12987. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12988. texture.type = UnsignedInt248Type;
  12989. glType = utils.convert( texture.type );
  12990. }
  12991. }
  12992. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12993. } else if ( texture.isDataTexture ) {
  12994. // use manually created mipmaps if available
  12995. // if there are no manual mipmaps
  12996. // set 0 level mipmap and then use GL to generate other mipmap levels
  12997. if ( mipmaps.length > 0 && supportsMips ) {
  12998. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12999. mipmap = mipmaps[ i ];
  13000. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13001. }
  13002. texture.generateMipmaps = false;
  13003. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13004. } else {
  13005. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13006. textureProperties.__maxMipLevel = 0;
  13007. }
  13008. } else if ( texture.isCompressedTexture ) {
  13009. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13010. mipmap = mipmaps[ i ];
  13011. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13012. if ( glFormat !== null ) {
  13013. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13014. } else {
  13015. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  13016. }
  13017. } else {
  13018. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13019. }
  13020. }
  13021. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13022. } else if ( texture.isDataTexture2DArray ) {
  13023. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13024. textureProperties.__maxMipLevel = 0;
  13025. } else if ( texture.isDataTexture3D ) {
  13026. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13027. textureProperties.__maxMipLevel = 0;
  13028. } else {
  13029. // regular Texture (image, video, canvas)
  13030. // use manually created mipmaps if available
  13031. // if there are no manual mipmaps
  13032. // set 0 level mipmap and then use GL to generate other mipmap levels
  13033. if ( mipmaps.length > 0 && supportsMips ) {
  13034. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13035. mipmap = mipmaps[ i ];
  13036. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  13037. }
  13038. texture.generateMipmaps = false;
  13039. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13040. } else {
  13041. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  13042. textureProperties.__maxMipLevel = 0;
  13043. }
  13044. }
  13045. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13046. generateMipmap( 3553, texture, image.width, image.height );
  13047. }
  13048. textureProperties.__version = texture.version;
  13049. if ( texture.onUpdate ) texture.onUpdate( texture );
  13050. }
  13051. // Render targets
  13052. // Setup storage for target texture and bind it to correct framebuffer
  13053. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  13054. var glFormat = utils.convert( renderTarget.texture.format );
  13055. var glType = utils.convert( renderTarget.texture.type );
  13056. var glInternalFormat = getInternalFormat( glFormat, glType );
  13057. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13058. _gl.bindFramebuffer( 36160, framebuffer );
  13059. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  13060. _gl.bindFramebuffer( 36160, null );
  13061. }
  13062. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13063. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  13064. _gl.bindRenderbuffer( 36161, renderbuffer );
  13065. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13066. if ( isMultisample ) {
  13067. var samples = getRenderTargetSamples( renderTarget );
  13068. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  13069. } else {
  13070. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  13071. }
  13072. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  13073. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13074. if ( isMultisample ) {
  13075. var samples = getRenderTargetSamples( renderTarget );
  13076. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  13077. } else {
  13078. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  13079. }
  13080. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  13081. } else {
  13082. var glFormat = utils.convert( renderTarget.texture.format );
  13083. var glType = utils.convert( renderTarget.texture.type );
  13084. var glInternalFormat = getInternalFormat( glFormat, glType );
  13085. if ( isMultisample ) {
  13086. var samples = getRenderTargetSamples( renderTarget );
  13087. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13088. } else {
  13089. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13090. }
  13091. }
  13092. _gl.bindRenderbuffer( 36161, null );
  13093. }
  13094. // Setup resources for a Depth Texture for a FBO (needs an extension)
  13095. function setupDepthTexture( framebuffer, renderTarget ) {
  13096. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  13097. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  13098. _gl.bindFramebuffer( 36160, framebuffer );
  13099. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  13100. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  13101. }
  13102. // upload an empty depth texture with framebuffer size
  13103. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  13104. renderTarget.depthTexture.image.width !== renderTarget.width ||
  13105. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13106. renderTarget.depthTexture.image.width = renderTarget.width;
  13107. renderTarget.depthTexture.image.height = renderTarget.height;
  13108. renderTarget.depthTexture.needsUpdate = true;
  13109. }
  13110. setTexture2D( renderTarget.depthTexture, 0 );
  13111. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13112. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13113. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13114. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13115. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13116. } else {
  13117. throw new Error( 'Unknown depthTexture format' );
  13118. }
  13119. }
  13120. // Setup GL resources for a non-texture depth buffer
  13121. function setupDepthRenderbuffer( renderTarget ) {
  13122. var renderTargetProperties = properties.get( renderTarget );
  13123. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13124. if ( renderTarget.depthTexture ) {
  13125. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13126. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13127. } else {
  13128. if ( isCube ) {
  13129. renderTargetProperties.__webglDepthbuffer = [];
  13130. for ( var i = 0; i < 6; i ++ ) {
  13131. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13132. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13133. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  13134. }
  13135. } else {
  13136. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13137. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13138. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  13139. }
  13140. }
  13141. _gl.bindFramebuffer( 36160, null );
  13142. }
  13143. // Set up GL resources for the render target
  13144. function setupRenderTarget( renderTarget ) {
  13145. var renderTargetProperties = properties.get( renderTarget );
  13146. var textureProperties = properties.get( renderTarget.texture );
  13147. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13148. textureProperties.__webglTexture = _gl.createTexture();
  13149. info.memory.textures ++;
  13150. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13151. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13152. var isMultiview = ( renderTarget.isWebGLMultiviewRenderTarget === true );
  13153. var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13154. // Setup framebuffer
  13155. if ( isCube ) {
  13156. renderTargetProperties.__webglFramebuffer = [];
  13157. for ( var i = 0; i < 6; i ++ ) {
  13158. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13159. }
  13160. } else {
  13161. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13162. if ( isMultisample ) {
  13163. if ( isWebGL2 ) {
  13164. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13165. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13166. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13167. var glFormat = utils.convert( renderTarget.texture.format );
  13168. var glType = utils.convert( renderTarget.texture.type );
  13169. var glInternalFormat = getInternalFormat( glFormat, glType );
  13170. var samples = getRenderTargetSamples( renderTarget );
  13171. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13172. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13173. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13174. _gl.bindRenderbuffer( 36161, null );
  13175. if ( renderTarget.depthBuffer ) {
  13176. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13177. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13178. }
  13179. _gl.bindFramebuffer( 36160, null );
  13180. } else {
  13181. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13182. }
  13183. } else if ( isMultiview ) {
  13184. var width = renderTarget.width;
  13185. var height = renderTarget.height;
  13186. var numViews = renderTarget.numViews;
  13187. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13188. var ext = extensions.get( 'OVR_multiview2' );
  13189. info.memory.textures += 2;
  13190. var colorTexture = _gl.createTexture();
  13191. _gl.bindTexture( 35866, colorTexture );
  13192. _gl.texParameteri( 35866, 10240, 9728 );
  13193. _gl.texParameteri( 35866, 10241, 9728 );
  13194. _gl.texImage3D( 35866, 0, 32856, width, height, numViews, 0, 6408, 5121, null );
  13195. ext.framebufferTextureMultiviewOVR( 36160, 36064, colorTexture, 0, 0, numViews );
  13196. var depthStencilTexture = _gl.createTexture();
  13197. _gl.bindTexture( 35866, depthStencilTexture );
  13198. _gl.texParameteri( 35866, 10240, 9728 );
  13199. _gl.texParameteri( 35866, 10241, 9728 );
  13200. _gl.texImage3D( 35866, 0, 35056, width, height, numViews, 0, 34041, 34042, null );
  13201. ext.framebufferTextureMultiviewOVR( 36160, 33306, depthStencilTexture, 0, 0, numViews );
  13202. var viewFramebuffers = new Array( numViews );
  13203. for ( var i = 0; i < numViews; ++ i ) {
  13204. viewFramebuffers[ i ] = _gl.createFramebuffer();
  13205. _gl.bindFramebuffer( 36160, viewFramebuffers[ i ] );
  13206. _gl.framebufferTextureLayer( 36160, 36064, colorTexture, 0, i );
  13207. }
  13208. renderTargetProperties.__webglColorTexture = colorTexture;
  13209. renderTargetProperties.__webglDepthStencilTexture = depthStencilTexture;
  13210. renderTargetProperties.__webglViewFramebuffers = viewFramebuffers;
  13211. _gl.bindFramebuffer( 36160, null );
  13212. _gl.bindTexture( 35866, null );
  13213. }
  13214. }
  13215. // Setup color buffer
  13216. if ( isCube ) {
  13217. state.bindTexture( 34067, textureProperties.__webglTexture );
  13218. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13219. for ( var i = 0; i < 6; i ++ ) {
  13220. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13221. }
  13222. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13223. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13224. }
  13225. state.bindTexture( 34067, null );
  13226. } else if ( ! isMultiview ) {
  13227. state.bindTexture( 3553, textureProperties.__webglTexture );
  13228. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13229. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13230. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13231. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13232. }
  13233. state.bindTexture( 3553, null );
  13234. }
  13235. // Setup depth and stencil buffers
  13236. if ( renderTarget.depthBuffer ) {
  13237. setupDepthRenderbuffer( renderTarget );
  13238. }
  13239. }
  13240. function updateRenderTargetMipmap( renderTarget ) {
  13241. var texture = renderTarget.texture;
  13242. var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13243. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13244. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  13245. var webglTexture = properties.get( texture ).__webglTexture;
  13246. state.bindTexture( target, webglTexture );
  13247. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13248. state.bindTexture( target, null );
  13249. }
  13250. }
  13251. function updateMultisampleRenderTarget( renderTarget ) {
  13252. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13253. if ( isWebGL2 ) {
  13254. var renderTargetProperties = properties.get( renderTarget );
  13255. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13256. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13257. var width = renderTarget.width;
  13258. var height = renderTarget.height;
  13259. var mask = 16384;
  13260. if ( renderTarget.depthBuffer ) mask |= 256;
  13261. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13262. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13263. } else {
  13264. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13265. }
  13266. }
  13267. }
  13268. function getRenderTargetSamples( renderTarget ) {
  13269. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13270. Math.min( maxSamples, renderTarget.samples ) : 0;
  13271. }
  13272. function updateVideoTexture( texture ) {
  13273. var frame = info.render.frame;
  13274. // Check the last frame we updated the VideoTexture
  13275. if ( _videoTextures.get( texture ) !== frame ) {
  13276. _videoTextures.set( texture, frame );
  13277. texture.update();
  13278. }
  13279. }
  13280. // backwards compatibility
  13281. var warnedTexture2D = false;
  13282. var warnedTextureCube = false;
  13283. function safeSetTexture2D( texture, slot ) {
  13284. if ( texture && texture.isWebGLRenderTarget ) {
  13285. if ( warnedTexture2D === false ) {
  13286. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13287. warnedTexture2D = true;
  13288. }
  13289. texture = texture.texture;
  13290. }
  13291. setTexture2D( texture, slot );
  13292. }
  13293. function safeSetTextureCube( texture, slot ) {
  13294. if ( texture && texture.isWebGLRenderTargetCube ) {
  13295. if ( warnedTextureCube === false ) {
  13296. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13297. warnedTextureCube = true;
  13298. }
  13299. texture = texture.texture;
  13300. }
  13301. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13302. // TODO: unify these code paths
  13303. if ( ( texture && texture.isCubeTexture ) ||
  13304. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13305. // CompressedTexture can have Array in image :/
  13306. // this function alone should take care of cube textures
  13307. setTextureCube( texture, slot );
  13308. } else {
  13309. // assumed: texture property of THREE.WebGLRenderTargetCube
  13310. setTextureCubeDynamic( texture, slot );
  13311. }
  13312. }
  13313. //
  13314. this.allocateTextureUnit = allocateTextureUnit;
  13315. this.resetTextureUnits = resetTextureUnits;
  13316. this.setTexture2D = setTexture2D;
  13317. this.setTexture2DArray = setTexture2DArray;
  13318. this.setTexture3D = setTexture3D;
  13319. this.setTextureCube = setTextureCube;
  13320. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13321. this.setupRenderTarget = setupRenderTarget;
  13322. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13323. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13324. this.safeSetTexture2D = safeSetTexture2D;
  13325. this.safeSetTextureCube = safeSetTextureCube;
  13326. }
  13327. /**
  13328. * @author thespite / http://www.twitter.com/thespite
  13329. */
  13330. function WebGLUtils( gl, extensions, capabilities ) {
  13331. var isWebGL2 = capabilities.isWebGL2;
  13332. function convert( p ) {
  13333. var extension;
  13334. if ( p === UnsignedByteType ) return 5121;
  13335. if ( p === UnsignedShort4444Type ) return 32819;
  13336. if ( p === UnsignedShort5551Type ) return 32820;
  13337. if ( p === UnsignedShort565Type ) return 33635;
  13338. if ( p === ByteType ) return 5120;
  13339. if ( p === ShortType ) return 5122;
  13340. if ( p === UnsignedShortType ) return 5123;
  13341. if ( p === IntType ) return 5124;
  13342. if ( p === UnsignedIntType ) return 5125;
  13343. if ( p === FloatType ) return 5126;
  13344. if ( p === HalfFloatType ) {
  13345. if ( isWebGL2 ) return 5131;
  13346. extension = extensions.get( 'OES_texture_half_float' );
  13347. if ( extension !== null ) {
  13348. return extension.HALF_FLOAT_OES;
  13349. } else {
  13350. return null;
  13351. }
  13352. }
  13353. if ( p === AlphaFormat ) return 6406;
  13354. if ( p === RGBFormat ) return 6407;
  13355. if ( p === RGBAFormat ) return 6408;
  13356. if ( p === LuminanceFormat ) return 6409;
  13357. if ( p === LuminanceAlphaFormat ) return 6410;
  13358. if ( p === DepthFormat ) return 6402;
  13359. if ( p === DepthStencilFormat ) return 34041;
  13360. if ( p === RedFormat ) return 6403;
  13361. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13362. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13363. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13364. if ( extension !== null ) {
  13365. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13366. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13367. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13368. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13369. } else {
  13370. return null;
  13371. }
  13372. }
  13373. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13374. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13375. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13376. if ( extension !== null ) {
  13377. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13378. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13379. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13380. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13381. } else {
  13382. return null;
  13383. }
  13384. }
  13385. if ( p === RGB_ETC1_Format ) {
  13386. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13387. if ( extension !== null ) {
  13388. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13389. } else {
  13390. return null;
  13391. }
  13392. }
  13393. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13394. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13395. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13396. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13397. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  13398. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13399. if ( extension !== null ) {
  13400. // TODO Complete?
  13401. return p;
  13402. } else {
  13403. return null;
  13404. }
  13405. }
  13406. if ( p === UnsignedInt248Type ) {
  13407. if ( isWebGL2 ) return 34042;
  13408. extension = extensions.get( 'WEBGL_depth_texture' );
  13409. if ( extension !== null ) {
  13410. return extension.UNSIGNED_INT_24_8_WEBGL;
  13411. } else {
  13412. return null;
  13413. }
  13414. }
  13415. }
  13416. return { convert: convert };
  13417. }
  13418. /**
  13419. * @author fernandojsg / http://fernandojsg.com
  13420. * @author Takahiro https://github.com/takahirox
  13421. */
  13422. function WebGLMultiviewRenderTarget( width, height, numViews, options ) {
  13423. WebGLRenderTarget.call( this, width, height, options );
  13424. this.depthBuffer = false;
  13425. this.stencilBuffer = false;
  13426. this.numViews = numViews;
  13427. }
  13428. WebGLMultiviewRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  13429. constructor: WebGLMultiviewRenderTarget,
  13430. isWebGLMultiviewRenderTarget: true,
  13431. copy: function ( source ) {
  13432. WebGLRenderTarget.prototype.copy.call( this, source );
  13433. this.numViews = source.numViews;
  13434. return this;
  13435. },
  13436. setNumViews: function ( numViews ) {
  13437. if ( this.numViews !== numViews ) {
  13438. this.numViews = numViews;
  13439. this.dispose();
  13440. }
  13441. return this;
  13442. }
  13443. } );
  13444. /**
  13445. * @author fernandojsg / http://fernandojsg.com
  13446. * @author Takahiro https://github.com/takahirox
  13447. */
  13448. function WebGLMultiview( renderer, gl ) {
  13449. var DEFAULT_NUMVIEWS = 2;
  13450. var extensions = renderer.extensions;
  13451. var properties = renderer.properties;
  13452. var renderTarget, currentRenderTarget;
  13453. var mat3, mat4, cameraArray, renderSize;
  13454. var available;
  13455. var maxNumViews = 0;
  13456. //
  13457. function isAvailable() {
  13458. if ( available === undefined ) {
  13459. var extension = extensions.get( 'OVR_multiview2' );
  13460. available = extension !== null && gl.getContextAttributes().antialias === false;
  13461. if ( available ) {
  13462. maxNumViews = gl.getParameter( extension.MAX_VIEWS_OVR );
  13463. renderTarget = new WebGLMultiviewRenderTarget( 0, 0, DEFAULT_NUMVIEWS );
  13464. renderSize = new Vector2();
  13465. mat4 = [];
  13466. mat3 = [];
  13467. cameraArray = [];
  13468. for ( var i = 0; i < maxNumViews; i ++ ) {
  13469. mat4[ i ] = new Matrix4();
  13470. mat3[ i ] = new Matrix3();
  13471. }
  13472. }
  13473. }
  13474. return available;
  13475. }
  13476. function getCameraArray( camera ) {
  13477. if ( camera.isArrayCamera ) return camera.cameras;
  13478. cameraArray[ 0 ] = camera;
  13479. return cameraArray;
  13480. }
  13481. function updateCameraProjectionMatricesUniform( camera, uniforms ) {
  13482. var cameras = getCameraArray( camera );
  13483. for ( var i = 0; i < cameras.length; i ++ ) {
  13484. mat4[ i ].copy( cameras[ i ].projectionMatrix );
  13485. }
  13486. uniforms.setValue( gl, 'projectionMatrices', mat4 );
  13487. }
  13488. function updateCameraViewMatricesUniform( camera, uniforms ) {
  13489. var cameras = getCameraArray( camera );
  13490. for ( var i = 0; i < cameras.length; i ++ ) {
  13491. mat4[ i ].copy( cameras[ i ].matrixWorldInverse );
  13492. }
  13493. uniforms.setValue( gl, 'viewMatrices', mat4 );
  13494. }
  13495. function updateObjectMatricesUniforms( object, camera, uniforms ) {
  13496. var cameras = getCameraArray( camera );
  13497. for ( var i = 0; i < cameras.length; i ++ ) {
  13498. mat4[ i ].multiplyMatrices( cameras[ i ].matrixWorldInverse, object.matrixWorld );
  13499. mat3[ i ].getNormalMatrix( mat4[ i ] );
  13500. }
  13501. uniforms.setValue( gl, 'modelViewMatrices', mat4 );
  13502. uniforms.setValue( gl, 'normalMatrices', mat3 );
  13503. }
  13504. function isMultiviewCompatible( camera ) {
  13505. if ( camera.isArrayCamera === undefined ) return true;
  13506. var cameras = camera.cameras;
  13507. if ( cameras.length > maxNumViews ) return false;
  13508. for ( var i = 1, il = cameras.length; i < il; i ++ ) {
  13509. if ( cameras[ 0 ].viewport.z !== cameras[ i ].viewport.z ||
  13510. cameras[ 0 ].viewport.w !== cameras[ i ].viewport.w ) return false;
  13511. }
  13512. return true;
  13513. }
  13514. function resizeRenderTarget( camera ) {
  13515. if ( currentRenderTarget ) {
  13516. renderSize.set( currentRenderTarget.width, currentRenderTarget.height );
  13517. } else {
  13518. renderer.getDrawingBufferSize( renderSize );
  13519. }
  13520. if ( camera.isArrayCamera ) {
  13521. var viewport = camera.cameras[ 0 ].viewport;
  13522. renderTarget.setSize( viewport.z, viewport.w );
  13523. renderTarget.setNumViews( camera.cameras.length );
  13524. } else {
  13525. renderTarget.setSize( renderSize.x, renderSize.y );
  13526. renderTarget.setNumViews( DEFAULT_NUMVIEWS );
  13527. }
  13528. }
  13529. function attachCamera( camera ) {
  13530. if ( isMultiviewCompatible( camera ) === false ) return;
  13531. currentRenderTarget = renderer.getRenderTarget();
  13532. resizeRenderTarget( camera );
  13533. renderer.setRenderTarget( renderTarget );
  13534. }
  13535. function detachCamera( camera ) {
  13536. if ( renderTarget !== renderer.getRenderTarget() ) return;
  13537. renderer.setRenderTarget( currentRenderTarget );
  13538. flush( camera );
  13539. }
  13540. function flush( camera ) {
  13541. var srcRenderTarget = renderTarget;
  13542. var numViews = srcRenderTarget.numViews;
  13543. var srcFramebuffers = properties.get( srcRenderTarget ).__webglViewFramebuffers;
  13544. var viewWidth = srcRenderTarget.width;
  13545. var viewHeight = srcRenderTarget.height;
  13546. if ( camera.isArrayCamera ) {
  13547. for ( var i = 0; i < numViews; i ++ ) {
  13548. var viewport = camera.cameras[ i ].viewport;
  13549. var x1 = viewport.x;
  13550. var y1 = viewport.y;
  13551. var x2 = x1 + viewport.z;
  13552. var y2 = y1 + viewport.w;
  13553. gl.bindFramebuffer( 36008, srcFramebuffers[ i ] );
  13554. gl.blitFramebuffer( 0, 0, viewWidth, viewHeight, x1, y1, x2, y2, 16384, 9728 );
  13555. }
  13556. } else {
  13557. gl.bindFramebuffer( 36008, srcFramebuffers[ 0 ] );
  13558. gl.blitFramebuffer( 0, 0, viewWidth, viewHeight, 0, 0, renderSize.x, renderSize.y, 16384, 9728 );
  13559. }
  13560. }
  13561. this.isAvailable = isAvailable;
  13562. this.attachCamera = attachCamera;
  13563. this.detachCamera = detachCamera;
  13564. this.updateCameraProjectionMatricesUniform = updateCameraProjectionMatricesUniform;
  13565. this.updateCameraViewMatricesUniform = updateCameraViewMatricesUniform;
  13566. this.updateObjectMatricesUniforms = updateObjectMatricesUniforms;
  13567. }
  13568. /**
  13569. * @author mrdoob / http://mrdoob.com/
  13570. */
  13571. function Group() {
  13572. Object3D.call( this );
  13573. this.type = 'Group';
  13574. }
  13575. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13576. constructor: Group,
  13577. isGroup: true
  13578. } );
  13579. /**
  13580. * @author mrdoob / http://mrdoob.com/
  13581. */
  13582. function ArrayCamera( array ) {
  13583. PerspectiveCamera.call( this );
  13584. this.cameras = array || [];
  13585. }
  13586. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13587. constructor: ArrayCamera,
  13588. isArrayCamera: true
  13589. } );
  13590. /**
  13591. * @author jsantell / https://www.jsantell.com/
  13592. * @author mrdoob / http://mrdoob.com/
  13593. */
  13594. var cameraLPos = new Vector3();
  13595. var cameraRPos = new Vector3();
  13596. /**
  13597. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13598. * the cameras' projection and world matrices have already been set.
  13599. * And that near and far planes are identical for both cameras.
  13600. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13601. */
  13602. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13603. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13604. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13605. var ipd = cameraLPos.distanceTo( cameraRPos );
  13606. var projL = cameraL.projectionMatrix.elements;
  13607. var projR = cameraR.projectionMatrix.elements;
  13608. // VR systems will have identical far and near planes, and
  13609. // most likely identical top and bottom frustum extents.
  13610. // Use the left camera for these values.
  13611. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13612. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13613. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13614. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13615. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13616. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13617. var left = near * leftFov;
  13618. var right = near * rightFov;
  13619. // Calculate the new camera's position offset from the
  13620. // left camera. xOffset should be roughly half `ipd`.
  13621. var zOffset = ipd / ( - leftFov + rightFov );
  13622. var xOffset = zOffset * - leftFov;
  13623. // TODO: Better way to apply this offset?
  13624. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13625. camera.translateX( xOffset );
  13626. camera.translateZ( zOffset );
  13627. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13628. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13629. // Find the union of the frustum values of the cameras and scale
  13630. // the values so that the near plane's position does not change in world space,
  13631. // although must now be relative to the new union camera.
  13632. var near2 = near + zOffset;
  13633. var far2 = far + zOffset;
  13634. var left2 = left - xOffset;
  13635. var right2 = right + ( ipd - xOffset );
  13636. var top2 = topFov * far / far2 * near2;
  13637. var bottom2 = bottomFov * far / far2 * near2;
  13638. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13639. }
  13640. /**
  13641. * @author mrdoob / http://mrdoob.com/
  13642. */
  13643. function WebVRManager( renderer ) {
  13644. var renderWidth, renderHeight;
  13645. var scope = this;
  13646. var device = null;
  13647. var frameData = null;
  13648. var controllers = [];
  13649. var standingMatrix = new Matrix4();
  13650. var standingMatrixInverse = new Matrix4();
  13651. var framebufferScaleFactor = 1.0;
  13652. var referenceSpaceType = 'local-floor';
  13653. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13654. frameData = new window.VRFrameData();
  13655. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13656. }
  13657. var matrixWorldInverse = new Matrix4();
  13658. var tempQuaternion = new Quaternion();
  13659. var tempPosition = new Vector3();
  13660. var tempCamera = new PerspectiveCamera();
  13661. var cameraL = new PerspectiveCamera();
  13662. cameraL.viewport = new Vector4();
  13663. cameraL.layers.enable( 1 );
  13664. var cameraR = new PerspectiveCamera();
  13665. cameraR.viewport = new Vector4();
  13666. cameraR.layers.enable( 2 );
  13667. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13668. cameraVR.layers.enable( 1 );
  13669. cameraVR.layers.enable( 2 );
  13670. //
  13671. function isPresenting() {
  13672. return device !== null && device.isPresenting === true;
  13673. }
  13674. var currentSize = new Vector2(), currentPixelRatio;
  13675. function onVRDisplayPresentChange() {
  13676. if ( isPresenting() ) {
  13677. var eyeParameters = device.getEyeParameters( 'left' );
  13678. renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
  13679. renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13680. currentPixelRatio = renderer.getPixelRatio();
  13681. renderer.getSize( currentSize );
  13682. renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
  13683. cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
  13684. cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
  13685. animation.start();
  13686. scope.dispatchEvent( { type: 'sessionstart' } );
  13687. } else {
  13688. if ( scope.enabled ) {
  13689. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13690. }
  13691. animation.stop();
  13692. scope.dispatchEvent( { type: 'sessionend' } );
  13693. }
  13694. }
  13695. //
  13696. var triggers = [];
  13697. var grips = [];
  13698. function findGamepad( id ) {
  13699. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13700. for ( var i = 0, l = gamepads.length; i < l; i ++ ) {
  13701. var gamepad = gamepads[ i ];
  13702. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13703. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13704. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13705. gamepad.id.startsWith( 'HTC Vive Focus' ) ||
  13706. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13707. var hand = gamepad.hand;
  13708. if ( id === 0 && ( hand === '' || hand === 'right' ) ) return gamepad;
  13709. if ( id === 1 && ( hand === 'left' ) ) return gamepad;
  13710. }
  13711. }
  13712. }
  13713. function updateControllers() {
  13714. for ( var i = 0; i < controllers.length; i ++ ) {
  13715. var controller = controllers[ i ];
  13716. var gamepad = findGamepad( i );
  13717. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13718. if ( gamepad.pose === null ) return;
  13719. // Pose
  13720. var pose = gamepad.pose;
  13721. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13722. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13723. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13724. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13725. controller.matrix.premultiply( standingMatrix );
  13726. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13727. controller.matrixWorldNeedsUpdate = true;
  13728. controller.visible = true;
  13729. // Trigger
  13730. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13731. if ( triggers[ i ] === undefined ) triggers[ i ] = false;
  13732. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13733. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13734. if ( triggers[ i ] === true ) {
  13735. controller.dispatchEvent( { type: 'selectstart' } );
  13736. } else {
  13737. controller.dispatchEvent( { type: 'selectend' } );
  13738. controller.dispatchEvent( { type: 'select' } );
  13739. }
  13740. }
  13741. // Grip
  13742. buttonId = 2;
  13743. if ( grips[ i ] === undefined ) grips[ i ] = false;
  13744. // Skip if the grip button doesn't exist on this controller
  13745. if ( gamepad.buttons[ buttonId ] !== undefined ) {
  13746. if ( grips[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13747. grips[ i ] = gamepad.buttons[ buttonId ].pressed;
  13748. if ( grips[ i ] === true ) {
  13749. controller.dispatchEvent( { type: 'squeezestart' } );
  13750. } else {
  13751. controller.dispatchEvent( { type: 'squeezeend' } );
  13752. controller.dispatchEvent( { type: 'squeeze' } );
  13753. }
  13754. }
  13755. }
  13756. } else {
  13757. controller.visible = false;
  13758. }
  13759. }
  13760. }
  13761. function updateViewportFromBounds( viewport, bounds ) {
  13762. if ( bounds !== null && bounds.length === 4 ) {
  13763. viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
  13764. }
  13765. }
  13766. //
  13767. this.enabled = false;
  13768. this.getController = function ( id ) {
  13769. var controller = controllers[ id ];
  13770. if ( controller === undefined ) {
  13771. controller = new Group();
  13772. controller.matrixAutoUpdate = false;
  13773. controller.visible = false;
  13774. controllers[ id ] = controller;
  13775. }
  13776. return controller;
  13777. };
  13778. this.getDevice = function () {
  13779. return device;
  13780. };
  13781. this.setDevice = function ( value ) {
  13782. if ( value !== undefined ) device = value;
  13783. animation.setContext( value );
  13784. };
  13785. this.setFramebufferScaleFactor = function ( value ) {
  13786. framebufferScaleFactor = value;
  13787. };
  13788. this.setReferenceSpaceType = function ( value ) {
  13789. referenceSpaceType = value;
  13790. };
  13791. this.getCamera = function ( camera ) {
  13792. var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
  13793. device.depthNear = camera.near;
  13794. device.depthFar = camera.far;
  13795. device.getFrameData( frameData );
  13796. //
  13797. if ( referenceSpaceType === 'local-floor' ) {
  13798. var stageParameters = device.stageParameters;
  13799. if ( stageParameters ) {
  13800. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13801. } else {
  13802. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13803. }
  13804. }
  13805. var pose = frameData.pose;
  13806. tempCamera.matrix.copy( standingMatrix );
  13807. tempCamera.matrix.decompose( tempCamera.position, tempCamera.quaternion, tempCamera.scale );
  13808. if ( pose.orientation !== null ) {
  13809. tempQuaternion.fromArray( pose.orientation );
  13810. tempCamera.quaternion.multiply( tempQuaternion );
  13811. }
  13812. if ( pose.position !== null ) {
  13813. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13814. tempPosition.fromArray( pose.position );
  13815. tempPosition.applyQuaternion( tempQuaternion );
  13816. tempCamera.position.add( tempPosition );
  13817. }
  13818. tempCamera.updateMatrixWorld();
  13819. //
  13820. camera.matrixWorld.copy( tempCamera.matrixWorld );
  13821. var children = camera.children;
  13822. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13823. children[ i ].updateMatrixWorld( true );
  13824. }
  13825. //
  13826. cameraL.near = camera.near;
  13827. cameraR.near = camera.near;
  13828. cameraL.far = camera.far;
  13829. cameraR.far = camera.far;
  13830. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13831. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13832. // TODO (mrdoob) Double check this code
  13833. standingMatrixInverse.getInverse( standingMatrix );
  13834. if ( referenceSpaceType === 'local-floor' ) {
  13835. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13836. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13837. }
  13838. var parent = camera.parent;
  13839. if ( parent !== null ) {
  13840. matrixWorldInverse.getInverse( parent.matrixWorld );
  13841. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13842. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13843. }
  13844. // envMap and Mirror needs camera.matrixWorld
  13845. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13846. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13847. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13848. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13849. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13850. //
  13851. var layers = device.getLayers();
  13852. if ( layers.length ) {
  13853. var layer = layers[ 0 ];
  13854. updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
  13855. updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
  13856. }
  13857. updateControllers();
  13858. return cameraVR;
  13859. };
  13860. this.getStandingMatrix = function () {
  13861. return standingMatrix;
  13862. };
  13863. this.isPresenting = isPresenting;
  13864. // Animation Loop
  13865. var animation = new WebGLAnimation();
  13866. this.setAnimationLoop = function ( callback ) {
  13867. animation.setAnimationLoop( callback );
  13868. if ( isPresenting() ) animation.start();
  13869. };
  13870. this.submitFrame = function () {
  13871. if ( isPresenting() ) device.submitFrame();
  13872. };
  13873. this.dispose = function () {
  13874. if ( typeof window !== 'undefined' ) {
  13875. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13876. }
  13877. };
  13878. // DEPRECATED
  13879. this.setFrameOfReferenceType = function () {
  13880. console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
  13881. };
  13882. }
  13883. Object.assign( WebVRManager.prototype, EventDispatcher.prototype );
  13884. /**
  13885. * @author mrdoob / http://mrdoob.com/
  13886. */
  13887. function WebXRManager( renderer, gl ) {
  13888. var scope = this;
  13889. var session = null;
  13890. // var framebufferScaleFactor = 1.0;
  13891. var referenceSpace = null;
  13892. var referenceSpaceType = 'local-floor';
  13893. var pose = null;
  13894. var controllers = [];
  13895. var sortedInputSources = [];
  13896. function isPresenting() {
  13897. return session !== null && referenceSpace !== null;
  13898. }
  13899. //
  13900. var cameraL = new PerspectiveCamera();
  13901. cameraL.layers.enable( 1 );
  13902. cameraL.viewport = new Vector4();
  13903. var cameraR = new PerspectiveCamera();
  13904. cameraR.layers.enable( 2 );
  13905. cameraR.viewport = new Vector4();
  13906. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13907. cameraVR.layers.enable( 1 );
  13908. cameraVR.layers.enable( 2 );
  13909. //
  13910. this.enabled = false;
  13911. this.getController = function ( id ) {
  13912. var controller = controllers[ id ];
  13913. if ( controller === undefined ) {
  13914. controller = new Group();
  13915. controller.matrixAutoUpdate = false;
  13916. controller.visible = false;
  13917. controllers[ id ] = controller;
  13918. }
  13919. return controller;
  13920. };
  13921. //
  13922. function onSessionEvent( event ) {
  13923. for ( var i = 0; i < controllers.length; i ++ ) {
  13924. if ( sortedInputSources[ i ] === event.inputSource ) {
  13925. controllers[ i ].dispatchEvent( { type: event.type } );
  13926. }
  13927. }
  13928. }
  13929. function onSessionEnd() {
  13930. renderer.setFramebuffer( null );
  13931. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13932. animation.stop();
  13933. scope.dispatchEvent( { type: 'sessionend' } );
  13934. }
  13935. function onRequestReferenceSpace( value ) {
  13936. referenceSpace = value;
  13937. animation.setContext( session );
  13938. animation.start();
  13939. scope.dispatchEvent( { type: 'sessionstart' } );
  13940. }
  13941. this.setFramebufferScaleFactor = function ( /* value */ ) {
  13942. // framebufferScaleFactor = value;
  13943. };
  13944. this.setReferenceSpaceType = function ( value ) {
  13945. referenceSpaceType = value;
  13946. };
  13947. this.getSession = function () {
  13948. return session;
  13949. };
  13950. this.setSession = function ( value ) {
  13951. session = value;
  13952. if ( session !== null ) {
  13953. session.addEventListener( 'select', onSessionEvent );
  13954. session.addEventListener( 'selectstart', onSessionEvent );
  13955. session.addEventListener( 'selectend', onSessionEvent );
  13956. session.addEventListener( 'squeeze', onSessionEvent );
  13957. session.addEventListener( 'squeezestart', onSessionEvent );
  13958. session.addEventListener( 'squeezeend', onSessionEvent );
  13959. session.addEventListener( 'end', onSessionEnd );
  13960. // eslint-disable-next-line no-undef
  13961. session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
  13962. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13963. //
  13964. session.addEventListener( 'inputsourceschange', updateInputSources );
  13965. updateInputSources();
  13966. }
  13967. };
  13968. function updateInputSources() {
  13969. for ( var i = 0; i < controllers.length; i ++ ) {
  13970. sortedInputSources[ i ] = findInputSource( i );
  13971. }
  13972. }
  13973. function findInputSource( id ) {
  13974. var inputSources = session.inputSources;
  13975. for ( var i = 0; i < inputSources.length; i ++ ) {
  13976. var inputSource = inputSources[ i ];
  13977. var handedness = inputSource.handedness;
  13978. if ( id === 0 && ( handedness === 'none' || handedness === 'right' ) ) return inputSource;
  13979. if ( id === 1 && ( handedness === 'left' ) ) return inputSource;
  13980. }
  13981. }
  13982. //
  13983. function updateCamera( camera, parent ) {
  13984. if ( parent === null ) {
  13985. camera.matrixWorld.copy( camera.matrix );
  13986. } else {
  13987. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13988. }
  13989. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13990. }
  13991. this.getCamera = function ( camera ) {
  13992. var parent = camera.parent;
  13993. var cameras = cameraVR.cameras;
  13994. updateCamera( cameraVR, parent );
  13995. for ( var i = 0; i < cameras.length; i ++ ) {
  13996. updateCamera( cameras[ i ], parent );
  13997. }
  13998. // update camera and its children
  13999. camera.matrixWorld.copy( cameraVR.matrixWorld );
  14000. var children = camera.children;
  14001. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14002. children[ i ].updateMatrixWorld( true );
  14003. }
  14004. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  14005. return cameraVR;
  14006. };
  14007. this.isPresenting = isPresenting;
  14008. // Animation Loop
  14009. var onAnimationFrameCallback = null;
  14010. function onAnimationFrame( time, frame ) {
  14011. pose = frame.getViewerPose( referenceSpace );
  14012. if ( pose !== null ) {
  14013. var views = pose.views;
  14014. var baseLayer = session.renderState.baseLayer;
  14015. renderer.setFramebuffer( baseLayer.framebuffer );
  14016. for ( var i = 0; i < views.length; i ++ ) {
  14017. var view = views[ i ];
  14018. var viewport = baseLayer.getViewport( view );
  14019. var viewMatrix = view.transform.inverse.matrix;
  14020. var camera = cameraVR.cameras[ i ];
  14021. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  14022. camera.projectionMatrix.fromArray( view.projectionMatrix );
  14023. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  14024. if ( i === 0 ) {
  14025. cameraVR.matrix.copy( camera.matrix );
  14026. }
  14027. }
  14028. }
  14029. //
  14030. for ( var i = 0; i < controllers.length; i ++ ) {
  14031. var controller = controllers[ i ];
  14032. var inputSource = sortedInputSources[ i ];
  14033. if ( inputSource ) {
  14034. var inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  14035. if ( inputPose !== null ) {
  14036. controller.matrix.fromArray( inputPose.transform.matrix );
  14037. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  14038. controller.visible = true;
  14039. continue;
  14040. }
  14041. }
  14042. controller.visible = false;
  14043. }
  14044. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14045. }
  14046. var animation = new WebGLAnimation();
  14047. animation.setAnimationLoop( onAnimationFrame );
  14048. this.setAnimationLoop = function ( callback ) {
  14049. onAnimationFrameCallback = callback;
  14050. };
  14051. this.dispose = function () {};
  14052. // DEPRECATED
  14053. this.getStandingMatrix = function () {
  14054. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  14055. return new Matrix4();
  14056. };
  14057. this.getDevice = function () {
  14058. console.warn( 'THREE.WebXRManager: getDevice() has been deprecated.' );
  14059. };
  14060. this.setDevice = function () {
  14061. console.warn( 'THREE.WebXRManager: setDevice() has been deprecated.' );
  14062. };
  14063. this.setFrameOfReferenceType = function () {
  14064. console.warn( 'THREE.WebXRManager: setFrameOfReferenceType() has been deprecated.' );
  14065. };
  14066. this.submitFrame = function () {};
  14067. }
  14068. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  14069. /**
  14070. * @author supereggbert / http://www.paulbrunt.co.uk/
  14071. * @author mrdoob / http://mrdoob.com/
  14072. * @author alteredq / http://alteredqualia.com/
  14073. * @author szimek / https://github.com/szimek/
  14074. * @author tschw
  14075. */
  14076. function WebGLRenderer( parameters ) {
  14077. parameters = parameters || {};
  14078. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14079. _context = parameters.context !== undefined ? parameters.context : null,
  14080. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14081. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14082. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14083. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14084. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14085. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14086. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14087. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14088. var currentRenderList = null;
  14089. var currentRenderState = null;
  14090. // public properties
  14091. this.domElement = _canvas;
  14092. // Debug configuration container
  14093. this.debug = {
  14094. /**
  14095. * Enables error checking and reporting when shader programs are being compiled
  14096. * @type {boolean}
  14097. */
  14098. checkShaderErrors: true
  14099. };
  14100. // clearing
  14101. this.autoClear = true;
  14102. this.autoClearColor = true;
  14103. this.autoClearDepth = true;
  14104. this.autoClearStencil = true;
  14105. // scene graph
  14106. this.sortObjects = true;
  14107. // user-defined clipping
  14108. this.clippingPlanes = [];
  14109. this.localClippingEnabled = false;
  14110. // physically based shading
  14111. this.gammaFactor = 2.0; // for backwards compatibility
  14112. this.gammaInput = false;
  14113. this.gammaOutput = false;
  14114. // physical lights
  14115. this.physicallyCorrectLights = false;
  14116. // tone mapping
  14117. this.toneMapping = LinearToneMapping;
  14118. this.toneMappingExposure = 1.0;
  14119. this.toneMappingWhitePoint = 1.0;
  14120. // morphs
  14121. this.maxMorphTargets = 8;
  14122. this.maxMorphNormals = 4;
  14123. // internal properties
  14124. var _this = this,
  14125. _isContextLost = false,
  14126. // internal state cache
  14127. _framebuffer = null,
  14128. _currentActiveCubeFace = 0,
  14129. _currentActiveMipmapLevel = 0,
  14130. _currentRenderTarget = null,
  14131. _currentFramebuffer = null,
  14132. _currentMaterialId = - 1,
  14133. // geometry and program caching
  14134. _currentGeometryProgram = {
  14135. geometry: null,
  14136. program: null,
  14137. wireframe: false
  14138. },
  14139. _currentCamera = null,
  14140. _currentArrayCamera = null,
  14141. _currentViewport = new Vector4(),
  14142. _currentScissor = new Vector4(),
  14143. _currentScissorTest = null,
  14144. //
  14145. _width = _canvas.width,
  14146. _height = _canvas.height,
  14147. _pixelRatio = 1,
  14148. _viewport = new Vector4( 0, 0, _width, _height ),
  14149. _scissor = new Vector4( 0, 0, _width, _height ),
  14150. _scissorTest = false,
  14151. // frustum
  14152. _frustum = new Frustum(),
  14153. // clipping
  14154. _clipping = new WebGLClipping(),
  14155. _clippingEnabled = false,
  14156. _localClippingEnabled = false,
  14157. // camera matrices cache
  14158. _projScreenMatrix = new Matrix4(),
  14159. _vector3 = new Vector3();
  14160. function getTargetPixelRatio() {
  14161. return _currentRenderTarget === null ? _pixelRatio : 1;
  14162. }
  14163. // initialize
  14164. var _gl;
  14165. try {
  14166. var contextAttributes = {
  14167. alpha: _alpha,
  14168. depth: _depth,
  14169. stencil: _stencil,
  14170. antialias: _antialias,
  14171. premultipliedAlpha: _premultipliedAlpha,
  14172. preserveDrawingBuffer: _preserveDrawingBuffer,
  14173. powerPreference: _powerPreference,
  14174. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
  14175. xrCompatible: true
  14176. };
  14177. // event listeners must be registered before WebGL context is created, see #12753
  14178. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14179. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  14180. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  14181. if ( _gl === null ) {
  14182. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14183. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  14184. } else {
  14185. throw new Error( 'Error creating WebGL context.' );
  14186. }
  14187. }
  14188. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14189. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14190. _gl.getShaderPrecisionFormat = function () {
  14191. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14192. };
  14193. }
  14194. } catch ( error ) {
  14195. console.error( 'THREE.WebGLRenderer: ' + error.message );
  14196. throw error;
  14197. }
  14198. var extensions, capabilities, state, info;
  14199. var properties, textures, attributes, geometries, objects;
  14200. var programCache, renderLists, renderStates;
  14201. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14202. var utils;
  14203. function initGLContext() {
  14204. extensions = new WebGLExtensions( _gl );
  14205. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  14206. if ( capabilities.isWebGL2 === false ) {
  14207. extensions.get( 'WEBGL_depth_texture' );
  14208. extensions.get( 'OES_texture_float' );
  14209. extensions.get( 'OES_texture_half_float' );
  14210. extensions.get( 'OES_texture_half_float_linear' );
  14211. extensions.get( 'OES_standard_derivatives' );
  14212. extensions.get( 'OES_element_index_uint' );
  14213. extensions.get( 'ANGLE_instanced_arrays' );
  14214. }
  14215. extensions.get( 'OES_texture_float_linear' );
  14216. utils = new WebGLUtils( _gl, extensions, capabilities );
  14217. state = new WebGLState( _gl, extensions, capabilities );
  14218. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14219. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14220. info = new WebGLInfo( _gl );
  14221. properties = new WebGLProperties();
  14222. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  14223. attributes = new WebGLAttributes( _gl );
  14224. geometries = new WebGLGeometries( _gl, attributes, info );
  14225. objects = new WebGLObjects( _gl, geometries, attributes, info );
  14226. morphtargets = new WebGLMorphtargets( _gl );
  14227. programCache = new WebGLPrograms( _this, extensions, capabilities );
  14228. renderLists = new WebGLRenderLists();
  14229. renderStates = new WebGLRenderStates();
  14230. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  14231. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  14232. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  14233. info.programs = programCache.programs;
  14234. _this.capabilities = capabilities;
  14235. _this.extensions = extensions;
  14236. _this.properties = properties;
  14237. _this.renderLists = renderLists;
  14238. _this.state = state;
  14239. _this.info = info;
  14240. }
  14241. initGLContext();
  14242. // vr
  14243. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator ) ? new WebXRManager( _this, _gl ) : new WebVRManager( _this );
  14244. this.vr = vr;
  14245. // Multiview
  14246. var multiview = new WebGLMultiview( _this, _gl );
  14247. // shadow map
  14248. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  14249. this.shadowMap = shadowMap;
  14250. // API
  14251. this.getContext = function () {
  14252. return _gl;
  14253. };
  14254. this.getContextAttributes = function () {
  14255. return _gl.getContextAttributes();
  14256. };
  14257. this.forceContextLoss = function () {
  14258. var extension = extensions.get( 'WEBGL_lose_context' );
  14259. if ( extension ) extension.loseContext();
  14260. };
  14261. this.forceContextRestore = function () {
  14262. var extension = extensions.get( 'WEBGL_lose_context' );
  14263. if ( extension ) extension.restoreContext();
  14264. };
  14265. this.getPixelRatio = function () {
  14266. return _pixelRatio;
  14267. };
  14268. this.setPixelRatio = function ( value ) {
  14269. if ( value === undefined ) return;
  14270. _pixelRatio = value;
  14271. this.setSize( _width, _height, false );
  14272. };
  14273. this.getSize = function ( target ) {
  14274. if ( target === undefined ) {
  14275. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  14276. target = new Vector2();
  14277. }
  14278. return target.set( _width, _height );
  14279. };
  14280. this.setSize = function ( width, height, updateStyle ) {
  14281. if ( vr.isPresenting() ) {
  14282. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  14283. return;
  14284. }
  14285. _width = width;
  14286. _height = height;
  14287. _canvas.width = Math.floor( width * _pixelRatio );
  14288. _canvas.height = Math.floor( height * _pixelRatio );
  14289. if ( updateStyle !== false ) {
  14290. _canvas.style.width = width + 'px';
  14291. _canvas.style.height = height + 'px';
  14292. }
  14293. this.setViewport( 0, 0, width, height );
  14294. };
  14295. this.getDrawingBufferSize = function ( target ) {
  14296. if ( target === undefined ) {
  14297. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  14298. target = new Vector2();
  14299. }
  14300. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  14301. };
  14302. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14303. _width = width;
  14304. _height = height;
  14305. _pixelRatio = pixelRatio;
  14306. _canvas.width = Math.floor( width * pixelRatio );
  14307. _canvas.height = Math.floor( height * pixelRatio );
  14308. this.setViewport( 0, 0, width, height );
  14309. };
  14310. this.getCurrentViewport = function ( target ) {
  14311. if ( target === undefined ) {
  14312. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14313. target = new Vector4();
  14314. }
  14315. return target.copy( _currentViewport );
  14316. };
  14317. this.getViewport = function ( target ) {
  14318. return target.copy( _viewport );
  14319. };
  14320. this.setViewport = function ( x, y, width, height ) {
  14321. if ( x.isVector4 ) {
  14322. _viewport.set( x.x, x.y, x.z, x.w );
  14323. } else {
  14324. _viewport.set( x, y, width, height );
  14325. }
  14326. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14327. };
  14328. this.getScissor = function ( target ) {
  14329. return target.copy( _scissor );
  14330. };
  14331. this.setScissor = function ( x, y, width, height ) {
  14332. if ( x.isVector4 ) {
  14333. _scissor.set( x.x, x.y, x.z, x.w );
  14334. } else {
  14335. _scissor.set( x, y, width, height );
  14336. }
  14337. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14338. };
  14339. this.getScissorTest = function () {
  14340. return _scissorTest;
  14341. };
  14342. this.setScissorTest = function ( boolean ) {
  14343. state.setScissorTest( _scissorTest = boolean );
  14344. };
  14345. // Clearing
  14346. this.getClearColor = function () {
  14347. return background.getClearColor();
  14348. };
  14349. this.setClearColor = function () {
  14350. background.setClearColor.apply( background, arguments );
  14351. };
  14352. this.getClearAlpha = function () {
  14353. return background.getClearAlpha();
  14354. };
  14355. this.setClearAlpha = function () {
  14356. background.setClearAlpha.apply( background, arguments );
  14357. };
  14358. this.clear = function ( color, depth, stencil ) {
  14359. var bits = 0;
  14360. if ( color === undefined || color ) bits |= 16384;
  14361. if ( depth === undefined || depth ) bits |= 256;
  14362. if ( stencil === undefined || stencil ) bits |= 1024;
  14363. _gl.clear( bits );
  14364. };
  14365. this.clearColor = function () {
  14366. this.clear( true, false, false );
  14367. };
  14368. this.clearDepth = function () {
  14369. this.clear( false, true, false );
  14370. };
  14371. this.clearStencil = function () {
  14372. this.clear( false, false, true );
  14373. };
  14374. //
  14375. this.dispose = function () {
  14376. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14377. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14378. renderLists.dispose();
  14379. renderStates.dispose();
  14380. properties.dispose();
  14381. objects.dispose();
  14382. vr.dispose();
  14383. animation.stop();
  14384. };
  14385. // Events
  14386. function onContextLost( event ) {
  14387. event.preventDefault();
  14388. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14389. _isContextLost = true;
  14390. }
  14391. function onContextRestore( /* event */ ) {
  14392. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14393. _isContextLost = false;
  14394. initGLContext();
  14395. }
  14396. function onMaterialDispose( event ) {
  14397. var material = event.target;
  14398. material.removeEventListener( 'dispose', onMaterialDispose );
  14399. deallocateMaterial( material );
  14400. }
  14401. // Buffer deallocation
  14402. function deallocateMaterial( material ) {
  14403. releaseMaterialProgramReference( material );
  14404. properties.remove( material );
  14405. }
  14406. function releaseMaterialProgramReference( material ) {
  14407. var programInfo = properties.get( material ).program;
  14408. material.program = undefined;
  14409. if ( programInfo !== undefined ) {
  14410. programCache.releaseProgram( programInfo );
  14411. }
  14412. }
  14413. // Buffer rendering
  14414. function renderObjectImmediate( object, program ) {
  14415. object.render( function ( object ) {
  14416. _this.renderBufferImmediate( object, program );
  14417. } );
  14418. }
  14419. this.renderBufferImmediate = function ( object, program ) {
  14420. state.initAttributes();
  14421. var buffers = properties.get( object );
  14422. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14423. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14424. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14425. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14426. var programAttributes = program.getAttributes();
  14427. if ( object.hasPositions ) {
  14428. _gl.bindBuffer( 34962, buffers.position );
  14429. _gl.bufferData( 34962, object.positionArray, 35048 );
  14430. state.enableAttribute( programAttributes.position );
  14431. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14432. }
  14433. if ( object.hasNormals ) {
  14434. _gl.bindBuffer( 34962, buffers.normal );
  14435. _gl.bufferData( 34962, object.normalArray, 35048 );
  14436. state.enableAttribute( programAttributes.normal );
  14437. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14438. }
  14439. if ( object.hasUvs ) {
  14440. _gl.bindBuffer( 34962, buffers.uv );
  14441. _gl.bufferData( 34962, object.uvArray, 35048 );
  14442. state.enableAttribute( programAttributes.uv );
  14443. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14444. }
  14445. if ( object.hasColors ) {
  14446. _gl.bindBuffer( 34962, buffers.color );
  14447. _gl.bufferData( 34962, object.colorArray, 35048 );
  14448. state.enableAttribute( programAttributes.color );
  14449. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14450. }
  14451. state.disableUnusedAttributes();
  14452. _gl.drawArrays( 4, 0, object.count );
  14453. object.count = 0;
  14454. };
  14455. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14456. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14457. state.setMaterial( material, frontFaceCW );
  14458. var program = setProgram( camera, fog, material, object );
  14459. var updateBuffers = false;
  14460. if ( _currentGeometryProgram.geometry !== geometry.id ||
  14461. _currentGeometryProgram.program !== program.id ||
  14462. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  14463. _currentGeometryProgram.geometry = geometry.id;
  14464. _currentGeometryProgram.program = program.id;
  14465. _currentGeometryProgram.wireframe = material.wireframe === true;
  14466. updateBuffers = true;
  14467. }
  14468. if ( object.morphTargetInfluences ) {
  14469. morphtargets.update( object, geometry, material, program );
  14470. updateBuffers = true;
  14471. }
  14472. //
  14473. var index = geometry.index;
  14474. var position = geometry.attributes.position;
  14475. //
  14476. if ( index !== null && index.count === 0 ) return;
  14477. if ( position === undefined || position.count === 0 ) return;
  14478. //
  14479. var rangeFactor = 1;
  14480. if ( material.wireframe === true ) {
  14481. index = geometries.getWireframeAttribute( geometry );
  14482. rangeFactor = 2;
  14483. }
  14484. var attribute;
  14485. var renderer = bufferRenderer;
  14486. if ( index !== null ) {
  14487. attribute = attributes.get( index );
  14488. renderer = indexedBufferRenderer;
  14489. renderer.setIndex( attribute );
  14490. }
  14491. if ( updateBuffers ) {
  14492. setupVertexAttributes( object, geometry, material, program );
  14493. if ( index !== null ) {
  14494. _gl.bindBuffer( 34963, attribute.buffer );
  14495. }
  14496. }
  14497. //
  14498. var dataCount = Infinity;
  14499. if ( index !== null ) {
  14500. dataCount = index.count;
  14501. } else if ( position !== undefined ) {
  14502. dataCount = position.count;
  14503. }
  14504. var rangeStart = geometry.drawRange.start * rangeFactor;
  14505. var rangeCount = geometry.drawRange.count * rangeFactor;
  14506. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14507. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14508. var drawStart = Math.max( rangeStart, groupStart );
  14509. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14510. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14511. if ( drawCount === 0 ) return;
  14512. //
  14513. if ( object.isMesh ) {
  14514. if ( material.wireframe === true ) {
  14515. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14516. renderer.setMode( 1 );
  14517. } else {
  14518. switch ( object.drawMode ) {
  14519. case TrianglesDrawMode:
  14520. renderer.setMode( 4 );
  14521. break;
  14522. case TriangleStripDrawMode:
  14523. renderer.setMode( 5 );
  14524. break;
  14525. case TriangleFanDrawMode:
  14526. renderer.setMode( 6 );
  14527. break;
  14528. }
  14529. }
  14530. } else if ( object.isLine ) {
  14531. var lineWidth = material.linewidth;
  14532. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14533. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14534. if ( object.isLineSegments ) {
  14535. renderer.setMode( 1 );
  14536. } else if ( object.isLineLoop ) {
  14537. renderer.setMode( 2 );
  14538. } else {
  14539. renderer.setMode( 3 );
  14540. }
  14541. } else if ( object.isPoints ) {
  14542. renderer.setMode( 0 );
  14543. } else if ( object.isSprite ) {
  14544. renderer.setMode( 4 );
  14545. }
  14546. if ( object.isInstancedMesh ) {
  14547. renderer.renderInstances( geometry, drawStart, drawCount, object.count );
  14548. } else if ( geometry.isInstancedBufferGeometry ) {
  14549. renderer.renderInstances( geometry, drawStart, drawCount, geometry.maxInstancedCount );
  14550. } else {
  14551. renderer.render( drawStart, drawCount );
  14552. }
  14553. };
  14554. function setupVertexAttributes( object, geometry, material, program ) {
  14555. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  14556. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
  14557. }
  14558. state.initAttributes();
  14559. var geometryAttributes = geometry.attributes;
  14560. var programAttributes = program.getAttributes();
  14561. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14562. for ( var name in programAttributes ) {
  14563. var programAttribute = programAttributes[ name ];
  14564. if ( programAttribute >= 0 ) {
  14565. var geometryAttribute = geometryAttributes[ name ];
  14566. if ( geometryAttribute !== undefined ) {
  14567. var normalized = geometryAttribute.normalized;
  14568. var size = geometryAttribute.itemSize;
  14569. var attribute = attributes.get( geometryAttribute );
  14570. // TODO Attribute may not be available on context restore
  14571. if ( attribute === undefined ) continue;
  14572. var buffer = attribute.buffer;
  14573. var type = attribute.type;
  14574. var bytesPerElement = attribute.bytesPerElement;
  14575. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14576. var data = geometryAttribute.data;
  14577. var stride = data.stride;
  14578. var offset = geometryAttribute.offset;
  14579. if ( data && data.isInstancedInterleavedBuffer ) {
  14580. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14581. if ( geometry.maxInstancedCount === undefined ) {
  14582. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14583. }
  14584. } else {
  14585. state.enableAttribute( programAttribute );
  14586. }
  14587. _gl.bindBuffer( 34962, buffer );
  14588. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14589. } else {
  14590. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14591. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14592. if ( geometry.maxInstancedCount === undefined ) {
  14593. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14594. }
  14595. } else {
  14596. state.enableAttribute( programAttribute );
  14597. }
  14598. _gl.bindBuffer( 34962, buffer );
  14599. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14600. }
  14601. } else if ( name === 'instanceMatrix' ) {
  14602. var attribute = attributes.get( object.instanceMatrix );
  14603. // TODO Attribute may not be available on context restore
  14604. if ( attribute === undefined ) continue;
  14605. var buffer = attribute.buffer;
  14606. var type = attribute.type;
  14607. state.enableAttributeAndDivisor( programAttribute + 0, 1 );
  14608. state.enableAttributeAndDivisor( programAttribute + 1, 1 );
  14609. state.enableAttributeAndDivisor( programAttribute + 2, 1 );
  14610. state.enableAttributeAndDivisor( programAttribute + 3, 1 );
  14611. _gl.bindBuffer( 34962, buffer );
  14612. _gl.vertexAttribPointer( programAttribute + 0, 4, type, false, 64, 0 );
  14613. _gl.vertexAttribPointer( programAttribute + 1, 4, type, false, 64, 16 );
  14614. _gl.vertexAttribPointer( programAttribute + 2, 4, type, false, 64, 32 );
  14615. _gl.vertexAttribPointer( programAttribute + 3, 4, type, false, 64, 48 );
  14616. } else if ( materialDefaultAttributeValues !== undefined ) {
  14617. var value = materialDefaultAttributeValues[ name ];
  14618. if ( value !== undefined ) {
  14619. switch ( value.length ) {
  14620. case 2:
  14621. _gl.vertexAttrib2fv( programAttribute, value );
  14622. break;
  14623. case 3:
  14624. _gl.vertexAttrib3fv( programAttribute, value );
  14625. break;
  14626. case 4:
  14627. _gl.vertexAttrib4fv( programAttribute, value );
  14628. break;
  14629. default:
  14630. _gl.vertexAttrib1fv( programAttribute, value );
  14631. }
  14632. }
  14633. }
  14634. }
  14635. }
  14636. state.disableUnusedAttributes();
  14637. }
  14638. // Compile
  14639. this.compile = function ( scene, camera ) {
  14640. currentRenderState = renderStates.get( scene, camera );
  14641. currentRenderState.init();
  14642. scene.traverse( function ( object ) {
  14643. if ( object.isLight ) {
  14644. currentRenderState.pushLight( object );
  14645. if ( object.castShadow ) {
  14646. currentRenderState.pushShadow( object );
  14647. }
  14648. }
  14649. } );
  14650. currentRenderState.setupLights( camera );
  14651. scene.traverse( function ( object ) {
  14652. if ( object.material ) {
  14653. if ( Array.isArray( object.material ) ) {
  14654. for ( var i = 0; i < object.material.length; i ++ ) {
  14655. initMaterial( object.material[ i ], scene.fog, object );
  14656. }
  14657. } else {
  14658. initMaterial( object.material, scene.fog, object );
  14659. }
  14660. }
  14661. } );
  14662. };
  14663. // Animation Loop
  14664. var onAnimationFrameCallback = null;
  14665. function onAnimationFrame( time ) {
  14666. if ( vr.isPresenting() ) return;
  14667. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14668. }
  14669. var animation = new WebGLAnimation();
  14670. animation.setAnimationLoop( onAnimationFrame );
  14671. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14672. this.setAnimationLoop = function ( callback ) {
  14673. onAnimationFrameCallback = callback;
  14674. vr.setAnimationLoop( callback );
  14675. animation.start();
  14676. };
  14677. // Rendering
  14678. this.render = function ( scene, camera ) {
  14679. var renderTarget, forceClear;
  14680. if ( arguments[ 2 ] !== undefined ) {
  14681. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14682. renderTarget = arguments[ 2 ];
  14683. }
  14684. if ( arguments[ 3 ] !== undefined ) {
  14685. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14686. forceClear = arguments[ 3 ];
  14687. }
  14688. if ( ! ( camera && camera.isCamera ) ) {
  14689. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14690. return;
  14691. }
  14692. if ( _isContextLost ) return;
  14693. // reset caching for this frame
  14694. _currentGeometryProgram.geometry = null;
  14695. _currentGeometryProgram.program = null;
  14696. _currentGeometryProgram.wireframe = false;
  14697. _currentMaterialId = - 1;
  14698. _currentCamera = null;
  14699. // update scene graph
  14700. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14701. // update camera matrices and frustum
  14702. if ( camera.parent === null ) camera.updateMatrixWorld();
  14703. if ( vr.enabled && vr.isPresenting() ) {
  14704. camera = vr.getCamera( camera );
  14705. }
  14706. //
  14707. currentRenderState = renderStates.get( scene, camera );
  14708. currentRenderState.init();
  14709. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14710. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14711. _frustum.setFromMatrix( _projScreenMatrix );
  14712. _localClippingEnabled = this.localClippingEnabled;
  14713. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14714. currentRenderList = renderLists.get( scene, camera );
  14715. currentRenderList.init();
  14716. projectObject( scene, camera, 0, _this.sortObjects );
  14717. if ( _this.sortObjects === true ) {
  14718. currentRenderList.sort();
  14719. }
  14720. //
  14721. if ( _clippingEnabled ) _clipping.beginShadows();
  14722. var shadowsArray = currentRenderState.state.shadowsArray;
  14723. shadowMap.render( shadowsArray, scene, camera );
  14724. currentRenderState.setupLights( camera );
  14725. if ( _clippingEnabled ) _clipping.endShadows();
  14726. //
  14727. if ( this.info.autoReset ) this.info.reset();
  14728. if ( renderTarget !== undefined ) {
  14729. this.setRenderTarget( renderTarget );
  14730. }
  14731. if ( vr.enabled && multiview.isAvailable() ) {
  14732. multiview.attachCamera( camera );
  14733. }
  14734. //
  14735. background.render( currentRenderList, scene, camera, forceClear );
  14736. // render scene
  14737. var opaqueObjects = currentRenderList.opaque;
  14738. var transparentObjects = currentRenderList.transparent;
  14739. if ( scene.overrideMaterial ) {
  14740. var overrideMaterial = scene.overrideMaterial;
  14741. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14742. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14743. } else {
  14744. // opaque pass (front-to-back order)
  14745. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14746. // transparent pass (back-to-front order)
  14747. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14748. }
  14749. //
  14750. scene.onAfterRender( _this, scene, camera );
  14751. //
  14752. if ( _currentRenderTarget !== null ) {
  14753. // Generate mipmap if we're using any kind of mipmap filtering
  14754. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14755. // resolve multisample renderbuffers to a single-sample texture if necessary
  14756. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14757. }
  14758. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14759. state.buffers.depth.setTest( true );
  14760. state.buffers.depth.setMask( true );
  14761. state.buffers.color.setMask( true );
  14762. state.setPolygonOffset( false );
  14763. if ( vr.enabled ) {
  14764. if ( multiview.isAvailable() ) {
  14765. multiview.detachCamera( camera );
  14766. }
  14767. vr.submitFrame();
  14768. }
  14769. // _gl.finish();
  14770. currentRenderList = null;
  14771. currentRenderState = null;
  14772. };
  14773. function projectObject( object, camera, groupOrder, sortObjects ) {
  14774. if ( object.visible === false ) return;
  14775. var visible = object.layers.test( camera.layers );
  14776. if ( visible ) {
  14777. if ( object.isGroup ) {
  14778. groupOrder = object.renderOrder;
  14779. } else if ( object.isLOD ) {
  14780. if ( object.autoUpdate === true ) object.update( camera );
  14781. } else if ( object.isLight ) {
  14782. currentRenderState.pushLight( object );
  14783. if ( object.castShadow ) {
  14784. currentRenderState.pushShadow( object );
  14785. }
  14786. } else if ( object.isSprite ) {
  14787. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14788. if ( sortObjects ) {
  14789. _vector3.setFromMatrixPosition( object.matrixWorld )
  14790. .applyMatrix4( _projScreenMatrix );
  14791. }
  14792. var geometry = objects.update( object );
  14793. var material = object.material;
  14794. if ( material.visible ) {
  14795. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14796. }
  14797. }
  14798. } else if ( object.isImmediateRenderObject ) {
  14799. if ( sortObjects ) {
  14800. _vector3.setFromMatrixPosition( object.matrixWorld )
  14801. .applyMatrix4( _projScreenMatrix );
  14802. }
  14803. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14804. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14805. if ( object.isSkinnedMesh ) {
  14806. // update skeleton only once in a frame
  14807. if ( object.skeleton.frame !== info.render.frame ) {
  14808. object.skeleton.update();
  14809. object.skeleton.frame = info.render.frame;
  14810. }
  14811. }
  14812. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14813. if ( sortObjects ) {
  14814. _vector3.setFromMatrixPosition( object.matrixWorld )
  14815. .applyMatrix4( _projScreenMatrix );
  14816. }
  14817. var geometry = objects.update( object );
  14818. var material = object.material;
  14819. if ( Array.isArray( material ) ) {
  14820. var groups = geometry.groups;
  14821. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14822. var group = groups[ i ];
  14823. var groupMaterial = material[ group.materialIndex ];
  14824. if ( groupMaterial && groupMaterial.visible ) {
  14825. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14826. }
  14827. }
  14828. } else if ( material.visible ) {
  14829. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14830. }
  14831. }
  14832. }
  14833. }
  14834. var children = object.children;
  14835. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14836. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14837. }
  14838. }
  14839. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14840. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14841. var renderItem = renderList[ i ];
  14842. var object = renderItem.object;
  14843. var geometry = renderItem.geometry;
  14844. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14845. var group = renderItem.group;
  14846. if ( camera.isArrayCamera ) {
  14847. _currentArrayCamera = camera;
  14848. if ( vr.enabled && multiview.isAvailable() ) {
  14849. renderObject( object, scene, camera, geometry, material, group );
  14850. } else {
  14851. var cameras = camera.cameras;
  14852. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14853. var camera2 = cameras[ j ];
  14854. if ( object.layers.test( camera2.layers ) ) {
  14855. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14856. currentRenderState.setupLights( camera2 );
  14857. renderObject( object, scene, camera2, geometry, material, group );
  14858. }
  14859. }
  14860. }
  14861. } else {
  14862. _currentArrayCamera = null;
  14863. renderObject( object, scene, camera, geometry, material, group );
  14864. }
  14865. }
  14866. }
  14867. function renderObject( object, scene, camera, geometry, material, group ) {
  14868. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14869. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14870. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14871. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14872. if ( object.isImmediateRenderObject ) {
  14873. state.setMaterial( material );
  14874. var program = setProgram( camera, scene.fog, material, object );
  14875. _currentGeometryProgram.geometry = null;
  14876. _currentGeometryProgram.program = null;
  14877. _currentGeometryProgram.wireframe = false;
  14878. renderObjectImmediate( object, program );
  14879. } else {
  14880. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14881. }
  14882. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14883. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14884. }
  14885. function initMaterial( material, fog, object ) {
  14886. var materialProperties = properties.get( material );
  14887. var lights = currentRenderState.state.lights;
  14888. var shadowsArray = currentRenderState.state.shadowsArray;
  14889. var lightsStateVersion = lights.state.version;
  14890. var parameters = programCache.getParameters(
  14891. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14892. var programCacheKey = programCache.getProgramCacheKey( material, parameters );
  14893. var program = materialProperties.program;
  14894. var programChange = true;
  14895. if ( program === undefined ) {
  14896. // new material
  14897. material.addEventListener( 'dispose', onMaterialDispose );
  14898. } else if ( program.cacheKey !== programCacheKey ) {
  14899. // changed glsl or parameters
  14900. releaseMaterialProgramReference( material );
  14901. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  14902. materialProperties.lightsStateVersion = lightsStateVersion;
  14903. programChange = false;
  14904. } else if ( parameters.shaderID !== undefined ) {
  14905. // same glsl and uniform list
  14906. return;
  14907. } else {
  14908. // only rebuild uniform list
  14909. programChange = false;
  14910. }
  14911. if ( programChange ) {
  14912. if ( parameters.shaderID ) {
  14913. var shader = ShaderLib[ parameters.shaderID ];
  14914. materialProperties.shader = {
  14915. name: material.type,
  14916. uniforms: cloneUniforms( shader.uniforms ),
  14917. vertexShader: shader.vertexShader,
  14918. fragmentShader: shader.fragmentShader
  14919. };
  14920. } else {
  14921. materialProperties.shader = {
  14922. name: material.type,
  14923. uniforms: material.uniforms,
  14924. vertexShader: material.vertexShader,
  14925. fragmentShader: material.fragmentShader
  14926. };
  14927. }
  14928. material.onBeforeCompile( materialProperties.shader, _this );
  14929. // Computing cache key again as onBeforeCompile may have changed the shaders
  14930. programCacheKey = programCache.getProgramCacheKey( material, parameters );
  14931. program = programCache.acquireProgram( material, materialProperties.shader, parameters, programCacheKey );
  14932. materialProperties.program = program;
  14933. material.program = program;
  14934. }
  14935. var programAttributes = program.getAttributes();
  14936. if ( material.morphTargets ) {
  14937. material.numSupportedMorphTargets = 0;
  14938. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14939. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14940. material.numSupportedMorphTargets ++;
  14941. }
  14942. }
  14943. }
  14944. if ( material.morphNormals ) {
  14945. material.numSupportedMorphNormals = 0;
  14946. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14947. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14948. material.numSupportedMorphNormals ++;
  14949. }
  14950. }
  14951. }
  14952. var uniforms = materialProperties.shader.uniforms;
  14953. if ( ! material.isShaderMaterial &&
  14954. ! material.isRawShaderMaterial ||
  14955. material.clipping === true ) {
  14956. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14957. materialProperties.numIntersection = _clipping.numIntersection;
  14958. uniforms.clippingPlanes = _clipping.uniform;
  14959. }
  14960. materialProperties.fog = fog;
  14961. // store the light setup it was created for
  14962. materialProperties.needsLights = materialNeedsLights( material );
  14963. materialProperties.lightsStateVersion = lightsStateVersion;
  14964. if ( materialProperties.needsLights ) {
  14965. // wire up the material to this renderer's lighting state
  14966. uniforms.ambientLightColor.value = lights.state.ambient;
  14967. uniforms.lightProbe.value = lights.state.probe;
  14968. uniforms.directionalLights.value = lights.state.directional;
  14969. uniforms.spotLights.value = lights.state.spot;
  14970. uniforms.rectAreaLights.value = lights.state.rectArea;
  14971. uniforms.pointLights.value = lights.state.point;
  14972. uniforms.hemisphereLights.value = lights.state.hemi;
  14973. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14974. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14975. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14976. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14977. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14978. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14979. // TODO (abelnation): add area lights shadow info to uniforms
  14980. }
  14981. var progUniforms = materialProperties.program.getUniforms(),
  14982. uniformsList =
  14983. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14984. materialProperties.uniformsList = uniformsList;
  14985. }
  14986. function setProgram( camera, fog, material, object ) {
  14987. textures.resetTextureUnits();
  14988. var materialProperties = properties.get( material );
  14989. var lights = currentRenderState.state.lights;
  14990. if ( _clippingEnabled ) {
  14991. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14992. var useCache =
  14993. camera === _currentCamera &&
  14994. material.id === _currentMaterialId;
  14995. // we might want to call this function with some ClippingGroup
  14996. // object instead of the material, once it becomes feasible
  14997. // (#8465, #8379)
  14998. _clipping.setState(
  14999. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  15000. camera, materialProperties, useCache );
  15001. }
  15002. }
  15003. if ( material.version === materialProperties.__version ) {
  15004. if ( materialProperties.program === undefined ) {
  15005. material.needsUpdate = true;
  15006. } else if ( material.fog && materialProperties.fog !== fog ) {
  15007. material.needsUpdate = true;
  15008. } else if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  15009. material.needsUpdate = true;
  15010. } else if ( materialProperties.numClippingPlanes !== undefined &&
  15011. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  15012. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  15013. material.needsUpdate = true;
  15014. }
  15015. }
  15016. if ( material.version !== materialProperties.__version ) {
  15017. initMaterial( material, fog, object );
  15018. materialProperties.__version = material.version;
  15019. }
  15020. var refreshProgram = false;
  15021. var refreshMaterial = false;
  15022. var refreshLights = false;
  15023. var program = materialProperties.program,
  15024. p_uniforms = program.getUniforms(),
  15025. m_uniforms = materialProperties.shader.uniforms;
  15026. if ( state.useProgram( program.program ) ) {
  15027. refreshProgram = true;
  15028. refreshMaterial = true;
  15029. refreshLights = true;
  15030. }
  15031. if ( material.id !== _currentMaterialId ) {
  15032. _currentMaterialId = material.id;
  15033. refreshMaterial = true;
  15034. }
  15035. if ( refreshProgram || _currentCamera !== camera ) {
  15036. if ( program.numMultiviewViews > 0 ) {
  15037. multiview.updateCameraProjectionMatricesUniform( camera, p_uniforms );
  15038. } else {
  15039. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  15040. }
  15041. if ( capabilities.logarithmicDepthBuffer ) {
  15042. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15043. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15044. }
  15045. if ( _currentCamera !== camera ) {
  15046. _currentCamera = camera;
  15047. // lighting uniforms depend on the camera so enforce an update
  15048. // now, in case this material supports lights - or later, when
  15049. // the next material that does gets activated:
  15050. refreshMaterial = true; // set to true on material change
  15051. refreshLights = true; // remains set until update done
  15052. }
  15053. // load material specific uniforms
  15054. // (shader material also gets them for the sake of genericity)
  15055. if ( material.isShaderMaterial ||
  15056. material.isMeshPhongMaterial ||
  15057. material.isMeshStandardMaterial ||
  15058. material.envMap ) {
  15059. var uCamPos = p_uniforms.map.cameraPosition;
  15060. if ( uCamPos !== undefined ) {
  15061. uCamPos.setValue( _gl,
  15062. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15063. }
  15064. }
  15065. if ( material.isMeshPhongMaterial ||
  15066. material.isMeshLambertMaterial ||
  15067. material.isMeshBasicMaterial ||
  15068. material.isMeshStandardMaterial ||
  15069. material.isShaderMaterial ) {
  15070. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  15071. }
  15072. if ( material.isMeshPhongMaterial ||
  15073. material.isMeshLambertMaterial ||
  15074. material.isMeshBasicMaterial ||
  15075. material.isMeshStandardMaterial ||
  15076. material.isShaderMaterial ||
  15077. material.skinning ) {
  15078. if ( program.numMultiviewViews > 0 ) {
  15079. multiview.updateCameraViewMatricesUniform( camera, p_uniforms );
  15080. } else {
  15081. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15082. }
  15083. }
  15084. }
  15085. // skinning uniforms must be set even if material didn't change
  15086. // auto-setting of texture unit for bone texture must go before other textures
  15087. // not sure why, but otherwise weird things happen
  15088. if ( material.skinning ) {
  15089. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15090. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15091. var skeleton = object.skeleton;
  15092. if ( skeleton ) {
  15093. var bones = skeleton.bones;
  15094. if ( capabilities.floatVertexTextures ) {
  15095. if ( skeleton.boneTexture === undefined ) {
  15096. // layout (1 matrix = 4 pixels)
  15097. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15098. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15099. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15100. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15101. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15102. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  15103. size = _Math.ceilPowerOfTwo( size );
  15104. size = Math.max( size, 4 );
  15105. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  15106. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  15107. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  15108. skeleton.boneMatrices = boneMatrices;
  15109. skeleton.boneTexture = boneTexture;
  15110. skeleton.boneTextureSize = size;
  15111. }
  15112. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  15113. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  15114. } else {
  15115. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15116. }
  15117. }
  15118. }
  15119. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  15120. materialProperties.receiveShadow = object.receiveShadow;
  15121. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  15122. }
  15123. if ( refreshMaterial ) {
  15124. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  15125. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  15126. if ( materialProperties.needsLights ) {
  15127. // the current material requires lighting info
  15128. // note: all lighting uniforms are always set correctly
  15129. // they simply reference the renderer's state for their
  15130. // values
  15131. //
  15132. // use the current material's .needsUpdate flags to set
  15133. // the GL state when required
  15134. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15135. }
  15136. // refresh uniforms common to several materials
  15137. if ( fog && material.fog ) {
  15138. refreshUniformsFog( m_uniforms, fog );
  15139. }
  15140. if ( material.isMeshBasicMaterial ) {
  15141. refreshUniformsCommon( m_uniforms, material );
  15142. } else if ( material.isMeshLambertMaterial ) {
  15143. refreshUniformsCommon( m_uniforms, material );
  15144. refreshUniformsLambert( m_uniforms, material );
  15145. } else if ( material.isMeshPhongMaterial ) {
  15146. refreshUniformsCommon( m_uniforms, material );
  15147. if ( material.isMeshToonMaterial ) {
  15148. refreshUniformsToon( m_uniforms, material );
  15149. } else {
  15150. refreshUniformsPhong( m_uniforms, material );
  15151. }
  15152. } else if ( material.isMeshStandardMaterial ) {
  15153. refreshUniformsCommon( m_uniforms, material );
  15154. if ( material.isMeshPhysicalMaterial ) {
  15155. refreshUniformsPhysical( m_uniforms, material );
  15156. } else {
  15157. refreshUniformsStandard( m_uniforms, material );
  15158. }
  15159. } else if ( material.isMeshMatcapMaterial ) {
  15160. refreshUniformsCommon( m_uniforms, material );
  15161. refreshUniformsMatcap( m_uniforms, material );
  15162. } else if ( material.isMeshDepthMaterial ) {
  15163. refreshUniformsCommon( m_uniforms, material );
  15164. refreshUniformsDepth( m_uniforms, material );
  15165. } else if ( material.isMeshDistanceMaterial ) {
  15166. refreshUniformsCommon( m_uniforms, material );
  15167. refreshUniformsDistance( m_uniforms, material );
  15168. } else if ( material.isMeshNormalMaterial ) {
  15169. refreshUniformsCommon( m_uniforms, material );
  15170. refreshUniformsNormal( m_uniforms, material );
  15171. } else if ( material.isLineBasicMaterial ) {
  15172. refreshUniformsLine( m_uniforms, material );
  15173. if ( material.isLineDashedMaterial ) {
  15174. refreshUniformsDash( m_uniforms, material );
  15175. }
  15176. } else if ( material.isPointsMaterial ) {
  15177. refreshUniformsPoints( m_uniforms, material );
  15178. } else if ( material.isSpriteMaterial ) {
  15179. refreshUniformsSprites( m_uniforms, material );
  15180. } else if ( material.isShadowMaterial ) {
  15181. m_uniforms.color.value.copy( material.color );
  15182. m_uniforms.opacity.value = material.opacity;
  15183. }
  15184. // RectAreaLight Texture
  15185. // TODO (mrdoob): Find a nicer implementation
  15186. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  15187. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  15188. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15189. if ( material.isShaderMaterial ) {
  15190. material.uniformsNeedUpdate = false; // #15581
  15191. }
  15192. }
  15193. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  15194. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15195. material.uniformsNeedUpdate = false;
  15196. }
  15197. if ( material.isSpriteMaterial ) {
  15198. p_uniforms.setValue( _gl, 'center', object.center );
  15199. }
  15200. // common matrices
  15201. if ( program.numMultiviewViews > 0 ) {
  15202. multiview.updateObjectMatricesUniforms( object, camera, p_uniforms );
  15203. } else {
  15204. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  15205. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  15206. }
  15207. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15208. return program;
  15209. }
  15210. // Uniforms (refresh uniforms objects)
  15211. function refreshUniformsCommon( uniforms, material ) {
  15212. uniforms.opacity.value = material.opacity;
  15213. if ( material.color ) {
  15214. uniforms.diffuse.value.copy( material.color );
  15215. }
  15216. if ( material.emissive ) {
  15217. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15218. }
  15219. if ( material.map ) {
  15220. uniforms.map.value = material.map;
  15221. }
  15222. if ( material.alphaMap ) {
  15223. uniforms.alphaMap.value = material.alphaMap;
  15224. }
  15225. if ( material.specularMap ) {
  15226. uniforms.specularMap.value = material.specularMap;
  15227. }
  15228. if ( material.envMap ) {
  15229. uniforms.envMap.value = material.envMap;
  15230. // don't flip CubeTexture envMaps, flip everything else:
  15231. // WebGLRenderTargetCube will be flipped for backwards compatibility
  15232. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  15233. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  15234. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  15235. uniforms.reflectivity.value = material.reflectivity;
  15236. uniforms.refractionRatio.value = material.refractionRatio;
  15237. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  15238. }
  15239. if ( material.lightMap ) {
  15240. uniforms.lightMap.value = material.lightMap;
  15241. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15242. }
  15243. if ( material.aoMap ) {
  15244. uniforms.aoMap.value = material.aoMap;
  15245. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15246. }
  15247. // uv repeat and offset setting priorities
  15248. // 1. color map
  15249. // 2. specular map
  15250. // 3. normal map
  15251. // 4. bump map
  15252. // 5. alpha map
  15253. // 6. emissive map
  15254. var uvScaleMap;
  15255. if ( material.map ) {
  15256. uvScaleMap = material.map;
  15257. } else if ( material.specularMap ) {
  15258. uvScaleMap = material.specularMap;
  15259. } else if ( material.displacementMap ) {
  15260. uvScaleMap = material.displacementMap;
  15261. } else if ( material.normalMap ) {
  15262. uvScaleMap = material.normalMap;
  15263. } else if ( material.bumpMap ) {
  15264. uvScaleMap = material.bumpMap;
  15265. } else if ( material.roughnessMap ) {
  15266. uvScaleMap = material.roughnessMap;
  15267. } else if ( material.metalnessMap ) {
  15268. uvScaleMap = material.metalnessMap;
  15269. } else if ( material.alphaMap ) {
  15270. uvScaleMap = material.alphaMap;
  15271. } else if ( material.emissiveMap ) {
  15272. uvScaleMap = material.emissiveMap;
  15273. }
  15274. if ( uvScaleMap !== undefined ) {
  15275. // backwards compatibility
  15276. if ( uvScaleMap.isWebGLRenderTarget ) {
  15277. uvScaleMap = uvScaleMap.texture;
  15278. }
  15279. if ( uvScaleMap.matrixAutoUpdate === true ) {
  15280. uvScaleMap.updateMatrix();
  15281. }
  15282. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  15283. }
  15284. }
  15285. function refreshUniformsLine( uniforms, material ) {
  15286. uniforms.diffuse.value.copy( material.color );
  15287. uniforms.opacity.value = material.opacity;
  15288. }
  15289. function refreshUniformsDash( uniforms, material ) {
  15290. uniforms.dashSize.value = material.dashSize;
  15291. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15292. uniforms.scale.value = material.scale;
  15293. }
  15294. function refreshUniformsPoints( uniforms, material ) {
  15295. uniforms.diffuse.value.copy( material.color );
  15296. uniforms.opacity.value = material.opacity;
  15297. uniforms.size.value = material.size * _pixelRatio;
  15298. uniforms.scale.value = _height * 0.5;
  15299. if ( material.map ) {
  15300. uniforms.map.value = material.map;
  15301. }
  15302. if ( material.alphaMap ) {
  15303. uniforms.alphaMap.value = material.alphaMap;
  15304. }
  15305. // uv repeat and offset setting priorities
  15306. // 1. color map
  15307. // 2. alpha map
  15308. var uvScaleMap;
  15309. if ( material.map ) {
  15310. uvScaleMap = material.map;
  15311. } else if ( material.alphaMap ) {
  15312. uvScaleMap = material.alphaMap;
  15313. }
  15314. if ( uvScaleMap !== undefined ) {
  15315. if ( uvScaleMap.matrixAutoUpdate === true ) {
  15316. uvScaleMap.updateMatrix();
  15317. }
  15318. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  15319. }
  15320. }
  15321. function refreshUniformsSprites( uniforms, material ) {
  15322. uniforms.diffuse.value.copy( material.color );
  15323. uniforms.opacity.value = material.opacity;
  15324. uniforms.rotation.value = material.rotation;
  15325. if ( material.map ) {
  15326. uniforms.map.value = material.map;
  15327. }
  15328. if ( material.alphaMap ) {
  15329. uniforms.alphaMap.value = material.alphaMap;
  15330. }
  15331. // uv repeat and offset setting priorities
  15332. // 1. color map
  15333. // 2. alpha map
  15334. var uvScaleMap;
  15335. if ( material.map ) {
  15336. uvScaleMap = material.map;
  15337. } else if ( material.alphaMap ) {
  15338. uvScaleMap = material.alphaMap;
  15339. }
  15340. if ( uvScaleMap !== undefined ) {
  15341. if ( uvScaleMap.matrixAutoUpdate === true ) {
  15342. uvScaleMap.updateMatrix();
  15343. }
  15344. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  15345. }
  15346. }
  15347. function refreshUniformsFog( uniforms, fog ) {
  15348. uniforms.fogColor.value.copy( fog.color );
  15349. if ( fog.isFog ) {
  15350. uniforms.fogNear.value = fog.near;
  15351. uniforms.fogFar.value = fog.far;
  15352. } else if ( fog.isFogExp2 ) {
  15353. uniforms.fogDensity.value = fog.density;
  15354. }
  15355. }
  15356. function refreshUniformsLambert( uniforms, material ) {
  15357. if ( material.emissiveMap ) {
  15358. uniforms.emissiveMap.value = material.emissiveMap;
  15359. }
  15360. }
  15361. function refreshUniformsPhong( uniforms, material ) {
  15362. uniforms.specular.value.copy( material.specular );
  15363. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15364. if ( material.emissiveMap ) {
  15365. uniforms.emissiveMap.value = material.emissiveMap;
  15366. }
  15367. if ( material.bumpMap ) {
  15368. uniforms.bumpMap.value = material.bumpMap;
  15369. uniforms.bumpScale.value = material.bumpScale;
  15370. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15371. }
  15372. if ( material.normalMap ) {
  15373. uniforms.normalMap.value = material.normalMap;
  15374. uniforms.normalScale.value.copy( material.normalScale );
  15375. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15376. }
  15377. if ( material.displacementMap ) {
  15378. uniforms.displacementMap.value = material.displacementMap;
  15379. uniforms.displacementScale.value = material.displacementScale;
  15380. uniforms.displacementBias.value = material.displacementBias;
  15381. }
  15382. }
  15383. function refreshUniformsToon( uniforms, material ) {
  15384. refreshUniformsPhong( uniforms, material );
  15385. if ( material.gradientMap ) {
  15386. uniforms.gradientMap.value = material.gradientMap;
  15387. }
  15388. }
  15389. function refreshUniformsStandard( uniforms, material ) {
  15390. uniforms.roughness.value = material.roughness;
  15391. uniforms.metalness.value = material.metalness;
  15392. if ( material.roughnessMap ) {
  15393. uniforms.roughnessMap.value = material.roughnessMap;
  15394. }
  15395. if ( material.metalnessMap ) {
  15396. uniforms.metalnessMap.value = material.metalnessMap;
  15397. }
  15398. if ( material.emissiveMap ) {
  15399. uniforms.emissiveMap.value = material.emissiveMap;
  15400. }
  15401. if ( material.bumpMap ) {
  15402. uniforms.bumpMap.value = material.bumpMap;
  15403. uniforms.bumpScale.value = material.bumpScale;
  15404. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15405. }
  15406. if ( material.normalMap ) {
  15407. uniforms.normalMap.value = material.normalMap;
  15408. uniforms.normalScale.value.copy( material.normalScale );
  15409. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15410. }
  15411. if ( material.displacementMap ) {
  15412. uniforms.displacementMap.value = material.displacementMap;
  15413. uniforms.displacementScale.value = material.displacementScale;
  15414. uniforms.displacementBias.value = material.displacementBias;
  15415. }
  15416. if ( material.envMap ) {
  15417. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15418. uniforms.envMapIntensity.value = material.envMapIntensity;
  15419. }
  15420. }
  15421. function refreshUniformsPhysical( uniforms, material ) {
  15422. refreshUniformsStandard( uniforms, material );
  15423. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  15424. uniforms.clearcoat.value = material.clearcoat;
  15425. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  15426. if ( material.sheen ) uniforms.sheen.value.copy( material.sheen );
  15427. if ( material.clearcoatNormalMap ) {
  15428. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  15429. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  15430. if ( material.side === BackSide ) {
  15431. uniforms.clearcoatNormalScale.value.negate();
  15432. }
  15433. }
  15434. uniforms.transparency.value = material.transparency;
  15435. }
  15436. function refreshUniformsMatcap( uniforms, material ) {
  15437. if ( material.matcap ) {
  15438. uniforms.matcap.value = material.matcap;
  15439. }
  15440. if ( material.bumpMap ) {
  15441. uniforms.bumpMap.value = material.bumpMap;
  15442. uniforms.bumpScale.value = material.bumpScale;
  15443. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15444. }
  15445. if ( material.normalMap ) {
  15446. uniforms.normalMap.value = material.normalMap;
  15447. uniforms.normalScale.value.copy( material.normalScale );
  15448. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15449. }
  15450. if ( material.displacementMap ) {
  15451. uniforms.displacementMap.value = material.displacementMap;
  15452. uniforms.displacementScale.value = material.displacementScale;
  15453. uniforms.displacementBias.value = material.displacementBias;
  15454. }
  15455. }
  15456. function refreshUniformsDepth( uniforms, material ) {
  15457. if ( material.displacementMap ) {
  15458. uniforms.displacementMap.value = material.displacementMap;
  15459. uniforms.displacementScale.value = material.displacementScale;
  15460. uniforms.displacementBias.value = material.displacementBias;
  15461. }
  15462. }
  15463. function refreshUniformsDistance( uniforms, material ) {
  15464. if ( material.displacementMap ) {
  15465. uniforms.displacementMap.value = material.displacementMap;
  15466. uniforms.displacementScale.value = material.displacementScale;
  15467. uniforms.displacementBias.value = material.displacementBias;
  15468. }
  15469. uniforms.referencePosition.value.copy( material.referencePosition );
  15470. uniforms.nearDistance.value = material.nearDistance;
  15471. uniforms.farDistance.value = material.farDistance;
  15472. }
  15473. function refreshUniformsNormal( uniforms, material ) {
  15474. if ( material.bumpMap ) {
  15475. uniforms.bumpMap.value = material.bumpMap;
  15476. uniforms.bumpScale.value = material.bumpScale;
  15477. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15478. }
  15479. if ( material.normalMap ) {
  15480. uniforms.normalMap.value = material.normalMap;
  15481. uniforms.normalScale.value.copy( material.normalScale );
  15482. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15483. }
  15484. if ( material.displacementMap ) {
  15485. uniforms.displacementMap.value = material.displacementMap;
  15486. uniforms.displacementScale.value = material.displacementScale;
  15487. uniforms.displacementBias.value = material.displacementBias;
  15488. }
  15489. }
  15490. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15491. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15492. uniforms.ambientLightColor.needsUpdate = value;
  15493. uniforms.lightProbe.needsUpdate = value;
  15494. uniforms.directionalLights.needsUpdate = value;
  15495. uniforms.pointLights.needsUpdate = value;
  15496. uniforms.spotLights.needsUpdate = value;
  15497. uniforms.rectAreaLights.needsUpdate = value;
  15498. uniforms.hemisphereLights.needsUpdate = value;
  15499. }
  15500. function materialNeedsLights( material ) {
  15501. return material.isMeshLambertMaterial || material.isMeshPhongMaterial ||
  15502. material.isMeshStandardMaterial || material.isShadowMaterial ||
  15503. ( material.isShaderMaterial && material.lights === true );
  15504. }
  15505. //
  15506. this.setFramebuffer = function ( value ) {
  15507. if ( _framebuffer !== value && _currentRenderTarget === null ) _gl.bindFramebuffer( 36160, value );
  15508. _framebuffer = value;
  15509. };
  15510. this.getActiveCubeFace = function () {
  15511. return _currentActiveCubeFace;
  15512. };
  15513. this.getActiveMipmapLevel = function () {
  15514. return _currentActiveMipmapLevel;
  15515. };
  15516. this.getRenderTarget = function () {
  15517. return _currentRenderTarget;
  15518. };
  15519. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15520. _currentRenderTarget = renderTarget;
  15521. _currentActiveCubeFace = activeCubeFace;
  15522. _currentActiveMipmapLevel = activeMipmapLevel;
  15523. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15524. textures.setupRenderTarget( renderTarget );
  15525. }
  15526. var framebuffer = _framebuffer;
  15527. var isCube = false;
  15528. if ( renderTarget ) {
  15529. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15530. if ( renderTarget.isWebGLRenderTargetCube ) {
  15531. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15532. isCube = true;
  15533. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15534. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15535. } else {
  15536. framebuffer = __webglFramebuffer;
  15537. }
  15538. _currentViewport.copy( renderTarget.viewport );
  15539. _currentScissor.copy( renderTarget.scissor );
  15540. _currentScissorTest = renderTarget.scissorTest;
  15541. } else {
  15542. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15543. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15544. _currentScissorTest = _scissorTest;
  15545. }
  15546. if ( _currentFramebuffer !== framebuffer ) {
  15547. _gl.bindFramebuffer( 36160, framebuffer );
  15548. _currentFramebuffer = framebuffer;
  15549. }
  15550. state.viewport( _currentViewport );
  15551. state.scissor( _currentScissor );
  15552. state.setScissorTest( _currentScissorTest );
  15553. if ( isCube ) {
  15554. var textureProperties = properties.get( renderTarget.texture );
  15555. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15556. }
  15557. };
  15558. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15559. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15560. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15561. return;
  15562. }
  15563. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15564. if ( renderTarget.isWebGLRenderTargetCube && activeCubeFaceIndex !== undefined ) {
  15565. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15566. }
  15567. if ( framebuffer ) {
  15568. var restore = false;
  15569. if ( framebuffer !== _currentFramebuffer ) {
  15570. _gl.bindFramebuffer( 36160, framebuffer );
  15571. restore = true;
  15572. }
  15573. try {
  15574. var texture = renderTarget.texture;
  15575. var textureFormat = texture.format;
  15576. var textureType = texture.type;
  15577. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15578. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15579. return;
  15580. }
  15581. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15582. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15583. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15584. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15585. return;
  15586. }
  15587. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15588. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15589. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15590. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15591. }
  15592. } else {
  15593. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15594. }
  15595. } finally {
  15596. if ( restore ) {
  15597. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15598. }
  15599. }
  15600. }
  15601. };
  15602. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15603. if ( level === undefined ) level = 0;
  15604. var levelScale = Math.pow( 2, - level );
  15605. var width = Math.floor( texture.image.width * levelScale );
  15606. var height = Math.floor( texture.image.height * levelScale );
  15607. var glFormat = utils.convert( texture.format );
  15608. textures.setTexture2D( texture, 0 );
  15609. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  15610. state.unbindTexture();
  15611. };
  15612. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15613. var width = srcTexture.image.width;
  15614. var height = srcTexture.image.height;
  15615. var glFormat = utils.convert( dstTexture.format );
  15616. var glType = utils.convert( dstTexture.type );
  15617. textures.setTexture2D( dstTexture, 0 );
  15618. if ( srcTexture.isDataTexture ) {
  15619. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15620. } else {
  15621. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  15622. }
  15623. state.unbindTexture();
  15624. };
  15625. this.initTexture = function ( texture ) {
  15626. textures.setTexture2D( texture, 0 );
  15627. state.unbindTexture();
  15628. };
  15629. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15630. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15631. }
  15632. }
  15633. /**
  15634. * @author mrdoob / http://mrdoob.com/
  15635. * @author alteredq / http://alteredqualia.com/
  15636. */
  15637. function FogExp2( color, density ) {
  15638. this.name = '';
  15639. this.color = new Color( color );
  15640. this.density = ( density !== undefined ) ? density : 0.00025;
  15641. }
  15642. Object.assign( FogExp2.prototype, {
  15643. isFogExp2: true,
  15644. clone: function () {
  15645. return new FogExp2( this.color, this.density );
  15646. },
  15647. toJSON: function ( /* meta */ ) {
  15648. return {
  15649. type: 'FogExp2',
  15650. color: this.color.getHex(),
  15651. density: this.density
  15652. };
  15653. }
  15654. } );
  15655. /**
  15656. * @author mrdoob / http://mrdoob.com/
  15657. * @author alteredq / http://alteredqualia.com/
  15658. */
  15659. function Fog( color, near, far ) {
  15660. this.name = '';
  15661. this.color = new Color( color );
  15662. this.near = ( near !== undefined ) ? near : 1;
  15663. this.far = ( far !== undefined ) ? far : 1000;
  15664. }
  15665. Object.assign( Fog.prototype, {
  15666. isFog: true,
  15667. clone: function () {
  15668. return new Fog( this.color, this.near, this.far );
  15669. },
  15670. toJSON: function ( /* meta */ ) {
  15671. return {
  15672. type: 'Fog',
  15673. color: this.color.getHex(),
  15674. near: this.near,
  15675. far: this.far
  15676. };
  15677. }
  15678. } );
  15679. /**
  15680. * @author benaadams / https://twitter.com/ben_a_adams
  15681. */
  15682. function InterleavedBuffer( array, stride ) {
  15683. this.array = array;
  15684. this.stride = stride;
  15685. this.count = array !== undefined ? array.length / stride : 0;
  15686. this.usage = StaticDrawUsage;
  15687. this.updateRange = { offset: 0, count: - 1 };
  15688. this.version = 0;
  15689. }
  15690. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15691. set: function ( value ) {
  15692. if ( value === true ) this.version ++;
  15693. }
  15694. } );
  15695. Object.assign( InterleavedBuffer.prototype, {
  15696. isInterleavedBuffer: true,
  15697. onUploadCallback: function () {},
  15698. setUsage: function ( value ) {
  15699. this.usage = value;
  15700. return this;
  15701. },
  15702. copy: function ( source ) {
  15703. this.array = new source.array.constructor( source.array );
  15704. this.count = source.count;
  15705. this.stride = source.stride;
  15706. this.usage = source.usage;
  15707. return this;
  15708. },
  15709. copyAt: function ( index1, attribute, index2 ) {
  15710. index1 *= this.stride;
  15711. index2 *= attribute.stride;
  15712. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15713. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15714. }
  15715. return this;
  15716. },
  15717. set: function ( value, offset ) {
  15718. if ( offset === undefined ) offset = 0;
  15719. this.array.set( value, offset );
  15720. return this;
  15721. },
  15722. clone: function () {
  15723. return new this.constructor().copy( this );
  15724. },
  15725. onUpload: function ( callback ) {
  15726. this.onUploadCallback = callback;
  15727. return this;
  15728. }
  15729. } );
  15730. /**
  15731. * @author benaadams / https://twitter.com/ben_a_adams
  15732. */
  15733. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15734. this.data = interleavedBuffer;
  15735. this.itemSize = itemSize;
  15736. this.offset = offset;
  15737. this.normalized = normalized === true;
  15738. }
  15739. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15740. count: {
  15741. get: function () {
  15742. return this.data.count;
  15743. }
  15744. },
  15745. array: {
  15746. get: function () {
  15747. return this.data.array;
  15748. }
  15749. }
  15750. } );
  15751. Object.assign( InterleavedBufferAttribute.prototype, {
  15752. isInterleavedBufferAttribute: true,
  15753. setX: function ( index, x ) {
  15754. this.data.array[ index * this.data.stride + this.offset ] = x;
  15755. return this;
  15756. },
  15757. setY: function ( index, y ) {
  15758. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15759. return this;
  15760. },
  15761. setZ: function ( index, z ) {
  15762. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15763. return this;
  15764. },
  15765. setW: function ( index, w ) {
  15766. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15767. return this;
  15768. },
  15769. getX: function ( index ) {
  15770. return this.data.array[ index * this.data.stride + this.offset ];
  15771. },
  15772. getY: function ( index ) {
  15773. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15774. },
  15775. getZ: function ( index ) {
  15776. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15777. },
  15778. getW: function ( index ) {
  15779. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15780. },
  15781. setXY: function ( index, x, y ) {
  15782. index = index * this.data.stride + this.offset;
  15783. this.data.array[ index + 0 ] = x;
  15784. this.data.array[ index + 1 ] = y;
  15785. return this;
  15786. },
  15787. setXYZ: function ( index, x, y, z ) {
  15788. index = index * this.data.stride + this.offset;
  15789. this.data.array[ index + 0 ] = x;
  15790. this.data.array[ index + 1 ] = y;
  15791. this.data.array[ index + 2 ] = z;
  15792. return this;
  15793. },
  15794. setXYZW: function ( index, x, y, z, w ) {
  15795. index = index * this.data.stride + this.offset;
  15796. this.data.array[ index + 0 ] = x;
  15797. this.data.array[ index + 1 ] = y;
  15798. this.data.array[ index + 2 ] = z;
  15799. this.data.array[ index + 3 ] = w;
  15800. return this;
  15801. }
  15802. } );
  15803. /**
  15804. * @author alteredq / http://alteredqualia.com/
  15805. *
  15806. * parameters = {
  15807. * color: <hex>,
  15808. * map: new THREE.Texture( <Image> ),
  15809. * alphaMap: new THREE.Texture( <Image> ),
  15810. * rotation: <float>,
  15811. * sizeAttenuation: <bool>
  15812. * }
  15813. */
  15814. function SpriteMaterial( parameters ) {
  15815. Material.call( this );
  15816. this.type = 'SpriteMaterial';
  15817. this.color = new Color( 0xffffff );
  15818. this.map = null;
  15819. this.alphaMap = null;
  15820. this.rotation = 0;
  15821. this.sizeAttenuation = true;
  15822. this.transparent = true;
  15823. this.setValues( parameters );
  15824. }
  15825. SpriteMaterial.prototype = Object.create( Material.prototype );
  15826. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15827. SpriteMaterial.prototype.isSpriteMaterial = true;
  15828. SpriteMaterial.prototype.copy = function ( source ) {
  15829. Material.prototype.copy.call( this, source );
  15830. this.color.copy( source.color );
  15831. this.map = source.map;
  15832. this.alphaMap = source.alphaMap;
  15833. this.rotation = source.rotation;
  15834. this.sizeAttenuation = source.sizeAttenuation;
  15835. return this;
  15836. };
  15837. /**
  15838. * @author mikael emtinger / http://gomo.se/
  15839. * @author alteredq / http://alteredqualia.com/
  15840. */
  15841. var _geometry;
  15842. var _intersectPoint = new Vector3();
  15843. var _worldScale = new Vector3();
  15844. var _mvPosition = new Vector3();
  15845. var _alignedPosition = new Vector2();
  15846. var _rotatedPosition = new Vector2();
  15847. var _viewWorldMatrix = new Matrix4();
  15848. var _vA$1 = new Vector3();
  15849. var _vB$1 = new Vector3();
  15850. var _vC$1 = new Vector3();
  15851. var _uvA$1 = new Vector2();
  15852. var _uvB$1 = new Vector2();
  15853. var _uvC$1 = new Vector2();
  15854. function Sprite( material ) {
  15855. Object3D.call( this );
  15856. this.type = 'Sprite';
  15857. if ( _geometry === undefined ) {
  15858. _geometry = new BufferGeometry();
  15859. var float32Array = new Float32Array( [
  15860. - 0.5, - 0.5, 0, 0, 0,
  15861. 0.5, - 0.5, 0, 1, 0,
  15862. 0.5, 0.5, 0, 1, 1,
  15863. - 0.5, 0.5, 0, 0, 1
  15864. ] );
  15865. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15866. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15867. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15868. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15869. }
  15870. this.geometry = _geometry;
  15871. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15872. this.center = new Vector2( 0.5, 0.5 );
  15873. }
  15874. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15875. constructor: Sprite,
  15876. isSprite: true,
  15877. raycast: function ( raycaster, intersects ) {
  15878. if ( raycaster.camera === null ) {
  15879. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  15880. }
  15881. _worldScale.setFromMatrixScale( this.matrixWorld );
  15882. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  15883. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  15884. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15885. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15886. _worldScale.multiplyScalar( - _mvPosition.z );
  15887. }
  15888. var rotation = this.material.rotation;
  15889. var sin, cos;
  15890. if ( rotation !== 0 ) {
  15891. cos = Math.cos( rotation );
  15892. sin = Math.sin( rotation );
  15893. }
  15894. var center = this.center;
  15895. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15896. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15897. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15898. _uvA$1.set( 0, 0 );
  15899. _uvB$1.set( 1, 0 );
  15900. _uvC$1.set( 1, 1 );
  15901. // check first triangle
  15902. var intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  15903. if ( intersect === null ) {
  15904. // check second triangle
  15905. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15906. _uvB$1.set( 0, 1 );
  15907. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  15908. if ( intersect === null ) {
  15909. return;
  15910. }
  15911. }
  15912. var distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  15913. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15914. intersects.push( {
  15915. distance: distance,
  15916. point: _intersectPoint.clone(),
  15917. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  15918. face: null,
  15919. object: this
  15920. } );
  15921. },
  15922. clone: function () {
  15923. return new this.constructor( this.material ).copy( this );
  15924. },
  15925. copy: function ( source ) {
  15926. Object3D.prototype.copy.call( this, source );
  15927. if ( source.center !== undefined ) this.center.copy( source.center );
  15928. return this;
  15929. }
  15930. } );
  15931. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15932. // compute position in camera space
  15933. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15934. // to check if rotation is not zero
  15935. if ( sin !== undefined ) {
  15936. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  15937. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  15938. } else {
  15939. _rotatedPosition.copy( _alignedPosition );
  15940. }
  15941. vertexPosition.copy( mvPosition );
  15942. vertexPosition.x += _rotatedPosition.x;
  15943. vertexPosition.y += _rotatedPosition.y;
  15944. // transform to world space
  15945. vertexPosition.applyMatrix4( _viewWorldMatrix );
  15946. }
  15947. /**
  15948. * @author mikael emtinger / http://gomo.se/
  15949. * @author alteredq / http://alteredqualia.com/
  15950. * @author mrdoob / http://mrdoob.com/
  15951. */
  15952. var _v1$4 = new Vector3();
  15953. var _v2$2 = new Vector3();
  15954. function LOD() {
  15955. Object3D.call( this );
  15956. this.type = 'LOD';
  15957. Object.defineProperties( this, {
  15958. levels: {
  15959. enumerable: true,
  15960. value: []
  15961. }
  15962. } );
  15963. this.autoUpdate = true;
  15964. }
  15965. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15966. constructor: LOD,
  15967. isLOD: true,
  15968. copy: function ( source ) {
  15969. Object3D.prototype.copy.call( this, source, false );
  15970. var levels = source.levels;
  15971. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15972. var level = levels[ i ];
  15973. this.addLevel( level.object.clone(), level.distance );
  15974. }
  15975. this.autoUpdate = source.autoUpdate;
  15976. return this;
  15977. },
  15978. addLevel: function ( object, distance ) {
  15979. if ( distance === undefined ) distance = 0;
  15980. distance = Math.abs( distance );
  15981. var levels = this.levels;
  15982. for ( var l = 0; l < levels.length; l ++ ) {
  15983. if ( distance < levels[ l ].distance ) {
  15984. break;
  15985. }
  15986. }
  15987. levels.splice( l, 0, { distance: distance, object: object } );
  15988. this.add( object );
  15989. return this;
  15990. },
  15991. getObjectForDistance: function ( distance ) {
  15992. var levels = this.levels;
  15993. if ( levels.length > 0 ) {
  15994. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15995. if ( distance < levels[ i ].distance ) {
  15996. break;
  15997. }
  15998. }
  15999. return levels[ i - 1 ].object;
  16000. }
  16001. return null;
  16002. },
  16003. raycast: function ( raycaster, intersects ) {
  16004. var levels = this.levels;
  16005. if ( levels.length > 0 ) {
  16006. _v1$4.setFromMatrixPosition( this.matrixWorld );
  16007. var distance = raycaster.ray.origin.distanceTo( _v1$4 );
  16008. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  16009. }
  16010. },
  16011. update: function ( camera ) {
  16012. var levels = this.levels;
  16013. if ( levels.length > 1 ) {
  16014. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  16015. _v2$2.setFromMatrixPosition( this.matrixWorld );
  16016. var distance = _v1$4.distanceTo( _v2$2 );
  16017. levels[ 0 ].object.visible = true;
  16018. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  16019. if ( distance >= levels[ i ].distance ) {
  16020. levels[ i - 1 ].object.visible = false;
  16021. levels[ i ].object.visible = true;
  16022. } else {
  16023. break;
  16024. }
  16025. }
  16026. for ( ; i < l; i ++ ) {
  16027. levels[ i ].object.visible = false;
  16028. }
  16029. }
  16030. },
  16031. toJSON: function ( meta ) {
  16032. var data = Object3D.prototype.toJSON.call( this, meta );
  16033. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  16034. data.object.levels = [];
  16035. var levels = this.levels;
  16036. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  16037. var level = levels[ i ];
  16038. data.object.levels.push( {
  16039. object: level.object.uuid,
  16040. distance: level.distance
  16041. } );
  16042. }
  16043. return data;
  16044. }
  16045. } );
  16046. /**
  16047. * @author mikael emtinger / http://gomo.se/
  16048. * @author alteredq / http://alteredqualia.com/
  16049. * @author ikerr / http://verold.com
  16050. */
  16051. function SkinnedMesh( geometry, material ) {
  16052. if ( geometry && geometry.isGeometry ) {
  16053. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16054. }
  16055. Mesh.call( this, geometry, material );
  16056. this.type = 'SkinnedMesh';
  16057. this.bindMode = 'attached';
  16058. this.bindMatrix = new Matrix4();
  16059. this.bindMatrixInverse = new Matrix4();
  16060. }
  16061. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16062. constructor: SkinnedMesh,
  16063. isSkinnedMesh: true,
  16064. bind: function ( skeleton, bindMatrix ) {
  16065. this.skeleton = skeleton;
  16066. if ( bindMatrix === undefined ) {
  16067. this.updateMatrixWorld( true );
  16068. this.skeleton.calculateInverses();
  16069. bindMatrix = this.matrixWorld;
  16070. }
  16071. this.bindMatrix.copy( bindMatrix );
  16072. this.bindMatrixInverse.getInverse( bindMatrix );
  16073. },
  16074. pose: function () {
  16075. this.skeleton.pose();
  16076. },
  16077. normalizeSkinWeights: function () {
  16078. var vector = new Vector4();
  16079. var skinWeight = this.geometry.attributes.skinWeight;
  16080. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  16081. vector.x = skinWeight.getX( i );
  16082. vector.y = skinWeight.getY( i );
  16083. vector.z = skinWeight.getZ( i );
  16084. vector.w = skinWeight.getW( i );
  16085. var scale = 1.0 / vector.manhattanLength();
  16086. if ( scale !== Infinity ) {
  16087. vector.multiplyScalar( scale );
  16088. } else {
  16089. vector.set( 1, 0, 0, 0 ); // do something reasonable
  16090. }
  16091. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  16092. }
  16093. },
  16094. updateMatrixWorld: function ( force ) {
  16095. Mesh.prototype.updateMatrixWorld.call( this, force );
  16096. if ( this.bindMode === 'attached' ) {
  16097. this.bindMatrixInverse.getInverse( this.matrixWorld );
  16098. } else if ( this.bindMode === 'detached' ) {
  16099. this.bindMatrixInverse.getInverse( this.bindMatrix );
  16100. } else {
  16101. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  16102. }
  16103. },
  16104. clone: function () {
  16105. return new this.constructor( this.geometry, this.material ).copy( this );
  16106. }
  16107. } );
  16108. /**
  16109. * @author mikael emtinger / http://gomo.se/
  16110. * @author alteredq / http://alteredqualia.com/
  16111. * @author michael guerrero / http://realitymeltdown.com
  16112. * @author ikerr / http://verold.com
  16113. */
  16114. var _offsetMatrix = new Matrix4();
  16115. var _identityMatrix = new Matrix4();
  16116. function Skeleton( bones, boneInverses ) {
  16117. // copy the bone array
  16118. bones = bones || [];
  16119. this.bones = bones.slice( 0 );
  16120. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  16121. this.frame = - 1;
  16122. // use the supplied bone inverses or calculate the inverses
  16123. if ( boneInverses === undefined ) {
  16124. this.calculateInverses();
  16125. } else {
  16126. if ( this.bones.length === boneInverses.length ) {
  16127. this.boneInverses = boneInverses.slice( 0 );
  16128. } else {
  16129. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  16130. this.boneInverses = [];
  16131. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16132. this.boneInverses.push( new Matrix4() );
  16133. }
  16134. }
  16135. }
  16136. }
  16137. Object.assign( Skeleton.prototype, {
  16138. calculateInverses: function () {
  16139. this.boneInverses = [];
  16140. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16141. var inverse = new Matrix4();
  16142. if ( this.bones[ i ] ) {
  16143. inverse.getInverse( this.bones[ i ].matrixWorld );
  16144. }
  16145. this.boneInverses.push( inverse );
  16146. }
  16147. },
  16148. pose: function () {
  16149. var bone, i, il;
  16150. // recover the bind-time world matrices
  16151. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  16152. bone = this.bones[ i ];
  16153. if ( bone ) {
  16154. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  16155. }
  16156. }
  16157. // compute the local matrices, positions, rotations and scales
  16158. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  16159. bone = this.bones[ i ];
  16160. if ( bone ) {
  16161. if ( bone.parent && bone.parent.isBone ) {
  16162. bone.matrix.getInverse( bone.parent.matrixWorld );
  16163. bone.matrix.multiply( bone.matrixWorld );
  16164. } else {
  16165. bone.matrix.copy( bone.matrixWorld );
  16166. }
  16167. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  16168. }
  16169. }
  16170. },
  16171. update: function () {
  16172. var bones = this.bones;
  16173. var boneInverses = this.boneInverses;
  16174. var boneMatrices = this.boneMatrices;
  16175. var boneTexture = this.boneTexture;
  16176. // flatten bone matrices to array
  16177. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  16178. // compute the offset between the current and the original transform
  16179. var matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  16180. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  16181. _offsetMatrix.toArray( boneMatrices, i * 16 );
  16182. }
  16183. if ( boneTexture !== undefined ) {
  16184. boneTexture.needsUpdate = true;
  16185. }
  16186. },
  16187. clone: function () {
  16188. return new Skeleton( this.bones, this.boneInverses );
  16189. },
  16190. getBoneByName: function ( name ) {
  16191. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  16192. var bone = this.bones[ i ];
  16193. if ( bone.name === name ) {
  16194. return bone;
  16195. }
  16196. }
  16197. return undefined;
  16198. }
  16199. } );
  16200. /**
  16201. * @author mikael emtinger / http://gomo.se/
  16202. * @author alteredq / http://alteredqualia.com/
  16203. * @author ikerr / http://verold.com
  16204. */
  16205. function Bone() {
  16206. Object3D.call( this );
  16207. this.type = 'Bone';
  16208. }
  16209. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16210. constructor: Bone,
  16211. isBone: true
  16212. } );
  16213. /**
  16214. * @author mrdoob / http://mrdoob.com/
  16215. */
  16216. var _instanceLocalMatrix = new Matrix4();
  16217. var _instanceWorldMatrix = new Matrix4();
  16218. var _instanceIntersects = [];
  16219. var _mesh = new Mesh();
  16220. function InstancedMesh( geometry, material, count ) {
  16221. Mesh.call( this, geometry, material );
  16222. this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
  16223. this.count = count;
  16224. }
  16225. InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16226. constructor: InstancedMesh,
  16227. isInstancedMesh: true,
  16228. getMatrixAt: function ( index, matrix ) {
  16229. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  16230. },
  16231. raycast: function ( raycaster, intersects ) {
  16232. var matrixWorld = this.matrixWorld;
  16233. var raycastTimes = this.count;
  16234. _mesh.geometry = this.geometry;
  16235. _mesh.material = this.material;
  16236. if ( _mesh.material === undefined ) return;
  16237. for ( var instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  16238. // calculate the world matrix for each instance
  16239. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  16240. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  16241. // the mesh represents this single instance
  16242. _mesh.matrixWorld = _instanceWorldMatrix;
  16243. _mesh.raycast( raycaster, _instanceIntersects );
  16244. // process the result of raycast
  16245. if ( _instanceIntersects.length > 0 ) {
  16246. _instanceIntersects[ 0 ].instanceId = instanceId;
  16247. _instanceIntersects[ 0 ].object = this;
  16248. intersects.push( _instanceIntersects[ 0 ] );
  16249. _instanceIntersects.length = 0;
  16250. }
  16251. }
  16252. },
  16253. setMatrixAt: function ( index, matrix ) {
  16254. matrix.toArray( this.instanceMatrix.array, index * 16 );
  16255. },
  16256. updateMorphTargets: function () {
  16257. }
  16258. } );
  16259. /**
  16260. * @author mrdoob / http://mrdoob.com/
  16261. * @author alteredq / http://alteredqualia.com/
  16262. *
  16263. * parameters = {
  16264. * color: <hex>,
  16265. * opacity: <float>,
  16266. *
  16267. * linewidth: <float>,
  16268. * linecap: "round",
  16269. * linejoin: "round"
  16270. * }
  16271. */
  16272. function LineBasicMaterial( parameters ) {
  16273. Material.call( this );
  16274. this.type = 'LineBasicMaterial';
  16275. this.color = new Color( 0xffffff );
  16276. this.linewidth = 1;
  16277. this.linecap = 'round';
  16278. this.linejoin = 'round';
  16279. this.setValues( parameters );
  16280. }
  16281. LineBasicMaterial.prototype = Object.create( Material.prototype );
  16282. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16283. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16284. LineBasicMaterial.prototype.copy = function ( source ) {
  16285. Material.prototype.copy.call( this, source );
  16286. this.color.copy( source.color );
  16287. this.linewidth = source.linewidth;
  16288. this.linecap = source.linecap;
  16289. this.linejoin = source.linejoin;
  16290. return this;
  16291. };
  16292. /**
  16293. * @author mrdoob / http://mrdoob.com/
  16294. */
  16295. var _start = new Vector3();
  16296. var _end = new Vector3();
  16297. var _inverseMatrix$1 = new Matrix4();
  16298. var _ray$1 = new Ray();
  16299. var _sphere$2 = new Sphere();
  16300. function Line( geometry, material, mode ) {
  16301. if ( mode === 1 ) {
  16302. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  16303. }
  16304. Object3D.call( this );
  16305. this.type = 'Line';
  16306. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16307. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  16308. }
  16309. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16310. constructor: Line,
  16311. isLine: true,
  16312. computeLineDistances: function () {
  16313. var geometry = this.geometry;
  16314. if ( geometry.isBufferGeometry ) {
  16315. // we assume non-indexed geometry
  16316. if ( geometry.index === null ) {
  16317. var positionAttribute = geometry.attributes.position;
  16318. var lineDistances = [ 0 ];
  16319. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  16320. _start.fromBufferAttribute( positionAttribute, i - 1 );
  16321. _end.fromBufferAttribute( positionAttribute, i );
  16322. lineDistances[ i ] = lineDistances[ i - 1 ];
  16323. lineDistances[ i ] += _start.distanceTo( _end );
  16324. }
  16325. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16326. } else {
  16327. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16328. }
  16329. } else if ( geometry.isGeometry ) {
  16330. var vertices = geometry.vertices;
  16331. var lineDistances = geometry.lineDistances;
  16332. lineDistances[ 0 ] = 0;
  16333. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  16334. lineDistances[ i ] = lineDistances[ i - 1 ];
  16335. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  16336. }
  16337. }
  16338. return this;
  16339. },
  16340. raycast: function ( raycaster, intersects ) {
  16341. var precision = raycaster.linePrecision;
  16342. var geometry = this.geometry;
  16343. var matrixWorld = this.matrixWorld;
  16344. // Checking boundingSphere distance to ray
  16345. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16346. _sphere$2.copy( geometry.boundingSphere );
  16347. _sphere$2.applyMatrix4( matrixWorld );
  16348. _sphere$2.radius += precision;
  16349. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
  16350. //
  16351. _inverseMatrix$1.getInverse( matrixWorld );
  16352. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  16353. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16354. var localPrecisionSq = localPrecision * localPrecision;
  16355. var vStart = new Vector3();
  16356. var vEnd = new Vector3();
  16357. var interSegment = new Vector3();
  16358. var interRay = new Vector3();
  16359. var step = ( this && this.isLineSegments ) ? 2 : 1;
  16360. if ( geometry.isBufferGeometry ) {
  16361. var index = geometry.index;
  16362. var attributes = geometry.attributes;
  16363. var positions = attributes.position.array;
  16364. if ( index !== null ) {
  16365. var indices = index.array;
  16366. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  16367. var a = indices[ i ];
  16368. var b = indices[ i + 1 ];
  16369. vStart.fromArray( positions, a * 3 );
  16370. vEnd.fromArray( positions, b * 3 );
  16371. var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16372. if ( distSq > localPrecisionSq ) continue;
  16373. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16374. var distance = raycaster.ray.origin.distanceTo( interRay );
  16375. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16376. intersects.push( {
  16377. distance: distance,
  16378. // What do we want? intersection point on the ray or on the segment??
  16379. // point: raycaster.ray.at( distance ),
  16380. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16381. index: i,
  16382. face: null,
  16383. faceIndex: null,
  16384. object: this
  16385. } );
  16386. }
  16387. } else {
  16388. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  16389. vStart.fromArray( positions, 3 * i );
  16390. vEnd.fromArray( positions, 3 * i + 3 );
  16391. var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16392. if ( distSq > localPrecisionSq ) continue;
  16393. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16394. var distance = raycaster.ray.origin.distanceTo( interRay );
  16395. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16396. intersects.push( {
  16397. distance: distance,
  16398. // What do we want? intersection point on the ray or on the segment??
  16399. // point: raycaster.ray.at( distance ),
  16400. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16401. index: i,
  16402. face: null,
  16403. faceIndex: null,
  16404. object: this
  16405. } );
  16406. }
  16407. }
  16408. } else if ( geometry.isGeometry ) {
  16409. var vertices = geometry.vertices;
  16410. var nbVertices = vertices.length;
  16411. for ( var i = 0; i < nbVertices - 1; i += step ) {
  16412. var distSq = _ray$1.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  16413. if ( distSq > localPrecisionSq ) continue;
  16414. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16415. var distance = raycaster.ray.origin.distanceTo( interRay );
  16416. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16417. intersects.push( {
  16418. distance: distance,
  16419. // What do we want? intersection point on the ray or on the segment??
  16420. // point: raycaster.ray.at( distance ),
  16421. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16422. index: i,
  16423. face: null,
  16424. faceIndex: null,
  16425. object: this
  16426. } );
  16427. }
  16428. }
  16429. },
  16430. clone: function () {
  16431. return new this.constructor( this.geometry, this.material ).copy( this );
  16432. }
  16433. } );
  16434. /**
  16435. * @author mrdoob / http://mrdoob.com/
  16436. */
  16437. var _start$1 = new Vector3();
  16438. var _end$1 = new Vector3();
  16439. function LineSegments( geometry, material ) {
  16440. Line.call( this, geometry, material );
  16441. this.type = 'LineSegments';
  16442. }
  16443. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16444. constructor: LineSegments,
  16445. isLineSegments: true,
  16446. computeLineDistances: function () {
  16447. var geometry = this.geometry;
  16448. if ( geometry.isBufferGeometry ) {
  16449. // we assume non-indexed geometry
  16450. if ( geometry.index === null ) {
  16451. var positionAttribute = geometry.attributes.position;
  16452. var lineDistances = [];
  16453. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16454. _start$1.fromBufferAttribute( positionAttribute, i );
  16455. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  16456. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16457. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16458. }
  16459. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16460. } else {
  16461. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16462. }
  16463. } else if ( geometry.isGeometry ) {
  16464. var vertices = geometry.vertices;
  16465. var lineDistances = geometry.lineDistances;
  16466. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  16467. _start$1.copy( vertices[ i ] );
  16468. _end$1.copy( vertices[ i + 1 ] );
  16469. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16470. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16471. }
  16472. }
  16473. return this;
  16474. }
  16475. } );
  16476. /**
  16477. * @author mgreter / http://github.com/mgreter
  16478. */
  16479. function LineLoop( geometry, material ) {
  16480. Line.call( this, geometry, material );
  16481. this.type = 'LineLoop';
  16482. }
  16483. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16484. constructor: LineLoop,
  16485. isLineLoop: true,
  16486. } );
  16487. /**
  16488. * @author mrdoob / http://mrdoob.com/
  16489. * @author alteredq / http://alteredqualia.com/
  16490. *
  16491. * parameters = {
  16492. * color: <hex>,
  16493. * opacity: <float>,
  16494. * map: new THREE.Texture( <Image> ),
  16495. * alphaMap: new THREE.Texture( <Image> ),
  16496. *
  16497. * size: <float>,
  16498. * sizeAttenuation: <bool>
  16499. *
  16500. * morphTargets: <bool>
  16501. * }
  16502. */
  16503. function PointsMaterial( parameters ) {
  16504. Material.call( this );
  16505. this.type = 'PointsMaterial';
  16506. this.color = new Color( 0xffffff );
  16507. this.map = null;
  16508. this.alphaMap = null;
  16509. this.size = 1;
  16510. this.sizeAttenuation = true;
  16511. this.morphTargets = false;
  16512. this.setValues( parameters );
  16513. }
  16514. PointsMaterial.prototype = Object.create( Material.prototype );
  16515. PointsMaterial.prototype.constructor = PointsMaterial;
  16516. PointsMaterial.prototype.isPointsMaterial = true;
  16517. PointsMaterial.prototype.copy = function ( source ) {
  16518. Material.prototype.copy.call( this, source );
  16519. this.color.copy( source.color );
  16520. this.map = source.map;
  16521. this.alphaMap = source.alphaMap;
  16522. this.size = source.size;
  16523. this.sizeAttenuation = source.sizeAttenuation;
  16524. this.morphTargets = source.morphTargets;
  16525. return this;
  16526. };
  16527. /**
  16528. * @author alteredq / http://alteredqualia.com/
  16529. */
  16530. var _inverseMatrix$2 = new Matrix4();
  16531. var _ray$2 = new Ray();
  16532. var _sphere$3 = new Sphere();
  16533. var _position$1 = new Vector3();
  16534. function Points( geometry, material ) {
  16535. Object3D.call( this );
  16536. this.type = 'Points';
  16537. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16538. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  16539. this.updateMorphTargets();
  16540. }
  16541. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16542. constructor: Points,
  16543. isPoints: true,
  16544. raycast: function ( raycaster, intersects ) {
  16545. var geometry = this.geometry;
  16546. var matrixWorld = this.matrixWorld;
  16547. var threshold = raycaster.params.Points.threshold;
  16548. // Checking boundingSphere distance to ray
  16549. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16550. _sphere$3.copy( geometry.boundingSphere );
  16551. _sphere$3.applyMatrix4( matrixWorld );
  16552. _sphere$3.radius += threshold;
  16553. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  16554. //
  16555. _inverseMatrix$2.getInverse( matrixWorld );
  16556. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  16557. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16558. var localThresholdSq = localThreshold * localThreshold;
  16559. if ( geometry.isBufferGeometry ) {
  16560. var index = geometry.index;
  16561. var attributes = geometry.attributes;
  16562. var positions = attributes.position.array;
  16563. if ( index !== null ) {
  16564. var indices = index.array;
  16565. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  16566. var a = indices[ i ];
  16567. _position$1.fromArray( positions, a * 3 );
  16568. testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16569. }
  16570. } else {
  16571. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  16572. _position$1.fromArray( positions, i * 3 );
  16573. testPoint( _position$1, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16574. }
  16575. }
  16576. } else {
  16577. var vertices = geometry.vertices;
  16578. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  16579. testPoint( vertices[ i ], i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16580. }
  16581. }
  16582. },
  16583. updateMorphTargets: function () {
  16584. var geometry = this.geometry;
  16585. var m, ml, name;
  16586. if ( geometry.isBufferGeometry ) {
  16587. var morphAttributes = geometry.morphAttributes;
  16588. var keys = Object.keys( morphAttributes );
  16589. if ( keys.length > 0 ) {
  16590. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16591. if ( morphAttribute !== undefined ) {
  16592. this.morphTargetInfluences = [];
  16593. this.morphTargetDictionary = {};
  16594. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16595. name = morphAttribute[ m ].name || String( m );
  16596. this.morphTargetInfluences.push( 0 );
  16597. this.morphTargetDictionary[ name ] = m;
  16598. }
  16599. }
  16600. }
  16601. } else {
  16602. var morphTargets = geometry.morphTargets;
  16603. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16604. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16605. }
  16606. }
  16607. },
  16608. clone: function () {
  16609. return new this.constructor( this.geometry, this.material ).copy( this );
  16610. }
  16611. } );
  16612. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  16613. var rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  16614. if ( rayPointDistanceSq < localThresholdSq ) {
  16615. var intersectPoint = new Vector3();
  16616. _ray$2.closestPointToPoint( point, intersectPoint );
  16617. intersectPoint.applyMatrix4( matrixWorld );
  16618. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16619. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16620. intersects.push( {
  16621. distance: distance,
  16622. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16623. point: intersectPoint,
  16624. index: index,
  16625. face: null,
  16626. object: object
  16627. } );
  16628. }
  16629. }
  16630. /**
  16631. * @author mrdoob / http://mrdoob.com/
  16632. */
  16633. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16634. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16635. this.format = format !== undefined ? format : RGBFormat;
  16636. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16637. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16638. this.generateMipmaps = false;
  16639. }
  16640. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16641. constructor: VideoTexture,
  16642. isVideoTexture: true,
  16643. update: function () {
  16644. var video = this.image;
  16645. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  16646. this.needsUpdate = true;
  16647. }
  16648. }
  16649. } );
  16650. /**
  16651. * @author alteredq / http://alteredqualia.com/
  16652. */
  16653. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16654. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16655. this.image = { width: width, height: height };
  16656. this.mipmaps = mipmaps;
  16657. // no flipping for cube textures
  16658. // (also flipping doesn't work for compressed textures )
  16659. this.flipY = false;
  16660. // can't generate mipmaps for compressed textures
  16661. // mips must be embedded in DDS files
  16662. this.generateMipmaps = false;
  16663. }
  16664. CompressedTexture.prototype = Object.create( Texture.prototype );
  16665. CompressedTexture.prototype.constructor = CompressedTexture;
  16666. CompressedTexture.prototype.isCompressedTexture = true;
  16667. /**
  16668. * @author mrdoob / http://mrdoob.com/
  16669. */
  16670. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16671. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16672. this.needsUpdate = true;
  16673. }
  16674. CanvasTexture.prototype = Object.create( Texture.prototype );
  16675. CanvasTexture.prototype.constructor = CanvasTexture;
  16676. CanvasTexture.prototype.isCanvasTexture = true;
  16677. /**
  16678. * @author Matt DesLauriers / @mattdesl
  16679. * @author atix / arthursilber.de
  16680. */
  16681. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16682. format = format !== undefined ? format : DepthFormat;
  16683. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16684. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16685. }
  16686. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16687. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16688. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16689. this.image = { width: width, height: height };
  16690. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16691. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16692. this.flipY = false;
  16693. this.generateMipmaps = false;
  16694. }
  16695. DepthTexture.prototype = Object.create( Texture.prototype );
  16696. DepthTexture.prototype.constructor = DepthTexture;
  16697. DepthTexture.prototype.isDepthTexture = true;
  16698. /**
  16699. * @author mrdoob / http://mrdoob.com/
  16700. * @author Mugen87 / https://github.com/Mugen87
  16701. */
  16702. function WireframeGeometry( geometry ) {
  16703. BufferGeometry.call( this );
  16704. this.type = 'WireframeGeometry';
  16705. // buffer
  16706. var vertices = [];
  16707. // helper variables
  16708. var i, j, l, o, ol;
  16709. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16710. var key, keys = [ 'a', 'b', 'c' ];
  16711. var vertex;
  16712. // different logic for Geometry and BufferGeometry
  16713. if ( geometry && geometry.isGeometry ) {
  16714. // create a data structure that contains all edges without duplicates
  16715. var faces = geometry.faces;
  16716. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16717. var face = faces[ i ];
  16718. for ( j = 0; j < 3; j ++ ) {
  16719. edge1 = face[ keys[ j ] ];
  16720. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16721. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16722. edge[ 1 ] = Math.max( edge1, edge2 );
  16723. key = edge[ 0 ] + ',' + edge[ 1 ];
  16724. if ( edges[ key ] === undefined ) {
  16725. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16726. }
  16727. }
  16728. }
  16729. // generate vertices
  16730. for ( key in edges ) {
  16731. e = edges[ key ];
  16732. vertex = geometry.vertices[ e.index1 ];
  16733. vertices.push( vertex.x, vertex.y, vertex.z );
  16734. vertex = geometry.vertices[ e.index2 ];
  16735. vertices.push( vertex.x, vertex.y, vertex.z );
  16736. }
  16737. } else if ( geometry && geometry.isBufferGeometry ) {
  16738. var position, indices, groups;
  16739. var group, start, count;
  16740. var index1, index2;
  16741. vertex = new Vector3();
  16742. if ( geometry.index !== null ) {
  16743. // indexed BufferGeometry
  16744. position = geometry.attributes.position;
  16745. indices = geometry.index;
  16746. groups = geometry.groups;
  16747. if ( groups.length === 0 ) {
  16748. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16749. }
  16750. // create a data structure that contains all eges without duplicates
  16751. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16752. group = groups[ o ];
  16753. start = group.start;
  16754. count = group.count;
  16755. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16756. for ( j = 0; j < 3; j ++ ) {
  16757. edge1 = indices.getX( i + j );
  16758. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16759. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16760. edge[ 1 ] = Math.max( edge1, edge2 );
  16761. key = edge[ 0 ] + ',' + edge[ 1 ];
  16762. if ( edges[ key ] === undefined ) {
  16763. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16764. }
  16765. }
  16766. }
  16767. }
  16768. // generate vertices
  16769. for ( key in edges ) {
  16770. e = edges[ key ];
  16771. vertex.fromBufferAttribute( position, e.index1 );
  16772. vertices.push( vertex.x, vertex.y, vertex.z );
  16773. vertex.fromBufferAttribute( position, e.index2 );
  16774. vertices.push( vertex.x, vertex.y, vertex.z );
  16775. }
  16776. } else {
  16777. // non-indexed BufferGeometry
  16778. position = geometry.attributes.position;
  16779. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16780. for ( j = 0; j < 3; j ++ ) {
  16781. // three edges per triangle, an edge is represented as (index1, index2)
  16782. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16783. index1 = 3 * i + j;
  16784. vertex.fromBufferAttribute( position, index1 );
  16785. vertices.push( vertex.x, vertex.y, vertex.z );
  16786. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16787. vertex.fromBufferAttribute( position, index2 );
  16788. vertices.push( vertex.x, vertex.y, vertex.z );
  16789. }
  16790. }
  16791. }
  16792. }
  16793. // build geometry
  16794. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16795. }
  16796. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16797. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16798. /**
  16799. * @author zz85 / https://github.com/zz85
  16800. * @author Mugen87 / https://github.com/Mugen87
  16801. *
  16802. * Parametric Surfaces Geometry
  16803. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16804. */
  16805. // ParametricGeometry
  16806. function ParametricGeometry( func, slices, stacks ) {
  16807. Geometry.call( this );
  16808. this.type = 'ParametricGeometry';
  16809. this.parameters = {
  16810. func: func,
  16811. slices: slices,
  16812. stacks: stacks
  16813. };
  16814. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16815. this.mergeVertices();
  16816. }
  16817. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16818. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16819. // ParametricBufferGeometry
  16820. function ParametricBufferGeometry( func, slices, stacks ) {
  16821. BufferGeometry.call( this );
  16822. this.type = 'ParametricBufferGeometry';
  16823. this.parameters = {
  16824. func: func,
  16825. slices: slices,
  16826. stacks: stacks
  16827. };
  16828. // buffers
  16829. var indices = [];
  16830. var vertices = [];
  16831. var normals = [];
  16832. var uvs = [];
  16833. var EPS = 0.00001;
  16834. var normal = new Vector3();
  16835. var p0 = new Vector3(), p1 = new Vector3();
  16836. var pu = new Vector3(), pv = new Vector3();
  16837. var i, j;
  16838. if ( func.length < 3 ) {
  16839. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16840. }
  16841. // generate vertices, normals and uvs
  16842. var sliceCount = slices + 1;
  16843. for ( i = 0; i <= stacks; i ++ ) {
  16844. var v = i / stacks;
  16845. for ( j = 0; j <= slices; j ++ ) {
  16846. var u = j / slices;
  16847. // vertex
  16848. func( u, v, p0 );
  16849. vertices.push( p0.x, p0.y, p0.z );
  16850. // normal
  16851. // approximate tangent vectors via finite differences
  16852. if ( u - EPS >= 0 ) {
  16853. func( u - EPS, v, p1 );
  16854. pu.subVectors( p0, p1 );
  16855. } else {
  16856. func( u + EPS, v, p1 );
  16857. pu.subVectors( p1, p0 );
  16858. }
  16859. if ( v - EPS >= 0 ) {
  16860. func( u, v - EPS, p1 );
  16861. pv.subVectors( p0, p1 );
  16862. } else {
  16863. func( u, v + EPS, p1 );
  16864. pv.subVectors( p1, p0 );
  16865. }
  16866. // cross product of tangent vectors returns surface normal
  16867. normal.crossVectors( pu, pv ).normalize();
  16868. normals.push( normal.x, normal.y, normal.z );
  16869. // uv
  16870. uvs.push( u, v );
  16871. }
  16872. }
  16873. // generate indices
  16874. for ( i = 0; i < stacks; i ++ ) {
  16875. for ( j = 0; j < slices; j ++ ) {
  16876. var a = i * sliceCount + j;
  16877. var b = i * sliceCount + j + 1;
  16878. var c = ( i + 1 ) * sliceCount + j + 1;
  16879. var d = ( i + 1 ) * sliceCount + j;
  16880. // faces one and two
  16881. indices.push( a, b, d );
  16882. indices.push( b, c, d );
  16883. }
  16884. }
  16885. // build geometry
  16886. this.setIndex( indices );
  16887. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16888. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16889. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16890. }
  16891. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16892. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16893. /**
  16894. * @author clockworkgeek / https://github.com/clockworkgeek
  16895. * @author timothypratley / https://github.com/timothypratley
  16896. * @author WestLangley / http://github.com/WestLangley
  16897. * @author Mugen87 / https://github.com/Mugen87
  16898. */
  16899. // PolyhedronGeometry
  16900. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16901. Geometry.call( this );
  16902. this.type = 'PolyhedronGeometry';
  16903. this.parameters = {
  16904. vertices: vertices,
  16905. indices: indices,
  16906. radius: radius,
  16907. detail: detail
  16908. };
  16909. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16910. this.mergeVertices();
  16911. }
  16912. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16913. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16914. // PolyhedronBufferGeometry
  16915. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16916. BufferGeometry.call( this );
  16917. this.type = 'PolyhedronBufferGeometry';
  16918. this.parameters = {
  16919. vertices: vertices,
  16920. indices: indices,
  16921. radius: radius,
  16922. detail: detail
  16923. };
  16924. radius = radius || 1;
  16925. detail = detail || 0;
  16926. // default buffer data
  16927. var vertexBuffer = [];
  16928. var uvBuffer = [];
  16929. // the subdivision creates the vertex buffer data
  16930. subdivide( detail );
  16931. // all vertices should lie on a conceptual sphere with a given radius
  16932. applyRadius( radius );
  16933. // finally, create the uv data
  16934. generateUVs();
  16935. // build non-indexed geometry
  16936. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16937. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16938. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16939. if ( detail === 0 ) {
  16940. this.computeVertexNormals(); // flat normals
  16941. } else {
  16942. this.normalizeNormals(); // smooth normals
  16943. }
  16944. // helper functions
  16945. function subdivide( detail ) {
  16946. var a = new Vector3();
  16947. var b = new Vector3();
  16948. var c = new Vector3();
  16949. // iterate over all faces and apply a subdivison with the given detail value
  16950. for ( var i = 0; i < indices.length; i += 3 ) {
  16951. // get the vertices of the face
  16952. getVertexByIndex( indices[ i + 0 ], a );
  16953. getVertexByIndex( indices[ i + 1 ], b );
  16954. getVertexByIndex( indices[ i + 2 ], c );
  16955. // perform subdivision
  16956. subdivideFace( a, b, c, detail );
  16957. }
  16958. }
  16959. function subdivideFace( a, b, c, detail ) {
  16960. var cols = Math.pow( 2, detail );
  16961. // we use this multidimensional array as a data structure for creating the subdivision
  16962. var v = [];
  16963. var i, j;
  16964. // construct all of the vertices for this subdivision
  16965. for ( i = 0; i <= cols; i ++ ) {
  16966. v[ i ] = [];
  16967. var aj = a.clone().lerp( c, i / cols );
  16968. var bj = b.clone().lerp( c, i / cols );
  16969. var rows = cols - i;
  16970. for ( j = 0; j <= rows; j ++ ) {
  16971. if ( j === 0 && i === cols ) {
  16972. v[ i ][ j ] = aj;
  16973. } else {
  16974. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16975. }
  16976. }
  16977. }
  16978. // construct all of the faces
  16979. for ( i = 0; i < cols; i ++ ) {
  16980. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16981. var k = Math.floor( j / 2 );
  16982. if ( j % 2 === 0 ) {
  16983. pushVertex( v[ i ][ k + 1 ] );
  16984. pushVertex( v[ i + 1 ][ k ] );
  16985. pushVertex( v[ i ][ k ] );
  16986. } else {
  16987. pushVertex( v[ i ][ k + 1 ] );
  16988. pushVertex( v[ i + 1 ][ k + 1 ] );
  16989. pushVertex( v[ i + 1 ][ k ] );
  16990. }
  16991. }
  16992. }
  16993. }
  16994. function applyRadius( radius ) {
  16995. var vertex = new Vector3();
  16996. // iterate over the entire buffer and apply the radius to each vertex
  16997. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16998. vertex.x = vertexBuffer[ i + 0 ];
  16999. vertex.y = vertexBuffer[ i + 1 ];
  17000. vertex.z = vertexBuffer[ i + 2 ];
  17001. vertex.normalize().multiplyScalar( radius );
  17002. vertexBuffer[ i + 0 ] = vertex.x;
  17003. vertexBuffer[ i + 1 ] = vertex.y;
  17004. vertexBuffer[ i + 2 ] = vertex.z;
  17005. }
  17006. }
  17007. function generateUVs() {
  17008. var vertex = new Vector3();
  17009. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  17010. vertex.x = vertexBuffer[ i + 0 ];
  17011. vertex.y = vertexBuffer[ i + 1 ];
  17012. vertex.z = vertexBuffer[ i + 2 ];
  17013. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  17014. var v = inclination( vertex ) / Math.PI + 0.5;
  17015. uvBuffer.push( u, 1 - v );
  17016. }
  17017. correctUVs();
  17018. correctSeam();
  17019. }
  17020. function correctSeam() {
  17021. // handle case when face straddles the seam, see #3269
  17022. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  17023. // uv data of a single face
  17024. var x0 = uvBuffer[ i + 0 ];
  17025. var x1 = uvBuffer[ i + 2 ];
  17026. var x2 = uvBuffer[ i + 4 ];
  17027. var max = Math.max( x0, x1, x2 );
  17028. var min = Math.min( x0, x1, x2 );
  17029. // 0.9 is somewhat arbitrary
  17030. if ( max > 0.9 && min < 0.1 ) {
  17031. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  17032. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  17033. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  17034. }
  17035. }
  17036. }
  17037. function pushVertex( vertex ) {
  17038. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  17039. }
  17040. function getVertexByIndex( index, vertex ) {
  17041. var stride = index * 3;
  17042. vertex.x = vertices[ stride + 0 ];
  17043. vertex.y = vertices[ stride + 1 ];
  17044. vertex.z = vertices[ stride + 2 ];
  17045. }
  17046. function correctUVs() {
  17047. var a = new Vector3();
  17048. var b = new Vector3();
  17049. var c = new Vector3();
  17050. var centroid = new Vector3();
  17051. var uvA = new Vector2();
  17052. var uvB = new Vector2();
  17053. var uvC = new Vector2();
  17054. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  17055. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  17056. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  17057. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  17058. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  17059. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  17060. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  17061. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  17062. var azi = azimuth( centroid );
  17063. correctUV( uvA, j + 0, a, azi );
  17064. correctUV( uvB, j + 2, b, azi );
  17065. correctUV( uvC, j + 4, c, azi );
  17066. }
  17067. }
  17068. function correctUV( uv, stride, vector, azimuth ) {
  17069. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  17070. uvBuffer[ stride ] = uv.x - 1;
  17071. }
  17072. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  17073. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  17074. }
  17075. }
  17076. // Angle around the Y axis, counter-clockwise when looking from above.
  17077. function azimuth( vector ) {
  17078. return Math.atan2( vector.z, - vector.x );
  17079. }
  17080. // Angle above the XZ plane.
  17081. function inclination( vector ) {
  17082. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  17083. }
  17084. }
  17085. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17086. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  17087. /**
  17088. * @author timothypratley / https://github.com/timothypratley
  17089. * @author Mugen87 / https://github.com/Mugen87
  17090. */
  17091. // TetrahedronGeometry
  17092. function TetrahedronGeometry( radius, detail ) {
  17093. Geometry.call( this );
  17094. this.type = 'TetrahedronGeometry';
  17095. this.parameters = {
  17096. radius: radius,
  17097. detail: detail
  17098. };
  17099. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  17100. this.mergeVertices();
  17101. }
  17102. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  17103. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  17104. // TetrahedronBufferGeometry
  17105. function TetrahedronBufferGeometry( radius, detail ) {
  17106. var vertices = [
  17107. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  17108. ];
  17109. var indices = [
  17110. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  17111. ];
  17112. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17113. this.type = 'TetrahedronBufferGeometry';
  17114. this.parameters = {
  17115. radius: radius,
  17116. detail: detail
  17117. };
  17118. }
  17119. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17120. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  17121. /**
  17122. * @author timothypratley / https://github.com/timothypratley
  17123. * @author Mugen87 / https://github.com/Mugen87
  17124. */
  17125. // OctahedronGeometry
  17126. function OctahedronGeometry( radius, detail ) {
  17127. Geometry.call( this );
  17128. this.type = 'OctahedronGeometry';
  17129. this.parameters = {
  17130. radius: radius,
  17131. detail: detail
  17132. };
  17133. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  17134. this.mergeVertices();
  17135. }
  17136. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  17137. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  17138. // OctahedronBufferGeometry
  17139. function OctahedronBufferGeometry( radius, detail ) {
  17140. var vertices = [
  17141. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  17142. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  17143. ];
  17144. var indices = [
  17145. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  17146. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  17147. 1, 3, 4, 1, 4, 2
  17148. ];
  17149. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17150. this.type = 'OctahedronBufferGeometry';
  17151. this.parameters = {
  17152. radius: radius,
  17153. detail: detail
  17154. };
  17155. }
  17156. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17157. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  17158. /**
  17159. * @author timothypratley / https://github.com/timothypratley
  17160. * @author Mugen87 / https://github.com/Mugen87
  17161. */
  17162. // IcosahedronGeometry
  17163. function IcosahedronGeometry( radius, detail ) {
  17164. Geometry.call( this );
  17165. this.type = 'IcosahedronGeometry';
  17166. this.parameters = {
  17167. radius: radius,
  17168. detail: detail
  17169. };
  17170. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  17171. this.mergeVertices();
  17172. }
  17173. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  17174. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  17175. // IcosahedronBufferGeometry
  17176. function IcosahedronBufferGeometry( radius, detail ) {
  17177. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17178. var vertices = [
  17179. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  17180. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  17181. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  17182. ];
  17183. var indices = [
  17184. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  17185. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17186. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  17187. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  17188. ];
  17189. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17190. this.type = 'IcosahedronBufferGeometry';
  17191. this.parameters = {
  17192. radius: radius,
  17193. detail: detail
  17194. };
  17195. }
  17196. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17197. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  17198. /**
  17199. * @author Abe Pazos / https://hamoid.com
  17200. * @author Mugen87 / https://github.com/Mugen87
  17201. */
  17202. // DodecahedronGeometry
  17203. function DodecahedronGeometry( radius, detail ) {
  17204. Geometry.call( this );
  17205. this.type = 'DodecahedronGeometry';
  17206. this.parameters = {
  17207. radius: radius,
  17208. detail: detail
  17209. };
  17210. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  17211. this.mergeVertices();
  17212. }
  17213. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  17214. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  17215. // DodecahedronBufferGeometry
  17216. function DodecahedronBufferGeometry( radius, detail ) {
  17217. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17218. var r = 1 / t;
  17219. var vertices = [
  17220. // (±1, ±1, ±1)
  17221. - 1, - 1, - 1, - 1, - 1, 1,
  17222. - 1, 1, - 1, - 1, 1, 1,
  17223. 1, - 1, - 1, 1, - 1, 1,
  17224. 1, 1, - 1, 1, 1, 1,
  17225. // (0, ±1/φ, ±φ)
  17226. 0, - r, - t, 0, - r, t,
  17227. 0, r, - t, 0, r, t,
  17228. // (±1/φ, ±φ, 0)
  17229. - r, - t, 0, - r, t, 0,
  17230. r, - t, 0, r, t, 0,
  17231. // (±φ, 0, ±1/φ)
  17232. - t, 0, - r, t, 0, - r,
  17233. - t, 0, r, t, 0, r
  17234. ];
  17235. var indices = [
  17236. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  17237. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  17238. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  17239. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  17240. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  17241. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  17242. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  17243. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  17244. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  17245. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  17246. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  17247. 1, 12, 14, 1, 14, 5, 1, 5, 9
  17248. ];
  17249. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17250. this.type = 'DodecahedronBufferGeometry';
  17251. this.parameters = {
  17252. radius: radius,
  17253. detail: detail
  17254. };
  17255. }
  17256. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17257. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  17258. /**
  17259. * @author oosmoxiecode / https://github.com/oosmoxiecode
  17260. * @author WestLangley / https://github.com/WestLangley
  17261. * @author zz85 / https://github.com/zz85
  17262. * @author miningold / https://github.com/miningold
  17263. * @author jonobr1 / https://github.com/jonobr1
  17264. * @author Mugen87 / https://github.com/Mugen87
  17265. *
  17266. */
  17267. // TubeGeometry
  17268. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  17269. Geometry.call( this );
  17270. this.type = 'TubeGeometry';
  17271. this.parameters = {
  17272. path: path,
  17273. tubularSegments: tubularSegments,
  17274. radius: radius,
  17275. radialSegments: radialSegments,
  17276. closed: closed
  17277. };
  17278. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  17279. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  17280. // expose internals
  17281. this.tangents = bufferGeometry.tangents;
  17282. this.normals = bufferGeometry.normals;
  17283. this.binormals = bufferGeometry.binormals;
  17284. // create geometry
  17285. this.fromBufferGeometry( bufferGeometry );
  17286. this.mergeVertices();
  17287. }
  17288. TubeGeometry.prototype = Object.create( Geometry.prototype );
  17289. TubeGeometry.prototype.constructor = TubeGeometry;
  17290. // TubeBufferGeometry
  17291. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  17292. BufferGeometry.call( this );
  17293. this.type = 'TubeBufferGeometry';
  17294. this.parameters = {
  17295. path: path,
  17296. tubularSegments: tubularSegments,
  17297. radius: radius,
  17298. radialSegments: radialSegments,
  17299. closed: closed
  17300. };
  17301. tubularSegments = tubularSegments || 64;
  17302. radius = radius || 1;
  17303. radialSegments = radialSegments || 8;
  17304. closed = closed || false;
  17305. var frames = path.computeFrenetFrames( tubularSegments, closed );
  17306. // expose internals
  17307. this.tangents = frames.tangents;
  17308. this.normals = frames.normals;
  17309. this.binormals = frames.binormals;
  17310. // helper variables
  17311. var vertex = new Vector3();
  17312. var normal = new Vector3();
  17313. var uv = new Vector2();
  17314. var P = new Vector3();
  17315. var i, j;
  17316. // buffer
  17317. var vertices = [];
  17318. var normals = [];
  17319. var uvs = [];
  17320. var indices = [];
  17321. // create buffer data
  17322. generateBufferData();
  17323. // build geometry
  17324. this.setIndex( indices );
  17325. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17326. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17327. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17328. // functions
  17329. function generateBufferData() {
  17330. for ( i = 0; i < tubularSegments; i ++ ) {
  17331. generateSegment( i );
  17332. }
  17333. // if the geometry is not closed, generate the last row of vertices and normals
  17334. // at the regular position on the given path
  17335. //
  17336. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  17337. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  17338. // uvs are generated in a separate function.
  17339. // this makes it easy compute correct values for closed geometries
  17340. generateUVs();
  17341. // finally create faces
  17342. generateIndices();
  17343. }
  17344. function generateSegment( i ) {
  17345. // we use getPointAt to sample evenly distributed points from the given path
  17346. P = path.getPointAt( i / tubularSegments, P );
  17347. // retrieve corresponding normal and binormal
  17348. var N = frames.normals[ i ];
  17349. var B = frames.binormals[ i ];
  17350. // generate normals and vertices for the current segment
  17351. for ( j = 0; j <= radialSegments; j ++ ) {
  17352. var v = j / radialSegments * Math.PI * 2;
  17353. var sin = Math.sin( v );
  17354. var cos = - Math.cos( v );
  17355. // normal
  17356. normal.x = ( cos * N.x + sin * B.x );
  17357. normal.y = ( cos * N.y + sin * B.y );
  17358. normal.z = ( cos * N.z + sin * B.z );
  17359. normal.normalize();
  17360. normals.push( normal.x, normal.y, normal.z );
  17361. // vertex
  17362. vertex.x = P.x + radius * normal.x;
  17363. vertex.y = P.y + radius * normal.y;
  17364. vertex.z = P.z + radius * normal.z;
  17365. vertices.push( vertex.x, vertex.y, vertex.z );
  17366. }
  17367. }
  17368. function generateIndices() {
  17369. for ( j = 1; j <= tubularSegments; j ++ ) {
  17370. for ( i = 1; i <= radialSegments; i ++ ) {
  17371. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17372. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17373. var c = ( radialSegments + 1 ) * j + i;
  17374. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17375. // faces
  17376. indices.push( a, b, d );
  17377. indices.push( b, c, d );
  17378. }
  17379. }
  17380. }
  17381. function generateUVs() {
  17382. for ( i = 0; i <= tubularSegments; i ++ ) {
  17383. for ( j = 0; j <= radialSegments; j ++ ) {
  17384. uv.x = i / tubularSegments;
  17385. uv.y = j / radialSegments;
  17386. uvs.push( uv.x, uv.y );
  17387. }
  17388. }
  17389. }
  17390. }
  17391. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17392. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  17393. TubeBufferGeometry.prototype.toJSON = function () {
  17394. var data = BufferGeometry.prototype.toJSON.call( this );
  17395. data.path = this.parameters.path.toJSON();
  17396. return data;
  17397. };
  17398. /**
  17399. * @author oosmoxiecode
  17400. * @author Mugen87 / https://github.com/Mugen87
  17401. *
  17402. * based on http://www.blackpawn.com/texts/pqtorus/
  17403. */
  17404. // TorusKnotGeometry
  17405. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  17406. Geometry.call( this );
  17407. this.type = 'TorusKnotGeometry';
  17408. this.parameters = {
  17409. radius: radius,
  17410. tube: tube,
  17411. tubularSegments: tubularSegments,
  17412. radialSegments: radialSegments,
  17413. p: p,
  17414. q: q
  17415. };
  17416. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  17417. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  17418. this.mergeVertices();
  17419. }
  17420. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  17421. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  17422. // TorusKnotBufferGeometry
  17423. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  17424. BufferGeometry.call( this );
  17425. this.type = 'TorusKnotBufferGeometry';
  17426. this.parameters = {
  17427. radius: radius,
  17428. tube: tube,
  17429. tubularSegments: tubularSegments,
  17430. radialSegments: radialSegments,
  17431. p: p,
  17432. q: q
  17433. };
  17434. radius = radius || 1;
  17435. tube = tube || 0.4;
  17436. tubularSegments = Math.floor( tubularSegments ) || 64;
  17437. radialSegments = Math.floor( radialSegments ) || 8;
  17438. p = p || 2;
  17439. q = q || 3;
  17440. // buffers
  17441. var indices = [];
  17442. var vertices = [];
  17443. var normals = [];
  17444. var uvs = [];
  17445. // helper variables
  17446. var i, j;
  17447. var vertex = new Vector3();
  17448. var normal = new Vector3();
  17449. var P1 = new Vector3();
  17450. var P2 = new Vector3();
  17451. var B = new Vector3();
  17452. var T = new Vector3();
  17453. var N = new Vector3();
  17454. // generate vertices, normals and uvs
  17455. for ( i = 0; i <= tubularSegments; ++ i ) {
  17456. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17457. var u = i / tubularSegments * p * Math.PI * 2;
  17458. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17459. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17460. calculatePositionOnCurve( u, p, q, radius, P1 );
  17461. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17462. // calculate orthonormal basis
  17463. T.subVectors( P2, P1 );
  17464. N.addVectors( P2, P1 );
  17465. B.crossVectors( T, N );
  17466. N.crossVectors( B, T );
  17467. // normalize B, N. T can be ignored, we don't use it
  17468. B.normalize();
  17469. N.normalize();
  17470. for ( j = 0; j <= radialSegments; ++ j ) {
  17471. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17472. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17473. var v = j / radialSegments * Math.PI * 2;
  17474. var cx = - tube * Math.cos( v );
  17475. var cy = tube * Math.sin( v );
  17476. // now calculate the final vertex position.
  17477. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17478. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17479. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17480. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17481. vertices.push( vertex.x, vertex.y, vertex.z );
  17482. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17483. normal.subVectors( vertex, P1 ).normalize();
  17484. normals.push( normal.x, normal.y, normal.z );
  17485. // uv
  17486. uvs.push( i / tubularSegments );
  17487. uvs.push( j / radialSegments );
  17488. }
  17489. }
  17490. // generate indices
  17491. for ( j = 1; j <= tubularSegments; j ++ ) {
  17492. for ( i = 1; i <= radialSegments; i ++ ) {
  17493. // indices
  17494. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17495. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17496. var c = ( radialSegments + 1 ) * j + i;
  17497. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17498. // faces
  17499. indices.push( a, b, d );
  17500. indices.push( b, c, d );
  17501. }
  17502. }
  17503. // build geometry
  17504. this.setIndex( indices );
  17505. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17506. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17507. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17508. // this function calculates the current position on the torus curve
  17509. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17510. var cu = Math.cos( u );
  17511. var su = Math.sin( u );
  17512. var quOverP = q / p * u;
  17513. var cs = Math.cos( quOverP );
  17514. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17515. position.y = radius * ( 2 + cs ) * su * 0.5;
  17516. position.z = radius * Math.sin( quOverP ) * 0.5;
  17517. }
  17518. }
  17519. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17520. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17521. /**
  17522. * @author oosmoxiecode
  17523. * @author mrdoob / http://mrdoob.com/
  17524. * @author Mugen87 / https://github.com/Mugen87
  17525. */
  17526. // TorusGeometry
  17527. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17528. Geometry.call( this );
  17529. this.type = 'TorusGeometry';
  17530. this.parameters = {
  17531. radius: radius,
  17532. tube: tube,
  17533. radialSegments: radialSegments,
  17534. tubularSegments: tubularSegments,
  17535. arc: arc
  17536. };
  17537. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17538. this.mergeVertices();
  17539. }
  17540. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17541. TorusGeometry.prototype.constructor = TorusGeometry;
  17542. // TorusBufferGeometry
  17543. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17544. BufferGeometry.call( this );
  17545. this.type = 'TorusBufferGeometry';
  17546. this.parameters = {
  17547. radius: radius,
  17548. tube: tube,
  17549. radialSegments: radialSegments,
  17550. tubularSegments: tubularSegments,
  17551. arc: arc
  17552. };
  17553. radius = radius || 1;
  17554. tube = tube || 0.4;
  17555. radialSegments = Math.floor( radialSegments ) || 8;
  17556. tubularSegments = Math.floor( tubularSegments ) || 6;
  17557. arc = arc || Math.PI * 2;
  17558. // buffers
  17559. var indices = [];
  17560. var vertices = [];
  17561. var normals = [];
  17562. var uvs = [];
  17563. // helper variables
  17564. var center = new Vector3();
  17565. var vertex = new Vector3();
  17566. var normal = new Vector3();
  17567. var j, i;
  17568. // generate vertices, normals and uvs
  17569. for ( j = 0; j <= radialSegments; j ++ ) {
  17570. for ( i = 0; i <= tubularSegments; i ++ ) {
  17571. var u = i / tubularSegments * arc;
  17572. var v = j / radialSegments * Math.PI * 2;
  17573. // vertex
  17574. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  17575. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  17576. vertex.z = tube * Math.sin( v );
  17577. vertices.push( vertex.x, vertex.y, vertex.z );
  17578. // normal
  17579. center.x = radius * Math.cos( u );
  17580. center.y = radius * Math.sin( u );
  17581. normal.subVectors( vertex, center ).normalize();
  17582. normals.push( normal.x, normal.y, normal.z );
  17583. // uv
  17584. uvs.push( i / tubularSegments );
  17585. uvs.push( j / radialSegments );
  17586. }
  17587. }
  17588. // generate indices
  17589. for ( j = 1; j <= radialSegments; j ++ ) {
  17590. for ( i = 1; i <= tubularSegments; i ++ ) {
  17591. // indices
  17592. var a = ( tubularSegments + 1 ) * j + i - 1;
  17593. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  17594. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  17595. var d = ( tubularSegments + 1 ) * j + i;
  17596. // faces
  17597. indices.push( a, b, d );
  17598. indices.push( b, c, d );
  17599. }
  17600. }
  17601. // build geometry
  17602. this.setIndex( indices );
  17603. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17604. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17605. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17606. }
  17607. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17608. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  17609. /**
  17610. * @author Mugen87 / https://github.com/Mugen87
  17611. * Port from https://github.com/mapbox/earcut (v2.1.5)
  17612. */
  17613. var Earcut = {
  17614. triangulate: function ( data, holeIndices, dim ) {
  17615. dim = dim || 2;
  17616. var hasHoles = holeIndices && holeIndices.length,
  17617. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  17618. outerNode = linkedList( data, 0, outerLen, dim, true ),
  17619. triangles = [];
  17620. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  17621. var minX, minY, maxX, maxY, x, y, invSize;
  17622. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  17623. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17624. if ( data.length > 80 * dim ) {
  17625. minX = maxX = data[ 0 ];
  17626. minY = maxY = data[ 1 ];
  17627. for ( var i = dim; i < outerLen; i += dim ) {
  17628. x = data[ i ];
  17629. y = data[ i + 1 ];
  17630. if ( x < minX ) minX = x;
  17631. if ( y < minY ) minY = y;
  17632. if ( x > maxX ) maxX = x;
  17633. if ( y > maxY ) maxY = y;
  17634. }
  17635. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17636. invSize = Math.max( maxX - minX, maxY - minY );
  17637. invSize = invSize !== 0 ? 1 / invSize : 0;
  17638. }
  17639. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  17640. return triangles;
  17641. }
  17642. };
  17643. // create a circular doubly linked list from polygon points in the specified winding order
  17644. function linkedList( data, start, end, dim, clockwise ) {
  17645. var i, last;
  17646. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  17647. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17648. } else {
  17649. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17650. }
  17651. if ( last && equals( last, last.next ) ) {
  17652. removeNode( last );
  17653. last = last.next;
  17654. }
  17655. return last;
  17656. }
  17657. // eliminate colinear or duplicate points
  17658. function filterPoints( start, end ) {
  17659. if ( ! start ) return start;
  17660. if ( ! end ) end = start;
  17661. var p = start,
  17662. again;
  17663. do {
  17664. again = false;
  17665. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17666. removeNode( p );
  17667. p = end = p.prev;
  17668. if ( p === p.next ) break;
  17669. again = true;
  17670. } else {
  17671. p = p.next;
  17672. }
  17673. } while ( again || p !== end );
  17674. return end;
  17675. }
  17676. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17677. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17678. if ( ! ear ) return;
  17679. // interlink polygon nodes in z-order
  17680. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17681. var stop = ear,
  17682. prev, next;
  17683. // iterate through ears, slicing them one by one
  17684. while ( ear.prev !== ear.next ) {
  17685. prev = ear.prev;
  17686. next = ear.next;
  17687. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17688. // cut off the triangle
  17689. triangles.push( prev.i / dim );
  17690. triangles.push( ear.i / dim );
  17691. triangles.push( next.i / dim );
  17692. removeNode( ear );
  17693. // skipping the next vertex leads to less sliver triangles
  17694. ear = next.next;
  17695. stop = next.next;
  17696. continue;
  17697. }
  17698. ear = next;
  17699. // if we looped through the whole remaining polygon and can't find any more ears
  17700. if ( ear === stop ) {
  17701. // try filtering points and slicing again
  17702. if ( ! pass ) {
  17703. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17704. // if this didn't work, try curing all small self-intersections locally
  17705. } else if ( pass === 1 ) {
  17706. ear = cureLocalIntersections( ear, triangles, dim );
  17707. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17708. // as a last resort, try splitting the remaining polygon into two
  17709. } else if ( pass === 2 ) {
  17710. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17711. }
  17712. break;
  17713. }
  17714. }
  17715. }
  17716. // check whether a polygon node forms a valid ear with adjacent nodes
  17717. function isEar( ear ) {
  17718. var a = ear.prev,
  17719. b = ear,
  17720. c = ear.next;
  17721. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17722. // now make sure we don't have other points inside the potential ear
  17723. var p = ear.next.next;
  17724. while ( p !== ear.prev ) {
  17725. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17726. area( p.prev, p, p.next ) >= 0 ) return false;
  17727. p = p.next;
  17728. }
  17729. return true;
  17730. }
  17731. function isEarHashed( ear, minX, minY, invSize ) {
  17732. var a = ear.prev,
  17733. b = ear,
  17734. c = ear.next;
  17735. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17736. // triangle bbox; min & max are calculated like this for speed
  17737. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17738. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17739. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17740. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17741. // z-order range for the current triangle bbox;
  17742. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17743. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17744. var p = ear.prevZ,
  17745. n = ear.nextZ;
  17746. // look for points inside the triangle in both directions
  17747. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  17748. if ( p !== ear.prev && p !== ear.next &&
  17749. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17750. area( p.prev, p, p.next ) >= 0 ) return false;
  17751. p = p.prevZ;
  17752. if ( n !== ear.prev && n !== ear.next &&
  17753. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17754. area( n.prev, n, n.next ) >= 0 ) return false;
  17755. n = n.nextZ;
  17756. }
  17757. // look for remaining points in decreasing z-order
  17758. while ( p && p.z >= minZ ) {
  17759. if ( p !== ear.prev && p !== ear.next &&
  17760. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17761. area( p.prev, p, p.next ) >= 0 ) return false;
  17762. p = p.prevZ;
  17763. }
  17764. // look for remaining points in increasing z-order
  17765. while ( n && n.z <= maxZ ) {
  17766. if ( n !== ear.prev && n !== ear.next &&
  17767. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17768. area( n.prev, n, n.next ) >= 0 ) return false;
  17769. n = n.nextZ;
  17770. }
  17771. return true;
  17772. }
  17773. // go through all polygon nodes and cure small local self-intersections
  17774. function cureLocalIntersections( start, triangles, dim ) {
  17775. var p = start;
  17776. do {
  17777. var a = p.prev,
  17778. b = p.next.next;
  17779. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17780. triangles.push( a.i / dim );
  17781. triangles.push( p.i / dim );
  17782. triangles.push( b.i / dim );
  17783. // remove two nodes involved
  17784. removeNode( p );
  17785. removeNode( p.next );
  17786. p = start = b;
  17787. }
  17788. p = p.next;
  17789. } while ( p !== start );
  17790. return p;
  17791. }
  17792. // try splitting polygon into two and triangulate them independently
  17793. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17794. // look for a valid diagonal that divides the polygon into two
  17795. var a = start;
  17796. do {
  17797. var b = a.next.next;
  17798. while ( b !== a.prev ) {
  17799. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17800. // split the polygon in two by the diagonal
  17801. var c = splitPolygon( a, b );
  17802. // filter colinear points around the cuts
  17803. a = filterPoints( a, a.next );
  17804. c = filterPoints( c, c.next );
  17805. // run earcut on each half
  17806. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17807. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17808. return;
  17809. }
  17810. b = b.next;
  17811. }
  17812. a = a.next;
  17813. } while ( a !== start );
  17814. }
  17815. // link every hole into the outer loop, producing a single-ring polygon without holes
  17816. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17817. var queue = [],
  17818. i, len, start, end, list;
  17819. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17820. start = holeIndices[ i ] * dim;
  17821. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17822. list = linkedList( data, start, end, dim, false );
  17823. if ( list === list.next ) list.steiner = true;
  17824. queue.push( getLeftmost( list ) );
  17825. }
  17826. queue.sort( compareX );
  17827. // process holes from left to right
  17828. for ( i = 0; i < queue.length; i ++ ) {
  17829. eliminateHole( queue[ i ], outerNode );
  17830. outerNode = filterPoints( outerNode, outerNode.next );
  17831. }
  17832. return outerNode;
  17833. }
  17834. function compareX( a, b ) {
  17835. return a.x - b.x;
  17836. }
  17837. // find a bridge between vertices that connects hole with an outer ring and and link it
  17838. function eliminateHole( hole, outerNode ) {
  17839. outerNode = findHoleBridge( hole, outerNode );
  17840. if ( outerNode ) {
  17841. var b = splitPolygon( outerNode, hole );
  17842. filterPoints( b, b.next );
  17843. }
  17844. }
  17845. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17846. function findHoleBridge( hole, outerNode ) {
  17847. var p = outerNode,
  17848. hx = hole.x,
  17849. hy = hole.y,
  17850. qx = - Infinity,
  17851. m;
  17852. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17853. // segment's endpoint with lesser x will be potential connection point
  17854. do {
  17855. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17856. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17857. if ( x <= hx && x > qx ) {
  17858. qx = x;
  17859. if ( x === hx ) {
  17860. if ( hy === p.y ) return p;
  17861. if ( hy === p.next.y ) return p.next;
  17862. }
  17863. m = p.x < p.next.x ? p : p.next;
  17864. }
  17865. }
  17866. p = p.next;
  17867. } while ( p !== outerNode );
  17868. if ( ! m ) return null;
  17869. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17870. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17871. // if there are no points found, we have a valid connection;
  17872. // otherwise choose the point of the minimum angle with the ray as connection point
  17873. var stop = m,
  17874. mx = m.x,
  17875. my = m.y,
  17876. tanMin = Infinity,
  17877. tan;
  17878. p = m.next;
  17879. while ( p !== stop ) {
  17880. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17881. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17882. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17883. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17884. m = p;
  17885. tanMin = tan;
  17886. }
  17887. }
  17888. p = p.next;
  17889. }
  17890. return m;
  17891. }
  17892. // interlink polygon nodes in z-order
  17893. function indexCurve( start, minX, minY, invSize ) {
  17894. var p = start;
  17895. do {
  17896. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17897. p.prevZ = p.prev;
  17898. p.nextZ = p.next;
  17899. p = p.next;
  17900. } while ( p !== start );
  17901. p.prevZ.nextZ = null;
  17902. p.prevZ = null;
  17903. sortLinked( p );
  17904. }
  17905. // Simon Tatham's linked list merge sort algorithm
  17906. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17907. function sortLinked( list ) {
  17908. var i, p, q, e, tail, numMerges, pSize, qSize,
  17909. inSize = 1;
  17910. do {
  17911. p = list;
  17912. list = null;
  17913. tail = null;
  17914. numMerges = 0;
  17915. while ( p ) {
  17916. numMerges ++;
  17917. q = p;
  17918. pSize = 0;
  17919. for ( i = 0; i < inSize; i ++ ) {
  17920. pSize ++;
  17921. q = q.nextZ;
  17922. if ( ! q ) break;
  17923. }
  17924. qSize = inSize;
  17925. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17926. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17927. e = p;
  17928. p = p.nextZ;
  17929. pSize --;
  17930. } else {
  17931. e = q;
  17932. q = q.nextZ;
  17933. qSize --;
  17934. }
  17935. if ( tail ) tail.nextZ = e;
  17936. else list = e;
  17937. e.prevZ = tail;
  17938. tail = e;
  17939. }
  17940. p = q;
  17941. }
  17942. tail.nextZ = null;
  17943. inSize *= 2;
  17944. } while ( numMerges > 1 );
  17945. return list;
  17946. }
  17947. // z-order of a point given coords and inverse of the longer side of data bbox
  17948. function zOrder( x, y, minX, minY, invSize ) {
  17949. // coords are transformed into non-negative 15-bit integer range
  17950. x = 32767 * ( x - minX ) * invSize;
  17951. y = 32767 * ( y - minY ) * invSize;
  17952. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17953. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17954. x = ( x | ( x << 2 ) ) & 0x33333333;
  17955. x = ( x | ( x << 1 ) ) & 0x55555555;
  17956. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17957. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17958. y = ( y | ( y << 2 ) ) & 0x33333333;
  17959. y = ( y | ( y << 1 ) ) & 0x55555555;
  17960. return x | ( y << 1 );
  17961. }
  17962. // find the leftmost node of a polygon ring
  17963. function getLeftmost( start ) {
  17964. var p = start,
  17965. leftmost = start;
  17966. do {
  17967. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  17968. p = p.next;
  17969. } while ( p !== start );
  17970. return leftmost;
  17971. }
  17972. // check if a point lies within a convex triangle
  17973. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17974. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17975. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17976. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17977. }
  17978. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17979. function isValidDiagonal( a, b ) {
  17980. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17981. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17982. }
  17983. // signed area of a triangle
  17984. function area( p, q, r ) {
  17985. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17986. }
  17987. // check if two points are equal
  17988. function equals( p1, p2 ) {
  17989. return p1.x === p2.x && p1.y === p2.y;
  17990. }
  17991. // check if two segments intersect
  17992. function intersects( p1, q1, p2, q2 ) {
  17993. if ( ( equals( p1, p2 ) && equals( q1, q2 ) ) ||
  17994. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17995. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17996. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17997. }
  17998. // check if a polygon diagonal intersects any polygon segments
  17999. function intersectsPolygon( a, b ) {
  18000. var p = a;
  18001. do {
  18002. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  18003. intersects( p, p.next, a, b ) ) return true;
  18004. p = p.next;
  18005. } while ( p !== a );
  18006. return false;
  18007. }
  18008. // check if a polygon diagonal is locally inside the polygon
  18009. function locallyInside( a, b ) {
  18010. return area( a.prev, a, a.next ) < 0 ?
  18011. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  18012. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  18013. }
  18014. // check if the middle point of a polygon diagonal is inside the polygon
  18015. function middleInside( a, b ) {
  18016. var p = a,
  18017. inside = false,
  18018. px = ( a.x + b.x ) / 2,
  18019. py = ( a.y + b.y ) / 2;
  18020. do {
  18021. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  18022. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  18023. inside = ! inside;
  18024. p = p.next;
  18025. } while ( p !== a );
  18026. return inside;
  18027. }
  18028. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18029. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18030. function splitPolygon( a, b ) {
  18031. var a2 = new Node( a.i, a.x, a.y ),
  18032. b2 = new Node( b.i, b.x, b.y ),
  18033. an = a.next,
  18034. bp = b.prev;
  18035. a.next = b;
  18036. b.prev = a;
  18037. a2.next = an;
  18038. an.prev = a2;
  18039. b2.next = a2;
  18040. a2.prev = b2;
  18041. bp.next = b2;
  18042. b2.prev = bp;
  18043. return b2;
  18044. }
  18045. // create a node and optionally link it with previous one (in a circular doubly linked list)
  18046. function insertNode( i, x, y, last ) {
  18047. var p = new Node( i, x, y );
  18048. if ( ! last ) {
  18049. p.prev = p;
  18050. p.next = p;
  18051. } else {
  18052. p.next = last.next;
  18053. p.prev = last;
  18054. last.next.prev = p;
  18055. last.next = p;
  18056. }
  18057. return p;
  18058. }
  18059. function removeNode( p ) {
  18060. p.next.prev = p.prev;
  18061. p.prev.next = p.next;
  18062. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  18063. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  18064. }
  18065. function Node( i, x, y ) {
  18066. // vertex index in coordinates array
  18067. this.i = i;
  18068. // vertex coordinates
  18069. this.x = x;
  18070. this.y = y;
  18071. // previous and next vertex nodes in a polygon ring
  18072. this.prev = null;
  18073. this.next = null;
  18074. // z-order curve value
  18075. this.z = null;
  18076. // previous and next nodes in z-order
  18077. this.prevZ = null;
  18078. this.nextZ = null;
  18079. // indicates whether this is a steiner point
  18080. this.steiner = false;
  18081. }
  18082. function signedArea( data, start, end, dim ) {
  18083. var sum = 0;
  18084. for ( var i = start, j = end - dim; i < end; i += dim ) {
  18085. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  18086. j = i;
  18087. }
  18088. return sum;
  18089. }
  18090. /**
  18091. * @author zz85 / http://www.lab4games.net/zz85/blog
  18092. */
  18093. var ShapeUtils = {
  18094. // calculate area of the contour polygon
  18095. area: function ( contour ) {
  18096. var n = contour.length;
  18097. var a = 0.0;
  18098. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  18099. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  18100. }
  18101. return a * 0.5;
  18102. },
  18103. isClockWise: function ( pts ) {
  18104. return ShapeUtils.area( pts ) < 0;
  18105. },
  18106. triangulateShape: function ( contour, holes ) {
  18107. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18108. var holeIndices = []; // array of hole indices
  18109. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18110. removeDupEndPts( contour );
  18111. addContour( vertices, contour );
  18112. //
  18113. var holeIndex = contour.length;
  18114. holes.forEach( removeDupEndPts );
  18115. for ( var i = 0; i < holes.length; i ++ ) {
  18116. holeIndices.push( holeIndex );
  18117. holeIndex += holes[ i ].length;
  18118. addContour( vertices, holes[ i ] );
  18119. }
  18120. //
  18121. var triangles = Earcut.triangulate( vertices, holeIndices );
  18122. //
  18123. for ( var i = 0; i < triangles.length; i += 3 ) {
  18124. faces.push( triangles.slice( i, i + 3 ) );
  18125. }
  18126. return faces;
  18127. }
  18128. };
  18129. function removeDupEndPts( points ) {
  18130. var l = points.length;
  18131. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  18132. points.pop();
  18133. }
  18134. }
  18135. function addContour( vertices, contour ) {
  18136. for ( var i = 0; i < contour.length; i ++ ) {
  18137. vertices.push( contour[ i ].x );
  18138. vertices.push( contour[ i ].y );
  18139. }
  18140. }
  18141. /**
  18142. * @author zz85 / http://www.lab4games.net/zz85/blog
  18143. *
  18144. * Creates extruded geometry from a path shape.
  18145. *
  18146. * parameters = {
  18147. *
  18148. * curveSegments: <int>, // number of points on the curves
  18149. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18150. * depth: <float>, // Depth to extrude the shape
  18151. *
  18152. * bevelEnabled: <bool>, // turn on bevel
  18153. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18154. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  18155. * bevelOffset: <float>, // how far from shape outline does bevel start
  18156. * bevelSegments: <int>, // number of bevel layers
  18157. *
  18158. * extrudePath: <THREE.Curve> // curve to extrude shape along
  18159. *
  18160. * UVGenerator: <Object> // object that provides UV generator functions
  18161. *
  18162. * }
  18163. */
  18164. // ExtrudeGeometry
  18165. function ExtrudeGeometry( shapes, options ) {
  18166. Geometry.call( this );
  18167. this.type = 'ExtrudeGeometry';
  18168. this.parameters = {
  18169. shapes: shapes,
  18170. options: options
  18171. };
  18172. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  18173. this.mergeVertices();
  18174. }
  18175. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  18176. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  18177. ExtrudeGeometry.prototype.toJSON = function () {
  18178. var data = Geometry.prototype.toJSON.call( this );
  18179. var shapes = this.parameters.shapes;
  18180. var options = this.parameters.options;
  18181. return toJSON( shapes, options, data );
  18182. };
  18183. // ExtrudeBufferGeometry
  18184. function ExtrudeBufferGeometry( shapes, options ) {
  18185. BufferGeometry.call( this );
  18186. this.type = 'ExtrudeBufferGeometry';
  18187. this.parameters = {
  18188. shapes: shapes,
  18189. options: options
  18190. };
  18191. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18192. var scope = this;
  18193. var verticesArray = [];
  18194. var uvArray = [];
  18195. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18196. var shape = shapes[ i ];
  18197. addShape( shape );
  18198. }
  18199. // build geometry
  18200. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  18201. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  18202. this.computeVertexNormals();
  18203. // functions
  18204. function addShape( shape ) {
  18205. var placeholder = [];
  18206. // options
  18207. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18208. var steps = options.steps !== undefined ? options.steps : 1;
  18209. var depth = options.depth !== undefined ? options.depth : 100;
  18210. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18211. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18212. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18213. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18214. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18215. var extrudePath = options.extrudePath;
  18216. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  18217. // deprecated options
  18218. if ( options.amount !== undefined ) {
  18219. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  18220. depth = options.amount;
  18221. }
  18222. //
  18223. var extrudePts, extrudeByPath = false;
  18224. var splineTube, binormal, normal, position2;
  18225. if ( extrudePath ) {
  18226. extrudePts = extrudePath.getSpacedPoints( steps );
  18227. extrudeByPath = true;
  18228. bevelEnabled = false; // bevels not supported for path extrusion
  18229. // SETUP TNB variables
  18230. // TODO1 - have a .isClosed in spline?
  18231. splineTube = extrudePath.computeFrenetFrames( steps, false );
  18232. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18233. binormal = new Vector3();
  18234. normal = new Vector3();
  18235. position2 = new Vector3();
  18236. }
  18237. // Safeguards if bevels are not enabled
  18238. if ( ! bevelEnabled ) {
  18239. bevelSegments = 0;
  18240. bevelThickness = 0;
  18241. bevelSize = 0;
  18242. bevelOffset = 0;
  18243. }
  18244. // Variables initialization
  18245. var ahole, h, hl; // looping of holes
  18246. var shapePoints = shape.extractPoints( curveSegments );
  18247. var vertices = shapePoints.shape;
  18248. var holes = shapePoints.holes;
  18249. var reverse = ! ShapeUtils.isClockWise( vertices );
  18250. if ( reverse ) {
  18251. vertices = vertices.reverse();
  18252. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18253. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18254. ahole = holes[ h ];
  18255. if ( ShapeUtils.isClockWise( ahole ) ) {
  18256. holes[ h ] = ahole.reverse();
  18257. }
  18258. }
  18259. }
  18260. var faces = ShapeUtils.triangulateShape( vertices, holes );
  18261. /* Vertices */
  18262. var contour = vertices; // vertices has all points but contour has only points of circumference
  18263. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18264. ahole = holes[ h ];
  18265. vertices = vertices.concat( ahole );
  18266. }
  18267. function scalePt2( pt, vec, size ) {
  18268. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18269. return vec.clone().multiplyScalar( size ).add( pt );
  18270. }
  18271. var b, bs, t, z,
  18272. vert, vlen = vertices.length,
  18273. face, flen = faces.length;
  18274. // Find directions for point movement
  18275. function getBevelVec( inPt, inPrev, inNext ) {
  18276. // computes for inPt the corresponding point inPt' on a new contour
  18277. // shifted by 1 unit (length of normalized vector) to the left
  18278. // if we walk along contour clockwise, this new contour is outside the old one
  18279. //
  18280. // inPt' is the intersection of the two lines parallel to the two
  18281. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18282. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18283. // good reading for geometry algorithms (here: line-line intersection)
  18284. // http://geomalgorithms.com/a05-_intersect-1.html
  18285. var v_prev_x = inPt.x - inPrev.x,
  18286. v_prev_y = inPt.y - inPrev.y;
  18287. var v_next_x = inNext.x - inPt.x,
  18288. v_next_y = inNext.y - inPt.y;
  18289. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18290. // check for collinear edges
  18291. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18292. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  18293. // not collinear
  18294. // length of vectors for normalizing
  18295. var v_prev_len = Math.sqrt( v_prev_lensq );
  18296. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18297. // shift adjacent points by unit vectors to the left
  18298. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18299. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18300. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18301. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18302. // scaling factor for v_prev to intersection point
  18303. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18304. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18305. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18306. // vector from inPt to intersection point
  18307. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18308. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18309. // Don't normalize!, otherwise sharp corners become ugly
  18310. // but prevent crazy spikes
  18311. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18312. if ( v_trans_lensq <= 2 ) {
  18313. return new Vector2( v_trans_x, v_trans_y );
  18314. } else {
  18315. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18316. }
  18317. } else {
  18318. // handle special case of collinear edges
  18319. var direction_eq = false; // assumes: opposite
  18320. if ( v_prev_x > Number.EPSILON ) {
  18321. if ( v_next_x > Number.EPSILON ) {
  18322. direction_eq = true;
  18323. }
  18324. } else {
  18325. if ( v_prev_x < - Number.EPSILON ) {
  18326. if ( v_next_x < - Number.EPSILON ) {
  18327. direction_eq = true;
  18328. }
  18329. } else {
  18330. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18331. direction_eq = true;
  18332. }
  18333. }
  18334. }
  18335. if ( direction_eq ) {
  18336. // console.log("Warning: lines are a straight sequence");
  18337. v_trans_x = - v_prev_y;
  18338. v_trans_y = v_prev_x;
  18339. shrink_by = Math.sqrt( v_prev_lensq );
  18340. } else {
  18341. // console.log("Warning: lines are a straight spike");
  18342. v_trans_x = v_prev_x;
  18343. v_trans_y = v_prev_y;
  18344. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18345. }
  18346. }
  18347. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18348. }
  18349. var contourMovements = [];
  18350. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18351. if ( j === il ) j = 0;
  18352. if ( k === il ) k = 0;
  18353. // (j)---(i)---(k)
  18354. // console.log('i,j,k', i, j , k)
  18355. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18356. }
  18357. var holesMovements = [],
  18358. oneHoleMovements, verticesMovements = contourMovements.concat();
  18359. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18360. ahole = holes[ h ];
  18361. oneHoleMovements = [];
  18362. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18363. if ( j === il ) j = 0;
  18364. if ( k === il ) k = 0;
  18365. // (j)---(i)---(k)
  18366. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18367. }
  18368. holesMovements.push( oneHoleMovements );
  18369. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18370. }
  18371. // Loop bevelSegments, 1 for the front, 1 for the back
  18372. for ( b = 0; b < bevelSegments; b ++ ) {
  18373. //for ( b = bevelSegments; b > 0; b -- ) {
  18374. t = b / bevelSegments;
  18375. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18376. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18377. // contract shape
  18378. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18379. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18380. v( vert.x, vert.y, - z );
  18381. }
  18382. // expand holes
  18383. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18384. ahole = holes[ h ];
  18385. oneHoleMovements = holesMovements[ h ];
  18386. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18387. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18388. v( vert.x, vert.y, - z );
  18389. }
  18390. }
  18391. }
  18392. bs = bevelSize + bevelOffset;
  18393. // Back facing vertices
  18394. for ( i = 0; i < vlen; i ++ ) {
  18395. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18396. if ( ! extrudeByPath ) {
  18397. v( vert.x, vert.y, 0 );
  18398. } else {
  18399. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18400. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  18401. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  18402. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18403. v( position2.x, position2.y, position2.z );
  18404. }
  18405. }
  18406. // Add stepped vertices...
  18407. // Including front facing vertices
  18408. var s;
  18409. for ( s = 1; s <= steps; s ++ ) {
  18410. for ( i = 0; i < vlen; i ++ ) {
  18411. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18412. if ( ! extrudeByPath ) {
  18413. v( vert.x, vert.y, depth / steps * s );
  18414. } else {
  18415. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18416. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  18417. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  18418. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18419. v( position2.x, position2.y, position2.z );
  18420. }
  18421. }
  18422. }
  18423. // Add bevel segments planes
  18424. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18425. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18426. t = b / bevelSegments;
  18427. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18428. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18429. // contract shape
  18430. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18431. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18432. v( vert.x, vert.y, depth + z );
  18433. }
  18434. // expand holes
  18435. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18436. ahole = holes[ h ];
  18437. oneHoleMovements = holesMovements[ h ];
  18438. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18439. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18440. if ( ! extrudeByPath ) {
  18441. v( vert.x, vert.y, depth + z );
  18442. } else {
  18443. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18444. }
  18445. }
  18446. }
  18447. }
  18448. /* Faces */
  18449. // Top and bottom faces
  18450. buildLidFaces();
  18451. // Sides faces
  18452. buildSideFaces();
  18453. ///// Internal functions
  18454. function buildLidFaces() {
  18455. var start = verticesArray.length / 3;
  18456. if ( bevelEnabled ) {
  18457. var layer = 0; // steps + 1
  18458. var offset = vlen * layer;
  18459. // Bottom faces
  18460. for ( i = 0; i < flen; i ++ ) {
  18461. face = faces[ i ];
  18462. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18463. }
  18464. layer = steps + bevelSegments * 2;
  18465. offset = vlen * layer;
  18466. // Top faces
  18467. for ( i = 0; i < flen; i ++ ) {
  18468. face = faces[ i ];
  18469. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18470. }
  18471. } else {
  18472. // Bottom faces
  18473. for ( i = 0; i < flen; i ++ ) {
  18474. face = faces[ i ];
  18475. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18476. }
  18477. // Top faces
  18478. for ( i = 0; i < flen; i ++ ) {
  18479. face = faces[ i ];
  18480. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18481. }
  18482. }
  18483. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18484. }
  18485. // Create faces for the z-sides of the shape
  18486. function buildSideFaces() {
  18487. var start = verticesArray.length / 3;
  18488. var layeroffset = 0;
  18489. sidewalls( contour, layeroffset );
  18490. layeroffset += contour.length;
  18491. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18492. ahole = holes[ h ];
  18493. sidewalls( ahole, layeroffset );
  18494. //, true
  18495. layeroffset += ahole.length;
  18496. }
  18497. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18498. }
  18499. function sidewalls( contour, layeroffset ) {
  18500. var j, k;
  18501. i = contour.length;
  18502. while ( -- i >= 0 ) {
  18503. j = i;
  18504. k = i - 1;
  18505. if ( k < 0 ) k = contour.length - 1;
  18506. //console.log('b', i,j, i-1, k,vertices.length);
  18507. var s = 0,
  18508. sl = steps + bevelSegments * 2;
  18509. for ( s = 0; s < sl; s ++ ) {
  18510. var slen1 = vlen * s;
  18511. var slen2 = vlen * ( s + 1 );
  18512. var a = layeroffset + j + slen1,
  18513. b = layeroffset + k + slen1,
  18514. c = layeroffset + k + slen2,
  18515. d = layeroffset + j + slen2;
  18516. f4( a, b, c, d );
  18517. }
  18518. }
  18519. }
  18520. function v( x, y, z ) {
  18521. placeholder.push( x );
  18522. placeholder.push( y );
  18523. placeholder.push( z );
  18524. }
  18525. function f3( a, b, c ) {
  18526. addVertex( a );
  18527. addVertex( b );
  18528. addVertex( c );
  18529. var nextIndex = verticesArray.length / 3;
  18530. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18531. addUV( uvs[ 0 ] );
  18532. addUV( uvs[ 1 ] );
  18533. addUV( uvs[ 2 ] );
  18534. }
  18535. function f4( a, b, c, d ) {
  18536. addVertex( a );
  18537. addVertex( b );
  18538. addVertex( d );
  18539. addVertex( b );
  18540. addVertex( c );
  18541. addVertex( d );
  18542. var nextIndex = verticesArray.length / 3;
  18543. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18544. addUV( uvs[ 0 ] );
  18545. addUV( uvs[ 1 ] );
  18546. addUV( uvs[ 3 ] );
  18547. addUV( uvs[ 1 ] );
  18548. addUV( uvs[ 2 ] );
  18549. addUV( uvs[ 3 ] );
  18550. }
  18551. function addVertex( index ) {
  18552. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18553. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18554. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18555. }
  18556. function addUV( vector2 ) {
  18557. uvArray.push( vector2.x );
  18558. uvArray.push( vector2.y );
  18559. }
  18560. }
  18561. }
  18562. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18563. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  18564. ExtrudeBufferGeometry.prototype.toJSON = function () {
  18565. var data = BufferGeometry.prototype.toJSON.call( this );
  18566. var shapes = this.parameters.shapes;
  18567. var options = this.parameters.options;
  18568. return toJSON( shapes, options, data );
  18569. };
  18570. //
  18571. var WorldUVGenerator = {
  18572. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18573. var a_x = vertices[ indexA * 3 ];
  18574. var a_y = vertices[ indexA * 3 + 1 ];
  18575. var b_x = vertices[ indexB * 3 ];
  18576. var b_y = vertices[ indexB * 3 + 1 ];
  18577. var c_x = vertices[ indexC * 3 ];
  18578. var c_y = vertices[ indexC * 3 + 1 ];
  18579. return [
  18580. new Vector2( a_x, a_y ),
  18581. new Vector2( b_x, b_y ),
  18582. new Vector2( c_x, c_y )
  18583. ];
  18584. },
  18585. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  18586. var a_x = vertices[ indexA * 3 ];
  18587. var a_y = vertices[ indexA * 3 + 1 ];
  18588. var a_z = vertices[ indexA * 3 + 2 ];
  18589. var b_x = vertices[ indexB * 3 ];
  18590. var b_y = vertices[ indexB * 3 + 1 ];
  18591. var b_z = vertices[ indexB * 3 + 2 ];
  18592. var c_x = vertices[ indexC * 3 ];
  18593. var c_y = vertices[ indexC * 3 + 1 ];
  18594. var c_z = vertices[ indexC * 3 + 2 ];
  18595. var d_x = vertices[ indexD * 3 ];
  18596. var d_y = vertices[ indexD * 3 + 1 ];
  18597. var d_z = vertices[ indexD * 3 + 2 ];
  18598. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  18599. return [
  18600. new Vector2( a_x, 1 - a_z ),
  18601. new Vector2( b_x, 1 - b_z ),
  18602. new Vector2( c_x, 1 - c_z ),
  18603. new Vector2( d_x, 1 - d_z )
  18604. ];
  18605. } else {
  18606. return [
  18607. new Vector2( a_y, 1 - a_z ),
  18608. new Vector2( b_y, 1 - b_z ),
  18609. new Vector2( c_y, 1 - c_z ),
  18610. new Vector2( d_y, 1 - d_z )
  18611. ];
  18612. }
  18613. }
  18614. };
  18615. function toJSON( shapes, options, data ) {
  18616. //
  18617. data.shapes = [];
  18618. if ( Array.isArray( shapes ) ) {
  18619. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18620. var shape = shapes[ i ];
  18621. data.shapes.push( shape.uuid );
  18622. }
  18623. } else {
  18624. data.shapes.push( shapes.uuid );
  18625. }
  18626. //
  18627. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18628. return data;
  18629. }
  18630. /**
  18631. * @author zz85 / http://www.lab4games.net/zz85/blog
  18632. * @author alteredq / http://alteredqualia.com/
  18633. *
  18634. * Text = 3D Text
  18635. *
  18636. * parameters = {
  18637. * font: <THREE.Font>, // font
  18638. *
  18639. * size: <float>, // size of the text
  18640. * height: <float>, // thickness to extrude text
  18641. * curveSegments: <int>, // number of points on the curves
  18642. *
  18643. * bevelEnabled: <bool>, // turn on bevel
  18644. * bevelThickness: <float>, // how deep into text bevel goes
  18645. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18646. * bevelOffset: <float> // how far from text outline does bevel start
  18647. * }
  18648. */
  18649. // TextGeometry
  18650. function TextGeometry( text, parameters ) {
  18651. Geometry.call( this );
  18652. this.type = 'TextGeometry';
  18653. this.parameters = {
  18654. text: text,
  18655. parameters: parameters
  18656. };
  18657. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  18658. this.mergeVertices();
  18659. }
  18660. TextGeometry.prototype = Object.create( Geometry.prototype );
  18661. TextGeometry.prototype.constructor = TextGeometry;
  18662. // TextBufferGeometry
  18663. function TextBufferGeometry( text, parameters ) {
  18664. parameters = parameters || {};
  18665. var font = parameters.font;
  18666. if ( ! ( font && font.isFont ) ) {
  18667. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18668. return new Geometry();
  18669. }
  18670. var shapes = font.generateShapes( text, parameters.size );
  18671. // translate parameters to ExtrudeGeometry API
  18672. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18673. // defaults
  18674. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18675. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18676. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18677. ExtrudeBufferGeometry.call( this, shapes, parameters );
  18678. this.type = 'TextBufferGeometry';
  18679. }
  18680. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  18681. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  18682. /**
  18683. * @author mrdoob / http://mrdoob.com/
  18684. * @author benaadams / https://twitter.com/ben_a_adams
  18685. * @author Mugen87 / https://github.com/Mugen87
  18686. */
  18687. // SphereGeometry
  18688. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18689. Geometry.call( this );
  18690. this.type = 'SphereGeometry';
  18691. this.parameters = {
  18692. radius: radius,
  18693. widthSegments: widthSegments,
  18694. heightSegments: heightSegments,
  18695. phiStart: phiStart,
  18696. phiLength: phiLength,
  18697. thetaStart: thetaStart,
  18698. thetaLength: thetaLength
  18699. };
  18700. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  18701. this.mergeVertices();
  18702. }
  18703. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18704. SphereGeometry.prototype.constructor = SphereGeometry;
  18705. // SphereBufferGeometry
  18706. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18707. BufferGeometry.call( this );
  18708. this.type = 'SphereBufferGeometry';
  18709. this.parameters = {
  18710. radius: radius,
  18711. widthSegments: widthSegments,
  18712. heightSegments: heightSegments,
  18713. phiStart: phiStart,
  18714. phiLength: phiLength,
  18715. thetaStart: thetaStart,
  18716. thetaLength: thetaLength
  18717. };
  18718. radius = radius || 1;
  18719. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18720. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18721. phiStart = phiStart !== undefined ? phiStart : 0;
  18722. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18723. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18724. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18725. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18726. var ix, iy;
  18727. var index = 0;
  18728. var grid = [];
  18729. var vertex = new Vector3();
  18730. var normal = new Vector3();
  18731. // buffers
  18732. var indices = [];
  18733. var vertices = [];
  18734. var normals = [];
  18735. var uvs = [];
  18736. // generate vertices, normals and uvs
  18737. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18738. var verticesRow = [];
  18739. var v = iy / heightSegments;
  18740. // special case for the poles
  18741. var uOffset = 0;
  18742. if ( iy == 0 && thetaStart == 0 ) {
  18743. uOffset = 0.5 / widthSegments;
  18744. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18745. uOffset = - 0.5 / widthSegments;
  18746. }
  18747. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18748. var u = ix / widthSegments;
  18749. // vertex
  18750. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18751. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18752. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18753. vertices.push( vertex.x, vertex.y, vertex.z );
  18754. // normal
  18755. normal.copy( vertex ).normalize();
  18756. normals.push( normal.x, normal.y, normal.z );
  18757. // uv
  18758. uvs.push( u + uOffset, 1 - v );
  18759. verticesRow.push( index ++ );
  18760. }
  18761. grid.push( verticesRow );
  18762. }
  18763. // indices
  18764. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18765. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18766. var a = grid[ iy ][ ix + 1 ];
  18767. var b = grid[ iy ][ ix ];
  18768. var c = grid[ iy + 1 ][ ix ];
  18769. var d = grid[ iy + 1 ][ ix + 1 ];
  18770. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18771. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18772. }
  18773. }
  18774. // build geometry
  18775. this.setIndex( indices );
  18776. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18777. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18778. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18779. }
  18780. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18781. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18782. /**
  18783. * @author Kaleb Murphy
  18784. * @author Mugen87 / https://github.com/Mugen87
  18785. */
  18786. // RingGeometry
  18787. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18788. Geometry.call( this );
  18789. this.type = 'RingGeometry';
  18790. this.parameters = {
  18791. innerRadius: innerRadius,
  18792. outerRadius: outerRadius,
  18793. thetaSegments: thetaSegments,
  18794. phiSegments: phiSegments,
  18795. thetaStart: thetaStart,
  18796. thetaLength: thetaLength
  18797. };
  18798. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18799. this.mergeVertices();
  18800. }
  18801. RingGeometry.prototype = Object.create( Geometry.prototype );
  18802. RingGeometry.prototype.constructor = RingGeometry;
  18803. // RingBufferGeometry
  18804. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18805. BufferGeometry.call( this );
  18806. this.type = 'RingBufferGeometry';
  18807. this.parameters = {
  18808. innerRadius: innerRadius,
  18809. outerRadius: outerRadius,
  18810. thetaSegments: thetaSegments,
  18811. phiSegments: phiSegments,
  18812. thetaStart: thetaStart,
  18813. thetaLength: thetaLength
  18814. };
  18815. innerRadius = innerRadius || 0.5;
  18816. outerRadius = outerRadius || 1;
  18817. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18818. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18819. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18820. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18821. // buffers
  18822. var indices = [];
  18823. var vertices = [];
  18824. var normals = [];
  18825. var uvs = [];
  18826. // some helper variables
  18827. var segment;
  18828. var radius = innerRadius;
  18829. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18830. var vertex = new Vector3();
  18831. var uv = new Vector2();
  18832. var j, i;
  18833. // generate vertices, normals and uvs
  18834. for ( j = 0; j <= phiSegments; j ++ ) {
  18835. for ( i = 0; i <= thetaSegments; i ++ ) {
  18836. // values are generate from the inside of the ring to the outside
  18837. segment = thetaStart + i / thetaSegments * thetaLength;
  18838. // vertex
  18839. vertex.x = radius * Math.cos( segment );
  18840. vertex.y = radius * Math.sin( segment );
  18841. vertices.push( vertex.x, vertex.y, vertex.z );
  18842. // normal
  18843. normals.push( 0, 0, 1 );
  18844. // uv
  18845. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18846. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18847. uvs.push( uv.x, uv.y );
  18848. }
  18849. // increase the radius for next row of vertices
  18850. radius += radiusStep;
  18851. }
  18852. // indices
  18853. for ( j = 0; j < phiSegments; j ++ ) {
  18854. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18855. for ( i = 0; i < thetaSegments; i ++ ) {
  18856. segment = i + thetaSegmentLevel;
  18857. var a = segment;
  18858. var b = segment + thetaSegments + 1;
  18859. var c = segment + thetaSegments + 2;
  18860. var d = segment + 1;
  18861. // faces
  18862. indices.push( a, b, d );
  18863. indices.push( b, c, d );
  18864. }
  18865. }
  18866. // build geometry
  18867. this.setIndex( indices );
  18868. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18869. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18870. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18871. }
  18872. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18873. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18874. /**
  18875. * @author zz85 / https://github.com/zz85
  18876. * @author bhouston / http://clara.io
  18877. * @author Mugen87 / https://github.com/Mugen87
  18878. */
  18879. // LatheGeometry
  18880. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18881. Geometry.call( this );
  18882. this.type = 'LatheGeometry';
  18883. this.parameters = {
  18884. points: points,
  18885. segments: segments,
  18886. phiStart: phiStart,
  18887. phiLength: phiLength
  18888. };
  18889. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18890. this.mergeVertices();
  18891. }
  18892. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18893. LatheGeometry.prototype.constructor = LatheGeometry;
  18894. // LatheBufferGeometry
  18895. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18896. BufferGeometry.call( this );
  18897. this.type = 'LatheBufferGeometry';
  18898. this.parameters = {
  18899. points: points,
  18900. segments: segments,
  18901. phiStart: phiStart,
  18902. phiLength: phiLength
  18903. };
  18904. segments = Math.floor( segments ) || 12;
  18905. phiStart = phiStart || 0;
  18906. phiLength = phiLength || Math.PI * 2;
  18907. // clamp phiLength so it's in range of [ 0, 2PI ]
  18908. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18909. // buffers
  18910. var indices = [];
  18911. var vertices = [];
  18912. var uvs = [];
  18913. // helper variables
  18914. var base;
  18915. var inverseSegments = 1.0 / segments;
  18916. var vertex = new Vector3();
  18917. var uv = new Vector2();
  18918. var i, j;
  18919. // generate vertices and uvs
  18920. for ( i = 0; i <= segments; i ++ ) {
  18921. var phi = phiStart + i * inverseSegments * phiLength;
  18922. var sin = Math.sin( phi );
  18923. var cos = Math.cos( phi );
  18924. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18925. // vertex
  18926. vertex.x = points[ j ].x * sin;
  18927. vertex.y = points[ j ].y;
  18928. vertex.z = points[ j ].x * cos;
  18929. vertices.push( vertex.x, vertex.y, vertex.z );
  18930. // uv
  18931. uv.x = i / segments;
  18932. uv.y = j / ( points.length - 1 );
  18933. uvs.push( uv.x, uv.y );
  18934. }
  18935. }
  18936. // indices
  18937. for ( i = 0; i < segments; i ++ ) {
  18938. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18939. base = j + i * points.length;
  18940. var a = base;
  18941. var b = base + points.length;
  18942. var c = base + points.length + 1;
  18943. var d = base + 1;
  18944. // faces
  18945. indices.push( a, b, d );
  18946. indices.push( b, c, d );
  18947. }
  18948. }
  18949. // build geometry
  18950. this.setIndex( indices );
  18951. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18952. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18953. // generate normals
  18954. this.computeVertexNormals();
  18955. // if the geometry is closed, we need to average the normals along the seam.
  18956. // because the corresponding vertices are identical (but still have different UVs).
  18957. if ( phiLength === Math.PI * 2 ) {
  18958. var normals = this.attributes.normal.array;
  18959. var n1 = new Vector3();
  18960. var n2 = new Vector3();
  18961. var n = new Vector3();
  18962. // this is the buffer offset for the last line of vertices
  18963. base = segments * points.length * 3;
  18964. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18965. // select the normal of the vertex in the first line
  18966. n1.x = normals[ j + 0 ];
  18967. n1.y = normals[ j + 1 ];
  18968. n1.z = normals[ j + 2 ];
  18969. // select the normal of the vertex in the last line
  18970. n2.x = normals[ base + j + 0 ];
  18971. n2.y = normals[ base + j + 1 ];
  18972. n2.z = normals[ base + j + 2 ];
  18973. // average normals
  18974. n.addVectors( n1, n2 ).normalize();
  18975. // assign the new values to both normals
  18976. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18977. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18978. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18979. }
  18980. }
  18981. }
  18982. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18983. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18984. /**
  18985. * @author jonobr1 / http://jonobr1.com
  18986. * @author Mugen87 / https://github.com/Mugen87
  18987. */
  18988. // ShapeGeometry
  18989. function ShapeGeometry( shapes, curveSegments ) {
  18990. Geometry.call( this );
  18991. this.type = 'ShapeGeometry';
  18992. if ( typeof curveSegments === 'object' ) {
  18993. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18994. curveSegments = curveSegments.curveSegments;
  18995. }
  18996. this.parameters = {
  18997. shapes: shapes,
  18998. curveSegments: curveSegments
  18999. };
  19000. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  19001. this.mergeVertices();
  19002. }
  19003. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  19004. ShapeGeometry.prototype.constructor = ShapeGeometry;
  19005. ShapeGeometry.prototype.toJSON = function () {
  19006. var data = Geometry.prototype.toJSON.call( this );
  19007. var shapes = this.parameters.shapes;
  19008. return toJSON$1( shapes, data );
  19009. };
  19010. // ShapeBufferGeometry
  19011. function ShapeBufferGeometry( shapes, curveSegments ) {
  19012. BufferGeometry.call( this );
  19013. this.type = 'ShapeBufferGeometry';
  19014. this.parameters = {
  19015. shapes: shapes,
  19016. curveSegments: curveSegments
  19017. };
  19018. curveSegments = curveSegments || 12;
  19019. // buffers
  19020. var indices = [];
  19021. var vertices = [];
  19022. var normals = [];
  19023. var uvs = [];
  19024. // helper variables
  19025. var groupStart = 0;
  19026. var groupCount = 0;
  19027. // allow single and array values for "shapes" parameter
  19028. if ( Array.isArray( shapes ) === false ) {
  19029. addShape( shapes );
  19030. } else {
  19031. for ( var i = 0; i < shapes.length; i ++ ) {
  19032. addShape( shapes[ i ] );
  19033. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  19034. groupStart += groupCount;
  19035. groupCount = 0;
  19036. }
  19037. }
  19038. // build geometry
  19039. this.setIndex( indices );
  19040. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19041. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19042. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19043. // helper functions
  19044. function addShape( shape ) {
  19045. var i, l, shapeHole;
  19046. var indexOffset = vertices.length / 3;
  19047. var points = shape.extractPoints( curveSegments );
  19048. var shapeVertices = points.shape;
  19049. var shapeHoles = points.holes;
  19050. // check direction of vertices
  19051. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  19052. shapeVertices = shapeVertices.reverse();
  19053. }
  19054. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19055. shapeHole = shapeHoles[ i ];
  19056. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  19057. shapeHoles[ i ] = shapeHole.reverse();
  19058. }
  19059. }
  19060. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  19061. // join vertices of inner and outer paths to a single array
  19062. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19063. shapeHole = shapeHoles[ i ];
  19064. shapeVertices = shapeVertices.concat( shapeHole );
  19065. }
  19066. // vertices, normals, uvs
  19067. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  19068. var vertex = shapeVertices[ i ];
  19069. vertices.push( vertex.x, vertex.y, 0 );
  19070. normals.push( 0, 0, 1 );
  19071. uvs.push( vertex.x, vertex.y ); // world uvs
  19072. }
  19073. // incides
  19074. for ( i = 0, l = faces.length; i < l; i ++ ) {
  19075. var face = faces[ i ];
  19076. var a = face[ 0 ] + indexOffset;
  19077. var b = face[ 1 ] + indexOffset;
  19078. var c = face[ 2 ] + indexOffset;
  19079. indices.push( a, b, c );
  19080. groupCount += 3;
  19081. }
  19082. }
  19083. }
  19084. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19085. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  19086. ShapeBufferGeometry.prototype.toJSON = function () {
  19087. var data = BufferGeometry.prototype.toJSON.call( this );
  19088. var shapes = this.parameters.shapes;
  19089. return toJSON$1( shapes, data );
  19090. };
  19091. //
  19092. function toJSON$1( shapes, data ) {
  19093. data.shapes = [];
  19094. if ( Array.isArray( shapes ) ) {
  19095. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19096. var shape = shapes[ i ];
  19097. data.shapes.push( shape.uuid );
  19098. }
  19099. } else {
  19100. data.shapes.push( shapes.uuid );
  19101. }
  19102. return data;
  19103. }
  19104. /**
  19105. * @author WestLangley / http://github.com/WestLangley
  19106. * @author Mugen87 / https://github.com/Mugen87
  19107. */
  19108. function EdgesGeometry( geometry, thresholdAngle ) {
  19109. BufferGeometry.call( this );
  19110. this.type = 'EdgesGeometry';
  19111. this.parameters = {
  19112. thresholdAngle: thresholdAngle
  19113. };
  19114. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19115. // buffer
  19116. var vertices = [];
  19117. // helper variables
  19118. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  19119. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  19120. var key, keys = [ 'a', 'b', 'c' ];
  19121. // prepare source geometry
  19122. var geometry2;
  19123. if ( geometry.isBufferGeometry ) {
  19124. geometry2 = new Geometry();
  19125. geometry2.fromBufferGeometry( geometry );
  19126. } else {
  19127. geometry2 = geometry.clone();
  19128. }
  19129. geometry2.mergeVertices();
  19130. geometry2.computeFaceNormals();
  19131. var sourceVertices = geometry2.vertices;
  19132. var faces = geometry2.faces;
  19133. // now create a data structure where each entry represents an edge with its adjoining faces
  19134. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19135. var face = faces[ i ];
  19136. for ( var j = 0; j < 3; j ++ ) {
  19137. edge1 = face[ keys[ j ] ];
  19138. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  19139. edge[ 0 ] = Math.min( edge1, edge2 );
  19140. edge[ 1 ] = Math.max( edge1, edge2 );
  19141. key = edge[ 0 ] + ',' + edge[ 1 ];
  19142. if ( edges[ key ] === undefined ) {
  19143. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  19144. } else {
  19145. edges[ key ].face2 = i;
  19146. }
  19147. }
  19148. }
  19149. // generate vertices
  19150. for ( key in edges ) {
  19151. var e = edges[ key ];
  19152. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  19153. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  19154. var vertex = sourceVertices[ e.index1 ];
  19155. vertices.push( vertex.x, vertex.y, vertex.z );
  19156. vertex = sourceVertices[ e.index2 ];
  19157. vertices.push( vertex.x, vertex.y, vertex.z );
  19158. }
  19159. }
  19160. // build geometry
  19161. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19162. }
  19163. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  19164. EdgesGeometry.prototype.constructor = EdgesGeometry;
  19165. /**
  19166. * @author mrdoob / http://mrdoob.com/
  19167. * @author Mugen87 / https://github.com/Mugen87
  19168. */
  19169. // CylinderGeometry
  19170. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19171. Geometry.call( this );
  19172. this.type = 'CylinderGeometry';
  19173. this.parameters = {
  19174. radiusTop: radiusTop,
  19175. radiusBottom: radiusBottom,
  19176. height: height,
  19177. radialSegments: radialSegments,
  19178. heightSegments: heightSegments,
  19179. openEnded: openEnded,
  19180. thetaStart: thetaStart,
  19181. thetaLength: thetaLength
  19182. };
  19183. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  19184. this.mergeVertices();
  19185. }
  19186. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  19187. CylinderGeometry.prototype.constructor = CylinderGeometry;
  19188. // CylinderBufferGeometry
  19189. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19190. BufferGeometry.call( this );
  19191. this.type = 'CylinderBufferGeometry';
  19192. this.parameters = {
  19193. radiusTop: radiusTop,
  19194. radiusBottom: radiusBottom,
  19195. height: height,
  19196. radialSegments: radialSegments,
  19197. heightSegments: heightSegments,
  19198. openEnded: openEnded,
  19199. thetaStart: thetaStart,
  19200. thetaLength: thetaLength
  19201. };
  19202. var scope = this;
  19203. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  19204. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  19205. height = height || 1;
  19206. radialSegments = Math.floor( radialSegments ) || 8;
  19207. heightSegments = Math.floor( heightSegments ) || 1;
  19208. openEnded = openEnded !== undefined ? openEnded : false;
  19209. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  19210. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19211. // buffers
  19212. var indices = [];
  19213. var vertices = [];
  19214. var normals = [];
  19215. var uvs = [];
  19216. // helper variables
  19217. var index = 0;
  19218. var indexArray = [];
  19219. var halfHeight = height / 2;
  19220. var groupStart = 0;
  19221. // generate geometry
  19222. generateTorso();
  19223. if ( openEnded === false ) {
  19224. if ( radiusTop > 0 ) generateCap( true );
  19225. if ( radiusBottom > 0 ) generateCap( false );
  19226. }
  19227. // build geometry
  19228. this.setIndex( indices );
  19229. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19230. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19231. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19232. function generateTorso() {
  19233. var x, y;
  19234. var normal = new Vector3();
  19235. var vertex = new Vector3();
  19236. var groupCount = 0;
  19237. // this will be used to calculate the normal
  19238. var slope = ( radiusBottom - radiusTop ) / height;
  19239. // generate vertices, normals and uvs
  19240. for ( y = 0; y <= heightSegments; y ++ ) {
  19241. var indexRow = [];
  19242. var v = y / heightSegments;
  19243. // calculate the radius of the current row
  19244. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19245. for ( x = 0; x <= radialSegments; x ++ ) {
  19246. var u = x / radialSegments;
  19247. var theta = u * thetaLength + thetaStart;
  19248. var sinTheta = Math.sin( theta );
  19249. var cosTheta = Math.cos( theta );
  19250. // vertex
  19251. vertex.x = radius * sinTheta;
  19252. vertex.y = - v * height + halfHeight;
  19253. vertex.z = radius * cosTheta;
  19254. vertices.push( vertex.x, vertex.y, vertex.z );
  19255. // normal
  19256. normal.set( sinTheta, slope, cosTheta ).normalize();
  19257. normals.push( normal.x, normal.y, normal.z );
  19258. // uv
  19259. uvs.push( u, 1 - v );
  19260. // save index of vertex in respective row
  19261. indexRow.push( index ++ );
  19262. }
  19263. // now save vertices of the row in our index array
  19264. indexArray.push( indexRow );
  19265. }
  19266. // generate indices
  19267. for ( x = 0; x < radialSegments; x ++ ) {
  19268. for ( y = 0; y < heightSegments; y ++ ) {
  19269. // we use the index array to access the correct indices
  19270. var a = indexArray[ y ][ x ];
  19271. var b = indexArray[ y + 1 ][ x ];
  19272. var c = indexArray[ y + 1 ][ x + 1 ];
  19273. var d = indexArray[ y ][ x + 1 ];
  19274. // faces
  19275. indices.push( a, b, d );
  19276. indices.push( b, c, d );
  19277. // update group counter
  19278. groupCount += 6;
  19279. }
  19280. }
  19281. // add a group to the geometry. this will ensure multi material support
  19282. scope.addGroup( groupStart, groupCount, 0 );
  19283. // calculate new start value for groups
  19284. groupStart += groupCount;
  19285. }
  19286. function generateCap( top ) {
  19287. var x, centerIndexStart, centerIndexEnd;
  19288. var uv = new Vector2();
  19289. var vertex = new Vector3();
  19290. var groupCount = 0;
  19291. var radius = ( top === true ) ? radiusTop : radiusBottom;
  19292. var sign = ( top === true ) ? 1 : - 1;
  19293. // save the index of the first center vertex
  19294. centerIndexStart = index;
  19295. // first we generate the center vertex data of the cap.
  19296. // because the geometry needs one set of uvs per face,
  19297. // we must generate a center vertex per face/segment
  19298. for ( x = 1; x <= radialSegments; x ++ ) {
  19299. // vertex
  19300. vertices.push( 0, halfHeight * sign, 0 );
  19301. // normal
  19302. normals.push( 0, sign, 0 );
  19303. // uv
  19304. uvs.push( 0.5, 0.5 );
  19305. // increase index
  19306. index ++;
  19307. }
  19308. // save the index of the last center vertex
  19309. centerIndexEnd = index;
  19310. // now we generate the surrounding vertices, normals and uvs
  19311. for ( x = 0; x <= radialSegments; x ++ ) {
  19312. var u = x / radialSegments;
  19313. var theta = u * thetaLength + thetaStart;
  19314. var cosTheta = Math.cos( theta );
  19315. var sinTheta = Math.sin( theta );
  19316. // vertex
  19317. vertex.x = radius * sinTheta;
  19318. vertex.y = halfHeight * sign;
  19319. vertex.z = radius * cosTheta;
  19320. vertices.push( vertex.x, vertex.y, vertex.z );
  19321. // normal
  19322. normals.push( 0, sign, 0 );
  19323. // uv
  19324. uv.x = ( cosTheta * 0.5 ) + 0.5;
  19325. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  19326. uvs.push( uv.x, uv.y );
  19327. // increase index
  19328. index ++;
  19329. }
  19330. // generate indices
  19331. for ( x = 0; x < radialSegments; x ++ ) {
  19332. var c = centerIndexStart + x;
  19333. var i = centerIndexEnd + x;
  19334. if ( top === true ) {
  19335. // face top
  19336. indices.push( i, i + 1, c );
  19337. } else {
  19338. // face bottom
  19339. indices.push( i + 1, i, c );
  19340. }
  19341. groupCount += 3;
  19342. }
  19343. // add a group to the geometry. this will ensure multi material support
  19344. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  19345. // calculate new start value for groups
  19346. groupStart += groupCount;
  19347. }
  19348. }
  19349. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19350. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  19351. /**
  19352. * @author abelnation / http://github.com/abelnation
  19353. */
  19354. // ConeGeometry
  19355. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19356. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19357. this.type = 'ConeGeometry';
  19358. this.parameters = {
  19359. radius: radius,
  19360. height: height,
  19361. radialSegments: radialSegments,
  19362. heightSegments: heightSegments,
  19363. openEnded: openEnded,
  19364. thetaStart: thetaStart,
  19365. thetaLength: thetaLength
  19366. };
  19367. }
  19368. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  19369. ConeGeometry.prototype.constructor = ConeGeometry;
  19370. // ConeBufferGeometry
  19371. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19372. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19373. this.type = 'ConeBufferGeometry';
  19374. this.parameters = {
  19375. radius: radius,
  19376. height: height,
  19377. radialSegments: radialSegments,
  19378. heightSegments: heightSegments,
  19379. openEnded: openEnded,
  19380. thetaStart: thetaStart,
  19381. thetaLength: thetaLength
  19382. };
  19383. }
  19384. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  19385. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  19386. /**
  19387. * @author benaadams / https://twitter.com/ben_a_adams
  19388. * @author Mugen87 / https://github.com/Mugen87
  19389. * @author hughes
  19390. */
  19391. // CircleGeometry
  19392. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  19393. Geometry.call( this );
  19394. this.type = 'CircleGeometry';
  19395. this.parameters = {
  19396. radius: radius,
  19397. segments: segments,
  19398. thetaStart: thetaStart,
  19399. thetaLength: thetaLength
  19400. };
  19401. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  19402. this.mergeVertices();
  19403. }
  19404. CircleGeometry.prototype = Object.create( Geometry.prototype );
  19405. CircleGeometry.prototype.constructor = CircleGeometry;
  19406. // CircleBufferGeometry
  19407. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  19408. BufferGeometry.call( this );
  19409. this.type = 'CircleBufferGeometry';
  19410. this.parameters = {
  19411. radius: radius,
  19412. segments: segments,
  19413. thetaStart: thetaStart,
  19414. thetaLength: thetaLength
  19415. };
  19416. radius = radius || 1;
  19417. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19418. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19419. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19420. // buffers
  19421. var indices = [];
  19422. var vertices = [];
  19423. var normals = [];
  19424. var uvs = [];
  19425. // helper variables
  19426. var i, s;
  19427. var vertex = new Vector3();
  19428. var uv = new Vector2();
  19429. // center point
  19430. vertices.push( 0, 0, 0 );
  19431. normals.push( 0, 0, 1 );
  19432. uvs.push( 0.5, 0.5 );
  19433. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  19434. var segment = thetaStart + s / segments * thetaLength;
  19435. // vertex
  19436. vertex.x = radius * Math.cos( segment );
  19437. vertex.y = radius * Math.sin( segment );
  19438. vertices.push( vertex.x, vertex.y, vertex.z );
  19439. // normal
  19440. normals.push( 0, 0, 1 );
  19441. // uvs
  19442. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19443. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19444. uvs.push( uv.x, uv.y );
  19445. }
  19446. // indices
  19447. for ( i = 1; i <= segments; i ++ ) {
  19448. indices.push( i, i + 1, 0 );
  19449. }
  19450. // build geometry
  19451. this.setIndex( indices );
  19452. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19453. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19454. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19455. }
  19456. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19457. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19458. var Geometries = /*#__PURE__*/Object.freeze({
  19459. __proto__: null,
  19460. WireframeGeometry: WireframeGeometry,
  19461. ParametricGeometry: ParametricGeometry,
  19462. ParametricBufferGeometry: ParametricBufferGeometry,
  19463. TetrahedronGeometry: TetrahedronGeometry,
  19464. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19465. OctahedronGeometry: OctahedronGeometry,
  19466. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19467. IcosahedronGeometry: IcosahedronGeometry,
  19468. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19469. DodecahedronGeometry: DodecahedronGeometry,
  19470. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19471. PolyhedronGeometry: PolyhedronGeometry,
  19472. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19473. TubeGeometry: TubeGeometry,
  19474. TubeBufferGeometry: TubeBufferGeometry,
  19475. TorusKnotGeometry: TorusKnotGeometry,
  19476. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19477. TorusGeometry: TorusGeometry,
  19478. TorusBufferGeometry: TorusBufferGeometry,
  19479. TextGeometry: TextGeometry,
  19480. TextBufferGeometry: TextBufferGeometry,
  19481. SphereGeometry: SphereGeometry,
  19482. SphereBufferGeometry: SphereBufferGeometry,
  19483. RingGeometry: RingGeometry,
  19484. RingBufferGeometry: RingBufferGeometry,
  19485. PlaneGeometry: PlaneGeometry,
  19486. PlaneBufferGeometry: PlaneBufferGeometry,
  19487. LatheGeometry: LatheGeometry,
  19488. LatheBufferGeometry: LatheBufferGeometry,
  19489. ShapeGeometry: ShapeGeometry,
  19490. ShapeBufferGeometry: ShapeBufferGeometry,
  19491. ExtrudeGeometry: ExtrudeGeometry,
  19492. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19493. EdgesGeometry: EdgesGeometry,
  19494. ConeGeometry: ConeGeometry,
  19495. ConeBufferGeometry: ConeBufferGeometry,
  19496. CylinderGeometry: CylinderGeometry,
  19497. CylinderBufferGeometry: CylinderBufferGeometry,
  19498. CircleGeometry: CircleGeometry,
  19499. CircleBufferGeometry: CircleBufferGeometry,
  19500. BoxGeometry: BoxGeometry,
  19501. BoxBufferGeometry: BoxBufferGeometry
  19502. });
  19503. /**
  19504. * @author mrdoob / http://mrdoob.com/
  19505. *
  19506. * parameters = {
  19507. * color: <THREE.Color>
  19508. * }
  19509. */
  19510. function ShadowMaterial( parameters ) {
  19511. Material.call( this );
  19512. this.type = 'ShadowMaterial';
  19513. this.color = new Color( 0x000000 );
  19514. this.transparent = true;
  19515. this.setValues( parameters );
  19516. }
  19517. ShadowMaterial.prototype = Object.create( Material.prototype );
  19518. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19519. ShadowMaterial.prototype.isShadowMaterial = true;
  19520. ShadowMaterial.prototype.copy = function ( source ) {
  19521. Material.prototype.copy.call( this, source );
  19522. this.color.copy( source.color );
  19523. return this;
  19524. };
  19525. /**
  19526. * @author mrdoob / http://mrdoob.com/
  19527. */
  19528. function RawShaderMaterial( parameters ) {
  19529. ShaderMaterial.call( this, parameters );
  19530. this.type = 'RawShaderMaterial';
  19531. }
  19532. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19533. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19534. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19535. /**
  19536. * @author WestLangley / http://github.com/WestLangley
  19537. *
  19538. * parameters = {
  19539. * color: <hex>,
  19540. * roughness: <float>,
  19541. * metalness: <float>,
  19542. * opacity: <float>,
  19543. *
  19544. * map: new THREE.Texture( <Image> ),
  19545. *
  19546. * lightMap: new THREE.Texture( <Image> ),
  19547. * lightMapIntensity: <float>
  19548. *
  19549. * aoMap: new THREE.Texture( <Image> ),
  19550. * aoMapIntensity: <float>
  19551. *
  19552. * emissive: <hex>,
  19553. * emissiveIntensity: <float>
  19554. * emissiveMap: new THREE.Texture( <Image> ),
  19555. *
  19556. * bumpMap: new THREE.Texture( <Image> ),
  19557. * bumpScale: <float>,
  19558. *
  19559. * normalMap: new THREE.Texture( <Image> ),
  19560. * normalMapType: THREE.TangentSpaceNormalMap,
  19561. * normalScale: <Vector2>,
  19562. *
  19563. * displacementMap: new THREE.Texture( <Image> ),
  19564. * displacementScale: <float>,
  19565. * displacementBias: <float>,
  19566. *
  19567. * roughnessMap: new THREE.Texture( <Image> ),
  19568. *
  19569. * metalnessMap: new THREE.Texture( <Image> ),
  19570. *
  19571. * alphaMap: new THREE.Texture( <Image> ),
  19572. *
  19573. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19574. * envMapIntensity: <float>
  19575. *
  19576. * refractionRatio: <float>,
  19577. *
  19578. * wireframe: <boolean>,
  19579. * wireframeLinewidth: <float>,
  19580. *
  19581. * skinning: <bool>,
  19582. * morphTargets: <bool>,
  19583. * morphNormals: <bool>
  19584. * }
  19585. */
  19586. function MeshStandardMaterial( parameters ) {
  19587. Material.call( this );
  19588. this.defines = { 'STANDARD': '' };
  19589. this.type = 'MeshStandardMaterial';
  19590. this.color = new Color( 0xffffff ); // diffuse
  19591. this.roughness = 0.5;
  19592. this.metalness = 0.5;
  19593. this.map = null;
  19594. this.lightMap = null;
  19595. this.lightMapIntensity = 1.0;
  19596. this.aoMap = null;
  19597. this.aoMapIntensity = 1.0;
  19598. this.emissive = new Color( 0x000000 );
  19599. this.emissiveIntensity = 1.0;
  19600. this.emissiveMap = null;
  19601. this.bumpMap = null;
  19602. this.bumpScale = 1;
  19603. this.normalMap = null;
  19604. this.normalMapType = TangentSpaceNormalMap;
  19605. this.normalScale = new Vector2( 1, 1 );
  19606. this.displacementMap = null;
  19607. this.displacementScale = 1;
  19608. this.displacementBias = 0;
  19609. this.roughnessMap = null;
  19610. this.metalnessMap = null;
  19611. this.alphaMap = null;
  19612. this.envMap = null;
  19613. this.envMapIntensity = 1.0;
  19614. this.refractionRatio = 0.98;
  19615. this.wireframe = false;
  19616. this.wireframeLinewidth = 1;
  19617. this.wireframeLinecap = 'round';
  19618. this.wireframeLinejoin = 'round';
  19619. this.skinning = false;
  19620. this.morphTargets = false;
  19621. this.morphNormals = false;
  19622. this.setValues( parameters );
  19623. }
  19624. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  19625. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19626. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19627. MeshStandardMaterial.prototype.copy = function ( source ) {
  19628. Material.prototype.copy.call( this, source );
  19629. this.defines = { 'STANDARD': '' };
  19630. this.color.copy( source.color );
  19631. this.roughness = source.roughness;
  19632. this.metalness = source.metalness;
  19633. this.map = source.map;
  19634. this.lightMap = source.lightMap;
  19635. this.lightMapIntensity = source.lightMapIntensity;
  19636. this.aoMap = source.aoMap;
  19637. this.aoMapIntensity = source.aoMapIntensity;
  19638. this.emissive.copy( source.emissive );
  19639. this.emissiveMap = source.emissiveMap;
  19640. this.emissiveIntensity = source.emissiveIntensity;
  19641. this.bumpMap = source.bumpMap;
  19642. this.bumpScale = source.bumpScale;
  19643. this.normalMap = source.normalMap;
  19644. this.normalMapType = source.normalMapType;
  19645. this.normalScale.copy( source.normalScale );
  19646. this.displacementMap = source.displacementMap;
  19647. this.displacementScale = source.displacementScale;
  19648. this.displacementBias = source.displacementBias;
  19649. this.roughnessMap = source.roughnessMap;
  19650. this.metalnessMap = source.metalnessMap;
  19651. this.alphaMap = source.alphaMap;
  19652. this.envMap = source.envMap;
  19653. this.envMapIntensity = source.envMapIntensity;
  19654. this.refractionRatio = source.refractionRatio;
  19655. this.wireframe = source.wireframe;
  19656. this.wireframeLinewidth = source.wireframeLinewidth;
  19657. this.wireframeLinecap = source.wireframeLinecap;
  19658. this.wireframeLinejoin = source.wireframeLinejoin;
  19659. this.skinning = source.skinning;
  19660. this.morphTargets = source.morphTargets;
  19661. this.morphNormals = source.morphNormals;
  19662. return this;
  19663. };
  19664. /**
  19665. * @author WestLangley / http://github.com/WestLangley
  19666. *
  19667. * parameters = {
  19668. * reflectivity: <float>
  19669. * clearcoat: <float>
  19670. * clearcoatRoughness: <float>
  19671. *
  19672. * sheen: <Color>
  19673. *
  19674. * clearcoatNormalScale: <Vector2>,
  19675. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19676. * }
  19677. */
  19678. function MeshPhysicalMaterial( parameters ) {
  19679. MeshStandardMaterial.call( this );
  19680. this.defines = {
  19681. 'STANDARD': '',
  19682. 'PHYSICAL': ''
  19683. };
  19684. this.type = 'MeshPhysicalMaterial';
  19685. this.reflectivity = 0.5; // maps to F0 = 0.04
  19686. this.clearcoat = 0.0;
  19687. this.clearcoatRoughness = 0.0;
  19688. this.sheen = null; // null will disable sheen bsdf
  19689. this.clearcoatNormalScale = new Vector2( 1, 1 );
  19690. this.clearcoatNormalMap = null;
  19691. this.transparency = 0.0;
  19692. this.setValues( parameters );
  19693. }
  19694. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  19695. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19696. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19697. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  19698. MeshStandardMaterial.prototype.copy.call( this, source );
  19699. this.defines = {
  19700. 'STANDARD': '',
  19701. 'PHYSICAL': ''
  19702. };
  19703. this.reflectivity = source.reflectivity;
  19704. this.clearcoat = source.clearcoat;
  19705. this.clearcoatRoughness = source.clearcoatRoughness;
  19706. if ( source.sheen ) this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  19707. else this.sheen = null;
  19708. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19709. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  19710. this.transparency = source.transparency;
  19711. return this;
  19712. };
  19713. /**
  19714. * @author mrdoob / http://mrdoob.com/
  19715. * @author alteredq / http://alteredqualia.com/
  19716. *
  19717. * parameters = {
  19718. * color: <hex>,
  19719. * specular: <hex>,
  19720. * shininess: <float>,
  19721. * opacity: <float>,
  19722. *
  19723. * map: new THREE.Texture( <Image> ),
  19724. *
  19725. * lightMap: new THREE.Texture( <Image> ),
  19726. * lightMapIntensity: <float>
  19727. *
  19728. * aoMap: new THREE.Texture( <Image> ),
  19729. * aoMapIntensity: <float>
  19730. *
  19731. * emissive: <hex>,
  19732. * emissiveIntensity: <float>
  19733. * emissiveMap: new THREE.Texture( <Image> ),
  19734. *
  19735. * bumpMap: new THREE.Texture( <Image> ),
  19736. * bumpScale: <float>,
  19737. *
  19738. * normalMap: new THREE.Texture( <Image> ),
  19739. * normalMapType: THREE.TangentSpaceNormalMap,
  19740. * normalScale: <Vector2>,
  19741. *
  19742. * displacementMap: new THREE.Texture( <Image> ),
  19743. * displacementScale: <float>,
  19744. * displacementBias: <float>,
  19745. *
  19746. * specularMap: new THREE.Texture( <Image> ),
  19747. *
  19748. * alphaMap: new THREE.Texture( <Image> ),
  19749. *
  19750. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19751. * combine: THREE.MultiplyOperation,
  19752. * reflectivity: <float>,
  19753. * refractionRatio: <float>,
  19754. *
  19755. * wireframe: <boolean>,
  19756. * wireframeLinewidth: <float>,
  19757. *
  19758. * skinning: <bool>,
  19759. * morphTargets: <bool>,
  19760. * morphNormals: <bool>
  19761. * }
  19762. */
  19763. function MeshPhongMaterial( parameters ) {
  19764. Material.call( this );
  19765. this.type = 'MeshPhongMaterial';
  19766. this.color = new Color( 0xffffff ); // diffuse
  19767. this.specular = new Color( 0x111111 );
  19768. this.shininess = 30;
  19769. this.map = null;
  19770. this.lightMap = null;
  19771. this.lightMapIntensity = 1.0;
  19772. this.aoMap = null;
  19773. this.aoMapIntensity = 1.0;
  19774. this.emissive = new Color( 0x000000 );
  19775. this.emissiveIntensity = 1.0;
  19776. this.emissiveMap = null;
  19777. this.bumpMap = null;
  19778. this.bumpScale = 1;
  19779. this.normalMap = null;
  19780. this.normalMapType = TangentSpaceNormalMap;
  19781. this.normalScale = new Vector2( 1, 1 );
  19782. this.displacementMap = null;
  19783. this.displacementScale = 1;
  19784. this.displacementBias = 0;
  19785. this.specularMap = null;
  19786. this.alphaMap = null;
  19787. this.envMap = null;
  19788. this.combine = MultiplyOperation;
  19789. this.reflectivity = 1;
  19790. this.refractionRatio = 0.98;
  19791. this.wireframe = false;
  19792. this.wireframeLinewidth = 1;
  19793. this.wireframeLinecap = 'round';
  19794. this.wireframeLinejoin = 'round';
  19795. this.skinning = false;
  19796. this.morphTargets = false;
  19797. this.morphNormals = false;
  19798. this.setValues( parameters );
  19799. }
  19800. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19801. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19802. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19803. MeshPhongMaterial.prototype.copy = function ( source ) {
  19804. Material.prototype.copy.call( this, source );
  19805. this.color.copy( source.color );
  19806. this.specular.copy( source.specular );
  19807. this.shininess = source.shininess;
  19808. this.map = source.map;
  19809. this.lightMap = source.lightMap;
  19810. this.lightMapIntensity = source.lightMapIntensity;
  19811. this.aoMap = source.aoMap;
  19812. this.aoMapIntensity = source.aoMapIntensity;
  19813. this.emissive.copy( source.emissive );
  19814. this.emissiveMap = source.emissiveMap;
  19815. this.emissiveIntensity = source.emissiveIntensity;
  19816. this.bumpMap = source.bumpMap;
  19817. this.bumpScale = source.bumpScale;
  19818. this.normalMap = source.normalMap;
  19819. this.normalMapType = source.normalMapType;
  19820. this.normalScale.copy( source.normalScale );
  19821. this.displacementMap = source.displacementMap;
  19822. this.displacementScale = source.displacementScale;
  19823. this.displacementBias = source.displacementBias;
  19824. this.specularMap = source.specularMap;
  19825. this.alphaMap = source.alphaMap;
  19826. this.envMap = source.envMap;
  19827. this.combine = source.combine;
  19828. this.reflectivity = source.reflectivity;
  19829. this.refractionRatio = source.refractionRatio;
  19830. this.wireframe = source.wireframe;
  19831. this.wireframeLinewidth = source.wireframeLinewidth;
  19832. this.wireframeLinecap = source.wireframeLinecap;
  19833. this.wireframeLinejoin = source.wireframeLinejoin;
  19834. this.skinning = source.skinning;
  19835. this.morphTargets = source.morphTargets;
  19836. this.morphNormals = source.morphNormals;
  19837. return this;
  19838. };
  19839. /**
  19840. * @author takahirox / http://github.com/takahirox
  19841. *
  19842. * parameters = {
  19843. * gradientMap: new THREE.Texture( <Image> )
  19844. * }
  19845. */
  19846. function MeshToonMaterial( parameters ) {
  19847. MeshPhongMaterial.call( this );
  19848. this.defines = { 'TOON': '' };
  19849. this.type = 'MeshToonMaterial';
  19850. this.gradientMap = null;
  19851. this.setValues( parameters );
  19852. }
  19853. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19854. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19855. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19856. MeshToonMaterial.prototype.copy = function ( source ) {
  19857. MeshPhongMaterial.prototype.copy.call( this, source );
  19858. this.gradientMap = source.gradientMap;
  19859. return this;
  19860. };
  19861. /**
  19862. * @author mrdoob / http://mrdoob.com/
  19863. * @author WestLangley / http://github.com/WestLangley
  19864. *
  19865. * parameters = {
  19866. * opacity: <float>,
  19867. *
  19868. * bumpMap: new THREE.Texture( <Image> ),
  19869. * bumpScale: <float>,
  19870. *
  19871. * normalMap: new THREE.Texture( <Image> ),
  19872. * normalMapType: THREE.TangentSpaceNormalMap,
  19873. * normalScale: <Vector2>,
  19874. *
  19875. * displacementMap: new THREE.Texture( <Image> ),
  19876. * displacementScale: <float>,
  19877. * displacementBias: <float>,
  19878. *
  19879. * wireframe: <boolean>,
  19880. * wireframeLinewidth: <float>
  19881. *
  19882. * skinning: <bool>,
  19883. * morphTargets: <bool>,
  19884. * morphNormals: <bool>
  19885. * }
  19886. */
  19887. function MeshNormalMaterial( parameters ) {
  19888. Material.call( this );
  19889. this.type = 'MeshNormalMaterial';
  19890. this.bumpMap = null;
  19891. this.bumpScale = 1;
  19892. this.normalMap = null;
  19893. this.normalMapType = TangentSpaceNormalMap;
  19894. this.normalScale = new Vector2( 1, 1 );
  19895. this.displacementMap = null;
  19896. this.displacementScale = 1;
  19897. this.displacementBias = 0;
  19898. this.wireframe = false;
  19899. this.wireframeLinewidth = 1;
  19900. this.fog = false;
  19901. this.skinning = false;
  19902. this.morphTargets = false;
  19903. this.morphNormals = false;
  19904. this.setValues( parameters );
  19905. }
  19906. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19907. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19908. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19909. MeshNormalMaterial.prototype.copy = function ( source ) {
  19910. Material.prototype.copy.call( this, source );
  19911. this.bumpMap = source.bumpMap;
  19912. this.bumpScale = source.bumpScale;
  19913. this.normalMap = source.normalMap;
  19914. this.normalMapType = source.normalMapType;
  19915. this.normalScale.copy( source.normalScale );
  19916. this.displacementMap = source.displacementMap;
  19917. this.displacementScale = source.displacementScale;
  19918. this.displacementBias = source.displacementBias;
  19919. this.wireframe = source.wireframe;
  19920. this.wireframeLinewidth = source.wireframeLinewidth;
  19921. this.skinning = source.skinning;
  19922. this.morphTargets = source.morphTargets;
  19923. this.morphNormals = source.morphNormals;
  19924. return this;
  19925. };
  19926. /**
  19927. * @author mrdoob / http://mrdoob.com/
  19928. * @author alteredq / http://alteredqualia.com/
  19929. *
  19930. * parameters = {
  19931. * color: <hex>,
  19932. * opacity: <float>,
  19933. *
  19934. * map: new THREE.Texture( <Image> ),
  19935. *
  19936. * lightMap: new THREE.Texture( <Image> ),
  19937. * lightMapIntensity: <float>
  19938. *
  19939. * aoMap: new THREE.Texture( <Image> ),
  19940. * aoMapIntensity: <float>
  19941. *
  19942. * emissive: <hex>,
  19943. * emissiveIntensity: <float>
  19944. * emissiveMap: new THREE.Texture( <Image> ),
  19945. *
  19946. * specularMap: new THREE.Texture( <Image> ),
  19947. *
  19948. * alphaMap: new THREE.Texture( <Image> ),
  19949. *
  19950. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19951. * combine: THREE.Multiply,
  19952. * reflectivity: <float>,
  19953. * refractionRatio: <float>,
  19954. *
  19955. * wireframe: <boolean>,
  19956. * wireframeLinewidth: <float>,
  19957. *
  19958. * skinning: <bool>,
  19959. * morphTargets: <bool>,
  19960. * morphNormals: <bool>
  19961. * }
  19962. */
  19963. function MeshLambertMaterial( parameters ) {
  19964. Material.call( this );
  19965. this.type = 'MeshLambertMaterial';
  19966. this.color = new Color( 0xffffff ); // diffuse
  19967. this.map = null;
  19968. this.lightMap = null;
  19969. this.lightMapIntensity = 1.0;
  19970. this.aoMap = null;
  19971. this.aoMapIntensity = 1.0;
  19972. this.emissive = new Color( 0x000000 );
  19973. this.emissiveIntensity = 1.0;
  19974. this.emissiveMap = null;
  19975. this.specularMap = null;
  19976. this.alphaMap = null;
  19977. this.envMap = null;
  19978. this.combine = MultiplyOperation;
  19979. this.reflectivity = 1;
  19980. this.refractionRatio = 0.98;
  19981. this.wireframe = false;
  19982. this.wireframeLinewidth = 1;
  19983. this.wireframeLinecap = 'round';
  19984. this.wireframeLinejoin = 'round';
  19985. this.skinning = false;
  19986. this.morphTargets = false;
  19987. this.morphNormals = false;
  19988. this.setValues( parameters );
  19989. }
  19990. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19991. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19992. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19993. MeshLambertMaterial.prototype.copy = function ( source ) {
  19994. Material.prototype.copy.call( this, source );
  19995. this.color.copy( source.color );
  19996. this.map = source.map;
  19997. this.lightMap = source.lightMap;
  19998. this.lightMapIntensity = source.lightMapIntensity;
  19999. this.aoMap = source.aoMap;
  20000. this.aoMapIntensity = source.aoMapIntensity;
  20001. this.emissive.copy( source.emissive );
  20002. this.emissiveMap = source.emissiveMap;
  20003. this.emissiveIntensity = source.emissiveIntensity;
  20004. this.specularMap = source.specularMap;
  20005. this.alphaMap = source.alphaMap;
  20006. this.envMap = source.envMap;
  20007. this.combine = source.combine;
  20008. this.reflectivity = source.reflectivity;
  20009. this.refractionRatio = source.refractionRatio;
  20010. this.wireframe = source.wireframe;
  20011. this.wireframeLinewidth = source.wireframeLinewidth;
  20012. this.wireframeLinecap = source.wireframeLinecap;
  20013. this.wireframeLinejoin = source.wireframeLinejoin;
  20014. this.skinning = source.skinning;
  20015. this.morphTargets = source.morphTargets;
  20016. this.morphNormals = source.morphNormals;
  20017. return this;
  20018. };
  20019. /**
  20020. * @author WestLangley / http://github.com/WestLangley
  20021. *
  20022. * parameters = {
  20023. * color: <hex>,
  20024. * opacity: <float>,
  20025. *
  20026. * matcap: new THREE.Texture( <Image> ),
  20027. *
  20028. * map: new THREE.Texture( <Image> ),
  20029. *
  20030. * bumpMap: new THREE.Texture( <Image> ),
  20031. * bumpScale: <float>,
  20032. *
  20033. * normalMap: new THREE.Texture( <Image> ),
  20034. * normalMapType: THREE.TangentSpaceNormalMap,
  20035. * normalScale: <Vector2>,
  20036. *
  20037. * displacementMap: new THREE.Texture( <Image> ),
  20038. * displacementScale: <float>,
  20039. * displacementBias: <float>,
  20040. *
  20041. * alphaMap: new THREE.Texture( <Image> ),
  20042. *
  20043. * skinning: <bool>,
  20044. * morphTargets: <bool>,
  20045. * morphNormals: <bool>
  20046. * }
  20047. */
  20048. function MeshMatcapMaterial( parameters ) {
  20049. Material.call( this );
  20050. this.defines = { 'MATCAP': '' };
  20051. this.type = 'MeshMatcapMaterial';
  20052. this.color = new Color( 0xffffff ); // diffuse
  20053. this.matcap = null;
  20054. this.map = null;
  20055. this.bumpMap = null;
  20056. this.bumpScale = 1;
  20057. this.normalMap = null;
  20058. this.normalMapType = TangentSpaceNormalMap;
  20059. this.normalScale = new Vector2( 1, 1 );
  20060. this.displacementMap = null;
  20061. this.displacementScale = 1;
  20062. this.displacementBias = 0;
  20063. this.alphaMap = null;
  20064. this.skinning = false;
  20065. this.morphTargets = false;
  20066. this.morphNormals = false;
  20067. this.setValues( parameters );
  20068. }
  20069. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  20070. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20071. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20072. MeshMatcapMaterial.prototype.copy = function ( source ) {
  20073. Material.prototype.copy.call( this, source );
  20074. this.defines = { 'MATCAP': '' };
  20075. this.color.copy( source.color );
  20076. this.matcap = source.matcap;
  20077. this.map = source.map;
  20078. this.bumpMap = source.bumpMap;
  20079. this.bumpScale = source.bumpScale;
  20080. this.normalMap = source.normalMap;
  20081. this.normalMapType = source.normalMapType;
  20082. this.normalScale.copy( source.normalScale );
  20083. this.displacementMap = source.displacementMap;
  20084. this.displacementScale = source.displacementScale;
  20085. this.displacementBias = source.displacementBias;
  20086. this.alphaMap = source.alphaMap;
  20087. this.skinning = source.skinning;
  20088. this.morphTargets = source.morphTargets;
  20089. this.morphNormals = source.morphNormals;
  20090. return this;
  20091. };
  20092. /**
  20093. * @author alteredq / http://alteredqualia.com/
  20094. *
  20095. * parameters = {
  20096. * color: <hex>,
  20097. * opacity: <float>,
  20098. *
  20099. * linewidth: <float>,
  20100. *
  20101. * scale: <float>,
  20102. * dashSize: <float>,
  20103. * gapSize: <float>
  20104. * }
  20105. */
  20106. function LineDashedMaterial( parameters ) {
  20107. LineBasicMaterial.call( this );
  20108. this.type = 'LineDashedMaterial';
  20109. this.scale = 1;
  20110. this.dashSize = 3;
  20111. this.gapSize = 1;
  20112. this.setValues( parameters );
  20113. }
  20114. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  20115. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20116. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20117. LineDashedMaterial.prototype.copy = function ( source ) {
  20118. LineBasicMaterial.prototype.copy.call( this, source );
  20119. this.scale = source.scale;
  20120. this.dashSize = source.dashSize;
  20121. this.gapSize = source.gapSize;
  20122. return this;
  20123. };
  20124. var Materials = /*#__PURE__*/Object.freeze({
  20125. __proto__: null,
  20126. ShadowMaterial: ShadowMaterial,
  20127. SpriteMaterial: SpriteMaterial,
  20128. RawShaderMaterial: RawShaderMaterial,
  20129. ShaderMaterial: ShaderMaterial,
  20130. PointsMaterial: PointsMaterial,
  20131. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20132. MeshStandardMaterial: MeshStandardMaterial,
  20133. MeshPhongMaterial: MeshPhongMaterial,
  20134. MeshToonMaterial: MeshToonMaterial,
  20135. MeshNormalMaterial: MeshNormalMaterial,
  20136. MeshLambertMaterial: MeshLambertMaterial,
  20137. MeshDepthMaterial: MeshDepthMaterial,
  20138. MeshDistanceMaterial: MeshDistanceMaterial,
  20139. MeshBasicMaterial: MeshBasicMaterial,
  20140. MeshMatcapMaterial: MeshMatcapMaterial,
  20141. LineDashedMaterial: LineDashedMaterial,
  20142. LineBasicMaterial: LineBasicMaterial,
  20143. Material: Material
  20144. });
  20145. /**
  20146. * @author tschw
  20147. * @author Ben Houston / http://clara.io/
  20148. * @author David Sarno / http://lighthaus.us/
  20149. */
  20150. var AnimationUtils = {
  20151. // same as Array.prototype.slice, but also works on typed arrays
  20152. arraySlice: function ( array, from, to ) {
  20153. if ( AnimationUtils.isTypedArray( array ) ) {
  20154. // in ios9 array.subarray(from, undefined) will return empty array
  20155. // but array.subarray(from) or array.subarray(from, len) is correct
  20156. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20157. }
  20158. return array.slice( from, to );
  20159. },
  20160. // converts an array to a specific type
  20161. convertArray: function ( array, type, forceClone ) {
  20162. if ( ! array || // let 'undefined' and 'null' pass
  20163. ! forceClone && array.constructor === type ) return array;
  20164. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20165. return new type( array ); // create typed array
  20166. }
  20167. return Array.prototype.slice.call( array ); // create Array
  20168. },
  20169. isTypedArray: function ( object ) {
  20170. return ArrayBuffer.isView( object ) &&
  20171. ! ( object instanceof DataView );
  20172. },
  20173. // returns an array by which times and values can be sorted
  20174. getKeyframeOrder: function ( times ) {
  20175. function compareTime( i, j ) {
  20176. return times[ i ] - times[ j ];
  20177. }
  20178. var n = times.length;
  20179. var result = new Array( n );
  20180. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  20181. result.sort( compareTime );
  20182. return result;
  20183. },
  20184. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20185. sortedArray: function ( values, stride, order ) {
  20186. var nValues = values.length;
  20187. var result = new values.constructor( nValues );
  20188. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20189. var srcOffset = order[ i ] * stride;
  20190. for ( var j = 0; j !== stride; ++ j ) {
  20191. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20192. }
  20193. }
  20194. return result;
  20195. },
  20196. // function for parsing AOS keyframe formats
  20197. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20198. var i = 1, key = jsonKeys[ 0 ];
  20199. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20200. key = jsonKeys[ i ++ ];
  20201. }
  20202. if ( key === undefined ) return; // no data
  20203. var value = key[ valuePropertyName ];
  20204. if ( value === undefined ) return; // no data
  20205. if ( Array.isArray( value ) ) {
  20206. do {
  20207. value = key[ valuePropertyName ];
  20208. if ( value !== undefined ) {
  20209. times.push( key.time );
  20210. values.push.apply( values, value ); // push all elements
  20211. }
  20212. key = jsonKeys[ i ++ ];
  20213. } while ( key !== undefined );
  20214. } else if ( value.toArray !== undefined ) {
  20215. // ...assume THREE.Math-ish
  20216. do {
  20217. value = key[ valuePropertyName ];
  20218. if ( value !== undefined ) {
  20219. times.push( key.time );
  20220. value.toArray( values, values.length );
  20221. }
  20222. key = jsonKeys[ i ++ ];
  20223. } while ( key !== undefined );
  20224. } else {
  20225. // otherwise push as-is
  20226. do {
  20227. value = key[ valuePropertyName ];
  20228. if ( value !== undefined ) {
  20229. times.push( key.time );
  20230. values.push( value );
  20231. }
  20232. key = jsonKeys[ i ++ ];
  20233. } while ( key !== undefined );
  20234. }
  20235. },
  20236. subclip: function ( sourceClip, name, startFrame, endFrame, fps ) {
  20237. fps = fps || 30;
  20238. var clip = sourceClip.clone();
  20239. clip.name = name;
  20240. var tracks = [];
  20241. for ( var i = 0; i < clip.tracks.length; ++ i ) {
  20242. var track = clip.tracks[ i ];
  20243. var valueSize = track.getValueSize();
  20244. var times = [];
  20245. var values = [];
  20246. for ( var j = 0; j < track.times.length; ++ j ) {
  20247. var frame = track.times[ j ] * fps;
  20248. if ( frame < startFrame || frame >= endFrame ) continue;
  20249. times.push( track.times[ j ] );
  20250. for ( var k = 0; k < valueSize; ++ k ) {
  20251. values.push( track.values[ j * valueSize + k ] );
  20252. }
  20253. }
  20254. if ( times.length === 0 ) continue;
  20255. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  20256. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  20257. tracks.push( track );
  20258. }
  20259. clip.tracks = tracks;
  20260. // find minimum .times value across all tracks in the trimmed clip
  20261. var minStartTime = Infinity;
  20262. for ( var i = 0; i < clip.tracks.length; ++ i ) {
  20263. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  20264. minStartTime = clip.tracks[ i ].times[ 0 ];
  20265. }
  20266. }
  20267. // shift all tracks such that clip begins at t=0
  20268. for ( var i = 0; i < clip.tracks.length; ++ i ) {
  20269. clip.tracks[ i ].shift( - 1 * minStartTime );
  20270. }
  20271. clip.resetDuration();
  20272. return clip;
  20273. }
  20274. };
  20275. /**
  20276. * Abstract base class of interpolants over parametric samples.
  20277. *
  20278. * The parameter domain is one dimensional, typically the time or a path
  20279. * along a curve defined by the data.
  20280. *
  20281. * The sample values can have any dimensionality and derived classes may
  20282. * apply special interpretations to the data.
  20283. *
  20284. * This class provides the interval seek in a Template Method, deferring
  20285. * the actual interpolation to derived classes.
  20286. *
  20287. * Time complexity is O(1) for linear access crossing at most two points
  20288. * and O(log N) for random access, where N is the number of positions.
  20289. *
  20290. * References:
  20291. *
  20292. * http://www.oodesign.com/template-method-pattern.html
  20293. *
  20294. * @author tschw
  20295. */
  20296. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20297. this.parameterPositions = parameterPositions;
  20298. this._cachedIndex = 0;
  20299. this.resultBuffer = resultBuffer !== undefined ?
  20300. resultBuffer : new sampleValues.constructor( sampleSize );
  20301. this.sampleValues = sampleValues;
  20302. this.valueSize = sampleSize;
  20303. }
  20304. Object.assign( Interpolant.prototype, {
  20305. evaluate: function ( t ) {
  20306. var pp = this.parameterPositions,
  20307. i1 = this._cachedIndex,
  20308. t1 = pp[ i1 ],
  20309. t0 = pp[ i1 - 1 ];
  20310. validate_interval: {
  20311. seek: {
  20312. var right;
  20313. linear_scan: {
  20314. //- See http://jsperf.com/comparison-to-undefined/3
  20315. //- slower code:
  20316. //-
  20317. //- if ( t >= t1 || t1 === undefined ) {
  20318. forward_scan: if ( ! ( t < t1 ) ) {
  20319. for ( var giveUpAt = i1 + 2; ; ) {
  20320. if ( t1 === undefined ) {
  20321. if ( t < t0 ) break forward_scan;
  20322. // after end
  20323. i1 = pp.length;
  20324. this._cachedIndex = i1;
  20325. return this.afterEnd_( i1 - 1, t, t0 );
  20326. }
  20327. if ( i1 === giveUpAt ) break; // this loop
  20328. t0 = t1;
  20329. t1 = pp[ ++ i1 ];
  20330. if ( t < t1 ) {
  20331. // we have arrived at the sought interval
  20332. break seek;
  20333. }
  20334. }
  20335. // prepare binary search on the right side of the index
  20336. right = pp.length;
  20337. break linear_scan;
  20338. }
  20339. //- slower code:
  20340. //- if ( t < t0 || t0 === undefined ) {
  20341. if ( ! ( t >= t0 ) ) {
  20342. // looping?
  20343. var t1global = pp[ 1 ];
  20344. if ( t < t1global ) {
  20345. i1 = 2; // + 1, using the scan for the details
  20346. t0 = t1global;
  20347. }
  20348. // linear reverse scan
  20349. for ( var giveUpAt = i1 - 2; ; ) {
  20350. if ( t0 === undefined ) {
  20351. // before start
  20352. this._cachedIndex = 0;
  20353. return this.beforeStart_( 0, t, t1 );
  20354. }
  20355. if ( i1 === giveUpAt ) break; // this loop
  20356. t1 = t0;
  20357. t0 = pp[ -- i1 - 1 ];
  20358. if ( t >= t0 ) {
  20359. // we have arrived at the sought interval
  20360. break seek;
  20361. }
  20362. }
  20363. // prepare binary search on the left side of the index
  20364. right = i1;
  20365. i1 = 0;
  20366. break linear_scan;
  20367. }
  20368. // the interval is valid
  20369. break validate_interval;
  20370. } // linear scan
  20371. // binary search
  20372. while ( i1 < right ) {
  20373. var mid = ( i1 + right ) >>> 1;
  20374. if ( t < pp[ mid ] ) {
  20375. right = mid;
  20376. } else {
  20377. i1 = mid + 1;
  20378. }
  20379. }
  20380. t1 = pp[ i1 ];
  20381. t0 = pp[ i1 - 1 ];
  20382. // check boundary cases, again
  20383. if ( t0 === undefined ) {
  20384. this._cachedIndex = 0;
  20385. return this.beforeStart_( 0, t, t1 );
  20386. }
  20387. if ( t1 === undefined ) {
  20388. i1 = pp.length;
  20389. this._cachedIndex = i1;
  20390. return this.afterEnd_( i1 - 1, t0, t );
  20391. }
  20392. } // seek
  20393. this._cachedIndex = i1;
  20394. this.intervalChanged_( i1, t0, t1 );
  20395. } // validate_interval
  20396. return this.interpolate_( i1, t0, t, t1 );
  20397. },
  20398. settings: null, // optional, subclass-specific settings structure
  20399. // Note: The indirection allows central control of many interpolants.
  20400. // --- Protected interface
  20401. DefaultSettings_: {},
  20402. getSettings_: function () {
  20403. return this.settings || this.DefaultSettings_;
  20404. },
  20405. copySampleValue_: function ( index ) {
  20406. // copies a sample value to the result buffer
  20407. var result = this.resultBuffer,
  20408. values = this.sampleValues,
  20409. stride = this.valueSize,
  20410. offset = index * stride;
  20411. for ( var i = 0; i !== stride; ++ i ) {
  20412. result[ i ] = values[ offset + i ];
  20413. }
  20414. return result;
  20415. },
  20416. // Template methods for derived classes:
  20417. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20418. throw new Error( 'call to abstract method' );
  20419. // implementations shall return this.resultBuffer
  20420. },
  20421. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20422. // empty
  20423. }
  20424. } );
  20425. //!\ DECLARE ALIAS AFTER assign prototype !
  20426. Object.assign( Interpolant.prototype, {
  20427. //( 0, t, t0 ), returns this.resultBuffer
  20428. beforeStart_: Interpolant.prototype.copySampleValue_,
  20429. //( N-1, tN-1, t ), returns this.resultBuffer
  20430. afterEnd_: Interpolant.prototype.copySampleValue_,
  20431. } );
  20432. /**
  20433. * Fast and simple cubic spline interpolant.
  20434. *
  20435. * It was derived from a Hermitian construction setting the first derivative
  20436. * at each sample position to the linear slope between neighboring positions
  20437. * over their parameter interval.
  20438. *
  20439. * @author tschw
  20440. */
  20441. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20442. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20443. this._weightPrev = - 0;
  20444. this._offsetPrev = - 0;
  20445. this._weightNext = - 0;
  20446. this._offsetNext = - 0;
  20447. }
  20448. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20449. constructor: CubicInterpolant,
  20450. DefaultSettings_: {
  20451. endingStart: ZeroCurvatureEnding,
  20452. endingEnd: ZeroCurvatureEnding
  20453. },
  20454. intervalChanged_: function ( i1, t0, t1 ) {
  20455. var pp = this.parameterPositions,
  20456. iPrev = i1 - 2,
  20457. iNext = i1 + 1,
  20458. tPrev = pp[ iPrev ],
  20459. tNext = pp[ iNext ];
  20460. if ( tPrev === undefined ) {
  20461. switch ( this.getSettings_().endingStart ) {
  20462. case ZeroSlopeEnding:
  20463. // f'(t0) = 0
  20464. iPrev = i1;
  20465. tPrev = 2 * t0 - t1;
  20466. break;
  20467. case WrapAroundEnding:
  20468. // use the other end of the curve
  20469. iPrev = pp.length - 2;
  20470. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20471. break;
  20472. default: // ZeroCurvatureEnding
  20473. // f''(t0) = 0 a.k.a. Natural Spline
  20474. iPrev = i1;
  20475. tPrev = t1;
  20476. }
  20477. }
  20478. if ( tNext === undefined ) {
  20479. switch ( this.getSettings_().endingEnd ) {
  20480. case ZeroSlopeEnding:
  20481. // f'(tN) = 0
  20482. iNext = i1;
  20483. tNext = 2 * t1 - t0;
  20484. break;
  20485. case WrapAroundEnding:
  20486. // use the other end of the curve
  20487. iNext = 1;
  20488. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20489. break;
  20490. default: // ZeroCurvatureEnding
  20491. // f''(tN) = 0, a.k.a. Natural Spline
  20492. iNext = i1 - 1;
  20493. tNext = t0;
  20494. }
  20495. }
  20496. var halfDt = ( t1 - t0 ) * 0.5,
  20497. stride = this.valueSize;
  20498. this._weightPrev = halfDt / ( t0 - tPrev );
  20499. this._weightNext = halfDt / ( tNext - t1 );
  20500. this._offsetPrev = iPrev * stride;
  20501. this._offsetNext = iNext * stride;
  20502. },
  20503. interpolate_: function ( i1, t0, t, t1 ) {
  20504. var result = this.resultBuffer,
  20505. values = this.sampleValues,
  20506. stride = this.valueSize,
  20507. o1 = i1 * stride, o0 = o1 - stride,
  20508. oP = this._offsetPrev, oN = this._offsetNext,
  20509. wP = this._weightPrev, wN = this._weightNext,
  20510. p = ( t - t0 ) / ( t1 - t0 ),
  20511. pp = p * p,
  20512. ppp = pp * p;
  20513. // evaluate polynomials
  20514. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20515. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20516. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20517. var sN = wN * ppp - wN * pp;
  20518. // combine data linearly
  20519. for ( var i = 0; i !== stride; ++ i ) {
  20520. result[ i ] =
  20521. sP * values[ oP + i ] +
  20522. s0 * values[ o0 + i ] +
  20523. s1 * values[ o1 + i ] +
  20524. sN * values[ oN + i ];
  20525. }
  20526. return result;
  20527. }
  20528. } );
  20529. /**
  20530. * @author tschw
  20531. */
  20532. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20533. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20534. }
  20535. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20536. constructor: LinearInterpolant,
  20537. interpolate_: function ( i1, t0, t, t1 ) {
  20538. var result = this.resultBuffer,
  20539. values = this.sampleValues,
  20540. stride = this.valueSize,
  20541. offset1 = i1 * stride,
  20542. offset0 = offset1 - stride,
  20543. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20544. weight0 = 1 - weight1;
  20545. for ( var i = 0; i !== stride; ++ i ) {
  20546. result[ i ] =
  20547. values[ offset0 + i ] * weight0 +
  20548. values[ offset1 + i ] * weight1;
  20549. }
  20550. return result;
  20551. }
  20552. } );
  20553. /**
  20554. *
  20555. * Interpolant that evaluates to the sample value at the position preceeding
  20556. * the parameter.
  20557. *
  20558. * @author tschw
  20559. */
  20560. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20561. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20562. }
  20563. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20564. constructor: DiscreteInterpolant,
  20565. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20566. return this.copySampleValue_( i1 - 1 );
  20567. }
  20568. } );
  20569. /**
  20570. *
  20571. * A timed sequence of keyframes for a specific property.
  20572. *
  20573. *
  20574. * @author Ben Houston / http://clara.io/
  20575. * @author David Sarno / http://lighthaus.us/
  20576. * @author tschw
  20577. */
  20578. function KeyframeTrack( name, times, values, interpolation ) {
  20579. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20580. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20581. this.name = name;
  20582. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20583. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20584. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20585. }
  20586. // Static methods
  20587. Object.assign( KeyframeTrack, {
  20588. // Serialization (in static context, because of constructor invocation
  20589. // and automatic invocation of .toJSON):
  20590. toJSON: function ( track ) {
  20591. var trackType = track.constructor;
  20592. var json;
  20593. // derived classes can define a static toJSON method
  20594. if ( trackType.toJSON !== undefined ) {
  20595. json = trackType.toJSON( track );
  20596. } else {
  20597. // by default, we assume the data can be serialized as-is
  20598. json = {
  20599. 'name': track.name,
  20600. 'times': AnimationUtils.convertArray( track.times, Array ),
  20601. 'values': AnimationUtils.convertArray( track.values, Array )
  20602. };
  20603. var interpolation = track.getInterpolation();
  20604. if ( interpolation !== track.DefaultInterpolation ) {
  20605. json.interpolation = interpolation;
  20606. }
  20607. }
  20608. json.type = track.ValueTypeName; // mandatory
  20609. return json;
  20610. }
  20611. } );
  20612. Object.assign( KeyframeTrack.prototype, {
  20613. constructor: KeyframeTrack,
  20614. TimeBufferType: Float32Array,
  20615. ValueBufferType: Float32Array,
  20616. DefaultInterpolation: InterpolateLinear,
  20617. InterpolantFactoryMethodDiscrete: function ( result ) {
  20618. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20619. },
  20620. InterpolantFactoryMethodLinear: function ( result ) {
  20621. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20622. },
  20623. InterpolantFactoryMethodSmooth: function ( result ) {
  20624. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  20625. },
  20626. setInterpolation: function ( interpolation ) {
  20627. var factoryMethod;
  20628. switch ( interpolation ) {
  20629. case InterpolateDiscrete:
  20630. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20631. break;
  20632. case InterpolateLinear:
  20633. factoryMethod = this.InterpolantFactoryMethodLinear;
  20634. break;
  20635. case InterpolateSmooth:
  20636. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20637. break;
  20638. }
  20639. if ( factoryMethod === undefined ) {
  20640. var message = "unsupported interpolation for " +
  20641. this.ValueTypeName + " keyframe track named " + this.name;
  20642. if ( this.createInterpolant === undefined ) {
  20643. // fall back to default, unless the default itself is messed up
  20644. if ( interpolation !== this.DefaultInterpolation ) {
  20645. this.setInterpolation( this.DefaultInterpolation );
  20646. } else {
  20647. throw new Error( message ); // fatal, in this case
  20648. }
  20649. }
  20650. console.warn( 'THREE.KeyframeTrack:', message );
  20651. return this;
  20652. }
  20653. this.createInterpolant = factoryMethod;
  20654. return this;
  20655. },
  20656. getInterpolation: function () {
  20657. switch ( this.createInterpolant ) {
  20658. case this.InterpolantFactoryMethodDiscrete:
  20659. return InterpolateDiscrete;
  20660. case this.InterpolantFactoryMethodLinear:
  20661. return InterpolateLinear;
  20662. case this.InterpolantFactoryMethodSmooth:
  20663. return InterpolateSmooth;
  20664. }
  20665. },
  20666. getValueSize: function () {
  20667. return this.values.length / this.times.length;
  20668. },
  20669. // move all keyframes either forwards or backwards in time
  20670. shift: function ( timeOffset ) {
  20671. if ( timeOffset !== 0.0 ) {
  20672. var times = this.times;
  20673. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20674. times[ i ] += timeOffset;
  20675. }
  20676. }
  20677. return this;
  20678. },
  20679. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20680. scale: function ( timeScale ) {
  20681. if ( timeScale !== 1.0 ) {
  20682. var times = this.times;
  20683. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20684. times[ i ] *= timeScale;
  20685. }
  20686. }
  20687. return this;
  20688. },
  20689. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20690. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20691. trim: function ( startTime, endTime ) {
  20692. var times = this.times,
  20693. nKeys = times.length,
  20694. from = 0,
  20695. to = nKeys - 1;
  20696. while ( from !== nKeys && times[ from ] < startTime ) {
  20697. ++ from;
  20698. }
  20699. while ( to !== - 1 && times[ to ] > endTime ) {
  20700. -- to;
  20701. }
  20702. ++ to; // inclusive -> exclusive bound
  20703. if ( from !== 0 || to !== nKeys ) {
  20704. // empty tracks are forbidden, so keep at least one keyframe
  20705. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  20706. var stride = this.getValueSize();
  20707. this.times = AnimationUtils.arraySlice( times, from, to );
  20708. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  20709. }
  20710. return this;
  20711. },
  20712. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20713. validate: function () {
  20714. var valid = true;
  20715. var valueSize = this.getValueSize();
  20716. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  20717. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  20718. valid = false;
  20719. }
  20720. var times = this.times,
  20721. values = this.values,
  20722. nKeys = times.length;
  20723. if ( nKeys === 0 ) {
  20724. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20725. valid = false;
  20726. }
  20727. var prevTime = null;
  20728. for ( var i = 0; i !== nKeys; i ++ ) {
  20729. var currTime = times[ i ];
  20730. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20731. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20732. valid = false;
  20733. break;
  20734. }
  20735. if ( prevTime !== null && prevTime > currTime ) {
  20736. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20737. valid = false;
  20738. break;
  20739. }
  20740. prevTime = currTime;
  20741. }
  20742. if ( values !== undefined ) {
  20743. if ( AnimationUtils.isTypedArray( values ) ) {
  20744. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20745. var value = values[ i ];
  20746. if ( isNaN( value ) ) {
  20747. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20748. valid = false;
  20749. break;
  20750. }
  20751. }
  20752. }
  20753. }
  20754. return valid;
  20755. },
  20756. // removes equivalent sequential keys as common in morph target sequences
  20757. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20758. optimize: function () {
  20759. var times = this.times,
  20760. values = this.values,
  20761. stride = this.getValueSize(),
  20762. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20763. writeIndex = 1,
  20764. lastIndex = times.length - 1;
  20765. for ( var i = 1; i < lastIndex; ++ i ) {
  20766. var keep = false;
  20767. var time = times[ i ];
  20768. var timeNext = times[ i + 1 ];
  20769. // remove adjacent keyframes scheduled at the same time
  20770. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20771. if ( ! smoothInterpolation ) {
  20772. // remove unnecessary keyframes same as their neighbors
  20773. var offset = i * stride,
  20774. offsetP = offset - stride,
  20775. offsetN = offset + stride;
  20776. for ( var j = 0; j !== stride; ++ j ) {
  20777. var value = values[ offset + j ];
  20778. if ( value !== values[ offsetP + j ] ||
  20779. value !== values[ offsetN + j ] ) {
  20780. keep = true;
  20781. break;
  20782. }
  20783. }
  20784. } else {
  20785. keep = true;
  20786. }
  20787. }
  20788. // in-place compaction
  20789. if ( keep ) {
  20790. if ( i !== writeIndex ) {
  20791. times[ writeIndex ] = times[ i ];
  20792. var readOffset = i * stride,
  20793. writeOffset = writeIndex * stride;
  20794. for ( var j = 0; j !== stride; ++ j ) {
  20795. values[ writeOffset + j ] = values[ readOffset + j ];
  20796. }
  20797. }
  20798. ++ writeIndex;
  20799. }
  20800. }
  20801. // flush last keyframe (compaction looks ahead)
  20802. if ( lastIndex > 0 ) {
  20803. times[ writeIndex ] = times[ lastIndex ];
  20804. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20805. values[ writeOffset + j ] = values[ readOffset + j ];
  20806. }
  20807. ++ writeIndex;
  20808. }
  20809. if ( writeIndex !== times.length ) {
  20810. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20811. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20812. }
  20813. return this;
  20814. },
  20815. clone: function () {
  20816. var times = AnimationUtils.arraySlice( this.times, 0 );
  20817. var values = AnimationUtils.arraySlice( this.values, 0 );
  20818. var TypedKeyframeTrack = this.constructor;
  20819. var track = new TypedKeyframeTrack( this.name, times, values );
  20820. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20821. track.createInterpolant = this.createInterpolant;
  20822. return track;
  20823. }
  20824. } );
  20825. /**
  20826. *
  20827. * A Track of Boolean keyframe values.
  20828. *
  20829. *
  20830. * @author Ben Houston / http://clara.io/
  20831. * @author David Sarno / http://lighthaus.us/
  20832. * @author tschw
  20833. */
  20834. function BooleanKeyframeTrack( name, times, values ) {
  20835. KeyframeTrack.call( this, name, times, values );
  20836. }
  20837. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20838. constructor: BooleanKeyframeTrack,
  20839. ValueTypeName: 'bool',
  20840. ValueBufferType: Array,
  20841. DefaultInterpolation: InterpolateDiscrete,
  20842. InterpolantFactoryMethodLinear: undefined,
  20843. InterpolantFactoryMethodSmooth: undefined
  20844. // Note: Actually this track could have a optimized / compressed
  20845. // representation of a single value and a custom interpolant that
  20846. // computes "firstValue ^ isOdd( index )".
  20847. } );
  20848. /**
  20849. *
  20850. * A Track of keyframe values that represent color.
  20851. *
  20852. *
  20853. * @author Ben Houston / http://clara.io/
  20854. * @author David Sarno / http://lighthaus.us/
  20855. * @author tschw
  20856. */
  20857. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20858. KeyframeTrack.call( this, name, times, values, interpolation );
  20859. }
  20860. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20861. constructor: ColorKeyframeTrack,
  20862. ValueTypeName: 'color'
  20863. // ValueBufferType is inherited
  20864. // DefaultInterpolation is inherited
  20865. // Note: Very basic implementation and nothing special yet.
  20866. // However, this is the place for color space parameterization.
  20867. } );
  20868. /**
  20869. *
  20870. * A Track of numeric keyframe values.
  20871. *
  20872. * @author Ben Houston / http://clara.io/
  20873. * @author David Sarno / http://lighthaus.us/
  20874. * @author tschw
  20875. */
  20876. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20877. KeyframeTrack.call( this, name, times, values, interpolation );
  20878. }
  20879. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20880. constructor: NumberKeyframeTrack,
  20881. ValueTypeName: 'number'
  20882. // ValueBufferType is inherited
  20883. // DefaultInterpolation is inherited
  20884. } );
  20885. /**
  20886. * Spherical linear unit quaternion interpolant.
  20887. *
  20888. * @author tschw
  20889. */
  20890. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20891. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20892. }
  20893. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20894. constructor: QuaternionLinearInterpolant,
  20895. interpolate_: function ( i1, t0, t, t1 ) {
  20896. var result = this.resultBuffer,
  20897. values = this.sampleValues,
  20898. stride = this.valueSize,
  20899. offset = i1 * stride,
  20900. alpha = ( t - t0 ) / ( t1 - t0 );
  20901. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20902. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20903. }
  20904. return result;
  20905. }
  20906. } );
  20907. /**
  20908. *
  20909. * A Track of quaternion keyframe values.
  20910. *
  20911. * @author Ben Houston / http://clara.io/
  20912. * @author David Sarno / http://lighthaus.us/
  20913. * @author tschw
  20914. */
  20915. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20916. KeyframeTrack.call( this, name, times, values, interpolation );
  20917. }
  20918. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20919. constructor: QuaternionKeyframeTrack,
  20920. ValueTypeName: 'quaternion',
  20921. // ValueBufferType is inherited
  20922. DefaultInterpolation: InterpolateLinear,
  20923. InterpolantFactoryMethodLinear: function ( result ) {
  20924. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20925. },
  20926. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20927. } );
  20928. /**
  20929. *
  20930. * A Track that interpolates Strings
  20931. *
  20932. *
  20933. * @author Ben Houston / http://clara.io/
  20934. * @author David Sarno / http://lighthaus.us/
  20935. * @author tschw
  20936. */
  20937. function StringKeyframeTrack( name, times, values, interpolation ) {
  20938. KeyframeTrack.call( this, name, times, values, interpolation );
  20939. }
  20940. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20941. constructor: StringKeyframeTrack,
  20942. ValueTypeName: 'string',
  20943. ValueBufferType: Array,
  20944. DefaultInterpolation: InterpolateDiscrete,
  20945. InterpolantFactoryMethodLinear: undefined,
  20946. InterpolantFactoryMethodSmooth: undefined
  20947. } );
  20948. /**
  20949. *
  20950. * A Track of vectored keyframe values.
  20951. *
  20952. *
  20953. * @author Ben Houston / http://clara.io/
  20954. * @author David Sarno / http://lighthaus.us/
  20955. * @author tschw
  20956. */
  20957. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20958. KeyframeTrack.call( this, name, times, values, interpolation );
  20959. }
  20960. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20961. constructor: VectorKeyframeTrack,
  20962. ValueTypeName: 'vector'
  20963. // ValueBufferType is inherited
  20964. // DefaultInterpolation is inherited
  20965. } );
  20966. /**
  20967. *
  20968. * Reusable set of Tracks that represent an animation.
  20969. *
  20970. * @author Ben Houston / http://clara.io/
  20971. * @author David Sarno / http://lighthaus.us/
  20972. */
  20973. function AnimationClip( name, duration, tracks ) {
  20974. this.name = name;
  20975. this.tracks = tracks;
  20976. this.duration = ( duration !== undefined ) ? duration : - 1;
  20977. this.uuid = _Math.generateUUID();
  20978. // this means it should figure out its duration by scanning the tracks
  20979. if ( this.duration < 0 ) {
  20980. this.resetDuration();
  20981. }
  20982. }
  20983. function getTrackTypeForValueTypeName( typeName ) {
  20984. switch ( typeName.toLowerCase() ) {
  20985. case 'scalar':
  20986. case 'double':
  20987. case 'float':
  20988. case 'number':
  20989. case 'integer':
  20990. return NumberKeyframeTrack;
  20991. case 'vector':
  20992. case 'vector2':
  20993. case 'vector3':
  20994. case 'vector4':
  20995. return VectorKeyframeTrack;
  20996. case 'color':
  20997. return ColorKeyframeTrack;
  20998. case 'quaternion':
  20999. return QuaternionKeyframeTrack;
  21000. case 'bool':
  21001. case 'boolean':
  21002. return BooleanKeyframeTrack;
  21003. case 'string':
  21004. return StringKeyframeTrack;
  21005. }
  21006. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  21007. }
  21008. function parseKeyframeTrack( json ) {
  21009. if ( json.type === undefined ) {
  21010. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  21011. }
  21012. var trackType = getTrackTypeForValueTypeName( json.type );
  21013. if ( json.times === undefined ) {
  21014. var times = [], values = [];
  21015. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  21016. json.times = times;
  21017. json.values = values;
  21018. }
  21019. // derived classes can define a static parse method
  21020. if ( trackType.parse !== undefined ) {
  21021. return trackType.parse( json );
  21022. } else {
  21023. // by default, we assume a constructor compatible with the base
  21024. return new trackType( json.name, json.times, json.values, json.interpolation );
  21025. }
  21026. }
  21027. Object.assign( AnimationClip, {
  21028. parse: function ( json ) {
  21029. var tracks = [],
  21030. jsonTracks = json.tracks,
  21031. frameTime = 1.0 / ( json.fps || 1.0 );
  21032. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21033. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  21034. }
  21035. return new AnimationClip( json.name, json.duration, tracks );
  21036. },
  21037. toJSON: function ( clip ) {
  21038. var tracks = [],
  21039. clipTracks = clip.tracks;
  21040. var json = {
  21041. 'name': clip.name,
  21042. 'duration': clip.duration,
  21043. 'tracks': tracks,
  21044. 'uuid': clip.uuid
  21045. };
  21046. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21047. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21048. }
  21049. return json;
  21050. },
  21051. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21052. var numMorphTargets = morphTargetSequence.length;
  21053. var tracks = [];
  21054. for ( var i = 0; i < numMorphTargets; i ++ ) {
  21055. var times = [];
  21056. var values = [];
  21057. times.push(
  21058. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21059. i,
  21060. ( i + 1 ) % numMorphTargets );
  21061. values.push( 0, 1, 0 );
  21062. var order = AnimationUtils.getKeyframeOrder( times );
  21063. times = AnimationUtils.sortedArray( times, 1, order );
  21064. values = AnimationUtils.sortedArray( values, 1, order );
  21065. // if there is a key at the first frame, duplicate it as the
  21066. // last frame as well for perfect loop.
  21067. if ( ! noLoop && times[ 0 ] === 0 ) {
  21068. times.push( numMorphTargets );
  21069. values.push( values[ 0 ] );
  21070. }
  21071. tracks.push(
  21072. new NumberKeyframeTrack(
  21073. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21074. times, values
  21075. ).scale( 1.0 / fps ) );
  21076. }
  21077. return new AnimationClip( name, - 1, tracks );
  21078. },
  21079. findByName: function ( objectOrClipArray, name ) {
  21080. var clipArray = objectOrClipArray;
  21081. if ( ! Array.isArray( objectOrClipArray ) ) {
  21082. var o = objectOrClipArray;
  21083. clipArray = o.geometry && o.geometry.animations || o.animations;
  21084. }
  21085. for ( var i = 0; i < clipArray.length; i ++ ) {
  21086. if ( clipArray[ i ].name === name ) {
  21087. return clipArray[ i ];
  21088. }
  21089. }
  21090. return null;
  21091. },
  21092. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21093. var animationToMorphTargets = {};
  21094. // tested with https://regex101.com/ on trick sequences
  21095. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21096. var pattern = /^([\w-]*?)([\d]+)$/;
  21097. // sort morph target names into animation groups based
  21098. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21099. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  21100. var morphTarget = morphTargets[ i ];
  21101. var parts = morphTarget.name.match( pattern );
  21102. if ( parts && parts.length > 1 ) {
  21103. var name = parts[ 1 ];
  21104. var animationMorphTargets = animationToMorphTargets[ name ];
  21105. if ( ! animationMorphTargets ) {
  21106. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21107. }
  21108. animationMorphTargets.push( morphTarget );
  21109. }
  21110. }
  21111. var clips = [];
  21112. for ( var name in animationToMorphTargets ) {
  21113. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21114. }
  21115. return clips;
  21116. },
  21117. // parse the animation.hierarchy format
  21118. parseAnimation: function ( animation, bones ) {
  21119. if ( ! animation ) {
  21120. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21121. return null;
  21122. }
  21123. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21124. // only return track if there are actually keys.
  21125. if ( animationKeys.length !== 0 ) {
  21126. var times = [];
  21127. var values = [];
  21128. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21129. // empty keys are filtered out, so check again
  21130. if ( times.length !== 0 ) {
  21131. destTracks.push( new trackType( trackName, times, values ) );
  21132. }
  21133. }
  21134. };
  21135. var tracks = [];
  21136. var clipName = animation.name || 'default';
  21137. // automatic length determination in AnimationClip.
  21138. var duration = animation.length || - 1;
  21139. var fps = animation.fps || 30;
  21140. var hierarchyTracks = animation.hierarchy || [];
  21141. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  21142. var animationKeys = hierarchyTracks[ h ].keys;
  21143. // skip empty tracks
  21144. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21145. // process morph targets
  21146. if ( animationKeys[ 0 ].morphTargets ) {
  21147. // figure out all morph targets used in this track
  21148. var morphTargetNames = {};
  21149. for ( var k = 0; k < animationKeys.length; k ++ ) {
  21150. if ( animationKeys[ k ].morphTargets ) {
  21151. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21152. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21153. }
  21154. }
  21155. }
  21156. // create a track for each morph target with all zero
  21157. // morphTargetInfluences except for the keys in which
  21158. // the morphTarget is named.
  21159. for ( var morphTargetName in morphTargetNames ) {
  21160. var times = [];
  21161. var values = [];
  21162. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21163. var animationKey = animationKeys[ k ];
  21164. times.push( animationKey.time );
  21165. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21166. }
  21167. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21168. }
  21169. duration = morphTargetNames.length * ( fps || 1.0 );
  21170. } else {
  21171. // ...assume skeletal animation
  21172. var boneName = '.bones[' + bones[ h ].name + ']';
  21173. addNonemptyTrack(
  21174. VectorKeyframeTrack, boneName + '.position',
  21175. animationKeys, 'pos', tracks );
  21176. addNonemptyTrack(
  21177. QuaternionKeyframeTrack, boneName + '.quaternion',
  21178. animationKeys, 'rot', tracks );
  21179. addNonemptyTrack(
  21180. VectorKeyframeTrack, boneName + '.scale',
  21181. animationKeys, 'scl', tracks );
  21182. }
  21183. }
  21184. if ( tracks.length === 0 ) {
  21185. return null;
  21186. }
  21187. var clip = new AnimationClip( clipName, duration, tracks );
  21188. return clip;
  21189. }
  21190. } );
  21191. Object.assign( AnimationClip.prototype, {
  21192. resetDuration: function () {
  21193. var tracks = this.tracks, duration = 0;
  21194. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  21195. var track = this.tracks[ i ];
  21196. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21197. }
  21198. this.duration = duration;
  21199. return this;
  21200. },
  21201. trim: function () {
  21202. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21203. this.tracks[ i ].trim( 0, this.duration );
  21204. }
  21205. return this;
  21206. },
  21207. validate: function () {
  21208. var valid = true;
  21209. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21210. valid = valid && this.tracks[ i ].validate();
  21211. }
  21212. return valid;
  21213. },
  21214. optimize: function () {
  21215. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21216. this.tracks[ i ].optimize();
  21217. }
  21218. return this;
  21219. },
  21220. clone: function () {
  21221. var tracks = [];
  21222. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21223. tracks.push( this.tracks[ i ].clone() );
  21224. }
  21225. return new AnimationClip( this.name, this.duration, tracks );
  21226. }
  21227. } );
  21228. /**
  21229. * @author mrdoob / http://mrdoob.com/
  21230. */
  21231. var Cache = {
  21232. enabled: false,
  21233. files: {},
  21234. add: function ( key, file ) {
  21235. if ( this.enabled === false ) return;
  21236. // console.log( 'THREE.Cache', 'Adding key:', key );
  21237. this.files[ key ] = file;
  21238. },
  21239. get: function ( key ) {
  21240. if ( this.enabled === false ) return;
  21241. // console.log( 'THREE.Cache', 'Checking key:', key );
  21242. return this.files[ key ];
  21243. },
  21244. remove: function ( key ) {
  21245. delete this.files[ key ];
  21246. },
  21247. clear: function () {
  21248. this.files = {};
  21249. }
  21250. };
  21251. /**
  21252. * @author mrdoob / http://mrdoob.com/
  21253. */
  21254. function LoadingManager( onLoad, onProgress, onError ) {
  21255. var scope = this;
  21256. var isLoading = false;
  21257. var itemsLoaded = 0;
  21258. var itemsTotal = 0;
  21259. var urlModifier = undefined;
  21260. var handlers = [];
  21261. // Refer to #5689 for the reason why we don't set .onStart
  21262. // in the constructor
  21263. this.onStart = undefined;
  21264. this.onLoad = onLoad;
  21265. this.onProgress = onProgress;
  21266. this.onError = onError;
  21267. this.itemStart = function ( url ) {
  21268. itemsTotal ++;
  21269. if ( isLoading === false ) {
  21270. if ( scope.onStart !== undefined ) {
  21271. scope.onStart( url, itemsLoaded, itemsTotal );
  21272. }
  21273. }
  21274. isLoading = true;
  21275. };
  21276. this.itemEnd = function ( url ) {
  21277. itemsLoaded ++;
  21278. if ( scope.onProgress !== undefined ) {
  21279. scope.onProgress( url, itemsLoaded, itemsTotal );
  21280. }
  21281. if ( itemsLoaded === itemsTotal ) {
  21282. isLoading = false;
  21283. if ( scope.onLoad !== undefined ) {
  21284. scope.onLoad();
  21285. }
  21286. }
  21287. };
  21288. this.itemError = function ( url ) {
  21289. if ( scope.onError !== undefined ) {
  21290. scope.onError( url );
  21291. }
  21292. };
  21293. this.resolveURL = function ( url ) {
  21294. if ( urlModifier ) {
  21295. return urlModifier( url );
  21296. }
  21297. return url;
  21298. };
  21299. this.setURLModifier = function ( transform ) {
  21300. urlModifier = transform;
  21301. return this;
  21302. };
  21303. this.addHandler = function ( regex, loader ) {
  21304. handlers.push( regex, loader );
  21305. return this;
  21306. };
  21307. this.removeHandler = function ( regex ) {
  21308. var index = handlers.indexOf( regex );
  21309. if ( index !== - 1 ) {
  21310. handlers.splice( index, 2 );
  21311. }
  21312. return this;
  21313. };
  21314. this.getHandler = function ( file ) {
  21315. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  21316. var regex = handlers[ i ];
  21317. var loader = handlers[ i + 1 ];
  21318. if ( regex.global ) regex.lastIndex = 0; // see #17920
  21319. if ( regex.test( file ) ) {
  21320. return loader;
  21321. }
  21322. }
  21323. return null;
  21324. };
  21325. }
  21326. var DefaultLoadingManager = new LoadingManager();
  21327. /**
  21328. * @author alteredq / http://alteredqualia.com/
  21329. */
  21330. function Loader( manager ) {
  21331. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21332. this.crossOrigin = 'anonymous';
  21333. this.path = '';
  21334. this.resourcePath = '';
  21335. }
  21336. Object.assign( Loader.prototype, {
  21337. load: function ( /* url, onLoad, onProgress, onError */ ) {},
  21338. parse: function ( /* data */ ) {},
  21339. setCrossOrigin: function ( crossOrigin ) {
  21340. this.crossOrigin = crossOrigin;
  21341. return this;
  21342. },
  21343. setPath: function ( path ) {
  21344. this.path = path;
  21345. return this;
  21346. },
  21347. setResourcePath: function ( resourcePath ) {
  21348. this.resourcePath = resourcePath;
  21349. return this;
  21350. }
  21351. } );
  21352. /**
  21353. * @author mrdoob / http://mrdoob.com/
  21354. */
  21355. var loading = {};
  21356. function FileLoader( manager ) {
  21357. Loader.call( this, manager );
  21358. }
  21359. FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21360. constructor: FileLoader,
  21361. load: function ( url, onLoad, onProgress, onError ) {
  21362. if ( url === undefined ) url = '';
  21363. if ( this.path !== undefined ) url = this.path + url;
  21364. url = this.manager.resolveURL( url );
  21365. var scope = this;
  21366. var cached = Cache.get( url );
  21367. if ( cached !== undefined ) {
  21368. scope.manager.itemStart( url );
  21369. setTimeout( function () {
  21370. if ( onLoad ) onLoad( cached );
  21371. scope.manager.itemEnd( url );
  21372. }, 0 );
  21373. return cached;
  21374. }
  21375. // Check if request is duplicate
  21376. if ( loading[ url ] !== undefined ) {
  21377. loading[ url ].push( {
  21378. onLoad: onLoad,
  21379. onProgress: onProgress,
  21380. onError: onError
  21381. } );
  21382. return;
  21383. }
  21384. // Check for data: URI
  21385. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21386. var dataUriRegexResult = url.match( dataUriRegex );
  21387. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21388. if ( dataUriRegexResult ) {
  21389. var mimeType = dataUriRegexResult[ 1 ];
  21390. var isBase64 = !! dataUriRegexResult[ 2 ];
  21391. var data = dataUriRegexResult[ 3 ];
  21392. data = decodeURIComponent( data );
  21393. if ( isBase64 ) data = atob( data );
  21394. try {
  21395. var response;
  21396. var responseType = ( this.responseType || '' ).toLowerCase();
  21397. switch ( responseType ) {
  21398. case 'arraybuffer':
  21399. case 'blob':
  21400. var view = new Uint8Array( data.length );
  21401. for ( var i = 0; i < data.length; i ++ ) {
  21402. view[ i ] = data.charCodeAt( i );
  21403. }
  21404. if ( responseType === 'blob' ) {
  21405. response = new Blob( [ view.buffer ], { type: mimeType } );
  21406. } else {
  21407. response = view.buffer;
  21408. }
  21409. break;
  21410. case 'document':
  21411. var parser = new DOMParser();
  21412. response = parser.parseFromString( data, mimeType );
  21413. break;
  21414. case 'json':
  21415. response = JSON.parse( data );
  21416. break;
  21417. default: // 'text' or other
  21418. response = data;
  21419. break;
  21420. }
  21421. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21422. setTimeout( function () {
  21423. if ( onLoad ) onLoad( response );
  21424. scope.manager.itemEnd( url );
  21425. }, 0 );
  21426. } catch ( error ) {
  21427. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21428. setTimeout( function () {
  21429. if ( onError ) onError( error );
  21430. scope.manager.itemError( url );
  21431. scope.manager.itemEnd( url );
  21432. }, 0 );
  21433. }
  21434. } else {
  21435. // Initialise array for duplicate requests
  21436. loading[ url ] = [];
  21437. loading[ url ].push( {
  21438. onLoad: onLoad,
  21439. onProgress: onProgress,
  21440. onError: onError
  21441. } );
  21442. var request = new XMLHttpRequest();
  21443. request.open( 'GET', url, true );
  21444. request.addEventListener( 'load', function ( event ) {
  21445. var response = this.response;
  21446. var callbacks = loading[ url ];
  21447. delete loading[ url ];
  21448. if ( this.status === 200 || this.status === 0 ) {
  21449. // Some browsers return HTTP Status 0 when using non-http protocol
  21450. // e.g. 'file://' or 'data://'. Handle as success.
  21451. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  21452. // Add to cache only on HTTP success, so that we do not cache
  21453. // error response bodies as proper responses to requests.
  21454. Cache.add( url, response );
  21455. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21456. var callback = callbacks[ i ];
  21457. if ( callback.onLoad ) callback.onLoad( response );
  21458. }
  21459. scope.manager.itemEnd( url );
  21460. } else {
  21461. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21462. var callback = callbacks[ i ];
  21463. if ( callback.onError ) callback.onError( event );
  21464. }
  21465. scope.manager.itemError( url );
  21466. scope.manager.itemEnd( url );
  21467. }
  21468. }, false );
  21469. request.addEventListener( 'progress', function ( event ) {
  21470. var callbacks = loading[ url ];
  21471. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21472. var callback = callbacks[ i ];
  21473. if ( callback.onProgress ) callback.onProgress( event );
  21474. }
  21475. }, false );
  21476. request.addEventListener( 'error', function ( event ) {
  21477. var callbacks = loading[ url ];
  21478. delete loading[ url ];
  21479. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21480. var callback = callbacks[ i ];
  21481. if ( callback.onError ) callback.onError( event );
  21482. }
  21483. scope.manager.itemError( url );
  21484. scope.manager.itemEnd( url );
  21485. }, false );
  21486. request.addEventListener( 'abort', function ( event ) {
  21487. var callbacks = loading[ url ];
  21488. delete loading[ url ];
  21489. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  21490. var callback = callbacks[ i ];
  21491. if ( callback.onError ) callback.onError( event );
  21492. }
  21493. scope.manager.itemError( url );
  21494. scope.manager.itemEnd( url );
  21495. }, false );
  21496. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  21497. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  21498. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  21499. for ( var header in this.requestHeader ) {
  21500. request.setRequestHeader( header, this.requestHeader[ header ] );
  21501. }
  21502. request.send( null );
  21503. }
  21504. scope.manager.itemStart( url );
  21505. return request;
  21506. },
  21507. setResponseType: function ( value ) {
  21508. this.responseType = value;
  21509. return this;
  21510. },
  21511. setWithCredentials: function ( value ) {
  21512. this.withCredentials = value;
  21513. return this;
  21514. },
  21515. setMimeType: function ( value ) {
  21516. this.mimeType = value;
  21517. return this;
  21518. },
  21519. setRequestHeader: function ( value ) {
  21520. this.requestHeader = value;
  21521. return this;
  21522. }
  21523. } );
  21524. /**
  21525. * @author bhouston / http://clara.io/
  21526. */
  21527. function AnimationLoader( manager ) {
  21528. Loader.call( this, manager );
  21529. }
  21530. AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21531. constructor: AnimationLoader,
  21532. load: function ( url, onLoad, onProgress, onError ) {
  21533. var scope = this;
  21534. var loader = new FileLoader( scope.manager );
  21535. loader.setPath( scope.path );
  21536. loader.load( url, function ( text ) {
  21537. onLoad( scope.parse( JSON.parse( text ) ) );
  21538. }, onProgress, onError );
  21539. },
  21540. parse: function ( json ) {
  21541. var animations = [];
  21542. for ( var i = 0; i < json.length; i ++ ) {
  21543. var clip = AnimationClip.parse( json[ i ] );
  21544. animations.push( clip );
  21545. }
  21546. return animations;
  21547. }
  21548. } );
  21549. /**
  21550. * @author mrdoob / http://mrdoob.com/
  21551. *
  21552. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21553. *
  21554. * Sub classes have to implement the parse() method which will be used in load().
  21555. */
  21556. function CompressedTextureLoader( manager ) {
  21557. Loader.call( this, manager );
  21558. }
  21559. CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21560. constructor: CompressedTextureLoader,
  21561. load: function ( url, onLoad, onProgress, onError ) {
  21562. var scope = this;
  21563. var images = [];
  21564. var texture = new CompressedTexture();
  21565. texture.image = images;
  21566. var loader = new FileLoader( this.manager );
  21567. loader.setPath( this.path );
  21568. loader.setResponseType( 'arraybuffer' );
  21569. function loadTexture( i ) {
  21570. loader.load( url[ i ], function ( buffer ) {
  21571. var texDatas = scope.parse( buffer, true );
  21572. images[ i ] = {
  21573. width: texDatas.width,
  21574. height: texDatas.height,
  21575. format: texDatas.format,
  21576. mipmaps: texDatas.mipmaps
  21577. };
  21578. loaded += 1;
  21579. if ( loaded === 6 ) {
  21580. if ( texDatas.mipmapCount === 1 )
  21581. texture.minFilter = LinearFilter;
  21582. texture.format = texDatas.format;
  21583. texture.needsUpdate = true;
  21584. if ( onLoad ) onLoad( texture );
  21585. }
  21586. }, onProgress, onError );
  21587. }
  21588. if ( Array.isArray( url ) ) {
  21589. var loaded = 0;
  21590. for ( var i = 0, il = url.length; i < il; ++ i ) {
  21591. loadTexture( i );
  21592. }
  21593. } else {
  21594. // compressed cubemap texture stored in a single DDS file
  21595. loader.load( url, function ( buffer ) {
  21596. var texDatas = scope.parse( buffer, true );
  21597. if ( texDatas.isCubemap ) {
  21598. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21599. for ( var f = 0; f < faces; f ++ ) {
  21600. images[ f ] = { mipmaps: [] };
  21601. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  21602. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  21603. images[ f ].format = texDatas.format;
  21604. images[ f ].width = texDatas.width;
  21605. images[ f ].height = texDatas.height;
  21606. }
  21607. }
  21608. } else {
  21609. texture.image.width = texDatas.width;
  21610. texture.image.height = texDatas.height;
  21611. texture.mipmaps = texDatas.mipmaps;
  21612. }
  21613. if ( texDatas.mipmapCount === 1 ) {
  21614. texture.minFilter = LinearFilter;
  21615. }
  21616. texture.format = texDatas.format;
  21617. texture.needsUpdate = true;
  21618. if ( onLoad ) onLoad( texture );
  21619. }, onProgress, onError );
  21620. }
  21621. return texture;
  21622. }
  21623. } );
  21624. /**
  21625. * @author Nikos M. / https://github.com/foo123/
  21626. *
  21627. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21628. *
  21629. * Sub classes have to implement the parse() method which will be used in load().
  21630. */
  21631. function DataTextureLoader( manager ) {
  21632. Loader.call( this, manager );
  21633. }
  21634. DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21635. constructor: DataTextureLoader,
  21636. load: function ( url, onLoad, onProgress, onError ) {
  21637. var scope = this;
  21638. var texture = new DataTexture();
  21639. var loader = new FileLoader( this.manager );
  21640. loader.setResponseType( 'arraybuffer' );
  21641. loader.setPath( this.path );
  21642. loader.load( url, function ( buffer ) {
  21643. var texData = scope.parse( buffer );
  21644. if ( ! texData ) return;
  21645. if ( texData.image !== undefined ) {
  21646. texture.image = texData.image;
  21647. } else if ( texData.data !== undefined ) {
  21648. texture.image.width = texData.width;
  21649. texture.image.height = texData.height;
  21650. texture.image.data = texData.data;
  21651. }
  21652. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21653. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21654. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21655. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21656. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21657. if ( texData.format !== undefined ) {
  21658. texture.format = texData.format;
  21659. }
  21660. if ( texData.type !== undefined ) {
  21661. texture.type = texData.type;
  21662. }
  21663. if ( texData.mipmaps !== undefined ) {
  21664. texture.mipmaps = texData.mipmaps;
  21665. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21666. }
  21667. if ( texData.mipmapCount === 1 ) {
  21668. texture.minFilter = LinearFilter;
  21669. }
  21670. texture.needsUpdate = true;
  21671. if ( onLoad ) onLoad( texture, texData );
  21672. }, onProgress, onError );
  21673. return texture;
  21674. }
  21675. } );
  21676. /**
  21677. * @author mrdoob / http://mrdoob.com/
  21678. */
  21679. function ImageLoader( manager ) {
  21680. Loader.call( this, manager );
  21681. }
  21682. ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21683. constructor: ImageLoader,
  21684. load: function ( url, onLoad, onProgress, onError ) {
  21685. if ( this.path !== undefined ) url = this.path + url;
  21686. url = this.manager.resolveURL( url );
  21687. var scope = this;
  21688. var cached = Cache.get( url );
  21689. if ( cached !== undefined ) {
  21690. scope.manager.itemStart( url );
  21691. setTimeout( function () {
  21692. if ( onLoad ) onLoad( cached );
  21693. scope.manager.itemEnd( url );
  21694. }, 0 );
  21695. return cached;
  21696. }
  21697. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  21698. function onImageLoad() {
  21699. image.removeEventListener( 'load', onImageLoad, false );
  21700. image.removeEventListener( 'error', onImageError, false );
  21701. Cache.add( url, this );
  21702. if ( onLoad ) onLoad( this );
  21703. scope.manager.itemEnd( url );
  21704. }
  21705. function onImageError( event ) {
  21706. image.removeEventListener( 'load', onImageLoad, false );
  21707. image.removeEventListener( 'error', onImageError, false );
  21708. if ( onError ) onError( event );
  21709. scope.manager.itemError( url );
  21710. scope.manager.itemEnd( url );
  21711. }
  21712. image.addEventListener( 'load', onImageLoad, false );
  21713. image.addEventListener( 'error', onImageError, false );
  21714. if ( url.substr( 0, 5 ) !== 'data:' ) {
  21715. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  21716. }
  21717. scope.manager.itemStart( url );
  21718. image.src = url;
  21719. return image;
  21720. }
  21721. } );
  21722. /**
  21723. * @author mrdoob / http://mrdoob.com/
  21724. */
  21725. function CubeTextureLoader( manager ) {
  21726. Loader.call( this, manager );
  21727. }
  21728. CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21729. constructor: CubeTextureLoader,
  21730. load: function ( urls, onLoad, onProgress, onError ) {
  21731. var texture = new CubeTexture();
  21732. var loader = new ImageLoader( this.manager );
  21733. loader.setCrossOrigin( this.crossOrigin );
  21734. loader.setPath( this.path );
  21735. var loaded = 0;
  21736. function loadTexture( i ) {
  21737. loader.load( urls[ i ], function ( image ) {
  21738. texture.images[ i ] = image;
  21739. loaded ++;
  21740. if ( loaded === 6 ) {
  21741. texture.needsUpdate = true;
  21742. if ( onLoad ) onLoad( texture );
  21743. }
  21744. }, undefined, onError );
  21745. }
  21746. for ( var i = 0; i < urls.length; ++ i ) {
  21747. loadTexture( i );
  21748. }
  21749. return texture;
  21750. }
  21751. } );
  21752. /**
  21753. * @author mrdoob / http://mrdoob.com/
  21754. */
  21755. function TextureLoader( manager ) {
  21756. Loader.call( this, manager );
  21757. }
  21758. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21759. constructor: TextureLoader,
  21760. load: function ( url, onLoad, onProgress, onError ) {
  21761. var texture = new Texture();
  21762. var loader = new ImageLoader( this.manager );
  21763. loader.setCrossOrigin( this.crossOrigin );
  21764. loader.setPath( this.path );
  21765. loader.load( url, function ( image ) {
  21766. texture.image = image;
  21767. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21768. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  21769. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21770. texture.needsUpdate = true;
  21771. if ( onLoad !== undefined ) {
  21772. onLoad( texture );
  21773. }
  21774. }, onProgress, onError );
  21775. return texture;
  21776. }
  21777. } );
  21778. /**
  21779. * @author zz85 / http://www.lab4games.net/zz85/blog
  21780. * Extensible curve object
  21781. *
  21782. * Some common of curve methods:
  21783. * .getPoint( t, optionalTarget ), .getTangent( t )
  21784. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  21785. * .getPoints(), .getSpacedPoints()
  21786. * .getLength()
  21787. * .updateArcLengths()
  21788. *
  21789. * This following curves inherit from THREE.Curve:
  21790. *
  21791. * -- 2D curves --
  21792. * THREE.ArcCurve
  21793. * THREE.CubicBezierCurve
  21794. * THREE.EllipseCurve
  21795. * THREE.LineCurve
  21796. * THREE.QuadraticBezierCurve
  21797. * THREE.SplineCurve
  21798. *
  21799. * -- 3D curves --
  21800. * THREE.CatmullRomCurve3
  21801. * THREE.CubicBezierCurve3
  21802. * THREE.LineCurve3
  21803. * THREE.QuadraticBezierCurve3
  21804. *
  21805. * A series of curves can be represented as a THREE.CurvePath.
  21806. *
  21807. **/
  21808. /**************************************************************
  21809. * Abstract Curve base class
  21810. **************************************************************/
  21811. function Curve() {
  21812. this.type = 'Curve';
  21813. this.arcLengthDivisions = 200;
  21814. }
  21815. Object.assign( Curve.prototype, {
  21816. // Virtual base class method to overwrite and implement in subclasses
  21817. // - t [0 .. 1]
  21818. getPoint: function ( /* t, optionalTarget */ ) {
  21819. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21820. return null;
  21821. },
  21822. // Get point at relative position in curve according to arc length
  21823. // - u [0 .. 1]
  21824. getPointAt: function ( u, optionalTarget ) {
  21825. var t = this.getUtoTmapping( u );
  21826. return this.getPoint( t, optionalTarget );
  21827. },
  21828. // Get sequence of points using getPoint( t )
  21829. getPoints: function ( divisions ) {
  21830. if ( divisions === undefined ) divisions = 5;
  21831. var points = [];
  21832. for ( var d = 0; d <= divisions; d ++ ) {
  21833. points.push( this.getPoint( d / divisions ) );
  21834. }
  21835. return points;
  21836. },
  21837. // Get sequence of points using getPointAt( u )
  21838. getSpacedPoints: function ( divisions ) {
  21839. if ( divisions === undefined ) divisions = 5;
  21840. var points = [];
  21841. for ( var d = 0; d <= divisions; d ++ ) {
  21842. points.push( this.getPointAt( d / divisions ) );
  21843. }
  21844. return points;
  21845. },
  21846. // Get total curve arc length
  21847. getLength: function () {
  21848. var lengths = this.getLengths();
  21849. return lengths[ lengths.length - 1 ];
  21850. },
  21851. // Get list of cumulative segment lengths
  21852. getLengths: function ( divisions ) {
  21853. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21854. if ( this.cacheArcLengths &&
  21855. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21856. ! this.needsUpdate ) {
  21857. return this.cacheArcLengths;
  21858. }
  21859. this.needsUpdate = false;
  21860. var cache = [];
  21861. var current, last = this.getPoint( 0 );
  21862. var p, sum = 0;
  21863. cache.push( 0 );
  21864. for ( p = 1; p <= divisions; p ++ ) {
  21865. current = this.getPoint( p / divisions );
  21866. sum += current.distanceTo( last );
  21867. cache.push( sum );
  21868. last = current;
  21869. }
  21870. this.cacheArcLengths = cache;
  21871. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21872. },
  21873. updateArcLengths: function () {
  21874. this.needsUpdate = true;
  21875. this.getLengths();
  21876. },
  21877. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21878. getUtoTmapping: function ( u, distance ) {
  21879. var arcLengths = this.getLengths();
  21880. var i = 0, il = arcLengths.length;
  21881. var targetArcLength; // The targeted u distance value to get
  21882. if ( distance ) {
  21883. targetArcLength = distance;
  21884. } else {
  21885. targetArcLength = u * arcLengths[ il - 1 ];
  21886. }
  21887. // binary search for the index with largest value smaller than target u distance
  21888. var low = 0, high = il - 1, comparison;
  21889. while ( low <= high ) {
  21890. 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
  21891. comparison = arcLengths[ i ] - targetArcLength;
  21892. if ( comparison < 0 ) {
  21893. low = i + 1;
  21894. } else if ( comparison > 0 ) {
  21895. high = i - 1;
  21896. } else {
  21897. high = i;
  21898. break;
  21899. // DONE
  21900. }
  21901. }
  21902. i = high;
  21903. if ( arcLengths[ i ] === targetArcLength ) {
  21904. return i / ( il - 1 );
  21905. }
  21906. // we could get finer grain at lengths, or use simple interpolation between two points
  21907. var lengthBefore = arcLengths[ i ];
  21908. var lengthAfter = arcLengths[ i + 1 ];
  21909. var segmentLength = lengthAfter - lengthBefore;
  21910. // determine where we are between the 'before' and 'after' points
  21911. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21912. // add that fractional amount to t
  21913. var t = ( i + segmentFraction ) / ( il - 1 );
  21914. return t;
  21915. },
  21916. // Returns a unit vector tangent at t
  21917. // In case any sub curve does not implement its tangent derivation,
  21918. // 2 points a small delta apart will be used to find its gradient
  21919. // which seems to give a reasonable approximation
  21920. getTangent: function ( t ) {
  21921. var delta = 0.0001;
  21922. var t1 = t - delta;
  21923. var t2 = t + delta;
  21924. // Capping in case of danger
  21925. if ( t1 < 0 ) t1 = 0;
  21926. if ( t2 > 1 ) t2 = 1;
  21927. var pt1 = this.getPoint( t1 );
  21928. var pt2 = this.getPoint( t2 );
  21929. var vec = pt2.clone().sub( pt1 );
  21930. return vec.normalize();
  21931. },
  21932. getTangentAt: function ( u ) {
  21933. var t = this.getUtoTmapping( u );
  21934. return this.getTangent( t );
  21935. },
  21936. computeFrenetFrames: function ( segments, closed ) {
  21937. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21938. var normal = new Vector3();
  21939. var tangents = [];
  21940. var normals = [];
  21941. var binormals = [];
  21942. var vec = new Vector3();
  21943. var mat = new Matrix4();
  21944. var i, u, theta;
  21945. // compute the tangent vectors for each segment on the curve
  21946. for ( i = 0; i <= segments; i ++ ) {
  21947. u = i / segments;
  21948. tangents[ i ] = this.getTangentAt( u );
  21949. tangents[ i ].normalize();
  21950. }
  21951. // select an initial normal vector perpendicular to the first tangent vector,
  21952. // and in the direction of the minimum tangent xyz component
  21953. normals[ 0 ] = new Vector3();
  21954. binormals[ 0 ] = new Vector3();
  21955. var min = Number.MAX_VALUE;
  21956. var tx = Math.abs( tangents[ 0 ].x );
  21957. var ty = Math.abs( tangents[ 0 ].y );
  21958. var tz = Math.abs( tangents[ 0 ].z );
  21959. if ( tx <= min ) {
  21960. min = tx;
  21961. normal.set( 1, 0, 0 );
  21962. }
  21963. if ( ty <= min ) {
  21964. min = ty;
  21965. normal.set( 0, 1, 0 );
  21966. }
  21967. if ( tz <= min ) {
  21968. normal.set( 0, 0, 1 );
  21969. }
  21970. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21971. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21972. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21973. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21974. for ( i = 1; i <= segments; i ++ ) {
  21975. normals[ i ] = normals[ i - 1 ].clone();
  21976. binormals[ i ] = binormals[ i - 1 ].clone();
  21977. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21978. if ( vec.length() > Number.EPSILON ) {
  21979. vec.normalize();
  21980. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21981. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21982. }
  21983. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21984. }
  21985. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21986. if ( closed === true ) {
  21987. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21988. theta /= segments;
  21989. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21990. theta = - theta;
  21991. }
  21992. for ( i = 1; i <= segments; i ++ ) {
  21993. // twist a little...
  21994. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21995. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21996. }
  21997. }
  21998. return {
  21999. tangents: tangents,
  22000. normals: normals,
  22001. binormals: binormals
  22002. };
  22003. },
  22004. clone: function () {
  22005. return new this.constructor().copy( this );
  22006. },
  22007. copy: function ( source ) {
  22008. this.arcLengthDivisions = source.arcLengthDivisions;
  22009. return this;
  22010. },
  22011. toJSON: function () {
  22012. var data = {
  22013. metadata: {
  22014. version: 4.5,
  22015. type: 'Curve',
  22016. generator: 'Curve.toJSON'
  22017. }
  22018. };
  22019. data.arcLengthDivisions = this.arcLengthDivisions;
  22020. data.type = this.type;
  22021. return data;
  22022. },
  22023. fromJSON: function ( json ) {
  22024. this.arcLengthDivisions = json.arcLengthDivisions;
  22025. return this;
  22026. }
  22027. } );
  22028. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22029. Curve.call( this );
  22030. this.type = 'EllipseCurve';
  22031. this.aX = aX || 0;
  22032. this.aY = aY || 0;
  22033. this.xRadius = xRadius || 1;
  22034. this.yRadius = yRadius || 1;
  22035. this.aStartAngle = aStartAngle || 0;
  22036. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22037. this.aClockwise = aClockwise || false;
  22038. this.aRotation = aRotation || 0;
  22039. }
  22040. EllipseCurve.prototype = Object.create( Curve.prototype );
  22041. EllipseCurve.prototype.constructor = EllipseCurve;
  22042. EllipseCurve.prototype.isEllipseCurve = true;
  22043. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22044. var point = optionalTarget || new Vector2();
  22045. var twoPi = Math.PI * 2;
  22046. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22047. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  22048. // ensures that deltaAngle is 0 .. 2 PI
  22049. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  22050. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  22051. if ( deltaAngle < Number.EPSILON ) {
  22052. if ( samePoints ) {
  22053. deltaAngle = 0;
  22054. } else {
  22055. deltaAngle = twoPi;
  22056. }
  22057. }
  22058. if ( this.aClockwise === true && ! samePoints ) {
  22059. if ( deltaAngle === twoPi ) {
  22060. deltaAngle = - twoPi;
  22061. } else {
  22062. deltaAngle = deltaAngle - twoPi;
  22063. }
  22064. }
  22065. var angle = this.aStartAngle + t * deltaAngle;
  22066. var x = this.aX + this.xRadius * Math.cos( angle );
  22067. var y = this.aY + this.yRadius * Math.sin( angle );
  22068. if ( this.aRotation !== 0 ) {
  22069. var cos = Math.cos( this.aRotation );
  22070. var sin = Math.sin( this.aRotation );
  22071. var tx = x - this.aX;
  22072. var ty = y - this.aY;
  22073. // Rotate the point about the center of the ellipse.
  22074. x = tx * cos - ty * sin + this.aX;
  22075. y = tx * sin + ty * cos + this.aY;
  22076. }
  22077. return point.set( x, y );
  22078. };
  22079. EllipseCurve.prototype.copy = function ( source ) {
  22080. Curve.prototype.copy.call( this, source );
  22081. this.aX = source.aX;
  22082. this.aY = source.aY;
  22083. this.xRadius = source.xRadius;
  22084. this.yRadius = source.yRadius;
  22085. this.aStartAngle = source.aStartAngle;
  22086. this.aEndAngle = source.aEndAngle;
  22087. this.aClockwise = source.aClockwise;
  22088. this.aRotation = source.aRotation;
  22089. return this;
  22090. };
  22091. EllipseCurve.prototype.toJSON = function () {
  22092. var data = Curve.prototype.toJSON.call( this );
  22093. data.aX = this.aX;
  22094. data.aY = this.aY;
  22095. data.xRadius = this.xRadius;
  22096. data.yRadius = this.yRadius;
  22097. data.aStartAngle = this.aStartAngle;
  22098. data.aEndAngle = this.aEndAngle;
  22099. data.aClockwise = this.aClockwise;
  22100. data.aRotation = this.aRotation;
  22101. return data;
  22102. };
  22103. EllipseCurve.prototype.fromJSON = function ( json ) {
  22104. Curve.prototype.fromJSON.call( this, json );
  22105. this.aX = json.aX;
  22106. this.aY = json.aY;
  22107. this.xRadius = json.xRadius;
  22108. this.yRadius = json.yRadius;
  22109. this.aStartAngle = json.aStartAngle;
  22110. this.aEndAngle = json.aEndAngle;
  22111. this.aClockwise = json.aClockwise;
  22112. this.aRotation = json.aRotation;
  22113. return this;
  22114. };
  22115. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22116. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22117. this.type = 'ArcCurve';
  22118. }
  22119. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  22120. ArcCurve.prototype.constructor = ArcCurve;
  22121. ArcCurve.prototype.isArcCurve = true;
  22122. /**
  22123. * @author zz85 https://github.com/zz85
  22124. *
  22125. * Centripetal CatmullRom Curve - which is useful for avoiding
  22126. * cusps and self-intersections in non-uniform catmull rom curves.
  22127. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22128. *
  22129. * curve.type accepts centripetal(default), chordal and catmullrom
  22130. * curve.tension is used for catmullrom which defaults to 0.5
  22131. */
  22132. /*
  22133. Based on an optimized c++ solution in
  22134. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22135. - http://ideone.com/NoEbVM
  22136. This CubicPoly class could be used for reusing some variables and calculations,
  22137. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22138. which can be placed in CurveUtils.
  22139. */
  22140. function CubicPoly() {
  22141. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  22142. /*
  22143. * Compute coefficients for a cubic polynomial
  22144. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22145. * such that
  22146. * p(0) = x0, p(1) = x1
  22147. * and
  22148. * p'(0) = t0, p'(1) = t1.
  22149. */
  22150. function init( x0, x1, t0, t1 ) {
  22151. c0 = x0;
  22152. c1 = t0;
  22153. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  22154. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22155. }
  22156. return {
  22157. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  22158. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  22159. },
  22160. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  22161. // compute tangents when parameterized in [t1,t2]
  22162. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  22163. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  22164. // rescale tangents for parametrization in [0,1]
  22165. t1 *= dt1;
  22166. t2 *= dt1;
  22167. init( x1, x2, t1, t2 );
  22168. },
  22169. calc: function ( t ) {
  22170. var t2 = t * t;
  22171. var t3 = t2 * t;
  22172. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22173. }
  22174. };
  22175. }
  22176. //
  22177. var tmp = new Vector3();
  22178. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  22179. function CatmullRomCurve3( points, closed, curveType, tension ) {
  22180. Curve.call( this );
  22181. this.type = 'CatmullRomCurve3';
  22182. this.points = points || [];
  22183. this.closed = closed || false;
  22184. this.curveType = curveType || 'centripetal';
  22185. this.tension = tension || 0.5;
  22186. }
  22187. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  22188. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22189. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22190. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22191. var point = optionalTarget || new Vector3();
  22192. var points = this.points;
  22193. var l = points.length;
  22194. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  22195. var intPoint = Math.floor( p );
  22196. var weight = p - intPoint;
  22197. if ( this.closed ) {
  22198. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  22199. } else if ( weight === 0 && intPoint === l - 1 ) {
  22200. intPoint = l - 2;
  22201. weight = 1;
  22202. }
  22203. var p0, p1, p2, p3; // 4 points
  22204. if ( this.closed || intPoint > 0 ) {
  22205. p0 = points[ ( intPoint - 1 ) % l ];
  22206. } else {
  22207. // extrapolate first point
  22208. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  22209. p0 = tmp;
  22210. }
  22211. p1 = points[ intPoint % l ];
  22212. p2 = points[ ( intPoint + 1 ) % l ];
  22213. if ( this.closed || intPoint + 2 < l ) {
  22214. p3 = points[ ( intPoint + 2 ) % l ];
  22215. } else {
  22216. // extrapolate last point
  22217. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  22218. p3 = tmp;
  22219. }
  22220. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  22221. // init Centripetal / Chordal Catmull-Rom
  22222. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22223. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  22224. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  22225. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  22226. // safety check for repeated points
  22227. if ( dt1 < 1e-4 ) dt1 = 1.0;
  22228. if ( dt0 < 1e-4 ) dt0 = dt1;
  22229. if ( dt2 < 1e-4 ) dt2 = dt1;
  22230. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  22231. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  22232. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  22233. } else if ( this.curveType === 'catmullrom' ) {
  22234. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  22235. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  22236. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  22237. }
  22238. point.set(
  22239. px.calc( weight ),
  22240. py.calc( weight ),
  22241. pz.calc( weight )
  22242. );
  22243. return point;
  22244. };
  22245. CatmullRomCurve3.prototype.copy = function ( source ) {
  22246. Curve.prototype.copy.call( this, source );
  22247. this.points = [];
  22248. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22249. var point = source.points[ i ];
  22250. this.points.push( point.clone() );
  22251. }
  22252. this.closed = source.closed;
  22253. this.curveType = source.curveType;
  22254. this.tension = source.tension;
  22255. return this;
  22256. };
  22257. CatmullRomCurve3.prototype.toJSON = function () {
  22258. var data = Curve.prototype.toJSON.call( this );
  22259. data.points = [];
  22260. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22261. var point = this.points[ i ];
  22262. data.points.push( point.toArray() );
  22263. }
  22264. data.closed = this.closed;
  22265. data.curveType = this.curveType;
  22266. data.tension = this.tension;
  22267. return data;
  22268. };
  22269. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  22270. Curve.prototype.fromJSON.call( this, json );
  22271. this.points = [];
  22272. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22273. var point = json.points[ i ];
  22274. this.points.push( new Vector3().fromArray( point ) );
  22275. }
  22276. this.closed = json.closed;
  22277. this.curveType = json.curveType;
  22278. this.tension = json.tension;
  22279. return this;
  22280. };
  22281. /**
  22282. * @author zz85 / http://www.lab4games.net/zz85/blog
  22283. *
  22284. * Bezier Curves formulas obtained from
  22285. * http://en.wikipedia.org/wiki/Bézier_curve
  22286. */
  22287. function CatmullRom( t, p0, p1, p2, p3 ) {
  22288. var v0 = ( p2 - p0 ) * 0.5;
  22289. var v1 = ( p3 - p1 ) * 0.5;
  22290. var t2 = t * t;
  22291. var t3 = t * t2;
  22292. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  22293. }
  22294. //
  22295. function QuadraticBezierP0( t, p ) {
  22296. var k = 1 - t;
  22297. return k * k * p;
  22298. }
  22299. function QuadraticBezierP1( t, p ) {
  22300. return 2 * ( 1 - t ) * t * p;
  22301. }
  22302. function QuadraticBezierP2( t, p ) {
  22303. return t * t * p;
  22304. }
  22305. function QuadraticBezier( t, p0, p1, p2 ) {
  22306. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  22307. QuadraticBezierP2( t, p2 );
  22308. }
  22309. //
  22310. function CubicBezierP0( t, p ) {
  22311. var k = 1 - t;
  22312. return k * k * k * p;
  22313. }
  22314. function CubicBezierP1( t, p ) {
  22315. var k = 1 - t;
  22316. return 3 * k * k * t * p;
  22317. }
  22318. function CubicBezierP2( t, p ) {
  22319. return 3 * ( 1 - t ) * t * t * p;
  22320. }
  22321. function CubicBezierP3( t, p ) {
  22322. return t * t * t * p;
  22323. }
  22324. function CubicBezier( t, p0, p1, p2, p3 ) {
  22325. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  22326. CubicBezierP3( t, p3 );
  22327. }
  22328. function CubicBezierCurve( v0, v1, v2, v3 ) {
  22329. Curve.call( this );
  22330. this.type = 'CubicBezierCurve';
  22331. this.v0 = v0 || new Vector2();
  22332. this.v1 = v1 || new Vector2();
  22333. this.v2 = v2 || new Vector2();
  22334. this.v3 = v3 || new Vector2();
  22335. }
  22336. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  22337. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22338. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22339. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22340. var point = optionalTarget || new Vector2();
  22341. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22342. point.set(
  22343. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22344. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  22345. );
  22346. return point;
  22347. };
  22348. CubicBezierCurve.prototype.copy = function ( source ) {
  22349. Curve.prototype.copy.call( this, source );
  22350. this.v0.copy( source.v0 );
  22351. this.v1.copy( source.v1 );
  22352. this.v2.copy( source.v2 );
  22353. this.v3.copy( source.v3 );
  22354. return this;
  22355. };
  22356. CubicBezierCurve.prototype.toJSON = function () {
  22357. var data = Curve.prototype.toJSON.call( this );
  22358. data.v0 = this.v0.toArray();
  22359. data.v1 = this.v1.toArray();
  22360. data.v2 = this.v2.toArray();
  22361. data.v3 = this.v3.toArray();
  22362. return data;
  22363. };
  22364. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  22365. Curve.prototype.fromJSON.call( this, json );
  22366. this.v0.fromArray( json.v0 );
  22367. this.v1.fromArray( json.v1 );
  22368. this.v2.fromArray( json.v2 );
  22369. this.v3.fromArray( json.v3 );
  22370. return this;
  22371. };
  22372. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  22373. Curve.call( this );
  22374. this.type = 'CubicBezierCurve3';
  22375. this.v0 = v0 || new Vector3();
  22376. this.v1 = v1 || new Vector3();
  22377. this.v2 = v2 || new Vector3();
  22378. this.v3 = v3 || new Vector3();
  22379. }
  22380. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  22381. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22382. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22383. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22384. var point = optionalTarget || new Vector3();
  22385. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22386. point.set(
  22387. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22388. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  22389. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  22390. );
  22391. return point;
  22392. };
  22393. CubicBezierCurve3.prototype.copy = function ( source ) {
  22394. Curve.prototype.copy.call( this, source );
  22395. this.v0.copy( source.v0 );
  22396. this.v1.copy( source.v1 );
  22397. this.v2.copy( source.v2 );
  22398. this.v3.copy( source.v3 );
  22399. return this;
  22400. };
  22401. CubicBezierCurve3.prototype.toJSON = function () {
  22402. var data = Curve.prototype.toJSON.call( this );
  22403. data.v0 = this.v0.toArray();
  22404. data.v1 = this.v1.toArray();
  22405. data.v2 = this.v2.toArray();
  22406. data.v3 = this.v3.toArray();
  22407. return data;
  22408. };
  22409. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  22410. Curve.prototype.fromJSON.call( this, json );
  22411. this.v0.fromArray( json.v0 );
  22412. this.v1.fromArray( json.v1 );
  22413. this.v2.fromArray( json.v2 );
  22414. this.v3.fromArray( json.v3 );
  22415. return this;
  22416. };
  22417. function LineCurve( v1, v2 ) {
  22418. Curve.call( this );
  22419. this.type = 'LineCurve';
  22420. this.v1 = v1 || new Vector2();
  22421. this.v2 = v2 || new Vector2();
  22422. }
  22423. LineCurve.prototype = Object.create( Curve.prototype );
  22424. LineCurve.prototype.constructor = LineCurve;
  22425. LineCurve.prototype.isLineCurve = true;
  22426. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22427. var point = optionalTarget || new Vector2();
  22428. if ( t === 1 ) {
  22429. point.copy( this.v2 );
  22430. } else {
  22431. point.copy( this.v2 ).sub( this.v1 );
  22432. point.multiplyScalar( t ).add( this.v1 );
  22433. }
  22434. return point;
  22435. };
  22436. // Line curve is linear, so we can overwrite default getPointAt
  22437. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  22438. return this.getPoint( u, optionalTarget );
  22439. };
  22440. LineCurve.prototype.getTangent = function ( /* t */ ) {
  22441. var tangent = this.v2.clone().sub( this.v1 );
  22442. return tangent.normalize();
  22443. };
  22444. LineCurve.prototype.copy = function ( source ) {
  22445. Curve.prototype.copy.call( this, source );
  22446. this.v1.copy( source.v1 );
  22447. this.v2.copy( source.v2 );
  22448. return this;
  22449. };
  22450. LineCurve.prototype.toJSON = function () {
  22451. var data = Curve.prototype.toJSON.call( this );
  22452. data.v1 = this.v1.toArray();
  22453. data.v2 = this.v2.toArray();
  22454. return data;
  22455. };
  22456. LineCurve.prototype.fromJSON = function ( json ) {
  22457. Curve.prototype.fromJSON.call( this, json );
  22458. this.v1.fromArray( json.v1 );
  22459. this.v2.fromArray( json.v2 );
  22460. return this;
  22461. };
  22462. function LineCurve3( v1, v2 ) {
  22463. Curve.call( this );
  22464. this.type = 'LineCurve3';
  22465. this.v1 = v1 || new Vector3();
  22466. this.v2 = v2 || new Vector3();
  22467. }
  22468. LineCurve3.prototype = Object.create( Curve.prototype );
  22469. LineCurve3.prototype.constructor = LineCurve3;
  22470. LineCurve3.prototype.isLineCurve3 = true;
  22471. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22472. var point = optionalTarget || new Vector3();
  22473. if ( t === 1 ) {
  22474. point.copy( this.v2 );
  22475. } else {
  22476. point.copy( this.v2 ).sub( this.v1 );
  22477. point.multiplyScalar( t ).add( this.v1 );
  22478. }
  22479. return point;
  22480. };
  22481. // Line curve is linear, so we can overwrite default getPointAt
  22482. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  22483. return this.getPoint( u, optionalTarget );
  22484. };
  22485. LineCurve3.prototype.copy = function ( source ) {
  22486. Curve.prototype.copy.call( this, source );
  22487. this.v1.copy( source.v1 );
  22488. this.v2.copy( source.v2 );
  22489. return this;
  22490. };
  22491. LineCurve3.prototype.toJSON = function () {
  22492. var data = Curve.prototype.toJSON.call( this );
  22493. data.v1 = this.v1.toArray();
  22494. data.v2 = this.v2.toArray();
  22495. return data;
  22496. };
  22497. LineCurve3.prototype.fromJSON = function ( json ) {
  22498. Curve.prototype.fromJSON.call( this, json );
  22499. this.v1.fromArray( json.v1 );
  22500. this.v2.fromArray( json.v2 );
  22501. return this;
  22502. };
  22503. function QuadraticBezierCurve( v0, v1, v2 ) {
  22504. Curve.call( this );
  22505. this.type = 'QuadraticBezierCurve';
  22506. this.v0 = v0 || new Vector2();
  22507. this.v1 = v1 || new Vector2();
  22508. this.v2 = v2 || new Vector2();
  22509. }
  22510. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  22511. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22512. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22513. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22514. var point = optionalTarget || new Vector2();
  22515. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22516. point.set(
  22517. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22518. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22519. );
  22520. return point;
  22521. };
  22522. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22523. Curve.prototype.copy.call( this, source );
  22524. this.v0.copy( source.v0 );
  22525. this.v1.copy( source.v1 );
  22526. this.v2.copy( source.v2 );
  22527. return this;
  22528. };
  22529. QuadraticBezierCurve.prototype.toJSON = function () {
  22530. var data = Curve.prototype.toJSON.call( this );
  22531. data.v0 = this.v0.toArray();
  22532. data.v1 = this.v1.toArray();
  22533. data.v2 = this.v2.toArray();
  22534. return data;
  22535. };
  22536. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22537. Curve.prototype.fromJSON.call( this, json );
  22538. this.v0.fromArray( json.v0 );
  22539. this.v1.fromArray( json.v1 );
  22540. this.v2.fromArray( json.v2 );
  22541. return this;
  22542. };
  22543. function QuadraticBezierCurve3( v0, v1, v2 ) {
  22544. Curve.call( this );
  22545. this.type = 'QuadraticBezierCurve3';
  22546. this.v0 = v0 || new Vector3();
  22547. this.v1 = v1 || new Vector3();
  22548. this.v2 = v2 || new Vector3();
  22549. }
  22550. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22551. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22552. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22553. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22554. var point = optionalTarget || new Vector3();
  22555. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22556. point.set(
  22557. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22558. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22559. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22560. );
  22561. return point;
  22562. };
  22563. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22564. Curve.prototype.copy.call( this, source );
  22565. this.v0.copy( source.v0 );
  22566. this.v1.copy( source.v1 );
  22567. this.v2.copy( source.v2 );
  22568. return this;
  22569. };
  22570. QuadraticBezierCurve3.prototype.toJSON = function () {
  22571. var data = Curve.prototype.toJSON.call( this );
  22572. data.v0 = this.v0.toArray();
  22573. data.v1 = this.v1.toArray();
  22574. data.v2 = this.v2.toArray();
  22575. return data;
  22576. };
  22577. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  22578. Curve.prototype.fromJSON.call( this, json );
  22579. this.v0.fromArray( json.v0 );
  22580. this.v1.fromArray( json.v1 );
  22581. this.v2.fromArray( json.v2 );
  22582. return this;
  22583. };
  22584. function SplineCurve( points /* array of Vector2 */ ) {
  22585. Curve.call( this );
  22586. this.type = 'SplineCurve';
  22587. this.points = points || [];
  22588. }
  22589. SplineCurve.prototype = Object.create( Curve.prototype );
  22590. SplineCurve.prototype.constructor = SplineCurve;
  22591. SplineCurve.prototype.isSplineCurve = true;
  22592. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22593. var point = optionalTarget || new Vector2();
  22594. var points = this.points;
  22595. var p = ( points.length - 1 ) * t;
  22596. var intPoint = Math.floor( p );
  22597. var weight = p - intPoint;
  22598. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  22599. var p1 = points[ intPoint ];
  22600. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  22601. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  22602. point.set(
  22603. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  22604. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  22605. );
  22606. return point;
  22607. };
  22608. SplineCurve.prototype.copy = function ( source ) {
  22609. Curve.prototype.copy.call( this, source );
  22610. this.points = [];
  22611. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22612. var point = source.points[ i ];
  22613. this.points.push( point.clone() );
  22614. }
  22615. return this;
  22616. };
  22617. SplineCurve.prototype.toJSON = function () {
  22618. var data = Curve.prototype.toJSON.call( this );
  22619. data.points = [];
  22620. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22621. var point = this.points[ i ];
  22622. data.points.push( point.toArray() );
  22623. }
  22624. return data;
  22625. };
  22626. SplineCurve.prototype.fromJSON = function ( json ) {
  22627. Curve.prototype.fromJSON.call( this, json );
  22628. this.points = [];
  22629. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22630. var point = json.points[ i ];
  22631. this.points.push( new Vector2().fromArray( point ) );
  22632. }
  22633. return this;
  22634. };
  22635. var Curves = /*#__PURE__*/Object.freeze({
  22636. __proto__: null,
  22637. ArcCurve: ArcCurve,
  22638. CatmullRomCurve3: CatmullRomCurve3,
  22639. CubicBezierCurve: CubicBezierCurve,
  22640. CubicBezierCurve3: CubicBezierCurve3,
  22641. EllipseCurve: EllipseCurve,
  22642. LineCurve: LineCurve,
  22643. LineCurve3: LineCurve3,
  22644. QuadraticBezierCurve: QuadraticBezierCurve,
  22645. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22646. SplineCurve: SplineCurve
  22647. });
  22648. /**
  22649. * @author zz85 / http://www.lab4games.net/zz85/blog
  22650. *
  22651. **/
  22652. /**************************************************************
  22653. * Curved Path - a curve path is simply a array of connected
  22654. * curves, but retains the api of a curve
  22655. **************************************************************/
  22656. function CurvePath() {
  22657. Curve.call( this );
  22658. this.type = 'CurvePath';
  22659. this.curves = [];
  22660. this.autoClose = false; // Automatically closes the path
  22661. }
  22662. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  22663. constructor: CurvePath,
  22664. add: function ( curve ) {
  22665. this.curves.push( curve );
  22666. },
  22667. closePath: function () {
  22668. // Add a line curve if start and end of lines are not connected
  22669. var startPoint = this.curves[ 0 ].getPoint( 0 );
  22670. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  22671. if ( ! startPoint.equals( endPoint ) ) {
  22672. this.curves.push( new LineCurve( endPoint, startPoint ) );
  22673. }
  22674. },
  22675. // To get accurate point with reference to
  22676. // entire path distance at time t,
  22677. // following has to be done:
  22678. // 1. Length of each sub path have to be known
  22679. // 2. Locate and identify type of curve
  22680. // 3. Get t for the curve
  22681. // 4. Return curve.getPointAt(t')
  22682. getPoint: function ( t ) {
  22683. var d = t * this.getLength();
  22684. var curveLengths = this.getCurveLengths();
  22685. var i = 0;
  22686. // To think about boundaries points.
  22687. while ( i < curveLengths.length ) {
  22688. if ( curveLengths[ i ] >= d ) {
  22689. var diff = curveLengths[ i ] - d;
  22690. var curve = this.curves[ i ];
  22691. var segmentLength = curve.getLength();
  22692. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22693. return curve.getPointAt( u );
  22694. }
  22695. i ++;
  22696. }
  22697. return null;
  22698. // loop where sum != 0, sum > d , sum+1 <d
  22699. },
  22700. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22701. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22702. // getPoint() depends on getLength
  22703. getLength: function () {
  22704. var lens = this.getCurveLengths();
  22705. return lens[ lens.length - 1 ];
  22706. },
  22707. // cacheLengths must be recalculated.
  22708. updateArcLengths: function () {
  22709. this.needsUpdate = true;
  22710. this.cacheLengths = null;
  22711. this.getCurveLengths();
  22712. },
  22713. // Compute lengths and cache them
  22714. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22715. getCurveLengths: function () {
  22716. // We use cache values if curves and cache array are same length
  22717. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  22718. return this.cacheLengths;
  22719. }
  22720. // Get length of sub-curve
  22721. // Push sums into cached array
  22722. var lengths = [], sums = 0;
  22723. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22724. sums += this.curves[ i ].getLength();
  22725. lengths.push( sums );
  22726. }
  22727. this.cacheLengths = lengths;
  22728. return lengths;
  22729. },
  22730. getSpacedPoints: function ( divisions ) {
  22731. if ( divisions === undefined ) divisions = 40;
  22732. var points = [];
  22733. for ( var i = 0; i <= divisions; i ++ ) {
  22734. points.push( this.getPoint( i / divisions ) );
  22735. }
  22736. if ( this.autoClose ) {
  22737. points.push( points[ 0 ] );
  22738. }
  22739. return points;
  22740. },
  22741. getPoints: function ( divisions ) {
  22742. divisions = divisions || 12;
  22743. var points = [], last;
  22744. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  22745. var curve = curves[ i ];
  22746. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  22747. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  22748. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  22749. : divisions;
  22750. var pts = curve.getPoints( resolution );
  22751. for ( var j = 0; j < pts.length; j ++ ) {
  22752. var point = pts[ j ];
  22753. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  22754. points.push( point );
  22755. last = point;
  22756. }
  22757. }
  22758. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  22759. points.push( points[ 0 ] );
  22760. }
  22761. return points;
  22762. },
  22763. copy: function ( source ) {
  22764. Curve.prototype.copy.call( this, source );
  22765. this.curves = [];
  22766. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  22767. var curve = source.curves[ i ];
  22768. this.curves.push( curve.clone() );
  22769. }
  22770. this.autoClose = source.autoClose;
  22771. return this;
  22772. },
  22773. toJSON: function () {
  22774. var data = Curve.prototype.toJSON.call( this );
  22775. data.autoClose = this.autoClose;
  22776. data.curves = [];
  22777. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22778. var curve = this.curves[ i ];
  22779. data.curves.push( curve.toJSON() );
  22780. }
  22781. return data;
  22782. },
  22783. fromJSON: function ( json ) {
  22784. Curve.prototype.fromJSON.call( this, json );
  22785. this.autoClose = json.autoClose;
  22786. this.curves = [];
  22787. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  22788. var curve = json.curves[ i ];
  22789. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22790. }
  22791. return this;
  22792. }
  22793. } );
  22794. /**
  22795. * @author zz85 / http://www.lab4games.net/zz85/blog
  22796. * Creates free form 2d path using series of points, lines or curves.
  22797. **/
  22798. function Path( points ) {
  22799. CurvePath.call( this );
  22800. this.type = 'Path';
  22801. this.currentPoint = new Vector2();
  22802. if ( points ) {
  22803. this.setFromPoints( points );
  22804. }
  22805. }
  22806. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22807. constructor: Path,
  22808. setFromPoints: function ( points ) {
  22809. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22810. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22811. this.lineTo( points[ i ].x, points[ i ].y );
  22812. }
  22813. return this;
  22814. },
  22815. moveTo: function ( x, y ) {
  22816. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22817. return this;
  22818. },
  22819. lineTo: function ( x, y ) {
  22820. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22821. this.curves.push( curve );
  22822. this.currentPoint.set( x, y );
  22823. return this;
  22824. },
  22825. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22826. var curve = new QuadraticBezierCurve(
  22827. this.currentPoint.clone(),
  22828. new Vector2( aCPx, aCPy ),
  22829. new Vector2( aX, aY )
  22830. );
  22831. this.curves.push( curve );
  22832. this.currentPoint.set( aX, aY );
  22833. return this;
  22834. },
  22835. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22836. var curve = new CubicBezierCurve(
  22837. this.currentPoint.clone(),
  22838. new Vector2( aCP1x, aCP1y ),
  22839. new Vector2( aCP2x, aCP2y ),
  22840. new Vector2( aX, aY )
  22841. );
  22842. this.curves.push( curve );
  22843. this.currentPoint.set( aX, aY );
  22844. return this;
  22845. },
  22846. splineThru: function ( pts /*Array of Vector*/ ) {
  22847. var npts = [ this.currentPoint.clone() ].concat( pts );
  22848. var curve = new SplineCurve( npts );
  22849. this.curves.push( curve );
  22850. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22851. return this;
  22852. },
  22853. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22854. var x0 = this.currentPoint.x;
  22855. var y0 = this.currentPoint.y;
  22856. this.absarc( aX + x0, aY + y0, aRadius,
  22857. aStartAngle, aEndAngle, aClockwise );
  22858. return this;
  22859. },
  22860. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22861. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22862. return this;
  22863. },
  22864. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22865. var x0 = this.currentPoint.x;
  22866. var y0 = this.currentPoint.y;
  22867. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22868. return this;
  22869. },
  22870. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22871. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22872. if ( this.curves.length > 0 ) {
  22873. // if a previous curve is present, attempt to join
  22874. var firstPoint = curve.getPoint( 0 );
  22875. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22876. this.lineTo( firstPoint.x, firstPoint.y );
  22877. }
  22878. }
  22879. this.curves.push( curve );
  22880. var lastPoint = curve.getPoint( 1 );
  22881. this.currentPoint.copy( lastPoint );
  22882. return this;
  22883. },
  22884. copy: function ( source ) {
  22885. CurvePath.prototype.copy.call( this, source );
  22886. this.currentPoint.copy( source.currentPoint );
  22887. return this;
  22888. },
  22889. toJSON: function () {
  22890. var data = CurvePath.prototype.toJSON.call( this );
  22891. data.currentPoint = this.currentPoint.toArray();
  22892. return data;
  22893. },
  22894. fromJSON: function ( json ) {
  22895. CurvePath.prototype.fromJSON.call( this, json );
  22896. this.currentPoint.fromArray( json.currentPoint );
  22897. return this;
  22898. }
  22899. } );
  22900. /**
  22901. * @author zz85 / http://www.lab4games.net/zz85/blog
  22902. * Defines a 2d shape plane using paths.
  22903. **/
  22904. // STEP 1 Create a path.
  22905. // STEP 2 Turn path into shape.
  22906. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22907. // STEP 3a - Extract points from each shape, turn to vertices
  22908. // STEP 3b - Triangulate each shape, add faces.
  22909. function Shape( points ) {
  22910. Path.call( this, points );
  22911. this.uuid = _Math.generateUUID();
  22912. this.type = 'Shape';
  22913. this.holes = [];
  22914. }
  22915. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22916. constructor: Shape,
  22917. getPointsHoles: function ( divisions ) {
  22918. var holesPts = [];
  22919. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22920. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22921. }
  22922. return holesPts;
  22923. },
  22924. // get points of shape and holes (keypoints based on segments parameter)
  22925. extractPoints: function ( divisions ) {
  22926. return {
  22927. shape: this.getPoints( divisions ),
  22928. holes: this.getPointsHoles( divisions )
  22929. };
  22930. },
  22931. copy: function ( source ) {
  22932. Path.prototype.copy.call( this, source );
  22933. this.holes = [];
  22934. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22935. var hole = source.holes[ i ];
  22936. this.holes.push( hole.clone() );
  22937. }
  22938. return this;
  22939. },
  22940. toJSON: function () {
  22941. var data = Path.prototype.toJSON.call( this );
  22942. data.uuid = this.uuid;
  22943. data.holes = [];
  22944. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22945. var hole = this.holes[ i ];
  22946. data.holes.push( hole.toJSON() );
  22947. }
  22948. return data;
  22949. },
  22950. fromJSON: function ( json ) {
  22951. Path.prototype.fromJSON.call( this, json );
  22952. this.uuid = json.uuid;
  22953. this.holes = [];
  22954. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22955. var hole = json.holes[ i ];
  22956. this.holes.push( new Path().fromJSON( hole ) );
  22957. }
  22958. return this;
  22959. }
  22960. } );
  22961. /**
  22962. * @author mrdoob / http://mrdoob.com/
  22963. * @author alteredq / http://alteredqualia.com/
  22964. */
  22965. function Light( color, intensity ) {
  22966. Object3D.call( this );
  22967. this.type = 'Light';
  22968. this.color = new Color( color );
  22969. this.intensity = intensity !== undefined ? intensity : 1;
  22970. this.receiveShadow = undefined;
  22971. }
  22972. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22973. constructor: Light,
  22974. isLight: true,
  22975. copy: function ( source ) {
  22976. Object3D.prototype.copy.call( this, source );
  22977. this.color.copy( source.color );
  22978. this.intensity = source.intensity;
  22979. return this;
  22980. },
  22981. toJSON: function ( meta ) {
  22982. var data = Object3D.prototype.toJSON.call( this, meta );
  22983. data.object.color = this.color.getHex();
  22984. data.object.intensity = this.intensity;
  22985. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22986. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22987. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22988. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22989. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22990. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22991. return data;
  22992. }
  22993. } );
  22994. /**
  22995. * @author alteredq / http://alteredqualia.com/
  22996. */
  22997. function HemisphereLight( skyColor, groundColor, intensity ) {
  22998. Light.call( this, skyColor, intensity );
  22999. this.type = 'HemisphereLight';
  23000. this.castShadow = undefined;
  23001. this.position.copy( Object3D.DefaultUp );
  23002. this.updateMatrix();
  23003. this.groundColor = new Color( groundColor );
  23004. }
  23005. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23006. constructor: HemisphereLight,
  23007. isHemisphereLight: true,
  23008. copy: function ( source ) {
  23009. Light.prototype.copy.call( this, source );
  23010. this.groundColor.copy( source.groundColor );
  23011. return this;
  23012. }
  23013. } );
  23014. /**
  23015. * @author mrdoob / http://mrdoob.com/
  23016. */
  23017. function LightShadow( camera ) {
  23018. this.camera = camera;
  23019. this.bias = 0;
  23020. this.radius = 1;
  23021. this.mapSize = new Vector2( 512, 512 );
  23022. this.map = null;
  23023. this.mapPass = null;
  23024. this.matrix = new Matrix4();
  23025. this._frustum = new Frustum();
  23026. this._frameExtents = new Vector2( 1, 1 );
  23027. this._viewportCount = 1;
  23028. this._viewports = [
  23029. new Vector4( 0, 0, 1, 1 )
  23030. ];
  23031. }
  23032. Object.assign( LightShadow.prototype, {
  23033. _projScreenMatrix: new Matrix4(),
  23034. _lightPositionWorld: new Vector3(),
  23035. _lookTarget: new Vector3(),
  23036. getViewportCount: function () {
  23037. return this._viewportCount;
  23038. },
  23039. getFrustum: function () {
  23040. return this._frustum;
  23041. },
  23042. updateMatrices: function ( light ) {
  23043. var shadowCamera = this.camera,
  23044. shadowMatrix = this.matrix,
  23045. projScreenMatrix = this._projScreenMatrix,
  23046. lookTarget = this._lookTarget,
  23047. lightPositionWorld = this._lightPositionWorld;
  23048. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23049. shadowCamera.position.copy( lightPositionWorld );
  23050. lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  23051. shadowCamera.lookAt( lookTarget );
  23052. shadowCamera.updateMatrixWorld();
  23053. projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23054. this._frustum.setFromMatrix( projScreenMatrix );
  23055. shadowMatrix.set(
  23056. 0.5, 0.0, 0.0, 0.5,
  23057. 0.0, 0.5, 0.0, 0.5,
  23058. 0.0, 0.0, 0.5, 0.5,
  23059. 0.0, 0.0, 0.0, 1.0
  23060. );
  23061. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  23062. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  23063. },
  23064. getViewport: function ( viewportIndex ) {
  23065. return this._viewports[ viewportIndex ];
  23066. },
  23067. getFrameExtents: function () {
  23068. return this._frameExtents;
  23069. },
  23070. copy: function ( source ) {
  23071. this.camera = source.camera.clone();
  23072. this.bias = source.bias;
  23073. this.radius = source.radius;
  23074. this.mapSize.copy( source.mapSize );
  23075. return this;
  23076. },
  23077. clone: function () {
  23078. return new this.constructor().copy( this );
  23079. },
  23080. toJSON: function () {
  23081. var object = {};
  23082. if ( this.bias !== 0 ) object.bias = this.bias;
  23083. if ( this.radius !== 1 ) object.radius = this.radius;
  23084. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  23085. object.camera = this.camera.toJSON( false ).object;
  23086. delete object.camera.matrix;
  23087. return object;
  23088. }
  23089. } );
  23090. /**
  23091. * @author mrdoob / http://mrdoob.com/
  23092. */
  23093. function SpotLightShadow() {
  23094. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  23095. }
  23096. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23097. constructor: SpotLightShadow,
  23098. isSpotLightShadow: true,
  23099. updateMatrices: function ( light ) {
  23100. var camera = this.camera;
  23101. var fov = _Math.RAD2DEG * 2 * light.angle;
  23102. var aspect = this.mapSize.width / this.mapSize.height;
  23103. var far = light.distance || camera.far;
  23104. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  23105. camera.fov = fov;
  23106. camera.aspect = aspect;
  23107. camera.far = far;
  23108. camera.updateProjectionMatrix();
  23109. }
  23110. LightShadow.prototype.updateMatrices.call( this, light );
  23111. }
  23112. } );
  23113. /**
  23114. * @author alteredq / http://alteredqualia.com/
  23115. */
  23116. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  23117. Light.call( this, color, intensity );
  23118. this.type = 'SpotLight';
  23119. this.position.copy( Object3D.DefaultUp );
  23120. this.updateMatrix();
  23121. this.target = new Object3D();
  23122. Object.defineProperty( this, 'power', {
  23123. get: function () {
  23124. // intensity = power per solid angle.
  23125. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23126. return this.intensity * Math.PI;
  23127. },
  23128. set: function ( power ) {
  23129. // intensity = power per solid angle.
  23130. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23131. this.intensity = power / Math.PI;
  23132. }
  23133. } );
  23134. this.distance = ( distance !== undefined ) ? distance : 0;
  23135. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  23136. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  23137. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23138. this.shadow = new SpotLightShadow();
  23139. }
  23140. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23141. constructor: SpotLight,
  23142. isSpotLight: true,
  23143. copy: function ( source ) {
  23144. Light.prototype.copy.call( this, source );
  23145. this.distance = source.distance;
  23146. this.angle = source.angle;
  23147. this.penumbra = source.penumbra;
  23148. this.decay = source.decay;
  23149. this.target = source.target.clone();
  23150. this.shadow = source.shadow.clone();
  23151. return this;
  23152. }
  23153. } );
  23154. function PointLightShadow() {
  23155. LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  23156. this._frameExtents = new Vector2( 4, 2 );
  23157. this._viewportCount = 6;
  23158. this._viewports = [
  23159. // These viewports map a cube-map onto a 2D texture with the
  23160. // following orientation:
  23161. //
  23162. // xzXZ
  23163. // y Y
  23164. //
  23165. // X - Positive x direction
  23166. // x - Negative x direction
  23167. // Y - Positive y direction
  23168. // y - Negative y direction
  23169. // Z - Positive z direction
  23170. // z - Negative z direction
  23171. // positive X
  23172. new Vector4( 2, 1, 1, 1 ),
  23173. // negative X
  23174. new Vector4( 0, 1, 1, 1 ),
  23175. // positive Z
  23176. new Vector4( 3, 1, 1, 1 ),
  23177. // negative Z
  23178. new Vector4( 1, 1, 1, 1 ),
  23179. // positive Y
  23180. new Vector4( 3, 0, 1, 1 ),
  23181. // negative Y
  23182. new Vector4( 1, 0, 1, 1 )
  23183. ];
  23184. this._cubeDirections = [
  23185. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  23186. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  23187. ];
  23188. this._cubeUps = [
  23189. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  23190. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  23191. ];
  23192. }
  23193. PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23194. constructor: PointLightShadow,
  23195. isPointLightShadow: true,
  23196. updateMatrices: function ( light, viewportIndex ) {
  23197. if ( viewportIndex === undefined ) viewportIndex = 0;
  23198. var camera = this.camera,
  23199. shadowMatrix = this.matrix,
  23200. lightPositionWorld = this._lightPositionWorld,
  23201. lookTarget = this._lookTarget,
  23202. projScreenMatrix = this._projScreenMatrix;
  23203. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23204. camera.position.copy( lightPositionWorld );
  23205. lookTarget.copy( camera.position );
  23206. lookTarget.add( this._cubeDirections[ viewportIndex ] );
  23207. camera.up.copy( this._cubeUps[ viewportIndex ] );
  23208. camera.lookAt( lookTarget );
  23209. camera.updateMatrixWorld();
  23210. shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
  23211. projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  23212. this._frustum.setFromMatrix( projScreenMatrix );
  23213. }
  23214. } );
  23215. /**
  23216. * @author mrdoob / http://mrdoob.com/
  23217. */
  23218. function PointLight( color, intensity, distance, decay ) {
  23219. Light.call( this, color, intensity );
  23220. this.type = 'PointLight';
  23221. Object.defineProperty( this, 'power', {
  23222. get: function () {
  23223. // intensity = power per solid angle.
  23224. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23225. return this.intensity * 4 * Math.PI;
  23226. },
  23227. set: function ( power ) {
  23228. // intensity = power per solid angle.
  23229. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23230. this.intensity = power / ( 4 * Math.PI );
  23231. }
  23232. } );
  23233. this.distance = ( distance !== undefined ) ? distance : 0;
  23234. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23235. this.shadow = new PointLightShadow();
  23236. }
  23237. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23238. constructor: PointLight,
  23239. isPointLight: true,
  23240. copy: function ( source ) {
  23241. Light.prototype.copy.call( this, source );
  23242. this.distance = source.distance;
  23243. this.decay = source.decay;
  23244. this.shadow = source.shadow.clone();
  23245. return this;
  23246. }
  23247. } );
  23248. /**
  23249. * @author alteredq / http://alteredqualia.com/
  23250. * @author arose / http://github.com/arose
  23251. */
  23252. function OrthographicCamera( left, right, top, bottom, near, far ) {
  23253. Camera.call( this );
  23254. this.type = 'OrthographicCamera';
  23255. this.zoom = 1;
  23256. this.view = null;
  23257. this.left = ( left !== undefined ) ? left : - 1;
  23258. this.right = ( right !== undefined ) ? right : 1;
  23259. this.top = ( top !== undefined ) ? top : 1;
  23260. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  23261. this.near = ( near !== undefined ) ? near : 0.1;
  23262. this.far = ( far !== undefined ) ? far : 2000;
  23263. this.updateProjectionMatrix();
  23264. }
  23265. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  23266. constructor: OrthographicCamera,
  23267. isOrthographicCamera: true,
  23268. copy: function ( source, recursive ) {
  23269. Camera.prototype.copy.call( this, source, recursive );
  23270. this.left = source.left;
  23271. this.right = source.right;
  23272. this.top = source.top;
  23273. this.bottom = source.bottom;
  23274. this.near = source.near;
  23275. this.far = source.far;
  23276. this.zoom = source.zoom;
  23277. this.view = source.view === null ? null : Object.assign( {}, source.view );
  23278. return this;
  23279. },
  23280. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  23281. if ( this.view === null ) {
  23282. this.view = {
  23283. enabled: true,
  23284. fullWidth: 1,
  23285. fullHeight: 1,
  23286. offsetX: 0,
  23287. offsetY: 0,
  23288. width: 1,
  23289. height: 1
  23290. };
  23291. }
  23292. this.view.enabled = true;
  23293. this.view.fullWidth = fullWidth;
  23294. this.view.fullHeight = fullHeight;
  23295. this.view.offsetX = x;
  23296. this.view.offsetY = y;
  23297. this.view.width = width;
  23298. this.view.height = height;
  23299. this.updateProjectionMatrix();
  23300. },
  23301. clearViewOffset: function () {
  23302. if ( this.view !== null ) {
  23303. this.view.enabled = false;
  23304. }
  23305. this.updateProjectionMatrix();
  23306. },
  23307. updateProjectionMatrix: function () {
  23308. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  23309. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  23310. var cx = ( this.right + this.left ) / 2;
  23311. var cy = ( this.top + this.bottom ) / 2;
  23312. var left = cx - dx;
  23313. var right = cx + dx;
  23314. var top = cy + dy;
  23315. var bottom = cy - dy;
  23316. if ( this.view !== null && this.view.enabled ) {
  23317. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  23318. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  23319. var scaleW = ( this.right - this.left ) / this.view.width;
  23320. var scaleH = ( this.top - this.bottom ) / this.view.height;
  23321. left += scaleW * ( this.view.offsetX / zoomW );
  23322. right = left + scaleW * ( this.view.width / zoomW );
  23323. top -= scaleH * ( this.view.offsetY / zoomH );
  23324. bottom = top - scaleH * ( this.view.height / zoomH );
  23325. }
  23326. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  23327. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  23328. },
  23329. toJSON: function ( meta ) {
  23330. var data = Object3D.prototype.toJSON.call( this, meta );
  23331. data.object.zoom = this.zoom;
  23332. data.object.left = this.left;
  23333. data.object.right = this.right;
  23334. data.object.top = this.top;
  23335. data.object.bottom = this.bottom;
  23336. data.object.near = this.near;
  23337. data.object.far = this.far;
  23338. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  23339. return data;
  23340. }
  23341. } );
  23342. /**
  23343. * @author mrdoob / http://mrdoob.com/
  23344. */
  23345. function DirectionalLightShadow() {
  23346. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  23347. }
  23348. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23349. constructor: DirectionalLightShadow,
  23350. isDirectionalLightShadow: true,
  23351. updateMatrices: function ( light ) {
  23352. LightShadow.prototype.updateMatrices.call( this, light );
  23353. }
  23354. } );
  23355. /**
  23356. * @author mrdoob / http://mrdoob.com/
  23357. * @author alteredq / http://alteredqualia.com/
  23358. */
  23359. function DirectionalLight( color, intensity ) {
  23360. Light.call( this, color, intensity );
  23361. this.type = 'DirectionalLight';
  23362. this.position.copy( Object3D.DefaultUp );
  23363. this.updateMatrix();
  23364. this.target = new Object3D();
  23365. this.shadow = new DirectionalLightShadow();
  23366. }
  23367. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23368. constructor: DirectionalLight,
  23369. isDirectionalLight: true,
  23370. copy: function ( source ) {
  23371. Light.prototype.copy.call( this, source );
  23372. this.target = source.target.clone();
  23373. this.shadow = source.shadow.clone();
  23374. return this;
  23375. }
  23376. } );
  23377. /**
  23378. * @author mrdoob / http://mrdoob.com/
  23379. */
  23380. function AmbientLight( color, intensity ) {
  23381. Light.call( this, color, intensity );
  23382. this.type = 'AmbientLight';
  23383. this.castShadow = undefined;
  23384. }
  23385. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23386. constructor: AmbientLight,
  23387. isAmbientLight: true
  23388. } );
  23389. /**
  23390. * @author abelnation / http://github.com/abelnation
  23391. */
  23392. function RectAreaLight( color, intensity, width, height ) {
  23393. Light.call( this, color, intensity );
  23394. this.type = 'RectAreaLight';
  23395. this.width = ( width !== undefined ) ? width : 10;
  23396. this.height = ( height !== undefined ) ? height : 10;
  23397. }
  23398. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23399. constructor: RectAreaLight,
  23400. isRectAreaLight: true,
  23401. copy: function ( source ) {
  23402. Light.prototype.copy.call( this, source );
  23403. this.width = source.width;
  23404. this.height = source.height;
  23405. return this;
  23406. },
  23407. toJSON: function ( meta ) {
  23408. var data = Light.prototype.toJSON.call( this, meta );
  23409. data.object.width = this.width;
  23410. data.object.height = this.height;
  23411. return data;
  23412. }
  23413. } );
  23414. /**
  23415. * @author mrdoob / http://mrdoob.com/
  23416. */
  23417. function MaterialLoader( manager ) {
  23418. Loader.call( this, manager );
  23419. this.textures = {};
  23420. }
  23421. MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  23422. constructor: MaterialLoader,
  23423. load: function ( url, onLoad, onProgress, onError ) {
  23424. var scope = this;
  23425. var loader = new FileLoader( scope.manager );
  23426. loader.setPath( scope.path );
  23427. loader.load( url, function ( text ) {
  23428. onLoad( scope.parse( JSON.parse( text ) ) );
  23429. }, onProgress, onError );
  23430. },
  23431. parse: function ( json ) {
  23432. var textures = this.textures;
  23433. function getTexture( name ) {
  23434. if ( textures[ name ] === undefined ) {
  23435. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  23436. }
  23437. return textures[ name ];
  23438. }
  23439. var material = new Materials[ json.type ]();
  23440. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  23441. if ( json.name !== undefined ) material.name = json.name;
  23442. if ( json.color !== undefined ) material.color.setHex( json.color );
  23443. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  23444. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  23445. if ( json.sheen !== undefined ) material.sheen = new Color().setHex( json.sheen );
  23446. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  23447. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  23448. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  23449. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  23450. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  23451. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  23452. if ( json.fog !== undefined ) material.fog = json.fog;
  23453. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  23454. if ( json.blending !== undefined ) material.blending = json.blending;
  23455. if ( json.combine !== undefined ) material.combine = json.combine;
  23456. if ( json.side !== undefined ) material.side = json.side;
  23457. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  23458. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  23459. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  23460. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  23461. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  23462. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  23463. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  23464. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  23465. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  23466. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  23467. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  23468. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  23469. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  23470. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  23471. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  23472. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  23473. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  23474. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  23475. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  23476. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  23477. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  23478. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  23479. if ( json.scale !== undefined ) material.scale = json.scale;
  23480. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  23481. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23482. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23483. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  23484. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  23485. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  23486. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  23487. if ( json.visible !== undefined ) material.visible = json.visible;
  23488. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  23489. if ( json.userData !== undefined ) material.userData = json.userData;
  23490. // Shader Material
  23491. if ( json.uniforms !== undefined ) {
  23492. for ( var name in json.uniforms ) {
  23493. var uniform = json.uniforms[ name ];
  23494. material.uniforms[ name ] = {};
  23495. switch ( uniform.type ) {
  23496. case 't':
  23497. material.uniforms[ name ].value = getTexture( uniform.value );
  23498. break;
  23499. case 'c':
  23500. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  23501. break;
  23502. case 'v2':
  23503. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  23504. break;
  23505. case 'v3':
  23506. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  23507. break;
  23508. case 'v4':
  23509. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  23510. break;
  23511. case 'm3':
  23512. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  23513. case 'm4':
  23514. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  23515. break;
  23516. default:
  23517. material.uniforms[ name ].value = uniform.value;
  23518. }
  23519. }
  23520. }
  23521. if ( json.defines !== undefined ) material.defines = json.defines;
  23522. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  23523. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  23524. if ( json.extensions !== undefined ) {
  23525. for ( var key in json.extensions ) {
  23526. material.extensions[ key ] = json.extensions[ key ];
  23527. }
  23528. }
  23529. // Deprecated
  23530. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  23531. // for PointsMaterial
  23532. if ( json.size !== undefined ) material.size = json.size;
  23533. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  23534. // maps
  23535. if ( json.map !== undefined ) material.map = getTexture( json.map );
  23536. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  23537. if ( json.alphaMap !== undefined ) {
  23538. material.alphaMap = getTexture( json.alphaMap );
  23539. material.transparent = true;
  23540. }
  23541. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  23542. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  23543. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  23544. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  23545. if ( json.normalScale !== undefined ) {
  23546. var normalScale = json.normalScale;
  23547. if ( Array.isArray( normalScale ) === false ) {
  23548. // Blender exporter used to export a scalar. See #7459
  23549. normalScale = [ normalScale, normalScale ];
  23550. }
  23551. material.normalScale = new Vector2().fromArray( normalScale );
  23552. }
  23553. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  23554. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  23555. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  23556. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  23557. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  23558. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  23559. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  23560. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  23561. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  23562. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  23563. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  23564. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  23565. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  23566. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  23567. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  23568. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  23569. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  23570. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  23571. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  23572. return material;
  23573. },
  23574. setTextures: function ( value ) {
  23575. this.textures = value;
  23576. return this;
  23577. }
  23578. } );
  23579. /**
  23580. * @author Don McCurdy / https://www.donmccurdy.com
  23581. */
  23582. var LoaderUtils = {
  23583. decodeText: function ( array ) {
  23584. if ( typeof TextDecoder !== 'undefined' ) {
  23585. return new TextDecoder().decode( array );
  23586. }
  23587. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23588. // throws a "maximum call stack size exceeded" error for large arrays.
  23589. var s = '';
  23590. for ( var i = 0, il = array.length; i < il; i ++ ) {
  23591. // Implicitly assumes little-endian.
  23592. s += String.fromCharCode( array[ i ] );
  23593. }
  23594. try {
  23595. // merges multi-byte utf-8 characters.
  23596. return decodeURIComponent( escape( s ) );
  23597. } catch ( e ) { // see #16358
  23598. return s;
  23599. }
  23600. },
  23601. extractUrlBase: function ( url ) {
  23602. var index = url.lastIndexOf( '/' );
  23603. if ( index === - 1 ) return './';
  23604. return url.substr( 0, index + 1 );
  23605. }
  23606. };
  23607. /**
  23608. * @author benaadams / https://twitter.com/ben_a_adams
  23609. */
  23610. function InstancedBufferGeometry() {
  23611. BufferGeometry.call( this );
  23612. this.type = 'InstancedBufferGeometry';
  23613. this.maxInstancedCount = undefined;
  23614. }
  23615. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  23616. constructor: InstancedBufferGeometry,
  23617. isInstancedBufferGeometry: true,
  23618. copy: function ( source ) {
  23619. BufferGeometry.prototype.copy.call( this, source );
  23620. this.maxInstancedCount = source.maxInstancedCount;
  23621. return this;
  23622. },
  23623. clone: function () {
  23624. return new this.constructor().copy( this );
  23625. },
  23626. toJSON: function () {
  23627. var data = BufferGeometry.prototype.toJSON.call( this );
  23628. data.maxInstancedCount = this.maxInstancedCount;
  23629. data.isInstancedBufferGeometry = true;
  23630. return data;
  23631. }
  23632. } );
  23633. /**
  23634. * @author benaadams / https://twitter.com/ben_a_adams
  23635. */
  23636. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  23637. if ( typeof ( normalized ) === 'number' ) {
  23638. meshPerAttribute = normalized;
  23639. normalized = false;
  23640. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  23641. }
  23642. BufferAttribute.call( this, array, itemSize, normalized );
  23643. this.meshPerAttribute = meshPerAttribute || 1;
  23644. }
  23645. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23646. constructor: InstancedBufferAttribute,
  23647. isInstancedBufferAttribute: true,
  23648. copy: function ( source ) {
  23649. BufferAttribute.prototype.copy.call( this, source );
  23650. this.meshPerAttribute = source.meshPerAttribute;
  23651. return this;
  23652. },
  23653. toJSON: function () {
  23654. var data = BufferAttribute.prototype.toJSON.call( this );
  23655. data.meshPerAttribute = this.meshPerAttribute;
  23656. data.isInstancedBufferAttribute = true;
  23657. return data;
  23658. }
  23659. } );
  23660. /**
  23661. * @author mrdoob / http://mrdoob.com/
  23662. */
  23663. function BufferGeometryLoader( manager ) {
  23664. Loader.call( this, manager );
  23665. }
  23666. BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  23667. constructor: BufferGeometryLoader,
  23668. load: function ( url, onLoad, onProgress, onError ) {
  23669. var scope = this;
  23670. var loader = new FileLoader( scope.manager );
  23671. loader.setPath( scope.path );
  23672. loader.load( url, function ( text ) {
  23673. onLoad( scope.parse( JSON.parse( text ) ) );
  23674. }, onProgress, onError );
  23675. },
  23676. parse: function ( json ) {
  23677. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23678. var index = json.data.index;
  23679. if ( index !== undefined ) {
  23680. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  23681. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  23682. }
  23683. var attributes = json.data.attributes;
  23684. for ( var key in attributes ) {
  23685. var attribute = attributes[ key ];
  23686. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23687. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23688. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  23689. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23690. geometry.setAttribute( key, bufferAttribute );
  23691. }
  23692. var morphAttributes = json.data.morphAttributes;
  23693. if ( morphAttributes ) {
  23694. for ( var key in morphAttributes ) {
  23695. var attributeArray = morphAttributes[ key ];
  23696. var array = [];
  23697. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  23698. var attribute = attributeArray[ i ];
  23699. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23700. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  23701. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23702. array.push( bufferAttribute );
  23703. }
  23704. geometry.morphAttributes[ key ] = array;
  23705. }
  23706. }
  23707. var morphTargetsRelative = json.data.morphTargetsRelative;
  23708. if ( morphTargetsRelative ) {
  23709. geometry.morphTargetsRelative = true;
  23710. }
  23711. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23712. if ( groups !== undefined ) {
  23713. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  23714. var group = groups[ i ];
  23715. geometry.addGroup( group.start, group.count, group.materialIndex );
  23716. }
  23717. }
  23718. var boundingSphere = json.data.boundingSphere;
  23719. if ( boundingSphere !== undefined ) {
  23720. var center = new Vector3();
  23721. if ( boundingSphere.center !== undefined ) {
  23722. center.fromArray( boundingSphere.center );
  23723. }
  23724. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  23725. }
  23726. if ( json.name ) geometry.name = json.name;
  23727. if ( json.userData ) geometry.userData = json.userData;
  23728. return geometry;
  23729. }
  23730. } );
  23731. var TYPED_ARRAYS = {
  23732. Int8Array: Int8Array,
  23733. Uint8Array: Uint8Array,
  23734. // Workaround for IE11 pre KB2929437. See #11440
  23735. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  23736. Int16Array: Int16Array,
  23737. Uint16Array: Uint16Array,
  23738. Int32Array: Int32Array,
  23739. Uint32Array: Uint32Array,
  23740. Float32Array: Float32Array,
  23741. Float64Array: Float64Array
  23742. };
  23743. /**
  23744. * @author mrdoob / http://mrdoob.com/
  23745. */
  23746. function ObjectLoader( manager ) {
  23747. Loader.call( this, manager );
  23748. }
  23749. ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  23750. constructor: ObjectLoader,
  23751. load: function ( url, onLoad, onProgress, onError ) {
  23752. var scope = this;
  23753. var path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  23754. this.resourcePath = this.resourcePath || path;
  23755. var loader = new FileLoader( scope.manager );
  23756. loader.setPath( this.path );
  23757. loader.load( url, function ( text ) {
  23758. var json = null;
  23759. try {
  23760. json = JSON.parse( text );
  23761. } catch ( error ) {
  23762. if ( onError !== undefined ) onError( error );
  23763. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  23764. return;
  23765. }
  23766. var metadata = json.metadata;
  23767. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  23768. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  23769. return;
  23770. }
  23771. scope.parse( json, onLoad );
  23772. }, onProgress, onError );
  23773. },
  23774. parse: function ( json, onLoad ) {
  23775. var shapes = this.parseShape( json.shapes );
  23776. var geometries = this.parseGeometries( json.geometries, shapes );
  23777. var images = this.parseImages( json.images, function () {
  23778. if ( onLoad !== undefined ) onLoad( object );
  23779. } );
  23780. var textures = this.parseTextures( json.textures, images );
  23781. var materials = this.parseMaterials( json.materials, textures );
  23782. var object = this.parseObject( json.object, geometries, materials );
  23783. if ( json.animations ) {
  23784. object.animations = this.parseAnimations( json.animations );
  23785. }
  23786. if ( json.images === undefined || json.images.length === 0 ) {
  23787. if ( onLoad !== undefined ) onLoad( object );
  23788. }
  23789. return object;
  23790. },
  23791. parseShape: function ( json ) {
  23792. var shapes = {};
  23793. if ( json !== undefined ) {
  23794. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23795. var shape = new Shape().fromJSON( json[ i ] );
  23796. shapes[ shape.uuid ] = shape;
  23797. }
  23798. }
  23799. return shapes;
  23800. },
  23801. parseGeometries: function ( json, shapes ) {
  23802. var geometries = {};
  23803. if ( json !== undefined ) {
  23804. var bufferGeometryLoader = new BufferGeometryLoader();
  23805. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23806. var geometry;
  23807. var data = json[ i ];
  23808. switch ( data.type ) {
  23809. case 'PlaneGeometry':
  23810. case 'PlaneBufferGeometry':
  23811. geometry = new Geometries[ data.type ](
  23812. data.width,
  23813. data.height,
  23814. data.widthSegments,
  23815. data.heightSegments
  23816. );
  23817. break;
  23818. case 'BoxGeometry':
  23819. case 'BoxBufferGeometry':
  23820. case 'CubeGeometry': // backwards compatible
  23821. geometry = new Geometries[ data.type ](
  23822. data.width,
  23823. data.height,
  23824. data.depth,
  23825. data.widthSegments,
  23826. data.heightSegments,
  23827. data.depthSegments
  23828. );
  23829. break;
  23830. case 'CircleGeometry':
  23831. case 'CircleBufferGeometry':
  23832. geometry = new Geometries[ data.type ](
  23833. data.radius,
  23834. data.segments,
  23835. data.thetaStart,
  23836. data.thetaLength
  23837. );
  23838. break;
  23839. case 'CylinderGeometry':
  23840. case 'CylinderBufferGeometry':
  23841. geometry = new Geometries[ data.type ](
  23842. data.radiusTop,
  23843. data.radiusBottom,
  23844. data.height,
  23845. data.radialSegments,
  23846. data.heightSegments,
  23847. data.openEnded,
  23848. data.thetaStart,
  23849. data.thetaLength
  23850. );
  23851. break;
  23852. case 'ConeGeometry':
  23853. case 'ConeBufferGeometry':
  23854. geometry = new Geometries[ data.type ](
  23855. data.radius,
  23856. data.height,
  23857. data.radialSegments,
  23858. data.heightSegments,
  23859. data.openEnded,
  23860. data.thetaStart,
  23861. data.thetaLength
  23862. );
  23863. break;
  23864. case 'SphereGeometry':
  23865. case 'SphereBufferGeometry':
  23866. geometry = new Geometries[ data.type ](
  23867. data.radius,
  23868. data.widthSegments,
  23869. data.heightSegments,
  23870. data.phiStart,
  23871. data.phiLength,
  23872. data.thetaStart,
  23873. data.thetaLength
  23874. );
  23875. break;
  23876. case 'DodecahedronGeometry':
  23877. case 'DodecahedronBufferGeometry':
  23878. case 'IcosahedronGeometry':
  23879. case 'IcosahedronBufferGeometry':
  23880. case 'OctahedronGeometry':
  23881. case 'OctahedronBufferGeometry':
  23882. case 'TetrahedronGeometry':
  23883. case 'TetrahedronBufferGeometry':
  23884. geometry = new Geometries[ data.type ](
  23885. data.radius,
  23886. data.detail
  23887. );
  23888. break;
  23889. case 'RingGeometry':
  23890. case 'RingBufferGeometry':
  23891. geometry = new Geometries[ data.type ](
  23892. data.innerRadius,
  23893. data.outerRadius,
  23894. data.thetaSegments,
  23895. data.phiSegments,
  23896. data.thetaStart,
  23897. data.thetaLength
  23898. );
  23899. break;
  23900. case 'TorusGeometry':
  23901. case 'TorusBufferGeometry':
  23902. geometry = new Geometries[ data.type ](
  23903. data.radius,
  23904. data.tube,
  23905. data.radialSegments,
  23906. data.tubularSegments,
  23907. data.arc
  23908. );
  23909. break;
  23910. case 'TorusKnotGeometry':
  23911. case 'TorusKnotBufferGeometry':
  23912. geometry = new Geometries[ data.type ](
  23913. data.radius,
  23914. data.tube,
  23915. data.tubularSegments,
  23916. data.radialSegments,
  23917. data.p,
  23918. data.q
  23919. );
  23920. break;
  23921. case 'TubeGeometry':
  23922. case 'TubeBufferGeometry':
  23923. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23924. // User defined curves or instances of CurvePath will not be deserialized.
  23925. geometry = new Geometries[ data.type ](
  23926. new Curves[ data.path.type ]().fromJSON( data.path ),
  23927. data.tubularSegments,
  23928. data.radius,
  23929. data.radialSegments,
  23930. data.closed
  23931. );
  23932. break;
  23933. case 'LatheGeometry':
  23934. case 'LatheBufferGeometry':
  23935. geometry = new Geometries[ data.type ](
  23936. data.points,
  23937. data.segments,
  23938. data.phiStart,
  23939. data.phiLength
  23940. );
  23941. break;
  23942. case 'PolyhedronGeometry':
  23943. case 'PolyhedronBufferGeometry':
  23944. geometry = new Geometries[ data.type ](
  23945. data.vertices,
  23946. data.indices,
  23947. data.radius,
  23948. data.details
  23949. );
  23950. break;
  23951. case 'ShapeGeometry':
  23952. case 'ShapeBufferGeometry':
  23953. var geometryShapes = [];
  23954. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23955. var shape = shapes[ data.shapes[ j ] ];
  23956. geometryShapes.push( shape );
  23957. }
  23958. geometry = new Geometries[ data.type ](
  23959. geometryShapes,
  23960. data.curveSegments
  23961. );
  23962. break;
  23963. case 'ExtrudeGeometry':
  23964. case 'ExtrudeBufferGeometry':
  23965. var geometryShapes = [];
  23966. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23967. var shape = shapes[ data.shapes[ j ] ];
  23968. geometryShapes.push( shape );
  23969. }
  23970. var extrudePath = data.options.extrudePath;
  23971. if ( extrudePath !== undefined ) {
  23972. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23973. }
  23974. geometry = new Geometries[ data.type ](
  23975. geometryShapes,
  23976. data.options
  23977. );
  23978. break;
  23979. case 'BufferGeometry':
  23980. case 'InstancedBufferGeometry':
  23981. geometry = bufferGeometryLoader.parse( data );
  23982. break;
  23983. case 'Geometry':
  23984. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23985. var geometryLoader = new THREE.LegacyJSONLoader();
  23986. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23987. } else {
  23988. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23989. }
  23990. break;
  23991. default:
  23992. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23993. continue;
  23994. }
  23995. geometry.uuid = data.uuid;
  23996. if ( data.name !== undefined ) geometry.name = data.name;
  23997. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23998. geometries[ data.uuid ] = geometry;
  23999. }
  24000. }
  24001. return geometries;
  24002. },
  24003. parseMaterials: function ( json, textures ) {
  24004. var cache = {}; // MultiMaterial
  24005. var materials = {};
  24006. if ( json !== undefined ) {
  24007. var loader = new MaterialLoader();
  24008. loader.setTextures( textures );
  24009. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24010. var data = json[ i ];
  24011. if ( data.type === 'MultiMaterial' ) {
  24012. // Deprecated
  24013. var array = [];
  24014. for ( var j = 0; j < data.materials.length; j ++ ) {
  24015. var material = data.materials[ j ];
  24016. if ( cache[ material.uuid ] === undefined ) {
  24017. cache[ material.uuid ] = loader.parse( material );
  24018. }
  24019. array.push( cache[ material.uuid ] );
  24020. }
  24021. materials[ data.uuid ] = array;
  24022. } else {
  24023. if ( cache[ data.uuid ] === undefined ) {
  24024. cache[ data.uuid ] = loader.parse( data );
  24025. }
  24026. materials[ data.uuid ] = cache[ data.uuid ];
  24027. }
  24028. }
  24029. }
  24030. return materials;
  24031. },
  24032. parseAnimations: function ( json ) {
  24033. var animations = [];
  24034. for ( var i = 0; i < json.length; i ++ ) {
  24035. var data = json[ i ];
  24036. var clip = AnimationClip.parse( data );
  24037. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  24038. animations.push( clip );
  24039. }
  24040. return animations;
  24041. },
  24042. parseImages: function ( json, onLoad ) {
  24043. var scope = this;
  24044. var images = {};
  24045. function loadImage( url ) {
  24046. scope.manager.itemStart( url );
  24047. return loader.load( url, function () {
  24048. scope.manager.itemEnd( url );
  24049. }, undefined, function () {
  24050. scope.manager.itemError( url );
  24051. scope.manager.itemEnd( url );
  24052. } );
  24053. }
  24054. if ( json !== undefined && json.length > 0 ) {
  24055. var manager = new LoadingManager( onLoad );
  24056. var loader = new ImageLoader( manager );
  24057. loader.setCrossOrigin( this.crossOrigin );
  24058. for ( var i = 0, il = json.length; i < il; i ++ ) {
  24059. var image = json[ i ];
  24060. var url = image.url;
  24061. if ( Array.isArray( url ) ) {
  24062. // load array of images e.g CubeTexture
  24063. images[ image.uuid ] = [];
  24064. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  24065. var currentUrl = url[ j ];
  24066. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  24067. images[ image.uuid ].push( loadImage( path ) );
  24068. }
  24069. } else {
  24070. // load single image
  24071. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  24072. images[ image.uuid ] = loadImage( path );
  24073. }
  24074. }
  24075. }
  24076. return images;
  24077. },
  24078. parseTextures: function ( json, images ) {
  24079. function parseConstant( value, type ) {
  24080. if ( typeof value === 'number' ) return value;
  24081. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  24082. return type[ value ];
  24083. }
  24084. var textures = {};
  24085. if ( json !== undefined ) {
  24086. for ( var i = 0, l = json.length; i < l; i ++ ) {
  24087. var data = json[ i ];
  24088. if ( data.image === undefined ) {
  24089. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  24090. }
  24091. if ( images[ data.image ] === undefined ) {
  24092. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  24093. }
  24094. var texture;
  24095. if ( Array.isArray( images[ data.image ] ) ) {
  24096. texture = new CubeTexture( images[ data.image ] );
  24097. } else {
  24098. texture = new Texture( images[ data.image ] );
  24099. }
  24100. texture.needsUpdate = true;
  24101. texture.uuid = data.uuid;
  24102. if ( data.name !== undefined ) texture.name = data.name;
  24103. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  24104. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  24105. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  24106. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  24107. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  24108. if ( data.wrap !== undefined ) {
  24109. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  24110. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  24111. }
  24112. if ( data.format !== undefined ) texture.format = data.format;
  24113. if ( data.type !== undefined ) texture.type = data.type;
  24114. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  24115. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  24116. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  24117. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  24118. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  24119. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  24120. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  24121. textures[ data.uuid ] = texture;
  24122. }
  24123. }
  24124. return textures;
  24125. },
  24126. parseObject: function ( data, geometries, materials ) {
  24127. var object;
  24128. function getGeometry( name ) {
  24129. if ( geometries[ name ] === undefined ) {
  24130. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  24131. }
  24132. return geometries[ name ];
  24133. }
  24134. function getMaterial( name ) {
  24135. if ( name === undefined ) return undefined;
  24136. if ( Array.isArray( name ) ) {
  24137. var array = [];
  24138. for ( var i = 0, l = name.length; i < l; i ++ ) {
  24139. var uuid = name[ i ];
  24140. if ( materials[ uuid ] === undefined ) {
  24141. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  24142. }
  24143. array.push( materials[ uuid ] );
  24144. }
  24145. return array;
  24146. }
  24147. if ( materials[ name ] === undefined ) {
  24148. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  24149. }
  24150. return materials[ name ];
  24151. }
  24152. switch ( data.type ) {
  24153. case 'Scene':
  24154. object = new Scene();
  24155. if ( data.background !== undefined ) {
  24156. if ( Number.isInteger( data.background ) ) {
  24157. object.background = new Color( data.background );
  24158. }
  24159. }
  24160. if ( data.fog !== undefined ) {
  24161. if ( data.fog.type === 'Fog' ) {
  24162. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  24163. } else if ( data.fog.type === 'FogExp2' ) {
  24164. object.fog = new FogExp2( data.fog.color, data.fog.density );
  24165. }
  24166. }
  24167. break;
  24168. case 'PerspectiveCamera':
  24169. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  24170. if ( data.focus !== undefined ) object.focus = data.focus;
  24171. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24172. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  24173. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  24174. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24175. break;
  24176. case 'OrthographicCamera':
  24177. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  24178. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24179. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24180. break;
  24181. case 'AmbientLight':
  24182. object = new AmbientLight( data.color, data.intensity );
  24183. break;
  24184. case 'DirectionalLight':
  24185. object = new DirectionalLight( data.color, data.intensity );
  24186. break;
  24187. case 'PointLight':
  24188. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  24189. break;
  24190. case 'RectAreaLight':
  24191. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  24192. break;
  24193. case 'SpotLight':
  24194. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  24195. break;
  24196. case 'HemisphereLight':
  24197. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  24198. break;
  24199. case 'SkinnedMesh':
  24200. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  24201. case 'Mesh':
  24202. var geometry = getGeometry( data.geometry );
  24203. var material = getMaterial( data.material );
  24204. if ( geometry.bones && geometry.bones.length > 0 ) {
  24205. object = new SkinnedMesh( geometry, material );
  24206. } else {
  24207. object = new Mesh( geometry, material );
  24208. }
  24209. break;
  24210. case 'InstancedMesh':
  24211. var geometry = getGeometry( data.geometry );
  24212. var material = getMaterial( data.material );
  24213. var count = data.count;
  24214. var instanceMatrix = data.instanceMatrix;
  24215. object = new InstancedMesh( geometry, material, count );
  24216. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  24217. break;
  24218. case 'LOD':
  24219. object = new LOD();
  24220. break;
  24221. case 'Line':
  24222. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  24223. break;
  24224. case 'LineLoop':
  24225. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  24226. break;
  24227. case 'LineSegments':
  24228. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  24229. break;
  24230. case 'PointCloud':
  24231. case 'Points':
  24232. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  24233. break;
  24234. case 'Sprite':
  24235. object = new Sprite( getMaterial( data.material ) );
  24236. break;
  24237. case 'Group':
  24238. object = new Group();
  24239. break;
  24240. default:
  24241. object = new Object3D();
  24242. }
  24243. object.uuid = data.uuid;
  24244. if ( data.name !== undefined ) object.name = data.name;
  24245. if ( data.matrix !== undefined ) {
  24246. object.matrix.fromArray( data.matrix );
  24247. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24248. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  24249. } else {
  24250. if ( data.position !== undefined ) object.position.fromArray( data.position );
  24251. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  24252. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  24253. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  24254. }
  24255. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  24256. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  24257. if ( data.shadow ) {
  24258. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  24259. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  24260. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  24261. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  24262. }
  24263. if ( data.visible !== undefined ) object.visible = data.visible;
  24264. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  24265. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  24266. if ( data.userData !== undefined ) object.userData = data.userData;
  24267. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  24268. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  24269. if ( data.children !== undefined ) {
  24270. var children = data.children;
  24271. for ( var i = 0; i < children.length; i ++ ) {
  24272. object.add( this.parseObject( children[ i ], geometries, materials ) );
  24273. }
  24274. }
  24275. if ( data.type === 'LOD' ) {
  24276. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  24277. var levels = data.levels;
  24278. for ( var l = 0; l < levels.length; l ++ ) {
  24279. var level = levels[ l ];
  24280. var child = object.getObjectByProperty( 'uuid', level.object );
  24281. if ( child !== undefined ) {
  24282. object.addLevel( child, level.distance );
  24283. }
  24284. }
  24285. }
  24286. return object;
  24287. }
  24288. } );
  24289. var TEXTURE_MAPPING = {
  24290. UVMapping: UVMapping,
  24291. CubeReflectionMapping: CubeReflectionMapping,
  24292. CubeRefractionMapping: CubeRefractionMapping,
  24293. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24294. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24295. SphericalReflectionMapping: SphericalReflectionMapping,
  24296. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24297. CubeUVRefractionMapping: CubeUVRefractionMapping
  24298. };
  24299. var TEXTURE_WRAPPING = {
  24300. RepeatWrapping: RepeatWrapping,
  24301. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24302. MirroredRepeatWrapping: MirroredRepeatWrapping
  24303. };
  24304. var TEXTURE_FILTER = {
  24305. NearestFilter: NearestFilter,
  24306. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24307. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24308. LinearFilter: LinearFilter,
  24309. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24310. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24311. };
  24312. /**
  24313. * @author thespite / http://clicktorelease.com/
  24314. */
  24315. function ImageBitmapLoader( manager ) {
  24316. if ( typeof createImageBitmap === 'undefined' ) {
  24317. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  24318. }
  24319. if ( typeof fetch === 'undefined' ) {
  24320. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  24321. }
  24322. Loader.call( this, manager );
  24323. this.options = undefined;
  24324. }
  24325. ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24326. constructor: ImageBitmapLoader,
  24327. setOptions: function setOptions( options ) {
  24328. this.options = options;
  24329. return this;
  24330. },
  24331. load: function ( url, onLoad, onProgress, onError ) {
  24332. if ( url === undefined ) url = '';
  24333. if ( this.path !== undefined ) url = this.path + url;
  24334. url = this.manager.resolveURL( url );
  24335. var scope = this;
  24336. var cached = Cache.get( url );
  24337. if ( cached !== undefined ) {
  24338. scope.manager.itemStart( url );
  24339. setTimeout( function () {
  24340. if ( onLoad ) onLoad( cached );
  24341. scope.manager.itemEnd( url );
  24342. }, 0 );
  24343. return cached;
  24344. }
  24345. fetch( url ).then( function ( res ) {
  24346. return res.blob();
  24347. } ).then( function ( blob ) {
  24348. if ( scope.options === undefined ) {
  24349. // Workaround for FireFox. It causes an error if you pass options.
  24350. return createImageBitmap( blob );
  24351. } else {
  24352. return createImageBitmap( blob, scope.options );
  24353. }
  24354. } ).then( function ( imageBitmap ) {
  24355. Cache.add( url, imageBitmap );
  24356. if ( onLoad ) onLoad( imageBitmap );
  24357. scope.manager.itemEnd( url );
  24358. } ).catch( function ( e ) {
  24359. if ( onError ) onError( e );
  24360. scope.manager.itemError( url );
  24361. scope.manager.itemEnd( url );
  24362. } );
  24363. scope.manager.itemStart( url );
  24364. }
  24365. } );
  24366. /**
  24367. * @author zz85 / http://www.lab4games.net/zz85/blog
  24368. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  24369. **/
  24370. function ShapePath() {
  24371. this.type = 'ShapePath';
  24372. this.color = new Color();
  24373. this.subPaths = [];
  24374. this.currentPath = null;
  24375. }
  24376. Object.assign( ShapePath.prototype, {
  24377. moveTo: function ( x, y ) {
  24378. this.currentPath = new Path();
  24379. this.subPaths.push( this.currentPath );
  24380. this.currentPath.moveTo( x, y );
  24381. return this;
  24382. },
  24383. lineTo: function ( x, y ) {
  24384. this.currentPath.lineTo( x, y );
  24385. return this;
  24386. },
  24387. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  24388. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  24389. return this;
  24390. },
  24391. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  24392. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  24393. return this;
  24394. },
  24395. splineThru: function ( pts ) {
  24396. this.currentPath.splineThru( pts );
  24397. return this;
  24398. },
  24399. toShapes: function ( isCCW, noHoles ) {
  24400. function toShapesNoHoles( inSubpaths ) {
  24401. var shapes = [];
  24402. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  24403. var tmpPath = inSubpaths[ i ];
  24404. var tmpShape = new Shape();
  24405. tmpShape.curves = tmpPath.curves;
  24406. shapes.push( tmpShape );
  24407. }
  24408. return shapes;
  24409. }
  24410. function isPointInsidePolygon( inPt, inPolygon ) {
  24411. var polyLen = inPolygon.length;
  24412. // inPt on polygon contour => immediate success or
  24413. // toggling of inside/outside at every single! intersection point of an edge
  24414. // with the horizontal line through inPt, left of inPt
  24415. // not counting lowerY endpoints of edges and whole edges on that line
  24416. var inside = false;
  24417. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  24418. var edgeLowPt = inPolygon[ p ];
  24419. var edgeHighPt = inPolygon[ q ];
  24420. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24421. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24422. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  24423. // not parallel
  24424. if ( edgeDy < 0 ) {
  24425. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  24426. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  24427. }
  24428. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  24429. if ( inPt.y === edgeLowPt.y ) {
  24430. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  24431. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24432. } else {
  24433. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  24434. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  24435. if ( perpEdge < 0 ) continue;
  24436. inside = ! inside; // true intersection left of inPt
  24437. }
  24438. } else {
  24439. // parallel or collinear
  24440. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  24441. // edge lies on the same horizontal line as inPt
  24442. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  24443. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  24444. // continue;
  24445. }
  24446. }
  24447. return inside;
  24448. }
  24449. var isClockWise = ShapeUtils.isClockWise;
  24450. var subPaths = this.subPaths;
  24451. if ( subPaths.length === 0 ) return [];
  24452. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  24453. var solid, tmpPath, tmpShape, shapes = [];
  24454. if ( subPaths.length === 1 ) {
  24455. tmpPath = subPaths[ 0 ];
  24456. tmpShape = new Shape();
  24457. tmpShape.curves = tmpPath.curves;
  24458. shapes.push( tmpShape );
  24459. return shapes;
  24460. }
  24461. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  24462. holesFirst = isCCW ? ! holesFirst : holesFirst;
  24463. // console.log("Holes first", holesFirst);
  24464. var betterShapeHoles = [];
  24465. var newShapes = [];
  24466. var newShapeHoles = [];
  24467. var mainIdx = 0;
  24468. var tmpPoints;
  24469. newShapes[ mainIdx ] = undefined;
  24470. newShapeHoles[ mainIdx ] = [];
  24471. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  24472. tmpPath = subPaths[ i ];
  24473. tmpPoints = tmpPath.getPoints();
  24474. solid = isClockWise( tmpPoints );
  24475. solid = isCCW ? ! solid : solid;
  24476. if ( solid ) {
  24477. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  24478. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  24479. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  24480. if ( holesFirst ) mainIdx ++;
  24481. newShapeHoles[ mainIdx ] = [];
  24482. //console.log('cw', i);
  24483. } else {
  24484. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  24485. //console.log('ccw', i);
  24486. }
  24487. }
  24488. // only Holes? -> probably all Shapes with wrong orientation
  24489. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  24490. if ( newShapes.length > 1 ) {
  24491. var ambiguous = false;
  24492. var toChange = [];
  24493. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  24494. betterShapeHoles[ sIdx ] = [];
  24495. }
  24496. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  24497. var sho = newShapeHoles[ sIdx ];
  24498. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  24499. var ho = sho[ hIdx ];
  24500. var hole_unassigned = true;
  24501. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  24502. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  24503. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  24504. if ( hole_unassigned ) {
  24505. hole_unassigned = false;
  24506. betterShapeHoles[ s2Idx ].push( ho );
  24507. } else {
  24508. ambiguous = true;
  24509. }
  24510. }
  24511. }
  24512. if ( hole_unassigned ) {
  24513. betterShapeHoles[ sIdx ].push( ho );
  24514. }
  24515. }
  24516. }
  24517. // console.log("ambiguous: ", ambiguous);
  24518. if ( toChange.length > 0 ) {
  24519. // console.log("to change: ", toChange);
  24520. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  24521. }
  24522. }
  24523. var tmpHoles;
  24524. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  24525. tmpShape = newShapes[ i ].s;
  24526. shapes.push( tmpShape );
  24527. tmpHoles = newShapeHoles[ i ];
  24528. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  24529. tmpShape.holes.push( tmpHoles[ j ].h );
  24530. }
  24531. }
  24532. //console.log("shape", shapes);
  24533. return shapes;
  24534. }
  24535. } );
  24536. /**
  24537. * @author zz85 / http://www.lab4games.net/zz85/blog
  24538. * @author mrdoob / http://mrdoob.com/
  24539. */
  24540. function Font( data ) {
  24541. this.type = 'Font';
  24542. this.data = data;
  24543. }
  24544. Object.assign( Font.prototype, {
  24545. isFont: true,
  24546. generateShapes: function ( text, size ) {
  24547. if ( size === undefined ) size = 100;
  24548. var shapes = [];
  24549. var paths = createPaths( text, size, this.data );
  24550. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  24551. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  24552. }
  24553. return shapes;
  24554. }
  24555. } );
  24556. function createPaths( text, size, data ) {
  24557. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  24558. var scale = size / data.resolution;
  24559. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  24560. var paths = [];
  24561. var offsetX = 0, offsetY = 0;
  24562. for ( var i = 0; i < chars.length; i ++ ) {
  24563. var char = chars[ i ];
  24564. if ( char === '\n' ) {
  24565. offsetX = 0;
  24566. offsetY -= line_height;
  24567. } else {
  24568. var ret = createPath( char, scale, offsetX, offsetY, data );
  24569. offsetX += ret.offsetX;
  24570. paths.push( ret.path );
  24571. }
  24572. }
  24573. return paths;
  24574. }
  24575. function createPath( char, scale, offsetX, offsetY, data ) {
  24576. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  24577. if ( ! glyph ) {
  24578. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  24579. return;
  24580. }
  24581. var path = new ShapePath();
  24582. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24583. if ( glyph.o ) {
  24584. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  24585. for ( var i = 0, l = outline.length; i < l; ) {
  24586. var action = outline[ i ++ ];
  24587. switch ( action ) {
  24588. case 'm': // moveTo
  24589. x = outline[ i ++ ] * scale + offsetX;
  24590. y = outline[ i ++ ] * scale + offsetY;
  24591. path.moveTo( x, y );
  24592. break;
  24593. case 'l': // lineTo
  24594. x = outline[ i ++ ] * scale + offsetX;
  24595. y = outline[ i ++ ] * scale + offsetY;
  24596. path.lineTo( x, y );
  24597. break;
  24598. case 'q': // quadraticCurveTo
  24599. cpx = outline[ i ++ ] * scale + offsetX;
  24600. cpy = outline[ i ++ ] * scale + offsetY;
  24601. cpx1 = outline[ i ++ ] * scale + offsetX;
  24602. cpy1 = outline[ i ++ ] * scale + offsetY;
  24603. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  24604. break;
  24605. case 'b': // bezierCurveTo
  24606. cpx = outline[ i ++ ] * scale + offsetX;
  24607. cpy = outline[ i ++ ] * scale + offsetY;
  24608. cpx1 = outline[ i ++ ] * scale + offsetX;
  24609. cpy1 = outline[ i ++ ] * scale + offsetY;
  24610. cpx2 = outline[ i ++ ] * scale + offsetX;
  24611. cpy2 = outline[ i ++ ] * scale + offsetY;
  24612. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  24613. break;
  24614. }
  24615. }
  24616. }
  24617. return { offsetX: glyph.ha * scale, path: path };
  24618. }
  24619. /**
  24620. * @author mrdoob / http://mrdoob.com/
  24621. */
  24622. function FontLoader( manager ) {
  24623. Loader.call( this, manager );
  24624. }
  24625. FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24626. constructor: FontLoader,
  24627. load: function ( url, onLoad, onProgress, onError ) {
  24628. var scope = this;
  24629. var loader = new FileLoader( this.manager );
  24630. loader.setPath( this.path );
  24631. loader.load( url, function ( text ) {
  24632. var json;
  24633. try {
  24634. json = JSON.parse( text );
  24635. } catch ( e ) {
  24636. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  24637. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  24638. }
  24639. var font = scope.parse( json );
  24640. if ( onLoad ) onLoad( font );
  24641. }, onProgress, onError );
  24642. },
  24643. parse: function ( json ) {
  24644. return new Font( json );
  24645. }
  24646. } );
  24647. /**
  24648. * @author mrdoob / http://mrdoob.com/
  24649. */
  24650. var _context;
  24651. var AudioContext = {
  24652. getContext: function () {
  24653. if ( _context === undefined ) {
  24654. _context = new ( window.AudioContext || window.webkitAudioContext )();
  24655. }
  24656. return _context;
  24657. },
  24658. setContext: function ( value ) {
  24659. _context = value;
  24660. }
  24661. };
  24662. /**
  24663. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24664. */
  24665. function AudioLoader( manager ) {
  24666. Loader.call( this, manager );
  24667. }
  24668. AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24669. constructor: AudioLoader,
  24670. load: function ( url, onLoad, onProgress, onError ) {
  24671. var loader = new FileLoader( this.manager );
  24672. loader.setResponseType( 'arraybuffer' );
  24673. loader.setPath( this.path );
  24674. loader.load( url, function ( buffer ) {
  24675. // Create a copy of the buffer. The `decodeAudioData` method
  24676. // detaches the buffer when complete, preventing reuse.
  24677. var bufferCopy = buffer.slice( 0 );
  24678. var context = AudioContext.getContext();
  24679. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  24680. onLoad( audioBuffer );
  24681. } );
  24682. }, onProgress, onError );
  24683. }
  24684. } );
  24685. /**
  24686. * @author bhouston / http://clara.io
  24687. * @author WestLangley / http://github.com/WestLangley
  24688. *
  24689. * Primary reference:
  24690. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24691. *
  24692. * Secondary reference:
  24693. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24694. */
  24695. // 3-band SH defined by 9 coefficients
  24696. function SphericalHarmonics3() {
  24697. this.coefficients = [];
  24698. for ( var i = 0; i < 9; i ++ ) {
  24699. this.coefficients.push( new Vector3() );
  24700. }
  24701. }
  24702. Object.assign( SphericalHarmonics3.prototype, {
  24703. isSphericalHarmonics3: true,
  24704. set: function ( coefficients ) {
  24705. for ( var i = 0; i < 9; i ++ ) {
  24706. this.coefficients[ i ].copy( coefficients[ i ] );
  24707. }
  24708. return this;
  24709. },
  24710. zero: function () {
  24711. for ( var i = 0; i < 9; i ++ ) {
  24712. this.coefficients[ i ].set( 0, 0, 0 );
  24713. }
  24714. return this;
  24715. },
  24716. // get the radiance in the direction of the normal
  24717. // target is a Vector3
  24718. getAt: function ( normal, target ) {
  24719. // normal is assumed to be unit length
  24720. var x = normal.x, y = normal.y, z = normal.z;
  24721. var coeff = this.coefficients;
  24722. // band 0
  24723. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  24724. // band 1
  24725. target.addScale( coeff[ 1 ], 0.488603 * y );
  24726. target.addScale( coeff[ 2 ], 0.488603 * z );
  24727. target.addScale( coeff[ 3 ], 0.488603 * x );
  24728. // band 2
  24729. target.addScale( coeff[ 4 ], 1.092548 * ( x * y ) );
  24730. target.addScale( coeff[ 5 ], 1.092548 * ( y * z ) );
  24731. target.addScale( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  24732. target.addScale( coeff[ 7 ], 1.092548 * ( x * z ) );
  24733. target.addScale( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  24734. return target;
  24735. },
  24736. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24737. // target is a Vector3
  24738. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24739. getIrradianceAt: function ( normal, target ) {
  24740. // normal is assumed to be unit length
  24741. var x = normal.x, y = normal.y, z = normal.z;
  24742. var coeff = this.coefficients;
  24743. // band 0
  24744. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  24745. // band 1
  24746. target.addScale( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  24747. target.addScale( coeff[ 2 ], 2.0 * 0.511664 * z );
  24748. target.addScale( coeff[ 3 ], 2.0 * 0.511664 * x );
  24749. // band 2
  24750. target.addScale( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  24751. target.addScale( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  24752. target.addScale( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24753. target.addScale( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  24754. target.addScale( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  24755. return target;
  24756. },
  24757. add: function ( sh ) {
  24758. for ( var i = 0; i < 9; i ++ ) {
  24759. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24760. }
  24761. return this;
  24762. },
  24763. scale: function ( s ) {
  24764. for ( var i = 0; i < 9; i ++ ) {
  24765. this.coefficients[ i ].multiplyScalar( s );
  24766. }
  24767. return this;
  24768. },
  24769. lerp: function ( sh, alpha ) {
  24770. for ( var i = 0; i < 9; i ++ ) {
  24771. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24772. }
  24773. return this;
  24774. },
  24775. equals: function ( sh ) {
  24776. for ( var i = 0; i < 9; i ++ ) {
  24777. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24778. return false;
  24779. }
  24780. }
  24781. return true;
  24782. },
  24783. copy: function ( sh ) {
  24784. return this.set( sh.coefficients );
  24785. },
  24786. clone: function () {
  24787. return new this.constructor().copy( this );
  24788. },
  24789. fromArray: function ( array, offset ) {
  24790. if ( offset === undefined ) offset = 0;
  24791. var coefficients = this.coefficients;
  24792. for ( var i = 0; i < 9; i ++ ) {
  24793. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  24794. }
  24795. return this;
  24796. },
  24797. toArray: function ( array, offset ) {
  24798. if ( array === undefined ) array = [];
  24799. if ( offset === undefined ) offset = 0;
  24800. var coefficients = this.coefficients;
  24801. for ( var i = 0; i < 9; i ++ ) {
  24802. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  24803. }
  24804. return array;
  24805. }
  24806. } );
  24807. Object.assign( SphericalHarmonics3, {
  24808. // evaluate the basis functions
  24809. // shBasis is an Array[ 9 ]
  24810. getBasisAt: function ( normal, shBasis ) {
  24811. // normal is assumed to be unit length
  24812. var x = normal.x, y = normal.y, z = normal.z;
  24813. // band 0
  24814. shBasis[ 0 ] = 0.282095;
  24815. // band 1
  24816. shBasis[ 1 ] = 0.488603 * y;
  24817. shBasis[ 2 ] = 0.488603 * z;
  24818. shBasis[ 3 ] = 0.488603 * x;
  24819. // band 2
  24820. shBasis[ 4 ] = 1.092548 * x * y;
  24821. shBasis[ 5 ] = 1.092548 * y * z;
  24822. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24823. shBasis[ 7 ] = 1.092548 * x * z;
  24824. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24825. }
  24826. } );
  24827. /**
  24828. * @author WestLangley / http://github.com/WestLangley
  24829. *
  24830. * A LightProbe is a source of indirect-diffuse light
  24831. */
  24832. function LightProbe( sh, intensity ) {
  24833. Light.call( this, undefined, intensity );
  24834. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24835. }
  24836. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24837. constructor: LightProbe,
  24838. isLightProbe: true,
  24839. copy: function ( source ) {
  24840. Light.prototype.copy.call( this, source );
  24841. this.sh.copy( source.sh );
  24842. this.intensity = source.intensity;
  24843. return this;
  24844. },
  24845. toJSON: function ( meta ) {
  24846. var data = Light.prototype.toJSON.call( this, meta );
  24847. // data.sh = this.sh.toArray(); // todo
  24848. return data;
  24849. }
  24850. } );
  24851. /**
  24852. * @author WestLangley / http://github.com/WestLangley
  24853. */
  24854. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24855. LightProbe.call( this, undefined, intensity );
  24856. var color1 = new Color().set( skyColor );
  24857. var color2 = new Color().set( groundColor );
  24858. var sky = new Vector3( color1.r, color1.g, color1.b );
  24859. var ground = new Vector3( color2.r, color2.g, color2.b );
  24860. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24861. var c0 = Math.sqrt( Math.PI );
  24862. var c1 = c0 * Math.sqrt( 0.75 );
  24863. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24864. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24865. }
  24866. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24867. constructor: HemisphereLightProbe,
  24868. isHemisphereLightProbe: true,
  24869. copy: function ( source ) { // modifying colors not currently supported
  24870. LightProbe.prototype.copy.call( this, source );
  24871. return this;
  24872. },
  24873. toJSON: function ( meta ) {
  24874. var data = LightProbe.prototype.toJSON.call( this, meta );
  24875. // data.sh = this.sh.toArray(); // todo
  24876. return data;
  24877. }
  24878. } );
  24879. /**
  24880. * @author WestLangley / http://github.com/WestLangley
  24881. */
  24882. function AmbientLightProbe( color, intensity ) {
  24883. LightProbe.call( this, undefined, intensity );
  24884. var color1 = new Color().set( color );
  24885. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24886. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24887. }
  24888. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24889. constructor: AmbientLightProbe,
  24890. isAmbientLightProbe: true,
  24891. copy: function ( source ) { // modifying color not currently supported
  24892. LightProbe.prototype.copy.call( this, source );
  24893. return this;
  24894. },
  24895. toJSON: function ( meta ) {
  24896. var data = LightProbe.prototype.toJSON.call( this, meta );
  24897. // data.sh = this.sh.toArray(); // todo
  24898. return data;
  24899. }
  24900. } );
  24901. var _eyeRight = new Matrix4();
  24902. var _eyeLeft = new Matrix4();
  24903. /**
  24904. * @author mrdoob / http://mrdoob.com/
  24905. */
  24906. function StereoCamera() {
  24907. this.type = 'StereoCamera';
  24908. this.aspect = 1;
  24909. this.eyeSep = 0.064;
  24910. this.cameraL = new PerspectiveCamera();
  24911. this.cameraL.layers.enable( 1 );
  24912. this.cameraL.matrixAutoUpdate = false;
  24913. this.cameraR = new PerspectiveCamera();
  24914. this.cameraR.layers.enable( 2 );
  24915. this.cameraR.matrixAutoUpdate = false;
  24916. this._cache = {
  24917. focus: null,
  24918. fov: null,
  24919. aspect: null,
  24920. near: null,
  24921. far: null,
  24922. zoom: null,
  24923. eyeSep: null
  24924. };
  24925. }
  24926. Object.assign( StereoCamera.prototype, {
  24927. update: function ( camera ) {
  24928. var cache = this._cache;
  24929. var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  24930. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  24931. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  24932. if ( needsUpdate ) {
  24933. cache.focus = camera.focus;
  24934. cache.fov = camera.fov;
  24935. cache.aspect = camera.aspect * this.aspect;
  24936. cache.near = camera.near;
  24937. cache.far = camera.far;
  24938. cache.zoom = camera.zoom;
  24939. cache.eyeSep = this.eyeSep;
  24940. // Off-axis stereoscopic effect based on
  24941. // http://paulbourke.net/stereographics/stereorender/
  24942. var projectionMatrix = camera.projectionMatrix.clone();
  24943. var eyeSepHalf = cache.eyeSep / 2;
  24944. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  24945. var ymax = ( cache.near * Math.tan( _Math.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  24946. var xmin, xmax;
  24947. // translate xOffset
  24948. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  24949. _eyeRight.elements[ 12 ] = eyeSepHalf;
  24950. // for left eye
  24951. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  24952. xmax = ymax * cache.aspect + eyeSepOnProjection;
  24953. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24954. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24955. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24956. // for right eye
  24957. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  24958. xmax = ymax * cache.aspect - eyeSepOnProjection;
  24959. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24960. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24961. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24962. }
  24963. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  24964. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  24965. }
  24966. } );
  24967. /**
  24968. * @author alteredq / http://alteredqualia.com/
  24969. */
  24970. function Clock( autoStart ) {
  24971. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24972. this.startTime = 0;
  24973. this.oldTime = 0;
  24974. this.elapsedTime = 0;
  24975. this.running = false;
  24976. }
  24977. Object.assign( Clock.prototype, {
  24978. start: function () {
  24979. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24980. this.oldTime = this.startTime;
  24981. this.elapsedTime = 0;
  24982. this.running = true;
  24983. },
  24984. stop: function () {
  24985. this.getElapsedTime();
  24986. this.running = false;
  24987. this.autoStart = false;
  24988. },
  24989. getElapsedTime: function () {
  24990. this.getDelta();
  24991. return this.elapsedTime;
  24992. },
  24993. getDelta: function () {
  24994. var diff = 0;
  24995. if ( this.autoStart && ! this.running ) {
  24996. this.start();
  24997. return 0;
  24998. }
  24999. if ( this.running ) {
  25000. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25001. diff = ( newTime - this.oldTime ) / 1000;
  25002. this.oldTime = newTime;
  25003. this.elapsedTime += diff;
  25004. }
  25005. return diff;
  25006. }
  25007. } );
  25008. /**
  25009. * @author mrdoob / http://mrdoob.com/
  25010. */
  25011. var _position$2 = new Vector3();
  25012. var _quaternion$3 = new Quaternion();
  25013. var _scale$1 = new Vector3();
  25014. var _orientation = new Vector3();
  25015. function AudioListener() {
  25016. Object3D.call( this );
  25017. this.type = 'AudioListener';
  25018. this.context = AudioContext.getContext();
  25019. this.gain = this.context.createGain();
  25020. this.gain.connect( this.context.destination );
  25021. this.filter = null;
  25022. this.timeDelta = 0;
  25023. // private
  25024. this._clock = new Clock();
  25025. }
  25026. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25027. constructor: AudioListener,
  25028. getInput: function () {
  25029. return this.gain;
  25030. },
  25031. removeFilter: function ( ) {
  25032. if ( this.filter !== null ) {
  25033. this.gain.disconnect( this.filter );
  25034. this.filter.disconnect( this.context.destination );
  25035. this.gain.connect( this.context.destination );
  25036. this.filter = null;
  25037. }
  25038. return this;
  25039. },
  25040. getFilter: function () {
  25041. return this.filter;
  25042. },
  25043. setFilter: function ( value ) {
  25044. if ( this.filter !== null ) {
  25045. this.gain.disconnect( this.filter );
  25046. this.filter.disconnect( this.context.destination );
  25047. } else {
  25048. this.gain.disconnect( this.context.destination );
  25049. }
  25050. this.filter = value;
  25051. this.gain.connect( this.filter );
  25052. this.filter.connect( this.context.destination );
  25053. return this;
  25054. },
  25055. getMasterVolume: function () {
  25056. return this.gain.gain.value;
  25057. },
  25058. setMasterVolume: function ( value ) {
  25059. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25060. return this;
  25061. },
  25062. updateMatrixWorld: function ( force ) {
  25063. Object3D.prototype.updateMatrixWorld.call( this, force );
  25064. var listener = this.context.listener;
  25065. var up = this.up;
  25066. this.timeDelta = this._clock.getDelta();
  25067. this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 );
  25068. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  25069. if ( listener.positionX ) {
  25070. // code path for Chrome (see #14393)
  25071. var endTime = this.context.currentTime + this.timeDelta;
  25072. listener.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  25073. listener.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  25074. listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  25075. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  25076. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  25077. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  25078. listener.upX.linearRampToValueAtTime( up.x, endTime );
  25079. listener.upY.linearRampToValueAtTime( up.y, endTime );
  25080. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  25081. } else {
  25082. listener.setPosition( _position$2.x, _position$2.y, _position$2.z );
  25083. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  25084. }
  25085. }
  25086. } );
  25087. /**
  25088. * @author mrdoob / http://mrdoob.com/
  25089. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25090. */
  25091. function Audio( listener ) {
  25092. Object3D.call( this );
  25093. this.type = 'Audio';
  25094. this.listener = listener;
  25095. this.context = listener.context;
  25096. this.gain = this.context.createGain();
  25097. this.gain.connect( listener.getInput() );
  25098. this.autoplay = false;
  25099. this.buffer = null;
  25100. this.detune = 0;
  25101. this.loop = false;
  25102. this.loopStart = 0;
  25103. this.loopEnd = 0;
  25104. this.offset = 0;
  25105. this.duration = undefined;
  25106. this.playbackRate = 1;
  25107. this.isPlaying = false;
  25108. this.hasPlaybackControl = true;
  25109. this.sourceType = 'empty';
  25110. this._startedAt = 0;
  25111. this._pausedAt = 0;
  25112. this.filters = [];
  25113. }
  25114. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25115. constructor: Audio,
  25116. getOutput: function () {
  25117. return this.gain;
  25118. },
  25119. setNodeSource: function ( audioNode ) {
  25120. this.hasPlaybackControl = false;
  25121. this.sourceType = 'audioNode';
  25122. this.source = audioNode;
  25123. this.connect();
  25124. return this;
  25125. },
  25126. setMediaElementSource: function ( mediaElement ) {
  25127. this.hasPlaybackControl = false;
  25128. this.sourceType = 'mediaNode';
  25129. this.source = this.context.createMediaElementSource( mediaElement );
  25130. this.connect();
  25131. return this;
  25132. },
  25133. setMediaStreamSource: function ( mediaStream ) {
  25134. this.hasPlaybackControl = false;
  25135. this.sourceType = 'mediaStreamNode';
  25136. this.source = this.context.createMediaStreamSource( mediaStream );
  25137. this.connect();
  25138. return this;
  25139. },
  25140. setBuffer: function ( audioBuffer ) {
  25141. this.buffer = audioBuffer;
  25142. this.sourceType = 'buffer';
  25143. if ( this.autoplay ) this.play();
  25144. return this;
  25145. },
  25146. play: function ( delay ) {
  25147. if ( delay === undefined ) delay = 0;
  25148. if ( this.isPlaying === true ) {
  25149. console.warn( 'THREE.Audio: Audio is already playing.' );
  25150. return;
  25151. }
  25152. if ( this.hasPlaybackControl === false ) {
  25153. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25154. return;
  25155. }
  25156. this._startedAt = this.context.currentTime + delay;
  25157. var source = this.context.createBufferSource();
  25158. source.buffer = this.buffer;
  25159. source.loop = this.loop;
  25160. source.loopStart = this.loopStart;
  25161. source.loopEnd = this.loopEnd;
  25162. source.onended = this.onEnded.bind( this );
  25163. source.start( this._startedAt, this._pausedAt + this.offset, this.duration );
  25164. this.isPlaying = true;
  25165. this.source = source;
  25166. this.setDetune( this.detune );
  25167. this.setPlaybackRate( this.playbackRate );
  25168. return this.connect();
  25169. },
  25170. pause: function () {
  25171. if ( this.hasPlaybackControl === false ) {
  25172. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25173. return;
  25174. }
  25175. if ( this.isPlaying === true ) {
  25176. this._pausedAt = ( this.context.currentTime - this._startedAt ) * this.playbackRate;
  25177. this.source.stop();
  25178. this.source.onended = null;
  25179. this.isPlaying = false;
  25180. }
  25181. return this;
  25182. },
  25183. stop: function () {
  25184. if ( this.hasPlaybackControl === false ) {
  25185. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25186. return;
  25187. }
  25188. this._pausedAt = 0;
  25189. this.source.stop();
  25190. this.source.onended = null;
  25191. this.isPlaying = false;
  25192. return this;
  25193. },
  25194. connect: function () {
  25195. if ( this.filters.length > 0 ) {
  25196. this.source.connect( this.filters[ 0 ] );
  25197. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25198. this.filters[ i - 1 ].connect( this.filters[ i ] );
  25199. }
  25200. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  25201. } else {
  25202. this.source.connect( this.getOutput() );
  25203. }
  25204. return this;
  25205. },
  25206. disconnect: function () {
  25207. if ( this.filters.length > 0 ) {
  25208. this.source.disconnect( this.filters[ 0 ] );
  25209. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  25210. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  25211. }
  25212. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  25213. } else {
  25214. this.source.disconnect( this.getOutput() );
  25215. }
  25216. return this;
  25217. },
  25218. getFilters: function () {
  25219. return this.filters;
  25220. },
  25221. setFilters: function ( value ) {
  25222. if ( ! value ) value = [];
  25223. if ( this.isPlaying === true ) {
  25224. this.disconnect();
  25225. this.filters = value;
  25226. this.connect();
  25227. } else {
  25228. this.filters = value;
  25229. }
  25230. return this;
  25231. },
  25232. setDetune: function ( value ) {
  25233. this.detune = value;
  25234. if ( this.source.detune === undefined ) return; // only set detune when available
  25235. if ( this.isPlaying === true ) {
  25236. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  25237. }
  25238. return this;
  25239. },
  25240. getDetune: function () {
  25241. return this.detune;
  25242. },
  25243. getFilter: function () {
  25244. return this.getFilters()[ 0 ];
  25245. },
  25246. setFilter: function ( filter ) {
  25247. return this.setFilters( filter ? [ filter ] : [] );
  25248. },
  25249. setPlaybackRate: function ( value ) {
  25250. if ( this.hasPlaybackControl === false ) {
  25251. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25252. return;
  25253. }
  25254. this.playbackRate = value;
  25255. if ( this.isPlaying === true ) {
  25256. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  25257. }
  25258. return this;
  25259. },
  25260. getPlaybackRate: function () {
  25261. return this.playbackRate;
  25262. },
  25263. onEnded: function () {
  25264. this.isPlaying = false;
  25265. },
  25266. getLoop: function () {
  25267. if ( this.hasPlaybackControl === false ) {
  25268. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25269. return false;
  25270. }
  25271. return this.loop;
  25272. },
  25273. setLoop: function ( value ) {
  25274. if ( this.hasPlaybackControl === false ) {
  25275. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25276. return;
  25277. }
  25278. this.loop = value;
  25279. if ( this.isPlaying === true ) {
  25280. this.source.loop = this.loop;
  25281. }
  25282. return this;
  25283. },
  25284. setLoopStart: function ( value ) {
  25285. this.loopStart = value;
  25286. return this;
  25287. },
  25288. setLoopEnd: function ( value ) {
  25289. this.loopEnd = value;
  25290. return this;
  25291. },
  25292. getVolume: function () {
  25293. return this.gain.gain.value;
  25294. },
  25295. setVolume: function ( value ) {
  25296. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25297. return this;
  25298. }
  25299. } );
  25300. /**
  25301. * @author mrdoob / http://mrdoob.com/
  25302. */
  25303. var _position$3 = new Vector3();
  25304. var _quaternion$4 = new Quaternion();
  25305. var _scale$2 = new Vector3();
  25306. var _orientation$1 = new Vector3();
  25307. function PositionalAudio( listener ) {
  25308. Audio.call( this, listener );
  25309. this.panner = this.context.createPanner();
  25310. this.panner.panningModel = 'HRTF';
  25311. this.panner.connect( this.gain );
  25312. }
  25313. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  25314. constructor: PositionalAudio,
  25315. getOutput: function () {
  25316. return this.panner;
  25317. },
  25318. getRefDistance: function () {
  25319. return this.panner.refDistance;
  25320. },
  25321. setRefDistance: function ( value ) {
  25322. this.panner.refDistance = value;
  25323. return this;
  25324. },
  25325. getRolloffFactor: function () {
  25326. return this.panner.rolloffFactor;
  25327. },
  25328. setRolloffFactor: function ( value ) {
  25329. this.panner.rolloffFactor = value;
  25330. return this;
  25331. },
  25332. getDistanceModel: function () {
  25333. return this.panner.distanceModel;
  25334. },
  25335. setDistanceModel: function ( value ) {
  25336. this.panner.distanceModel = value;
  25337. return this;
  25338. },
  25339. getMaxDistance: function () {
  25340. return this.panner.maxDistance;
  25341. },
  25342. setMaxDistance: function ( value ) {
  25343. this.panner.maxDistance = value;
  25344. return this;
  25345. },
  25346. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  25347. this.panner.coneInnerAngle = coneInnerAngle;
  25348. this.panner.coneOuterAngle = coneOuterAngle;
  25349. this.panner.coneOuterGain = coneOuterGain;
  25350. return this;
  25351. },
  25352. updateMatrixWorld: function ( force ) {
  25353. Object3D.prototype.updateMatrixWorld.call( this, force );
  25354. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  25355. this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 );
  25356. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  25357. var panner = this.panner;
  25358. if ( panner.positionX ) {
  25359. // code path for Chrome and Firefox (see #14393)
  25360. var endTime = this.context.currentTime + this.listener.timeDelta;
  25361. panner.positionX.linearRampToValueAtTime( _position$3.x, endTime );
  25362. panner.positionY.linearRampToValueAtTime( _position$3.y, endTime );
  25363. panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime );
  25364. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  25365. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  25366. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  25367. } else {
  25368. panner.setPosition( _position$3.x, _position$3.y, _position$3.z );
  25369. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  25370. }
  25371. }
  25372. } );
  25373. /**
  25374. * @author mrdoob / http://mrdoob.com/
  25375. */
  25376. function AudioAnalyser( audio, fftSize ) {
  25377. this.analyser = audio.context.createAnalyser();
  25378. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25379. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  25380. audio.getOutput().connect( this.analyser );
  25381. }
  25382. Object.assign( AudioAnalyser.prototype, {
  25383. getFrequencyData: function () {
  25384. this.analyser.getByteFrequencyData( this.data );
  25385. return this.data;
  25386. },
  25387. getAverageFrequency: function () {
  25388. var value = 0, data = this.getFrequencyData();
  25389. for ( var i = 0; i < data.length; i ++ ) {
  25390. value += data[ i ];
  25391. }
  25392. return value / data.length;
  25393. }
  25394. } );
  25395. /**
  25396. *
  25397. * Buffered scene graph property that allows weighted accumulation.
  25398. *
  25399. *
  25400. * @author Ben Houston / http://clara.io/
  25401. * @author David Sarno / http://lighthaus.us/
  25402. * @author tschw
  25403. */
  25404. function PropertyMixer( binding, typeName, valueSize ) {
  25405. this.binding = binding;
  25406. this.valueSize = valueSize;
  25407. var bufferType = Float64Array,
  25408. mixFunction;
  25409. switch ( typeName ) {
  25410. case 'quaternion':
  25411. mixFunction = this._slerp;
  25412. break;
  25413. case 'string':
  25414. case 'bool':
  25415. bufferType = Array;
  25416. mixFunction = this._select;
  25417. break;
  25418. default:
  25419. mixFunction = this._lerp;
  25420. }
  25421. this.buffer = new bufferType( valueSize * 4 );
  25422. // layout: [ incoming | accu0 | accu1 | orig ]
  25423. //
  25424. // interpolators can use .buffer as their .result
  25425. // the data then goes to 'incoming'
  25426. //
  25427. // 'accu0' and 'accu1' are used frame-interleaved for
  25428. // the cumulative result and are compared to detect
  25429. // changes
  25430. //
  25431. // 'orig' stores the original state of the property
  25432. this._mixBufferRegion = mixFunction;
  25433. this.cumulativeWeight = 0;
  25434. this.useCount = 0;
  25435. this.referenceCount = 0;
  25436. }
  25437. Object.assign( PropertyMixer.prototype, {
  25438. // accumulate data in the 'incoming' region into 'accu<i>'
  25439. accumulate: function ( accuIndex, weight ) {
  25440. // note: happily accumulating nothing when weight = 0, the caller knows
  25441. // the weight and shouldn't have made the call in the first place
  25442. var buffer = this.buffer,
  25443. stride = this.valueSize,
  25444. offset = accuIndex * stride + stride,
  25445. currentWeight = this.cumulativeWeight;
  25446. if ( currentWeight === 0 ) {
  25447. // accuN := incoming * weight
  25448. for ( var i = 0; i !== stride; ++ i ) {
  25449. buffer[ offset + i ] = buffer[ i ];
  25450. }
  25451. currentWeight = weight;
  25452. } else {
  25453. // accuN := accuN + incoming * weight
  25454. currentWeight += weight;
  25455. var mix = weight / currentWeight;
  25456. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25457. }
  25458. this.cumulativeWeight = currentWeight;
  25459. },
  25460. // apply the state of 'accu<i>' to the binding when accus differ
  25461. apply: function ( accuIndex ) {
  25462. var stride = this.valueSize,
  25463. buffer = this.buffer,
  25464. offset = accuIndex * stride + stride,
  25465. weight = this.cumulativeWeight,
  25466. binding = this.binding;
  25467. this.cumulativeWeight = 0;
  25468. if ( weight < 1 ) {
  25469. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25470. var originalValueOffset = stride * 3;
  25471. this._mixBufferRegion(
  25472. buffer, offset, originalValueOffset, 1 - weight, stride );
  25473. }
  25474. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  25475. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25476. // value has changed -> update scene graph
  25477. binding.setValue( buffer, offset );
  25478. break;
  25479. }
  25480. }
  25481. },
  25482. // remember the state of the bound property and copy it to both accus
  25483. saveOriginalState: function () {
  25484. var binding = this.binding;
  25485. var buffer = this.buffer,
  25486. stride = this.valueSize,
  25487. originalValueOffset = stride * 3;
  25488. binding.getValue( buffer, originalValueOffset );
  25489. // accu[0..1] := orig -- initially detect changes against the original
  25490. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25491. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25492. }
  25493. this.cumulativeWeight = 0;
  25494. },
  25495. // apply the state previously taken via 'saveOriginalState' to the binding
  25496. restoreOriginalState: function () {
  25497. var originalValueOffset = this.valueSize * 3;
  25498. this.binding.setValue( this.buffer, originalValueOffset );
  25499. },
  25500. // mix functions
  25501. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25502. if ( t >= 0.5 ) {
  25503. for ( var i = 0; i !== stride; ++ i ) {
  25504. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  25505. }
  25506. }
  25507. },
  25508. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  25509. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  25510. },
  25511. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25512. var s = 1 - t;
  25513. for ( var i = 0; i !== stride; ++ i ) {
  25514. var j = dstOffset + i;
  25515. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  25516. }
  25517. }
  25518. } );
  25519. /**
  25520. *
  25521. * A reference to a real property in the scene graph.
  25522. *
  25523. *
  25524. * @author Ben Houston / http://clara.io/
  25525. * @author David Sarno / http://lighthaus.us/
  25526. * @author tschw
  25527. */
  25528. // Characters [].:/ are reserved for track binding syntax.
  25529. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25530. var _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  25531. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25532. // only latin characters, and the unicode \p{L} is not yet supported. So
  25533. // instead, we exclude reserved characters and match everything else.
  25534. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25535. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  25536. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25537. // be matched to parse the rest of the track name.
  25538. var _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  25539. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25540. var _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  25541. // Object on target node, and accessor. May not contain reserved
  25542. // characters. Accessor may contain any character except closing bracket.
  25543. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  25544. // Property and accessor. May not contain reserved characters. Accessor may
  25545. // contain any non-bracket characters.
  25546. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  25547. var _trackRe = new RegExp( ''
  25548. + '^'
  25549. + _directoryRe
  25550. + _nodeRe
  25551. + _objectRe
  25552. + _propertyRe
  25553. + '$'
  25554. );
  25555. var _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  25556. function Composite( targetGroup, path, optionalParsedPath ) {
  25557. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  25558. this._targetGroup = targetGroup;
  25559. this._bindings = targetGroup.subscribe_( path, parsedPath );
  25560. }
  25561. Object.assign( Composite.prototype, {
  25562. getValue: function ( array, offset ) {
  25563. this.bind(); // bind all binding
  25564. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25565. binding = this._bindings[ firstValidIndex ];
  25566. // and only call .getValue on the first
  25567. if ( binding !== undefined ) binding.getValue( array, offset );
  25568. },
  25569. setValue: function ( array, offset ) {
  25570. var bindings = this._bindings;
  25571. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25572. bindings[ i ].setValue( array, offset );
  25573. }
  25574. },
  25575. bind: function () {
  25576. var bindings = this._bindings;
  25577. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25578. bindings[ i ].bind();
  25579. }
  25580. },
  25581. unbind: function () {
  25582. var bindings = this._bindings;
  25583. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25584. bindings[ i ].unbind();
  25585. }
  25586. }
  25587. } );
  25588. function PropertyBinding( rootNode, path, parsedPath ) {
  25589. this.path = path;
  25590. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  25591. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  25592. this.rootNode = rootNode;
  25593. }
  25594. Object.assign( PropertyBinding, {
  25595. Composite: Composite,
  25596. create: function ( root, path, parsedPath ) {
  25597. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  25598. return new PropertyBinding( root, path, parsedPath );
  25599. } else {
  25600. return new PropertyBinding.Composite( root, path, parsedPath );
  25601. }
  25602. },
  25603. /**
  25604. * Replaces spaces with underscores and removes unsupported characters from
  25605. * node names, to ensure compatibility with parseTrackName().
  25606. *
  25607. * @param {string} name Node name to be sanitized.
  25608. * @return {string}
  25609. */
  25610. sanitizeNodeName: function ( name ) {
  25611. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  25612. },
  25613. parseTrackName: function ( trackName ) {
  25614. var matches = _trackRe.exec( trackName );
  25615. if ( ! matches ) {
  25616. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  25617. }
  25618. var results = {
  25619. // directoryName: matches[ 1 ], // (tschw) currently unused
  25620. nodeName: matches[ 2 ],
  25621. objectName: matches[ 3 ],
  25622. objectIndex: matches[ 4 ],
  25623. propertyName: matches[ 5 ], // required
  25624. propertyIndex: matches[ 6 ]
  25625. };
  25626. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  25627. if ( lastDot !== undefined && lastDot !== - 1 ) {
  25628. var objectName = results.nodeName.substring( lastDot + 1 );
  25629. // Object names must be checked against a whitelist. Otherwise, there
  25630. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25631. // 'bar' could be the objectName, or part of a nodeName (which can
  25632. // include '.' characters).
  25633. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  25634. results.nodeName = results.nodeName.substring( 0, lastDot );
  25635. results.objectName = objectName;
  25636. }
  25637. }
  25638. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  25639. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  25640. }
  25641. return results;
  25642. },
  25643. findNode: function ( root, nodeName ) {
  25644. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  25645. return root;
  25646. }
  25647. // search into skeleton bones.
  25648. if ( root.skeleton ) {
  25649. var bone = root.skeleton.getBoneByName( nodeName );
  25650. if ( bone !== undefined ) {
  25651. return bone;
  25652. }
  25653. }
  25654. // search into node subtree.
  25655. if ( root.children ) {
  25656. var searchNodeSubtree = function ( children ) {
  25657. for ( var i = 0; i < children.length; i ++ ) {
  25658. var childNode = children[ i ];
  25659. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  25660. return childNode;
  25661. }
  25662. var result = searchNodeSubtree( childNode.children );
  25663. if ( result ) return result;
  25664. }
  25665. return null;
  25666. };
  25667. var subTreeNode = searchNodeSubtree( root.children );
  25668. if ( subTreeNode ) {
  25669. return subTreeNode;
  25670. }
  25671. }
  25672. return null;
  25673. }
  25674. } );
  25675. Object.assign( PropertyBinding.prototype, { // prototype, continued
  25676. // these are used to "bind" a nonexistent property
  25677. _getValue_unavailable: function () {},
  25678. _setValue_unavailable: function () {},
  25679. BindingType: {
  25680. Direct: 0,
  25681. EntireArray: 1,
  25682. ArrayElement: 2,
  25683. HasFromToArray: 3
  25684. },
  25685. Versioning: {
  25686. None: 0,
  25687. NeedsUpdate: 1,
  25688. MatrixWorldNeedsUpdate: 2
  25689. },
  25690. GetterByBindingType: [
  25691. function getValue_direct( buffer, offset ) {
  25692. buffer[ offset ] = this.node[ this.propertyName ];
  25693. },
  25694. function getValue_array( buffer, offset ) {
  25695. var source = this.resolvedProperty;
  25696. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25697. buffer[ offset ++ ] = source[ i ];
  25698. }
  25699. },
  25700. function getValue_arrayElement( buffer, offset ) {
  25701. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25702. },
  25703. function getValue_toArray( buffer, offset ) {
  25704. this.resolvedProperty.toArray( buffer, offset );
  25705. }
  25706. ],
  25707. SetterByBindingTypeAndVersioning: [
  25708. [
  25709. // Direct
  25710. function setValue_direct( buffer, offset ) {
  25711. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25712. },
  25713. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25714. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25715. this.targetObject.needsUpdate = true;
  25716. },
  25717. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25718. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25719. this.targetObject.matrixWorldNeedsUpdate = true;
  25720. }
  25721. ], [
  25722. // EntireArray
  25723. function setValue_array( buffer, offset ) {
  25724. var dest = this.resolvedProperty;
  25725. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25726. dest[ i ] = buffer[ offset ++ ];
  25727. }
  25728. },
  25729. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25730. var dest = this.resolvedProperty;
  25731. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25732. dest[ i ] = buffer[ offset ++ ];
  25733. }
  25734. this.targetObject.needsUpdate = true;
  25735. },
  25736. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25737. var dest = this.resolvedProperty;
  25738. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25739. dest[ i ] = buffer[ offset ++ ];
  25740. }
  25741. this.targetObject.matrixWorldNeedsUpdate = true;
  25742. }
  25743. ], [
  25744. // ArrayElement
  25745. function setValue_arrayElement( buffer, offset ) {
  25746. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25747. },
  25748. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25749. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25750. this.targetObject.needsUpdate = true;
  25751. },
  25752. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25753. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25754. this.targetObject.matrixWorldNeedsUpdate = true;
  25755. }
  25756. ], [
  25757. // HasToFromArray
  25758. function setValue_fromArray( buffer, offset ) {
  25759. this.resolvedProperty.fromArray( buffer, offset );
  25760. },
  25761. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25762. this.resolvedProperty.fromArray( buffer, offset );
  25763. this.targetObject.needsUpdate = true;
  25764. },
  25765. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25766. this.resolvedProperty.fromArray( buffer, offset );
  25767. this.targetObject.matrixWorldNeedsUpdate = true;
  25768. }
  25769. ]
  25770. ],
  25771. getValue: function getValue_unbound( targetArray, offset ) {
  25772. this.bind();
  25773. this.getValue( targetArray, offset );
  25774. // Note: This class uses a State pattern on a per-method basis:
  25775. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25776. // prototype version of these methods with one that represents
  25777. // the bound state. When the property is not found, the methods
  25778. // become no-ops.
  25779. },
  25780. setValue: function getValue_unbound( sourceArray, offset ) {
  25781. this.bind();
  25782. this.setValue( sourceArray, offset );
  25783. },
  25784. // create getter / setter pair for a property in the scene graph
  25785. bind: function () {
  25786. var targetObject = this.node,
  25787. parsedPath = this.parsedPath,
  25788. objectName = parsedPath.objectName,
  25789. propertyName = parsedPath.propertyName,
  25790. propertyIndex = parsedPath.propertyIndex;
  25791. if ( ! targetObject ) {
  25792. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25793. this.node = targetObject;
  25794. }
  25795. // set fail state so we can just 'return' on error
  25796. this.getValue = this._getValue_unavailable;
  25797. this.setValue = this._setValue_unavailable;
  25798. // ensure there is a value node
  25799. if ( ! targetObject ) {
  25800. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25801. return;
  25802. }
  25803. if ( objectName ) {
  25804. var objectIndex = parsedPath.objectIndex;
  25805. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25806. switch ( objectName ) {
  25807. case 'materials':
  25808. if ( ! targetObject.material ) {
  25809. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25810. return;
  25811. }
  25812. if ( ! targetObject.material.materials ) {
  25813. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25814. return;
  25815. }
  25816. targetObject = targetObject.material.materials;
  25817. break;
  25818. case 'bones':
  25819. if ( ! targetObject.skeleton ) {
  25820. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25821. return;
  25822. }
  25823. // potential future optimization: skip this if propertyIndex is already an integer
  25824. // and convert the integer string to a true integer.
  25825. targetObject = targetObject.skeleton.bones;
  25826. // support resolving morphTarget names into indices.
  25827. for ( var i = 0; i < targetObject.length; i ++ ) {
  25828. if ( targetObject[ i ].name === objectIndex ) {
  25829. objectIndex = i;
  25830. break;
  25831. }
  25832. }
  25833. break;
  25834. default:
  25835. if ( targetObject[ objectName ] === undefined ) {
  25836. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25837. return;
  25838. }
  25839. targetObject = targetObject[ objectName ];
  25840. }
  25841. if ( objectIndex !== undefined ) {
  25842. if ( targetObject[ objectIndex ] === undefined ) {
  25843. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25844. return;
  25845. }
  25846. targetObject = targetObject[ objectIndex ];
  25847. }
  25848. }
  25849. // resolve property
  25850. var nodeProperty = targetObject[ propertyName ];
  25851. if ( nodeProperty === undefined ) {
  25852. var nodeName = parsedPath.nodeName;
  25853. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25854. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25855. return;
  25856. }
  25857. // determine versioning scheme
  25858. var versioning = this.Versioning.None;
  25859. this.targetObject = targetObject;
  25860. if ( targetObject.needsUpdate !== undefined ) { // material
  25861. versioning = this.Versioning.NeedsUpdate;
  25862. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25863. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25864. }
  25865. // determine how the property gets bound
  25866. var bindingType = this.BindingType.Direct;
  25867. if ( propertyIndex !== undefined ) {
  25868. // access a sub element of the property array (only primitives are supported right now)
  25869. if ( propertyName === "morphTargetInfluences" ) {
  25870. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25871. // support resolving morphTarget names into indices.
  25872. if ( ! targetObject.geometry ) {
  25873. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25874. return;
  25875. }
  25876. if ( targetObject.geometry.isBufferGeometry ) {
  25877. if ( ! targetObject.geometry.morphAttributes ) {
  25878. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25879. return;
  25880. }
  25881. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25882. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25883. propertyIndex = i;
  25884. break;
  25885. }
  25886. }
  25887. } else {
  25888. if ( ! targetObject.geometry.morphTargets ) {
  25889. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25890. return;
  25891. }
  25892. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25893. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25894. propertyIndex = i;
  25895. break;
  25896. }
  25897. }
  25898. }
  25899. }
  25900. bindingType = this.BindingType.ArrayElement;
  25901. this.resolvedProperty = nodeProperty;
  25902. this.propertyIndex = propertyIndex;
  25903. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25904. // must use copy for Object3D.Euler/Quaternion
  25905. bindingType = this.BindingType.HasFromToArray;
  25906. this.resolvedProperty = nodeProperty;
  25907. } else if ( Array.isArray( nodeProperty ) ) {
  25908. bindingType = this.BindingType.EntireArray;
  25909. this.resolvedProperty = nodeProperty;
  25910. } else {
  25911. this.propertyName = propertyName;
  25912. }
  25913. // select getter / setter
  25914. this.getValue = this.GetterByBindingType[ bindingType ];
  25915. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25916. },
  25917. unbind: function () {
  25918. this.node = null;
  25919. // back to the prototype version of getValue / setValue
  25920. // note: avoiding to mutate the shape of 'this' via 'delete'
  25921. this.getValue = this._getValue_unbound;
  25922. this.setValue = this._setValue_unbound;
  25923. }
  25924. } );
  25925. //!\ DECLARE ALIAS AFTER assign prototype !
  25926. Object.assign( PropertyBinding.prototype, {
  25927. // initial state of these methods that calls 'bind'
  25928. _getValue_unbound: PropertyBinding.prototype.getValue,
  25929. _setValue_unbound: PropertyBinding.prototype.setValue,
  25930. } );
  25931. /**
  25932. *
  25933. * A group of objects that receives a shared animation state.
  25934. *
  25935. * Usage:
  25936. *
  25937. * - Add objects you would otherwise pass as 'root' to the
  25938. * constructor or the .clipAction method of AnimationMixer.
  25939. *
  25940. * - Instead pass this object as 'root'.
  25941. *
  25942. * - You can also add and remove objects later when the mixer
  25943. * is running.
  25944. *
  25945. * Note:
  25946. *
  25947. * Objects of this class appear as one object to the mixer,
  25948. * so cache control of the individual objects must be done
  25949. * on the group.
  25950. *
  25951. * Limitation:
  25952. *
  25953. * - The animated properties must be compatible among the
  25954. * all objects in the group.
  25955. *
  25956. * - A single property can either be controlled through a
  25957. * target group or directly, but not both.
  25958. *
  25959. * @author tschw
  25960. */
  25961. function AnimationObjectGroup() {
  25962. this.uuid = _Math.generateUUID();
  25963. // cached objects followed by the active ones
  25964. this._objects = Array.prototype.slice.call( arguments );
  25965. this.nCachedObjects_ = 0; // threshold
  25966. // note: read by PropertyBinding.Composite
  25967. var indices = {};
  25968. this._indicesByUUID = indices; // for bookkeeping
  25969. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25970. indices[ arguments[ i ].uuid ] = i;
  25971. }
  25972. this._paths = []; // inside: string
  25973. this._parsedPaths = []; // inside: { we don't care, here }
  25974. this._bindings = []; // inside: Array< PropertyBinding >
  25975. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25976. var scope = this;
  25977. this.stats = {
  25978. objects: {
  25979. get total() {
  25980. return scope._objects.length;
  25981. },
  25982. get inUse() {
  25983. return this.total - scope.nCachedObjects_;
  25984. }
  25985. },
  25986. get bindingsPerObject() {
  25987. return scope._bindings.length;
  25988. }
  25989. };
  25990. }
  25991. Object.assign( AnimationObjectGroup.prototype, {
  25992. isAnimationObjectGroup: true,
  25993. add: function () {
  25994. var objects = this._objects,
  25995. nObjects = objects.length,
  25996. nCachedObjects = this.nCachedObjects_,
  25997. indicesByUUID = this._indicesByUUID,
  25998. paths = this._paths,
  25999. parsedPaths = this._parsedPaths,
  26000. bindings = this._bindings,
  26001. nBindings = bindings.length,
  26002. knownObject = undefined;
  26003. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26004. var object = arguments[ i ],
  26005. uuid = object.uuid,
  26006. index = indicesByUUID[ uuid ];
  26007. if ( index === undefined ) {
  26008. // unknown object -> add it to the ACTIVE region
  26009. index = nObjects ++;
  26010. indicesByUUID[ uuid ] = index;
  26011. objects.push( object );
  26012. // accounting is done, now do the same for all bindings
  26013. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26014. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  26015. }
  26016. } else if ( index < nCachedObjects ) {
  26017. knownObject = objects[ index ];
  26018. // move existing object to the ACTIVE region
  26019. var firstActiveIndex = -- nCachedObjects,
  26020. lastCachedObject = objects[ firstActiveIndex ];
  26021. indicesByUUID[ lastCachedObject.uuid ] = index;
  26022. objects[ index ] = lastCachedObject;
  26023. indicesByUUID[ uuid ] = firstActiveIndex;
  26024. objects[ firstActiveIndex ] = object;
  26025. // accounting is done, now do the same for all bindings
  26026. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26027. var bindingsForPath = bindings[ j ],
  26028. lastCached = bindingsForPath[ firstActiveIndex ],
  26029. binding = bindingsForPath[ index ];
  26030. bindingsForPath[ index ] = lastCached;
  26031. if ( binding === undefined ) {
  26032. // since we do not bother to create new bindings
  26033. // for objects that are cached, the binding may
  26034. // or may not exist
  26035. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  26036. }
  26037. bindingsForPath[ firstActiveIndex ] = binding;
  26038. }
  26039. } else if ( objects[ index ] !== knownObject ) {
  26040. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  26041. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  26042. } // else the object is already where we want it to be
  26043. } // for arguments
  26044. this.nCachedObjects_ = nCachedObjects;
  26045. },
  26046. remove: function () {
  26047. var objects = this._objects,
  26048. nCachedObjects = this.nCachedObjects_,
  26049. indicesByUUID = this._indicesByUUID,
  26050. bindings = this._bindings,
  26051. nBindings = bindings.length;
  26052. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26053. var object = arguments[ i ],
  26054. uuid = object.uuid,
  26055. index = indicesByUUID[ uuid ];
  26056. if ( index !== undefined && index >= nCachedObjects ) {
  26057. // move existing object into the CACHED region
  26058. var lastCachedIndex = nCachedObjects ++,
  26059. firstActiveObject = objects[ lastCachedIndex ];
  26060. indicesByUUID[ firstActiveObject.uuid ] = index;
  26061. objects[ index ] = firstActiveObject;
  26062. indicesByUUID[ uuid ] = lastCachedIndex;
  26063. objects[ lastCachedIndex ] = object;
  26064. // accounting is done, now do the same for all bindings
  26065. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26066. var bindingsForPath = bindings[ j ],
  26067. firstActive = bindingsForPath[ lastCachedIndex ],
  26068. binding = bindingsForPath[ index ];
  26069. bindingsForPath[ index ] = firstActive;
  26070. bindingsForPath[ lastCachedIndex ] = binding;
  26071. }
  26072. }
  26073. } // for arguments
  26074. this.nCachedObjects_ = nCachedObjects;
  26075. },
  26076. // remove & forget
  26077. uncache: function () {
  26078. var objects = this._objects,
  26079. nObjects = objects.length,
  26080. nCachedObjects = this.nCachedObjects_,
  26081. indicesByUUID = this._indicesByUUID,
  26082. bindings = this._bindings,
  26083. nBindings = bindings.length;
  26084. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  26085. var object = arguments[ i ],
  26086. uuid = object.uuid,
  26087. index = indicesByUUID[ uuid ];
  26088. if ( index !== undefined ) {
  26089. delete indicesByUUID[ uuid ];
  26090. if ( index < nCachedObjects ) {
  26091. // object is cached, shrink the CACHED region
  26092. var firstActiveIndex = -- nCachedObjects,
  26093. lastCachedObject = objects[ firstActiveIndex ],
  26094. lastIndex = -- nObjects,
  26095. lastObject = objects[ lastIndex ];
  26096. // last cached object takes this object's place
  26097. indicesByUUID[ lastCachedObject.uuid ] = index;
  26098. objects[ index ] = lastCachedObject;
  26099. // last object goes to the activated slot and pop
  26100. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  26101. objects[ firstActiveIndex ] = lastObject;
  26102. objects.pop();
  26103. // accounting is done, now do the same for all bindings
  26104. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26105. var bindingsForPath = bindings[ j ],
  26106. lastCached = bindingsForPath[ firstActiveIndex ],
  26107. last = bindingsForPath[ lastIndex ];
  26108. bindingsForPath[ index ] = lastCached;
  26109. bindingsForPath[ firstActiveIndex ] = last;
  26110. bindingsForPath.pop();
  26111. }
  26112. } else {
  26113. // object is active, just swap with the last and pop
  26114. var lastIndex = -- nObjects,
  26115. lastObject = objects[ lastIndex ];
  26116. indicesByUUID[ lastObject.uuid ] = index;
  26117. objects[ index ] = lastObject;
  26118. objects.pop();
  26119. // accounting is done, now do the same for all bindings
  26120. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  26121. var bindingsForPath = bindings[ j ];
  26122. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  26123. bindingsForPath.pop();
  26124. }
  26125. } // cached or active
  26126. } // if object is known
  26127. } // for arguments
  26128. this.nCachedObjects_ = nCachedObjects;
  26129. },
  26130. // Internal interface used by befriended PropertyBinding.Composite:
  26131. subscribe_: function ( path, parsedPath ) {
  26132. // returns an array of bindings for the given path that is changed
  26133. // according to the contained objects in the group
  26134. var indicesByPath = this._bindingsIndicesByPath,
  26135. index = indicesByPath[ path ],
  26136. bindings = this._bindings;
  26137. if ( index !== undefined ) return bindings[ index ];
  26138. var paths = this._paths,
  26139. parsedPaths = this._parsedPaths,
  26140. objects = this._objects,
  26141. nObjects = objects.length,
  26142. nCachedObjects = this.nCachedObjects_,
  26143. bindingsForPath = new Array( nObjects );
  26144. index = bindings.length;
  26145. indicesByPath[ path ] = index;
  26146. paths.push( path );
  26147. parsedPaths.push( parsedPath );
  26148. bindings.push( bindingsForPath );
  26149. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  26150. var object = objects[ i ];
  26151. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  26152. }
  26153. return bindingsForPath;
  26154. },
  26155. unsubscribe_: function ( path ) {
  26156. // tells the group to forget about a property path and no longer
  26157. // update the array previously obtained with 'subscribe_'
  26158. var indicesByPath = this._bindingsIndicesByPath,
  26159. index = indicesByPath[ path ];
  26160. if ( index !== undefined ) {
  26161. var paths = this._paths,
  26162. parsedPaths = this._parsedPaths,
  26163. bindings = this._bindings,
  26164. lastBindingsIndex = bindings.length - 1,
  26165. lastBindings = bindings[ lastBindingsIndex ],
  26166. lastBindingsPath = path[ lastBindingsIndex ];
  26167. indicesByPath[ lastBindingsPath ] = index;
  26168. bindings[ index ] = lastBindings;
  26169. bindings.pop();
  26170. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  26171. parsedPaths.pop();
  26172. paths[ index ] = paths[ lastBindingsIndex ];
  26173. paths.pop();
  26174. }
  26175. }
  26176. } );
  26177. /**
  26178. *
  26179. * Action provided by AnimationMixer for scheduling clip playback on specific
  26180. * objects.
  26181. *
  26182. * @author Ben Houston / http://clara.io/
  26183. * @author David Sarno / http://lighthaus.us/
  26184. * @author tschw
  26185. *
  26186. */
  26187. function AnimationAction( mixer, clip, localRoot ) {
  26188. this._mixer = mixer;
  26189. this._clip = clip;
  26190. this._localRoot = localRoot || null;
  26191. var tracks = clip.tracks,
  26192. nTracks = tracks.length,
  26193. interpolants = new Array( nTracks );
  26194. var interpolantSettings = {
  26195. endingStart: ZeroCurvatureEnding,
  26196. endingEnd: ZeroCurvatureEnding
  26197. };
  26198. for ( var i = 0; i !== nTracks; ++ i ) {
  26199. var interpolant = tracks[ i ].createInterpolant( null );
  26200. interpolants[ i ] = interpolant;
  26201. interpolant.settings = interpolantSettings;
  26202. }
  26203. this._interpolantSettings = interpolantSettings;
  26204. this._interpolants = interpolants; // bound by the mixer
  26205. // inside: PropertyMixer (managed by the mixer)
  26206. this._propertyBindings = new Array( nTracks );
  26207. this._cacheIndex = null; // for the memory manager
  26208. this._byClipCacheIndex = null; // for the memory manager
  26209. this._timeScaleInterpolant = null;
  26210. this._weightInterpolant = null;
  26211. this.loop = LoopRepeat;
  26212. this._loopCount = - 1;
  26213. // global mixer time when the action is to be started
  26214. // it's set back to 'null' upon start of the action
  26215. this._startTime = null;
  26216. // scaled local time of the action
  26217. // gets clamped or wrapped to 0..clip.duration according to loop
  26218. this.time = 0;
  26219. this.timeScale = 1;
  26220. this._effectiveTimeScale = 1;
  26221. this.weight = 1;
  26222. this._effectiveWeight = 1;
  26223. this.repetitions = Infinity; // no. of repetitions when looping
  26224. this.paused = false; // true -> zero effective time scale
  26225. this.enabled = true; // false -> zero effective weight
  26226. this.clampWhenFinished = false;// keep feeding the last frame?
  26227. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  26228. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  26229. }
  26230. Object.assign( AnimationAction.prototype, {
  26231. // State & Scheduling
  26232. play: function () {
  26233. this._mixer._activateAction( this );
  26234. return this;
  26235. },
  26236. stop: function () {
  26237. this._mixer._deactivateAction( this );
  26238. return this.reset();
  26239. },
  26240. reset: function () {
  26241. this.paused = false;
  26242. this.enabled = true;
  26243. this.time = 0; // restart clip
  26244. this._loopCount = - 1;// forget previous loops
  26245. this._startTime = null;// forget scheduling
  26246. return this.stopFading().stopWarping();
  26247. },
  26248. isRunning: function () {
  26249. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  26250. this._startTime === null && this._mixer._isActiveAction( this );
  26251. },
  26252. // return true when play has been called
  26253. isScheduled: function () {
  26254. return this._mixer._isActiveAction( this );
  26255. },
  26256. startAt: function ( time ) {
  26257. this._startTime = time;
  26258. return this;
  26259. },
  26260. setLoop: function ( mode, repetitions ) {
  26261. this.loop = mode;
  26262. this.repetitions = repetitions;
  26263. return this;
  26264. },
  26265. // Weight
  26266. // set the weight stopping any scheduled fading
  26267. // although .enabled = false yields an effective weight of zero, this
  26268. // method does *not* change .enabled, because it would be confusing
  26269. setEffectiveWeight: function ( weight ) {
  26270. this.weight = weight;
  26271. // note: same logic as when updated at runtime
  26272. this._effectiveWeight = this.enabled ? weight : 0;
  26273. return this.stopFading();
  26274. },
  26275. // return the weight considering fading and .enabled
  26276. getEffectiveWeight: function () {
  26277. return this._effectiveWeight;
  26278. },
  26279. fadeIn: function ( duration ) {
  26280. return this._scheduleFading( duration, 0, 1 );
  26281. },
  26282. fadeOut: function ( duration ) {
  26283. return this._scheduleFading( duration, 1, 0 );
  26284. },
  26285. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  26286. fadeOutAction.fadeOut( duration );
  26287. this.fadeIn( duration );
  26288. if ( warp ) {
  26289. var fadeInDuration = this._clip.duration,
  26290. fadeOutDuration = fadeOutAction._clip.duration,
  26291. startEndRatio = fadeOutDuration / fadeInDuration,
  26292. endStartRatio = fadeInDuration / fadeOutDuration;
  26293. fadeOutAction.warp( 1.0, startEndRatio, duration );
  26294. this.warp( endStartRatio, 1.0, duration );
  26295. }
  26296. return this;
  26297. },
  26298. crossFadeTo: function ( fadeInAction, duration, warp ) {
  26299. return fadeInAction.crossFadeFrom( this, duration, warp );
  26300. },
  26301. stopFading: function () {
  26302. var weightInterpolant = this._weightInterpolant;
  26303. if ( weightInterpolant !== null ) {
  26304. this._weightInterpolant = null;
  26305. this._mixer._takeBackControlInterpolant( weightInterpolant );
  26306. }
  26307. return this;
  26308. },
  26309. // Time Scale Control
  26310. // set the time scale stopping any scheduled warping
  26311. // although .paused = true yields an effective time scale of zero, this
  26312. // method does *not* change .paused, because it would be confusing
  26313. setEffectiveTimeScale: function ( timeScale ) {
  26314. this.timeScale = timeScale;
  26315. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26316. return this.stopWarping();
  26317. },
  26318. // return the time scale considering warping and .paused
  26319. getEffectiveTimeScale: function () {
  26320. return this._effectiveTimeScale;
  26321. },
  26322. setDuration: function ( duration ) {
  26323. this.timeScale = this._clip.duration / duration;
  26324. return this.stopWarping();
  26325. },
  26326. syncWith: function ( action ) {
  26327. this.time = action.time;
  26328. this.timeScale = action.timeScale;
  26329. return this.stopWarping();
  26330. },
  26331. halt: function ( duration ) {
  26332. return this.warp( this._effectiveTimeScale, 0, duration );
  26333. },
  26334. warp: function ( startTimeScale, endTimeScale, duration ) {
  26335. var mixer = this._mixer, now = mixer.time,
  26336. interpolant = this._timeScaleInterpolant,
  26337. timeScale = this.timeScale;
  26338. if ( interpolant === null ) {
  26339. interpolant = mixer._lendControlInterpolant();
  26340. this._timeScaleInterpolant = interpolant;
  26341. }
  26342. var times = interpolant.parameterPositions,
  26343. values = interpolant.sampleValues;
  26344. times[ 0 ] = now;
  26345. times[ 1 ] = now + duration;
  26346. values[ 0 ] = startTimeScale / timeScale;
  26347. values[ 1 ] = endTimeScale / timeScale;
  26348. return this;
  26349. },
  26350. stopWarping: function () {
  26351. var timeScaleInterpolant = this._timeScaleInterpolant;
  26352. if ( timeScaleInterpolant !== null ) {
  26353. this._timeScaleInterpolant = null;
  26354. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  26355. }
  26356. return this;
  26357. },
  26358. // Object Accessors
  26359. getMixer: function () {
  26360. return this._mixer;
  26361. },
  26362. getClip: function () {
  26363. return this._clip;
  26364. },
  26365. getRoot: function () {
  26366. return this._localRoot || this._mixer._root;
  26367. },
  26368. // Interna
  26369. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  26370. // called by the mixer
  26371. if ( ! this.enabled ) {
  26372. // call ._updateWeight() to update ._effectiveWeight
  26373. this._updateWeight( time );
  26374. return;
  26375. }
  26376. var startTime = this._startTime;
  26377. if ( startTime !== null ) {
  26378. // check for scheduled start of action
  26379. var timeRunning = ( time - startTime ) * timeDirection;
  26380. if ( timeRunning < 0 || timeDirection === 0 ) {
  26381. return; // yet to come / don't decide when delta = 0
  26382. }
  26383. // start
  26384. this._startTime = null; // unschedule
  26385. deltaTime = timeDirection * timeRunning;
  26386. }
  26387. // apply time scale and advance time
  26388. deltaTime *= this._updateTimeScale( time );
  26389. var clipTime = this._updateTime( deltaTime );
  26390. // note: _updateTime may disable the action resulting in
  26391. // an effective weight of 0
  26392. var weight = this._updateWeight( time );
  26393. if ( weight > 0 ) {
  26394. var interpolants = this._interpolants;
  26395. var propertyMixers = this._propertyBindings;
  26396. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  26397. interpolants[ j ].evaluate( clipTime );
  26398. propertyMixers[ j ].accumulate( accuIndex, weight );
  26399. }
  26400. }
  26401. },
  26402. _updateWeight: function ( time ) {
  26403. var weight = 0;
  26404. if ( this.enabled ) {
  26405. weight = this.weight;
  26406. var interpolant = this._weightInterpolant;
  26407. if ( interpolant !== null ) {
  26408. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26409. weight *= interpolantValue;
  26410. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26411. this.stopFading();
  26412. if ( interpolantValue === 0 ) {
  26413. // faded out, disable
  26414. this.enabled = false;
  26415. }
  26416. }
  26417. }
  26418. }
  26419. this._effectiveWeight = weight;
  26420. return weight;
  26421. },
  26422. _updateTimeScale: function ( time ) {
  26423. var timeScale = 0;
  26424. if ( ! this.paused ) {
  26425. timeScale = this.timeScale;
  26426. var interpolant = this._timeScaleInterpolant;
  26427. if ( interpolant !== null ) {
  26428. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26429. timeScale *= interpolantValue;
  26430. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26431. this.stopWarping();
  26432. if ( timeScale === 0 ) {
  26433. // motion has halted, pause
  26434. this.paused = true;
  26435. } else {
  26436. // warp done - apply final time scale
  26437. this.timeScale = timeScale;
  26438. }
  26439. }
  26440. }
  26441. }
  26442. this._effectiveTimeScale = timeScale;
  26443. return timeScale;
  26444. },
  26445. _updateTime: function ( deltaTime ) {
  26446. var time = this.time + deltaTime;
  26447. var duration = this._clip.duration;
  26448. var loop = this.loop;
  26449. var loopCount = this._loopCount;
  26450. var pingPong = ( loop === LoopPingPong );
  26451. if ( deltaTime === 0 ) {
  26452. if ( loopCount === - 1 ) return time;
  26453. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26454. }
  26455. if ( loop === LoopOnce ) {
  26456. if ( loopCount === - 1 ) {
  26457. // just started
  26458. this._loopCount = 0;
  26459. this._setEndings( true, true, false );
  26460. }
  26461. handle_stop: {
  26462. if ( time >= duration ) {
  26463. time = duration;
  26464. } else if ( time < 0 ) {
  26465. time = 0;
  26466. } else {
  26467. this.time = time;
  26468. break handle_stop;
  26469. }
  26470. if ( this.clampWhenFinished ) this.paused = true;
  26471. else this.enabled = false;
  26472. this.time = time;
  26473. this._mixer.dispatchEvent( {
  26474. type: 'finished', action: this,
  26475. direction: deltaTime < 0 ? - 1 : 1
  26476. } );
  26477. }
  26478. } else { // repetitive Repeat or PingPong
  26479. if ( loopCount === - 1 ) {
  26480. // just started
  26481. if ( deltaTime >= 0 ) {
  26482. loopCount = 0;
  26483. this._setEndings( true, this.repetitions === 0, pingPong );
  26484. } else {
  26485. // when looping in reverse direction, the initial
  26486. // transition through zero counts as a repetition,
  26487. // so leave loopCount at -1
  26488. this._setEndings( this.repetitions === 0, true, pingPong );
  26489. }
  26490. }
  26491. if ( time >= duration || time < 0 ) {
  26492. // wrap around
  26493. var loopDelta = Math.floor( time / duration ); // signed
  26494. time -= duration * loopDelta;
  26495. loopCount += Math.abs( loopDelta );
  26496. var pending = this.repetitions - loopCount;
  26497. if ( pending <= 0 ) {
  26498. // have to stop (switch state, clamp time, fire event)
  26499. if ( this.clampWhenFinished ) this.paused = true;
  26500. else this.enabled = false;
  26501. time = deltaTime > 0 ? duration : 0;
  26502. this.time = time;
  26503. this._mixer.dispatchEvent( {
  26504. type: 'finished', action: this,
  26505. direction: deltaTime > 0 ? 1 : - 1
  26506. } );
  26507. } else {
  26508. // keep running
  26509. if ( pending === 1 ) {
  26510. // entering the last round
  26511. var atStart = deltaTime < 0;
  26512. this._setEndings( atStart, ! atStart, pingPong );
  26513. } else {
  26514. this._setEndings( false, false, pingPong );
  26515. }
  26516. this._loopCount = loopCount;
  26517. this.time = time;
  26518. this._mixer.dispatchEvent( {
  26519. type: 'loop', action: this, loopDelta: loopDelta
  26520. } );
  26521. }
  26522. } else {
  26523. this.time = time;
  26524. }
  26525. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  26526. // invert time for the "pong round"
  26527. return duration - time;
  26528. }
  26529. }
  26530. return time;
  26531. },
  26532. _setEndings: function ( atStart, atEnd, pingPong ) {
  26533. var settings = this._interpolantSettings;
  26534. if ( pingPong ) {
  26535. settings.endingStart = ZeroSlopeEnding;
  26536. settings.endingEnd = ZeroSlopeEnding;
  26537. } else {
  26538. // assuming for LoopOnce atStart == atEnd == true
  26539. if ( atStart ) {
  26540. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26541. } else {
  26542. settings.endingStart = WrapAroundEnding;
  26543. }
  26544. if ( atEnd ) {
  26545. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26546. } else {
  26547. settings.endingEnd = WrapAroundEnding;
  26548. }
  26549. }
  26550. },
  26551. _scheduleFading: function ( duration, weightNow, weightThen ) {
  26552. var mixer = this._mixer, now = mixer.time,
  26553. interpolant = this._weightInterpolant;
  26554. if ( interpolant === null ) {
  26555. interpolant = mixer._lendControlInterpolant();
  26556. this._weightInterpolant = interpolant;
  26557. }
  26558. var times = interpolant.parameterPositions,
  26559. values = interpolant.sampleValues;
  26560. times[ 0 ] = now;
  26561. values[ 0 ] = weightNow;
  26562. times[ 1 ] = now + duration;
  26563. values[ 1 ] = weightThen;
  26564. return this;
  26565. }
  26566. } );
  26567. /**
  26568. *
  26569. * Player for AnimationClips.
  26570. *
  26571. *
  26572. * @author Ben Houston / http://clara.io/
  26573. * @author David Sarno / http://lighthaus.us/
  26574. * @author tschw
  26575. */
  26576. function AnimationMixer( root ) {
  26577. this._root = root;
  26578. this._initMemoryManager();
  26579. this._accuIndex = 0;
  26580. this.time = 0;
  26581. this.timeScale = 1.0;
  26582. }
  26583. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  26584. constructor: AnimationMixer,
  26585. _bindAction: function ( action, prototypeAction ) {
  26586. var root = action._localRoot || this._root,
  26587. tracks = action._clip.tracks,
  26588. nTracks = tracks.length,
  26589. bindings = action._propertyBindings,
  26590. interpolants = action._interpolants,
  26591. rootUuid = root.uuid,
  26592. bindingsByRoot = this._bindingsByRootAndName,
  26593. bindingsByName = bindingsByRoot[ rootUuid ];
  26594. if ( bindingsByName === undefined ) {
  26595. bindingsByName = {};
  26596. bindingsByRoot[ rootUuid ] = bindingsByName;
  26597. }
  26598. for ( var i = 0; i !== nTracks; ++ i ) {
  26599. var track = tracks[ i ],
  26600. trackName = track.name,
  26601. binding = bindingsByName[ trackName ];
  26602. if ( binding !== undefined ) {
  26603. bindings[ i ] = binding;
  26604. } else {
  26605. binding = bindings[ i ];
  26606. if ( binding !== undefined ) {
  26607. // existing binding, make sure the cache knows
  26608. if ( binding._cacheIndex === null ) {
  26609. ++ binding.referenceCount;
  26610. this._addInactiveBinding( binding, rootUuid, trackName );
  26611. }
  26612. continue;
  26613. }
  26614. var path = prototypeAction && prototypeAction.
  26615. _propertyBindings[ i ].binding.parsedPath;
  26616. binding = new PropertyMixer(
  26617. PropertyBinding.create( root, trackName, path ),
  26618. track.ValueTypeName, track.getValueSize() );
  26619. ++ binding.referenceCount;
  26620. this._addInactiveBinding( binding, rootUuid, trackName );
  26621. bindings[ i ] = binding;
  26622. }
  26623. interpolants[ i ].resultBuffer = binding.buffer;
  26624. }
  26625. },
  26626. _activateAction: function ( action ) {
  26627. if ( ! this._isActiveAction( action ) ) {
  26628. if ( action._cacheIndex === null ) {
  26629. // this action has been forgotten by the cache, but the user
  26630. // appears to be still using it -> rebind
  26631. var rootUuid = ( action._localRoot || this._root ).uuid,
  26632. clipUuid = action._clip.uuid,
  26633. actionsForClip = this._actionsByClip[ clipUuid ];
  26634. this._bindAction( action,
  26635. actionsForClip && actionsForClip.knownActions[ 0 ] );
  26636. this._addInactiveAction( action, clipUuid, rootUuid );
  26637. }
  26638. var bindings = action._propertyBindings;
  26639. // increment reference counts / sort out state
  26640. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26641. var binding = bindings[ i ];
  26642. if ( binding.useCount ++ === 0 ) {
  26643. this._lendBinding( binding );
  26644. binding.saveOriginalState();
  26645. }
  26646. }
  26647. this._lendAction( action );
  26648. }
  26649. },
  26650. _deactivateAction: function ( action ) {
  26651. if ( this._isActiveAction( action ) ) {
  26652. var bindings = action._propertyBindings;
  26653. // decrement reference counts / sort out state
  26654. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26655. var binding = bindings[ i ];
  26656. if ( -- binding.useCount === 0 ) {
  26657. binding.restoreOriginalState();
  26658. this._takeBackBinding( binding );
  26659. }
  26660. }
  26661. this._takeBackAction( action );
  26662. }
  26663. },
  26664. // Memory manager
  26665. _initMemoryManager: function () {
  26666. this._actions = []; // 'nActiveActions' followed by inactive ones
  26667. this._nActiveActions = 0;
  26668. this._actionsByClip = {};
  26669. // inside:
  26670. // {
  26671. // knownActions: Array< AnimationAction > - used as prototypes
  26672. // actionByRoot: AnimationAction - lookup
  26673. // }
  26674. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26675. this._nActiveBindings = 0;
  26676. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26677. this._controlInterpolants = []; // same game as above
  26678. this._nActiveControlInterpolants = 0;
  26679. var scope = this;
  26680. this.stats = {
  26681. actions: {
  26682. get total() {
  26683. return scope._actions.length;
  26684. },
  26685. get inUse() {
  26686. return scope._nActiveActions;
  26687. }
  26688. },
  26689. bindings: {
  26690. get total() {
  26691. return scope._bindings.length;
  26692. },
  26693. get inUse() {
  26694. return scope._nActiveBindings;
  26695. }
  26696. },
  26697. controlInterpolants: {
  26698. get total() {
  26699. return scope._controlInterpolants.length;
  26700. },
  26701. get inUse() {
  26702. return scope._nActiveControlInterpolants;
  26703. }
  26704. }
  26705. };
  26706. },
  26707. // Memory management for AnimationAction objects
  26708. _isActiveAction: function ( action ) {
  26709. var index = action._cacheIndex;
  26710. return index !== null && index < this._nActiveActions;
  26711. },
  26712. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26713. var actions = this._actions,
  26714. actionsByClip = this._actionsByClip,
  26715. actionsForClip = actionsByClip[ clipUuid ];
  26716. if ( actionsForClip === undefined ) {
  26717. actionsForClip = {
  26718. knownActions: [ action ],
  26719. actionByRoot: {}
  26720. };
  26721. action._byClipCacheIndex = 0;
  26722. actionsByClip[ clipUuid ] = actionsForClip;
  26723. } else {
  26724. var knownActions = actionsForClip.knownActions;
  26725. action._byClipCacheIndex = knownActions.length;
  26726. knownActions.push( action );
  26727. }
  26728. action._cacheIndex = actions.length;
  26729. actions.push( action );
  26730. actionsForClip.actionByRoot[ rootUuid ] = action;
  26731. },
  26732. _removeInactiveAction: function ( action ) {
  26733. var actions = this._actions,
  26734. lastInactiveAction = actions[ actions.length - 1 ],
  26735. cacheIndex = action._cacheIndex;
  26736. lastInactiveAction._cacheIndex = cacheIndex;
  26737. actions[ cacheIndex ] = lastInactiveAction;
  26738. actions.pop();
  26739. action._cacheIndex = null;
  26740. var clipUuid = action._clip.uuid,
  26741. actionsByClip = this._actionsByClip,
  26742. actionsForClip = actionsByClip[ clipUuid ],
  26743. knownActionsForClip = actionsForClip.knownActions,
  26744. lastKnownAction =
  26745. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26746. byClipCacheIndex = action._byClipCacheIndex;
  26747. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26748. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26749. knownActionsForClip.pop();
  26750. action._byClipCacheIndex = null;
  26751. var actionByRoot = actionsForClip.actionByRoot,
  26752. rootUuid = ( action._localRoot || this._root ).uuid;
  26753. delete actionByRoot[ rootUuid ];
  26754. if ( knownActionsForClip.length === 0 ) {
  26755. delete actionsByClip[ clipUuid ];
  26756. }
  26757. this._removeInactiveBindingsForAction( action );
  26758. },
  26759. _removeInactiveBindingsForAction: function ( action ) {
  26760. var bindings = action._propertyBindings;
  26761. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26762. var binding = bindings[ i ];
  26763. if ( -- binding.referenceCount === 0 ) {
  26764. this._removeInactiveBinding( binding );
  26765. }
  26766. }
  26767. },
  26768. _lendAction: function ( action ) {
  26769. // [ active actions | inactive actions ]
  26770. // [ active actions >| inactive actions ]
  26771. // s a
  26772. // <-swap->
  26773. // a s
  26774. var actions = this._actions,
  26775. prevIndex = action._cacheIndex,
  26776. lastActiveIndex = this._nActiveActions ++,
  26777. firstInactiveAction = actions[ lastActiveIndex ];
  26778. action._cacheIndex = lastActiveIndex;
  26779. actions[ lastActiveIndex ] = action;
  26780. firstInactiveAction._cacheIndex = prevIndex;
  26781. actions[ prevIndex ] = firstInactiveAction;
  26782. },
  26783. _takeBackAction: function ( action ) {
  26784. // [ active actions | inactive actions ]
  26785. // [ active actions |< inactive actions ]
  26786. // a s
  26787. // <-swap->
  26788. // s a
  26789. var actions = this._actions,
  26790. prevIndex = action._cacheIndex,
  26791. firstInactiveIndex = -- this._nActiveActions,
  26792. lastActiveAction = actions[ firstInactiveIndex ];
  26793. action._cacheIndex = firstInactiveIndex;
  26794. actions[ firstInactiveIndex ] = action;
  26795. lastActiveAction._cacheIndex = prevIndex;
  26796. actions[ prevIndex ] = lastActiveAction;
  26797. },
  26798. // Memory management for PropertyMixer objects
  26799. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26800. var bindingsByRoot = this._bindingsByRootAndName,
  26801. bindingByName = bindingsByRoot[ rootUuid ],
  26802. bindings = this._bindings;
  26803. if ( bindingByName === undefined ) {
  26804. bindingByName = {};
  26805. bindingsByRoot[ rootUuid ] = bindingByName;
  26806. }
  26807. bindingByName[ trackName ] = binding;
  26808. binding._cacheIndex = bindings.length;
  26809. bindings.push( binding );
  26810. },
  26811. _removeInactiveBinding: function ( binding ) {
  26812. var bindings = this._bindings,
  26813. propBinding = binding.binding,
  26814. rootUuid = propBinding.rootNode.uuid,
  26815. trackName = propBinding.path,
  26816. bindingsByRoot = this._bindingsByRootAndName,
  26817. bindingByName = bindingsByRoot[ rootUuid ],
  26818. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26819. cacheIndex = binding._cacheIndex;
  26820. lastInactiveBinding._cacheIndex = cacheIndex;
  26821. bindings[ cacheIndex ] = lastInactiveBinding;
  26822. bindings.pop();
  26823. delete bindingByName[ trackName ];
  26824. if ( Object.keys( bindingByName ).length === 0 ) {
  26825. delete bindingsByRoot[ rootUuid ];
  26826. }
  26827. },
  26828. _lendBinding: function ( binding ) {
  26829. var bindings = this._bindings,
  26830. prevIndex = binding._cacheIndex,
  26831. lastActiveIndex = this._nActiveBindings ++,
  26832. firstInactiveBinding = bindings[ lastActiveIndex ];
  26833. binding._cacheIndex = lastActiveIndex;
  26834. bindings[ lastActiveIndex ] = binding;
  26835. firstInactiveBinding._cacheIndex = prevIndex;
  26836. bindings[ prevIndex ] = firstInactiveBinding;
  26837. },
  26838. _takeBackBinding: function ( binding ) {
  26839. var bindings = this._bindings,
  26840. prevIndex = binding._cacheIndex,
  26841. firstInactiveIndex = -- this._nActiveBindings,
  26842. lastActiveBinding = bindings[ firstInactiveIndex ];
  26843. binding._cacheIndex = firstInactiveIndex;
  26844. bindings[ firstInactiveIndex ] = binding;
  26845. lastActiveBinding._cacheIndex = prevIndex;
  26846. bindings[ prevIndex ] = lastActiveBinding;
  26847. },
  26848. // Memory management of Interpolants for weight and time scale
  26849. _lendControlInterpolant: function () {
  26850. var interpolants = this._controlInterpolants,
  26851. lastActiveIndex = this._nActiveControlInterpolants ++,
  26852. interpolant = interpolants[ lastActiveIndex ];
  26853. if ( interpolant === undefined ) {
  26854. interpolant = new LinearInterpolant(
  26855. new Float32Array( 2 ), new Float32Array( 2 ),
  26856. 1, this._controlInterpolantsResultBuffer );
  26857. interpolant.__cacheIndex = lastActiveIndex;
  26858. interpolants[ lastActiveIndex ] = interpolant;
  26859. }
  26860. return interpolant;
  26861. },
  26862. _takeBackControlInterpolant: function ( interpolant ) {
  26863. var interpolants = this._controlInterpolants,
  26864. prevIndex = interpolant.__cacheIndex,
  26865. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26866. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26867. interpolant.__cacheIndex = firstInactiveIndex;
  26868. interpolants[ firstInactiveIndex ] = interpolant;
  26869. lastActiveInterpolant.__cacheIndex = prevIndex;
  26870. interpolants[ prevIndex ] = lastActiveInterpolant;
  26871. },
  26872. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26873. // return an action for a clip optionally using a custom root target
  26874. // object (this method allocates a lot of dynamic memory in case a
  26875. // previously unknown clip/root combination is specified)
  26876. clipAction: function ( clip, optionalRoot ) {
  26877. var root = optionalRoot || this._root,
  26878. rootUuid = root.uuid,
  26879. clipObject = typeof clip === 'string' ?
  26880. AnimationClip.findByName( root, clip ) : clip,
  26881. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26882. actionsForClip = this._actionsByClip[ clipUuid ],
  26883. prototypeAction = null;
  26884. if ( actionsForClip !== undefined ) {
  26885. var existingAction =
  26886. actionsForClip.actionByRoot[ rootUuid ];
  26887. if ( existingAction !== undefined ) {
  26888. return existingAction;
  26889. }
  26890. // we know the clip, so we don't have to parse all
  26891. // the bindings again but can just copy
  26892. prototypeAction = actionsForClip.knownActions[ 0 ];
  26893. // also, take the clip from the prototype action
  26894. if ( clipObject === null )
  26895. clipObject = prototypeAction._clip;
  26896. }
  26897. // clip must be known when specified via string
  26898. if ( clipObject === null ) return null;
  26899. // allocate all resources required to run it
  26900. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26901. this._bindAction( newAction, prototypeAction );
  26902. // and make the action known to the memory manager
  26903. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26904. return newAction;
  26905. },
  26906. // get an existing action
  26907. existingAction: function ( clip, optionalRoot ) {
  26908. var root = optionalRoot || this._root,
  26909. rootUuid = root.uuid,
  26910. clipObject = typeof clip === 'string' ?
  26911. AnimationClip.findByName( root, clip ) : clip,
  26912. clipUuid = clipObject ? clipObject.uuid : clip,
  26913. actionsForClip = this._actionsByClip[ clipUuid ];
  26914. if ( actionsForClip !== undefined ) {
  26915. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26916. }
  26917. return null;
  26918. },
  26919. // deactivates all previously scheduled actions
  26920. stopAllAction: function () {
  26921. var actions = this._actions,
  26922. nActions = this._nActiveActions,
  26923. bindings = this._bindings,
  26924. nBindings = this._nActiveBindings;
  26925. this._nActiveActions = 0;
  26926. this._nActiveBindings = 0;
  26927. for ( var i = 0; i !== nActions; ++ i ) {
  26928. actions[ i ].reset();
  26929. }
  26930. for ( var i = 0; i !== nBindings; ++ i ) {
  26931. bindings[ i ].useCount = 0;
  26932. }
  26933. return this;
  26934. },
  26935. // advance the time and update apply the animation
  26936. update: function ( deltaTime ) {
  26937. deltaTime *= this.timeScale;
  26938. var actions = this._actions,
  26939. nActions = this._nActiveActions,
  26940. time = this.time += deltaTime,
  26941. timeDirection = Math.sign( deltaTime ),
  26942. accuIndex = this._accuIndex ^= 1;
  26943. // run active actions
  26944. for ( var i = 0; i !== nActions; ++ i ) {
  26945. var action = actions[ i ];
  26946. action._update( time, deltaTime, timeDirection, accuIndex );
  26947. }
  26948. // update scene graph
  26949. var bindings = this._bindings,
  26950. nBindings = this._nActiveBindings;
  26951. for ( var i = 0; i !== nBindings; ++ i ) {
  26952. bindings[ i ].apply( accuIndex );
  26953. }
  26954. return this;
  26955. },
  26956. // Allows you to seek to a specific time in an animation.
  26957. setTime: function ( timeInSeconds ) {
  26958. this.time = 0; // Zero out time attribute for AnimationMixer object;
  26959. for ( var i = 0; i < this._actions.length; i ++ ) {
  26960. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  26961. }
  26962. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  26963. },
  26964. // return this mixer's root target object
  26965. getRoot: function () {
  26966. return this._root;
  26967. },
  26968. // free all resources specific to a particular clip
  26969. uncacheClip: function ( clip ) {
  26970. var actions = this._actions,
  26971. clipUuid = clip.uuid,
  26972. actionsByClip = this._actionsByClip,
  26973. actionsForClip = actionsByClip[ clipUuid ];
  26974. if ( actionsForClip !== undefined ) {
  26975. // note: just calling _removeInactiveAction would mess up the
  26976. // iteration state and also require updating the state we can
  26977. // just throw away
  26978. var actionsToRemove = actionsForClip.knownActions;
  26979. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26980. var action = actionsToRemove[ i ];
  26981. this._deactivateAction( action );
  26982. var cacheIndex = action._cacheIndex,
  26983. lastInactiveAction = actions[ actions.length - 1 ];
  26984. action._cacheIndex = null;
  26985. action._byClipCacheIndex = null;
  26986. lastInactiveAction._cacheIndex = cacheIndex;
  26987. actions[ cacheIndex ] = lastInactiveAction;
  26988. actions.pop();
  26989. this._removeInactiveBindingsForAction( action );
  26990. }
  26991. delete actionsByClip[ clipUuid ];
  26992. }
  26993. },
  26994. // free all resources specific to a particular root target object
  26995. uncacheRoot: function ( root ) {
  26996. var rootUuid = root.uuid,
  26997. actionsByClip = this._actionsByClip;
  26998. for ( var clipUuid in actionsByClip ) {
  26999. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  27000. action = actionByRoot[ rootUuid ];
  27001. if ( action !== undefined ) {
  27002. this._deactivateAction( action );
  27003. this._removeInactiveAction( action );
  27004. }
  27005. }
  27006. var bindingsByRoot = this._bindingsByRootAndName,
  27007. bindingByName = bindingsByRoot[ rootUuid ];
  27008. if ( bindingByName !== undefined ) {
  27009. for ( var trackName in bindingByName ) {
  27010. var binding = bindingByName[ trackName ];
  27011. binding.restoreOriginalState();
  27012. this._removeInactiveBinding( binding );
  27013. }
  27014. }
  27015. },
  27016. // remove a targeted clip from the cache
  27017. uncacheAction: function ( clip, optionalRoot ) {
  27018. var action = this.existingAction( clip, optionalRoot );
  27019. if ( action !== null ) {
  27020. this._deactivateAction( action );
  27021. this._removeInactiveAction( action );
  27022. }
  27023. }
  27024. } );
  27025. /**
  27026. * @author mrdoob / http://mrdoob.com/
  27027. */
  27028. function Uniform( value ) {
  27029. if ( typeof value === 'string' ) {
  27030. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  27031. value = arguments[ 1 ];
  27032. }
  27033. this.value = value;
  27034. }
  27035. Uniform.prototype.clone = function () {
  27036. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  27037. };
  27038. /**
  27039. * @author benaadams / https://twitter.com/ben_a_adams
  27040. */
  27041. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  27042. InterleavedBuffer.call( this, array, stride );
  27043. this.meshPerAttribute = meshPerAttribute || 1;
  27044. }
  27045. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  27046. constructor: InstancedInterleavedBuffer,
  27047. isInstancedInterleavedBuffer: true,
  27048. copy: function ( source ) {
  27049. InterleavedBuffer.prototype.copy.call( this, source );
  27050. this.meshPerAttribute = source.meshPerAttribute;
  27051. return this;
  27052. }
  27053. } );
  27054. /**
  27055. * @author mrdoob / http://mrdoob.com/
  27056. * @author bhouston / http://clara.io/
  27057. * @author stephomi / http://stephaneginier.com/
  27058. */
  27059. function Raycaster( origin, direction, near, far ) {
  27060. this.ray = new Ray( origin, direction );
  27061. // direction is assumed to be normalized (for accurate distance calculations)
  27062. this.near = near || 0;
  27063. this.far = far || Infinity;
  27064. this.camera = null;
  27065. this.params = {
  27066. Mesh: {},
  27067. Line: {},
  27068. LOD: {},
  27069. Points: { threshold: 1 },
  27070. Sprite: {}
  27071. };
  27072. Object.defineProperties( this.params, {
  27073. PointCloud: {
  27074. get: function () {
  27075. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  27076. return this.Points;
  27077. }
  27078. }
  27079. } );
  27080. }
  27081. function ascSort( a, b ) {
  27082. return a.distance - b.distance;
  27083. }
  27084. function intersectObject( object, raycaster, intersects, recursive ) {
  27085. if ( object.visible === false ) return;
  27086. object.raycast( raycaster, intersects );
  27087. if ( recursive === true ) {
  27088. var children = object.children;
  27089. for ( var i = 0, l = children.length; i < l; i ++ ) {
  27090. intersectObject( children[ i ], raycaster, intersects, true );
  27091. }
  27092. }
  27093. }
  27094. Object.assign( Raycaster.prototype, {
  27095. linePrecision: 1,
  27096. set: function ( origin, direction ) {
  27097. // direction is assumed to be normalized (for accurate distance calculations)
  27098. this.ray.set( origin, direction );
  27099. },
  27100. setFromCamera: function ( coords, camera ) {
  27101. if ( ( camera && camera.isPerspectiveCamera ) ) {
  27102. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27103. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27104. this.camera = camera;
  27105. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  27106. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27107. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27108. this.camera = camera;
  27109. } else {
  27110. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  27111. }
  27112. },
  27113. intersectObject: function ( object, recursive, optionalTarget ) {
  27114. var intersects = optionalTarget || [];
  27115. intersectObject( object, this, intersects, recursive );
  27116. intersects.sort( ascSort );
  27117. return intersects;
  27118. },
  27119. intersectObjects: function ( objects, recursive, optionalTarget ) {
  27120. var intersects = optionalTarget || [];
  27121. if ( Array.isArray( objects ) === false ) {
  27122. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  27123. return intersects;
  27124. }
  27125. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  27126. intersectObject( objects[ i ], this, intersects, recursive );
  27127. }
  27128. intersects.sort( ascSort );
  27129. return intersects;
  27130. }
  27131. } );
  27132. /**
  27133. * @author bhouston / http://clara.io
  27134. * @author WestLangley / http://github.com/WestLangley
  27135. *
  27136. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27137. *
  27138. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27139. * The azimuthal angle (theta) is measured from the positive z-axis.
  27140. */
  27141. function Spherical( radius, phi, theta ) {
  27142. this.radius = ( radius !== undefined ) ? radius : 1.0;
  27143. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  27144. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  27145. return this;
  27146. }
  27147. Object.assign( Spherical.prototype, {
  27148. set: function ( radius, phi, theta ) {
  27149. this.radius = radius;
  27150. this.phi = phi;
  27151. this.theta = theta;
  27152. return this;
  27153. },
  27154. clone: function () {
  27155. return new this.constructor().copy( this );
  27156. },
  27157. copy: function ( other ) {
  27158. this.radius = other.radius;
  27159. this.phi = other.phi;
  27160. this.theta = other.theta;
  27161. return this;
  27162. },
  27163. // restrict phi to be betwee EPS and PI-EPS
  27164. makeSafe: function () {
  27165. var EPS = 0.000001;
  27166. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  27167. return this;
  27168. },
  27169. setFromVector3: function ( v ) {
  27170. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27171. },
  27172. setFromCartesianCoords: function ( x, y, z ) {
  27173. this.radius = Math.sqrt( x * x + y * y + z * z );
  27174. if ( this.radius === 0 ) {
  27175. this.theta = 0;
  27176. this.phi = 0;
  27177. } else {
  27178. this.theta = Math.atan2( x, z );
  27179. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  27180. }
  27181. return this;
  27182. }
  27183. } );
  27184. /**
  27185. * @author Mugen87 / https://github.com/Mugen87
  27186. *
  27187. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27188. *
  27189. */
  27190. function Cylindrical( radius, theta, y ) {
  27191. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27192. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27193. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  27194. return this;
  27195. }
  27196. Object.assign( Cylindrical.prototype, {
  27197. set: function ( radius, theta, y ) {
  27198. this.radius = radius;
  27199. this.theta = theta;
  27200. this.y = y;
  27201. return this;
  27202. },
  27203. clone: function () {
  27204. return new this.constructor().copy( this );
  27205. },
  27206. copy: function ( other ) {
  27207. this.radius = other.radius;
  27208. this.theta = other.theta;
  27209. this.y = other.y;
  27210. return this;
  27211. },
  27212. setFromVector3: function ( v ) {
  27213. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27214. },
  27215. setFromCartesianCoords: function ( x, y, z ) {
  27216. this.radius = Math.sqrt( x * x + z * z );
  27217. this.theta = Math.atan2( x, z );
  27218. this.y = y;
  27219. return this;
  27220. }
  27221. } );
  27222. /**
  27223. * @author bhouston / http://clara.io
  27224. */
  27225. var _vector$6 = new Vector2();
  27226. function Box2( min, max ) {
  27227. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  27228. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  27229. }
  27230. Object.assign( Box2.prototype, {
  27231. set: function ( min, max ) {
  27232. this.min.copy( min );
  27233. this.max.copy( max );
  27234. return this;
  27235. },
  27236. setFromPoints: function ( points ) {
  27237. this.makeEmpty();
  27238. for ( var i = 0, il = points.length; i < il; i ++ ) {
  27239. this.expandByPoint( points[ i ] );
  27240. }
  27241. return this;
  27242. },
  27243. setFromCenterAndSize: function ( center, size ) {
  27244. var halfSize = _vector$6.copy( size ).multiplyScalar( 0.5 );
  27245. this.min.copy( center ).sub( halfSize );
  27246. this.max.copy( center ).add( halfSize );
  27247. return this;
  27248. },
  27249. clone: function () {
  27250. return new this.constructor().copy( this );
  27251. },
  27252. copy: function ( box ) {
  27253. this.min.copy( box.min );
  27254. this.max.copy( box.max );
  27255. return this;
  27256. },
  27257. makeEmpty: function () {
  27258. this.min.x = this.min.y = + Infinity;
  27259. this.max.x = this.max.y = - Infinity;
  27260. return this;
  27261. },
  27262. isEmpty: function () {
  27263. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27264. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  27265. },
  27266. getCenter: function ( target ) {
  27267. if ( target === undefined ) {
  27268. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  27269. target = new Vector2();
  27270. }
  27271. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  27272. },
  27273. getSize: function ( target ) {
  27274. if ( target === undefined ) {
  27275. console.warn( 'THREE.Box2: .getSize() target is now required' );
  27276. target = new Vector2();
  27277. }
  27278. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  27279. },
  27280. expandByPoint: function ( point ) {
  27281. this.min.min( point );
  27282. this.max.max( point );
  27283. return this;
  27284. },
  27285. expandByVector: function ( vector ) {
  27286. this.min.sub( vector );
  27287. this.max.add( vector );
  27288. return this;
  27289. },
  27290. expandByScalar: function ( scalar ) {
  27291. this.min.addScalar( - scalar );
  27292. this.max.addScalar( scalar );
  27293. return this;
  27294. },
  27295. containsPoint: function ( point ) {
  27296. return point.x < this.min.x || point.x > this.max.x ||
  27297. point.y < this.min.y || point.y > this.max.y ? false : true;
  27298. },
  27299. containsBox: function ( box ) {
  27300. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  27301. this.min.y <= box.min.y && box.max.y <= this.max.y;
  27302. },
  27303. getParameter: function ( point, target ) {
  27304. // This can potentially have a divide by zero if the box
  27305. // has a size dimension of 0.
  27306. if ( target === undefined ) {
  27307. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  27308. target = new Vector2();
  27309. }
  27310. return target.set(
  27311. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  27312. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  27313. );
  27314. },
  27315. intersectsBox: function ( box ) {
  27316. // using 4 splitting planes to rule out intersections
  27317. return box.max.x < this.min.x || box.min.x > this.max.x ||
  27318. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  27319. },
  27320. clampPoint: function ( point, target ) {
  27321. if ( target === undefined ) {
  27322. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  27323. target = new Vector2();
  27324. }
  27325. return target.copy( point ).clamp( this.min, this.max );
  27326. },
  27327. distanceToPoint: function ( point ) {
  27328. var clampedPoint = _vector$6.copy( point ).clamp( this.min, this.max );
  27329. return clampedPoint.sub( point ).length();
  27330. },
  27331. intersect: function ( box ) {
  27332. this.min.max( box.min );
  27333. this.max.min( box.max );
  27334. return this;
  27335. },
  27336. union: function ( box ) {
  27337. this.min.min( box.min );
  27338. this.max.max( box.max );
  27339. return this;
  27340. },
  27341. translate: function ( offset ) {
  27342. this.min.add( offset );
  27343. this.max.add( offset );
  27344. return this;
  27345. },
  27346. equals: function ( box ) {
  27347. return box.min.equals( this.min ) && box.max.equals( this.max );
  27348. }
  27349. } );
  27350. /**
  27351. * @author bhouston / http://clara.io
  27352. */
  27353. var _startP = new Vector3();
  27354. var _startEnd = new Vector3();
  27355. function Line3( start, end ) {
  27356. this.start = ( start !== undefined ) ? start : new Vector3();
  27357. this.end = ( end !== undefined ) ? end : new Vector3();
  27358. }
  27359. Object.assign( Line3.prototype, {
  27360. set: function ( start, end ) {
  27361. this.start.copy( start );
  27362. this.end.copy( end );
  27363. return this;
  27364. },
  27365. clone: function () {
  27366. return new this.constructor().copy( this );
  27367. },
  27368. copy: function ( line ) {
  27369. this.start.copy( line.start );
  27370. this.end.copy( line.end );
  27371. return this;
  27372. },
  27373. getCenter: function ( target ) {
  27374. if ( target === undefined ) {
  27375. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  27376. target = new Vector3();
  27377. }
  27378. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  27379. },
  27380. delta: function ( target ) {
  27381. if ( target === undefined ) {
  27382. console.warn( 'THREE.Line3: .delta() target is now required' );
  27383. target = new Vector3();
  27384. }
  27385. return target.subVectors( this.end, this.start );
  27386. },
  27387. distanceSq: function () {
  27388. return this.start.distanceToSquared( this.end );
  27389. },
  27390. distance: function () {
  27391. return this.start.distanceTo( this.end );
  27392. },
  27393. at: function ( t, target ) {
  27394. if ( target === undefined ) {
  27395. console.warn( 'THREE.Line3: .at() target is now required' );
  27396. target = new Vector3();
  27397. }
  27398. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27399. },
  27400. closestPointToPointParameter: function ( point, clampToLine ) {
  27401. _startP.subVectors( point, this.start );
  27402. _startEnd.subVectors( this.end, this.start );
  27403. var startEnd2 = _startEnd.dot( _startEnd );
  27404. var startEnd_startP = _startEnd.dot( _startP );
  27405. var t = startEnd_startP / startEnd2;
  27406. if ( clampToLine ) {
  27407. t = _Math.clamp( t, 0, 1 );
  27408. }
  27409. return t;
  27410. },
  27411. closestPointToPoint: function ( point, clampToLine, target ) {
  27412. var t = this.closestPointToPointParameter( point, clampToLine );
  27413. if ( target === undefined ) {
  27414. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27415. target = new Vector3();
  27416. }
  27417. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27418. },
  27419. applyMatrix4: function ( matrix ) {
  27420. this.start.applyMatrix4( matrix );
  27421. this.end.applyMatrix4( matrix );
  27422. return this;
  27423. },
  27424. equals: function ( line ) {
  27425. return line.start.equals( this.start ) && line.end.equals( this.end );
  27426. }
  27427. } );
  27428. /**
  27429. * @author alteredq / http://alteredqualia.com/
  27430. */
  27431. function ImmediateRenderObject( material ) {
  27432. Object3D.call( this );
  27433. this.material = material;
  27434. this.render = function ( /* renderCallback */ ) {};
  27435. }
  27436. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27437. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27438. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27439. /**
  27440. * @author mrdoob / http://mrdoob.com/
  27441. * @author WestLangley / http://github.com/WestLangley
  27442. */
  27443. var _v1$5 = new Vector3();
  27444. var _v2$3 = new Vector3();
  27445. var _normalMatrix$1 = new Matrix3();
  27446. var _keys = [ 'a', 'b', 'c' ];
  27447. function VertexNormalsHelper( object, size, hex, linewidth ) {
  27448. this.object = object;
  27449. this.size = ( size !== undefined ) ? size : 1;
  27450. var color = ( hex !== undefined ) ? hex : 0xff0000;
  27451. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27452. //
  27453. var nNormals = 0;
  27454. var objGeometry = this.object.geometry;
  27455. if ( objGeometry && objGeometry.isGeometry ) {
  27456. nNormals = objGeometry.faces.length * 3;
  27457. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27458. nNormals = objGeometry.attributes.normal.count;
  27459. }
  27460. //
  27461. var geometry = new BufferGeometry();
  27462. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27463. geometry.setAttribute( 'position', positions );
  27464. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27465. //
  27466. this.matrixAutoUpdate = false;
  27467. this.update();
  27468. }
  27469. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27470. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  27471. VertexNormalsHelper.prototype.update = function () {
  27472. this.object.updateMatrixWorld( true );
  27473. _normalMatrix$1.getNormalMatrix( this.object.matrixWorld );
  27474. var matrixWorld = this.object.matrixWorld;
  27475. var position = this.geometry.attributes.position;
  27476. //
  27477. var objGeometry = this.object.geometry;
  27478. if ( objGeometry && objGeometry.isGeometry ) {
  27479. var vertices = objGeometry.vertices;
  27480. var faces = objGeometry.faces;
  27481. var idx = 0;
  27482. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27483. var face = faces[ i ];
  27484. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  27485. var vertex = vertices[ face[ _keys[ j ] ] ];
  27486. var normal = face.vertexNormals[ j ];
  27487. _v1$5.copy( vertex ).applyMatrix4( matrixWorld );
  27488. _v2$3.copy( normal ).applyMatrix3( _normalMatrix$1 ).normalize().multiplyScalar( this.size ).add( _v1$5 );
  27489. position.setXYZ( idx, _v1$5.x, _v1$5.y, _v1$5.z );
  27490. idx = idx + 1;
  27491. position.setXYZ( idx, _v2$3.x, _v2$3.y, _v2$3.z );
  27492. idx = idx + 1;
  27493. }
  27494. }
  27495. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27496. var objPos = objGeometry.attributes.position;
  27497. var objNorm = objGeometry.attributes.normal;
  27498. var idx = 0;
  27499. // for simplicity, ignore index and drawcalls, and render every normal
  27500. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  27501. _v1$5.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  27502. _v2$3.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  27503. _v2$3.applyMatrix3( _normalMatrix$1 ).normalize().multiplyScalar( this.size ).add( _v1$5 );
  27504. position.setXYZ( idx, _v1$5.x, _v1$5.y, _v1$5.z );
  27505. idx = idx + 1;
  27506. position.setXYZ( idx, _v2$3.x, _v2$3.y, _v2$3.z );
  27507. idx = idx + 1;
  27508. }
  27509. }
  27510. position.needsUpdate = true;
  27511. };
  27512. /**
  27513. * @author alteredq / http://alteredqualia.com/
  27514. * @author mrdoob / http://mrdoob.com/
  27515. * @author WestLangley / http://github.com/WestLangley
  27516. */
  27517. var _vector$7 = new Vector3();
  27518. function SpotLightHelper( light, color ) {
  27519. Object3D.call( this );
  27520. this.light = light;
  27521. this.light.updateMatrixWorld();
  27522. this.matrix = light.matrixWorld;
  27523. this.matrixAutoUpdate = false;
  27524. this.color = color;
  27525. var geometry = new BufferGeometry();
  27526. var positions = [
  27527. 0, 0, 0, 0, 0, 1,
  27528. 0, 0, 0, 1, 0, 1,
  27529. 0, 0, 0, - 1, 0, 1,
  27530. 0, 0, 0, 0, 1, 1,
  27531. 0, 0, 0, 0, - 1, 1
  27532. ];
  27533. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27534. var p1 = ( i / l ) * Math.PI * 2;
  27535. var p2 = ( j / l ) * Math.PI * 2;
  27536. positions.push(
  27537. Math.cos( p1 ), Math.sin( p1 ), 1,
  27538. Math.cos( p2 ), Math.sin( p2 ), 1
  27539. );
  27540. }
  27541. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27542. var material = new LineBasicMaterial( { fog: false } );
  27543. this.cone = new LineSegments( geometry, material );
  27544. this.add( this.cone );
  27545. this.update();
  27546. }
  27547. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  27548. SpotLightHelper.prototype.constructor = SpotLightHelper;
  27549. SpotLightHelper.prototype.dispose = function () {
  27550. this.cone.geometry.dispose();
  27551. this.cone.material.dispose();
  27552. };
  27553. SpotLightHelper.prototype.update = function () {
  27554. this.light.updateMatrixWorld();
  27555. var coneLength = this.light.distance ? this.light.distance : 1000;
  27556. var coneWidth = coneLength * Math.tan( this.light.angle );
  27557. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  27558. _vector$7.setFromMatrixPosition( this.light.target.matrixWorld );
  27559. this.cone.lookAt( _vector$7 );
  27560. if ( this.color !== undefined ) {
  27561. this.cone.material.color.set( this.color );
  27562. } else {
  27563. this.cone.material.color.copy( this.light.color );
  27564. }
  27565. };
  27566. /**
  27567. * @author Sean Griffin / http://twitter.com/sgrif
  27568. * @author Michael Guerrero / http://realitymeltdown.com
  27569. * @author mrdoob / http://mrdoob.com/
  27570. * @author ikerr / http://verold.com
  27571. * @author Mugen87 / https://github.com/Mugen87
  27572. */
  27573. var _vector$8 = new Vector3();
  27574. var _boneMatrix = new Matrix4();
  27575. var _matrixWorldInv = new Matrix4();
  27576. function getBoneList( object ) {
  27577. var boneList = [];
  27578. if ( object && object.isBone ) {
  27579. boneList.push( object );
  27580. }
  27581. for ( var i = 0; i < object.children.length; i ++ ) {
  27582. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  27583. }
  27584. return boneList;
  27585. }
  27586. function SkeletonHelper( object ) {
  27587. var bones = getBoneList( object );
  27588. var geometry = new BufferGeometry();
  27589. var vertices = [];
  27590. var colors = [];
  27591. var color1 = new Color( 0, 0, 1 );
  27592. var color2 = new Color( 0, 1, 0 );
  27593. for ( var i = 0; i < bones.length; i ++ ) {
  27594. var bone = bones[ i ];
  27595. if ( bone.parent && bone.parent.isBone ) {
  27596. vertices.push( 0, 0, 0 );
  27597. vertices.push( 0, 0, 0 );
  27598. colors.push( color1.r, color1.g, color1.b );
  27599. colors.push( color2.r, color2.g, color2.b );
  27600. }
  27601. }
  27602. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27603. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27604. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  27605. LineSegments.call( this, geometry, material );
  27606. this.root = object;
  27607. this.bones = bones;
  27608. this.matrix = object.matrixWorld;
  27609. this.matrixAutoUpdate = false;
  27610. }
  27611. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  27612. SkeletonHelper.prototype.constructor = SkeletonHelper;
  27613. SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
  27614. var bones = this.bones;
  27615. var geometry = this.geometry;
  27616. var position = geometry.getAttribute( 'position' );
  27617. _matrixWorldInv.getInverse( this.root.matrixWorld );
  27618. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  27619. var bone = bones[ i ];
  27620. if ( bone.parent && bone.parent.isBone ) {
  27621. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  27622. _vector$8.setFromMatrixPosition( _boneMatrix );
  27623. position.setXYZ( j, _vector$8.x, _vector$8.y, _vector$8.z );
  27624. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  27625. _vector$8.setFromMatrixPosition( _boneMatrix );
  27626. position.setXYZ( j + 1, _vector$8.x, _vector$8.y, _vector$8.z );
  27627. j += 2;
  27628. }
  27629. }
  27630. geometry.getAttribute( 'position' ).needsUpdate = true;
  27631. Object3D.prototype.updateMatrixWorld.call( this, force );
  27632. };
  27633. /**
  27634. * @author alteredq / http://alteredqualia.com/
  27635. * @author mrdoob / http://mrdoob.com/
  27636. */
  27637. function PointLightHelper( light, sphereSize, color ) {
  27638. this.light = light;
  27639. this.light.updateMatrixWorld();
  27640. this.color = color;
  27641. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  27642. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27643. Mesh.call( this, geometry, material );
  27644. this.matrix = this.light.matrixWorld;
  27645. this.matrixAutoUpdate = false;
  27646. this.update();
  27647. /*
  27648. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27649. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27650. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27651. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27652. var d = light.distance;
  27653. if ( d === 0.0 ) {
  27654. this.lightDistance.visible = false;
  27655. } else {
  27656. this.lightDistance.scale.set( d, d, d );
  27657. }
  27658. this.add( this.lightDistance );
  27659. */
  27660. }
  27661. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27662. PointLightHelper.prototype.constructor = PointLightHelper;
  27663. PointLightHelper.prototype.dispose = function () {
  27664. this.geometry.dispose();
  27665. this.material.dispose();
  27666. };
  27667. PointLightHelper.prototype.update = function () {
  27668. if ( this.color !== undefined ) {
  27669. this.material.color.set( this.color );
  27670. } else {
  27671. this.material.color.copy( this.light.color );
  27672. }
  27673. /*
  27674. var d = this.light.distance;
  27675. if ( d === 0.0 ) {
  27676. this.lightDistance.visible = false;
  27677. } else {
  27678. this.lightDistance.visible = true;
  27679. this.lightDistance.scale.set( d, d, d );
  27680. }
  27681. */
  27682. };
  27683. /**
  27684. * @author abelnation / http://github.com/abelnation
  27685. * @author Mugen87 / http://github.com/Mugen87
  27686. * @author WestLangley / http://github.com/WestLangley
  27687. *
  27688. * This helper must be added as a child of the light
  27689. */
  27690. function RectAreaLightHelper( light, color ) {
  27691. this.type = 'RectAreaLightHelper';
  27692. this.light = light;
  27693. this.color = color; // optional hardwired color for the helper
  27694. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27695. var geometry = new BufferGeometry();
  27696. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27697. geometry.computeBoundingSphere();
  27698. var material = new LineBasicMaterial( { fog: false } );
  27699. Line.call( this, geometry, material );
  27700. //
  27701. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27702. var geometry2 = new BufferGeometry();
  27703. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27704. geometry2.computeBoundingSphere();
  27705. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27706. this.update();
  27707. }
  27708. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27709. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27710. RectAreaLightHelper.prototype.update = function () {
  27711. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27712. if ( this.color !== undefined ) {
  27713. this.material.color.set( this.color );
  27714. this.children[ 0 ].material.color.set( this.color );
  27715. } else {
  27716. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27717. // prevent hue shift
  27718. var c = this.material.color;
  27719. var max = Math.max( c.r, c.g, c.b );
  27720. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27721. this.children[ 0 ].material.color.copy( this.material.color );
  27722. }
  27723. };
  27724. RectAreaLightHelper.prototype.dispose = function () {
  27725. this.geometry.dispose();
  27726. this.material.dispose();
  27727. this.children[ 0 ].geometry.dispose();
  27728. this.children[ 0 ].material.dispose();
  27729. };
  27730. /**
  27731. * @author alteredq / http://alteredqualia.com/
  27732. * @author mrdoob / http://mrdoob.com/
  27733. * @author Mugen87 / https://github.com/Mugen87
  27734. */
  27735. var _vector$9 = new Vector3();
  27736. var _color1 = new Color();
  27737. var _color2 = new Color();
  27738. function HemisphereLightHelper( light, size, color ) {
  27739. Object3D.call( this );
  27740. this.light = light;
  27741. this.light.updateMatrixWorld();
  27742. this.matrix = light.matrixWorld;
  27743. this.matrixAutoUpdate = false;
  27744. this.color = color;
  27745. var geometry = new OctahedronBufferGeometry( size );
  27746. geometry.rotateY( Math.PI * 0.5 );
  27747. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27748. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27749. var position = geometry.getAttribute( 'position' );
  27750. var colors = new Float32Array( position.count * 3 );
  27751. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27752. this.add( new Mesh( geometry, this.material ) );
  27753. this.update();
  27754. }
  27755. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27756. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27757. HemisphereLightHelper.prototype.dispose = function () {
  27758. this.children[ 0 ].geometry.dispose();
  27759. this.children[ 0 ].material.dispose();
  27760. };
  27761. HemisphereLightHelper.prototype.update = function () {
  27762. var mesh = this.children[ 0 ];
  27763. if ( this.color !== undefined ) {
  27764. this.material.color.set( this.color );
  27765. } else {
  27766. var colors = mesh.geometry.getAttribute( 'color' );
  27767. _color1.copy( this.light.color );
  27768. _color2.copy( this.light.groundColor );
  27769. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27770. var color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  27771. colors.setXYZ( i, color.r, color.g, color.b );
  27772. }
  27773. colors.needsUpdate = true;
  27774. }
  27775. mesh.lookAt( _vector$9.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27776. };
  27777. /**
  27778. * @author WestLangley / http://github.com/WestLangley
  27779. */
  27780. function LightProbeHelper( lightProbe, size ) {
  27781. this.lightProbe = lightProbe;
  27782. this.size = size;
  27783. var defines = {};
  27784. defines[ 'GAMMA_OUTPUT' ] = "";
  27785. // material
  27786. var material = new ShaderMaterial( {
  27787. defines: defines,
  27788. uniforms: {
  27789. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  27790. intensity: { value: this.lightProbe.intensity }
  27791. },
  27792. vertexShader: [
  27793. 'varying vec3 vNormal;',
  27794. 'void main() {',
  27795. ' vNormal = normalize( normalMatrix * normal );',
  27796. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  27797. '}',
  27798. ].join( '\n' ),
  27799. fragmentShader: [
  27800. '#define RECIPROCAL_PI 0.318309886',
  27801. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  27802. ' // matrix is assumed to be orthogonal',
  27803. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  27804. '}',
  27805. 'vec3 linearToOutput( in vec3 a ) {',
  27806. ' #ifdef GAMMA_OUTPUT',
  27807. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  27808. ' #else',
  27809. ' return a;',
  27810. ' #endif',
  27811. '}',
  27812. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  27813. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  27814. ' // normal is assumed to have unit length',
  27815. ' float x = normal.x, y = normal.y, z = normal.z;',
  27816. ' // band 0',
  27817. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  27818. ' // band 1',
  27819. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  27820. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  27821. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  27822. ' // band 2',
  27823. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  27824. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  27825. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  27826. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  27827. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  27828. ' return result;',
  27829. '}',
  27830. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  27831. 'uniform float intensity; // light probe intensity',
  27832. 'varying vec3 vNormal;',
  27833. 'void main() {',
  27834. ' vec3 normal = normalize( vNormal );',
  27835. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  27836. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  27837. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  27838. ' outgoingLight = linearToOutput( outgoingLight );',
  27839. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  27840. '}'
  27841. ].join( '\n' )
  27842. } );
  27843. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  27844. Mesh.call( this, geometry, material );
  27845. this.onBeforeRender();
  27846. }
  27847. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  27848. LightProbeHelper.prototype.constructor = LightProbeHelper;
  27849. LightProbeHelper.prototype.dispose = function () {
  27850. this.geometry.dispose();
  27851. this.material.dispose();
  27852. };
  27853. LightProbeHelper.prototype.onBeforeRender = function () {
  27854. this.position.copy( this.lightProbe.position );
  27855. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  27856. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  27857. };
  27858. /**
  27859. * @author mrdoob / http://mrdoob.com/
  27860. */
  27861. function GridHelper( size, divisions, color1, color2 ) {
  27862. size = size || 10;
  27863. divisions = divisions || 10;
  27864. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27865. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27866. var center = divisions / 2;
  27867. var step = size / divisions;
  27868. var halfSize = size / 2;
  27869. var vertices = [], colors = [];
  27870. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27871. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27872. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27873. var color = i === center ? color1 : color2;
  27874. color.toArray( colors, j ); j += 3;
  27875. color.toArray( colors, j ); j += 3;
  27876. color.toArray( colors, j ); j += 3;
  27877. color.toArray( colors, j ); j += 3;
  27878. }
  27879. var geometry = new BufferGeometry();
  27880. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27881. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27882. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27883. LineSegments.call( this, geometry, material );
  27884. }
  27885. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27886. constructor: GridHelper,
  27887. copy: function ( source ) {
  27888. LineSegments.prototype.copy.call( this, source );
  27889. this.geometry.copy( source.geometry );
  27890. this.material.copy( source.material );
  27891. return this;
  27892. },
  27893. clone: function () {
  27894. return new this.constructor().copy( this );
  27895. }
  27896. } );
  27897. /**
  27898. * @author mrdoob / http://mrdoob.com/
  27899. * @author Mugen87 / http://github.com/Mugen87
  27900. * @author Hectate / http://www.github.com/Hectate
  27901. */
  27902. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27903. radius = radius || 10;
  27904. radials = radials || 16;
  27905. circles = circles || 8;
  27906. divisions = divisions || 64;
  27907. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27908. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27909. var vertices = [];
  27910. var colors = [];
  27911. var x, z;
  27912. var v, i, j, r, color;
  27913. // create the radials
  27914. for ( i = 0; i <= radials; i ++ ) {
  27915. v = ( i / radials ) * ( Math.PI * 2 );
  27916. x = Math.sin( v ) * radius;
  27917. z = Math.cos( v ) * radius;
  27918. vertices.push( 0, 0, 0 );
  27919. vertices.push( x, 0, z );
  27920. color = ( i & 1 ) ? color1 : color2;
  27921. colors.push( color.r, color.g, color.b );
  27922. colors.push( color.r, color.g, color.b );
  27923. }
  27924. // create the circles
  27925. for ( i = 0; i <= circles; i ++ ) {
  27926. color = ( i & 1 ) ? color1 : color2;
  27927. r = radius - ( radius / circles * i );
  27928. for ( j = 0; j < divisions; j ++ ) {
  27929. // first vertex
  27930. v = ( j / divisions ) * ( Math.PI * 2 );
  27931. x = Math.sin( v ) * r;
  27932. z = Math.cos( v ) * r;
  27933. vertices.push( x, 0, z );
  27934. colors.push( color.r, color.g, color.b );
  27935. // second vertex
  27936. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27937. x = Math.sin( v ) * r;
  27938. z = Math.cos( v ) * r;
  27939. vertices.push( x, 0, z );
  27940. colors.push( color.r, color.g, color.b );
  27941. }
  27942. }
  27943. var geometry = new BufferGeometry();
  27944. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27945. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27946. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27947. LineSegments.call( this, geometry, material );
  27948. }
  27949. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27950. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27951. /**
  27952. * @author Mugen87 / http://github.com/Mugen87
  27953. */
  27954. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27955. this.audio = audio;
  27956. this.range = range || 1;
  27957. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27958. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27959. var geometry = new BufferGeometry();
  27960. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27961. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27962. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27963. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27964. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27965. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27966. this.update();
  27967. }
  27968. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27969. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27970. PositionalAudioHelper.prototype.update = function () {
  27971. var audio = this.audio;
  27972. var range = this.range;
  27973. var divisionsInnerAngle = this.divisionsInnerAngle;
  27974. var divisionsOuterAngle = this.divisionsOuterAngle;
  27975. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27976. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27977. var halfConeInnerAngle = coneInnerAngle / 2;
  27978. var halfConeOuterAngle = coneOuterAngle / 2;
  27979. var start = 0;
  27980. var count = 0;
  27981. var i, stride;
  27982. var geometry = this.geometry;
  27983. var positionAttribute = geometry.attributes.position;
  27984. geometry.clearGroups();
  27985. //
  27986. function generateSegment( from, to, divisions, materialIndex ) {
  27987. var step = ( to - from ) / divisions;
  27988. positionAttribute.setXYZ( start, 0, 0, 0 );
  27989. count ++;
  27990. for ( i = from; i < to; i += step ) {
  27991. stride = start + count;
  27992. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27993. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27994. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27995. count += 3;
  27996. }
  27997. geometry.addGroup( start, count, materialIndex );
  27998. start += count;
  27999. count = 0;
  28000. }
  28001. //
  28002. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  28003. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  28004. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  28005. //
  28006. positionAttribute.needsUpdate = true;
  28007. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  28008. };
  28009. PositionalAudioHelper.prototype.dispose = function () {
  28010. this.geometry.dispose();
  28011. this.material[ 0 ].dispose();
  28012. this.material[ 1 ].dispose();
  28013. };
  28014. /**
  28015. * @author mrdoob / http://mrdoob.com/
  28016. * @author WestLangley / http://github.com/WestLangley
  28017. */
  28018. var _v1$6 = new Vector3();
  28019. var _v2$4 = new Vector3();
  28020. var _normalMatrix$2 = new Matrix3();
  28021. function FaceNormalsHelper( object, size, hex, linewidth ) {
  28022. // FaceNormalsHelper only supports THREE.Geometry
  28023. this.object = object;
  28024. this.size = ( size !== undefined ) ? size : 1;
  28025. var color = ( hex !== undefined ) ? hex : 0xffff00;
  28026. var width = ( linewidth !== undefined ) ? linewidth : 1;
  28027. //
  28028. var nNormals = 0;
  28029. var objGeometry = this.object.geometry;
  28030. if ( objGeometry && objGeometry.isGeometry ) {
  28031. nNormals = objGeometry.faces.length;
  28032. } else {
  28033. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  28034. }
  28035. //
  28036. var geometry = new BufferGeometry();
  28037. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  28038. geometry.setAttribute( 'position', positions );
  28039. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  28040. //
  28041. this.matrixAutoUpdate = false;
  28042. this.update();
  28043. }
  28044. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  28045. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  28046. FaceNormalsHelper.prototype.update = function () {
  28047. this.object.updateMatrixWorld( true );
  28048. _normalMatrix$2.getNormalMatrix( this.object.matrixWorld );
  28049. var matrixWorld = this.object.matrixWorld;
  28050. var position = this.geometry.attributes.position;
  28051. //
  28052. var objGeometry = this.object.geometry;
  28053. var vertices = objGeometry.vertices;
  28054. var faces = objGeometry.faces;
  28055. var idx = 0;
  28056. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  28057. var face = faces[ i ];
  28058. var normal = face.normal;
  28059. _v1$6.copy( vertices[ face.a ] )
  28060. .add( vertices[ face.b ] )
  28061. .add( vertices[ face.c ] )
  28062. .divideScalar( 3 )
  28063. .applyMatrix4( matrixWorld );
  28064. _v2$4.copy( normal ).applyMatrix3( _normalMatrix$2 ).normalize().multiplyScalar( this.size ).add( _v1$6 );
  28065. position.setXYZ( idx, _v1$6.x, _v1$6.y, _v1$6.z );
  28066. idx = idx + 1;
  28067. position.setXYZ( idx, _v2$4.x, _v2$4.y, _v2$4.z );
  28068. idx = idx + 1;
  28069. }
  28070. position.needsUpdate = true;
  28071. };
  28072. /**
  28073. * @author alteredq / http://alteredqualia.com/
  28074. * @author mrdoob / http://mrdoob.com/
  28075. * @author WestLangley / http://github.com/WestLangley
  28076. */
  28077. var _v1$7 = new Vector3();
  28078. var _v2$5 = new Vector3();
  28079. var _v3$1 = new Vector3();
  28080. function DirectionalLightHelper( light, size, color ) {
  28081. Object3D.call( this );
  28082. this.light = light;
  28083. this.light.updateMatrixWorld();
  28084. this.matrix = light.matrixWorld;
  28085. this.matrixAutoUpdate = false;
  28086. this.color = color;
  28087. if ( size === undefined ) size = 1;
  28088. var geometry = new BufferGeometry();
  28089. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  28090. - size, size, 0,
  28091. size, size, 0,
  28092. size, - size, 0,
  28093. - size, - size, 0,
  28094. - size, size, 0
  28095. ], 3 ) );
  28096. var material = new LineBasicMaterial( { fog: false } );
  28097. this.lightPlane = new Line( geometry, material );
  28098. this.add( this.lightPlane );
  28099. geometry = new BufferGeometry();
  28100. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  28101. this.targetLine = new Line( geometry, material );
  28102. this.add( this.targetLine );
  28103. this.update();
  28104. }
  28105. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  28106. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  28107. DirectionalLightHelper.prototype.dispose = function () {
  28108. this.lightPlane.geometry.dispose();
  28109. this.lightPlane.material.dispose();
  28110. this.targetLine.geometry.dispose();
  28111. this.targetLine.material.dispose();
  28112. };
  28113. DirectionalLightHelper.prototype.update = function () {
  28114. _v1$7.setFromMatrixPosition( this.light.matrixWorld );
  28115. _v2$5.setFromMatrixPosition( this.light.target.matrixWorld );
  28116. _v3$1.subVectors( _v2$5, _v1$7 );
  28117. this.lightPlane.lookAt( _v2$5 );
  28118. if ( this.color !== undefined ) {
  28119. this.lightPlane.material.color.set( this.color );
  28120. this.targetLine.material.color.set( this.color );
  28121. } else {
  28122. this.lightPlane.material.color.copy( this.light.color );
  28123. this.targetLine.material.color.copy( this.light.color );
  28124. }
  28125. this.targetLine.lookAt( _v2$5 );
  28126. this.targetLine.scale.z = _v3$1.length();
  28127. };
  28128. /**
  28129. * @author alteredq / http://alteredqualia.com/
  28130. * @author Mugen87 / https://github.com/Mugen87
  28131. *
  28132. * - shows frustum, line of sight and up of the camera
  28133. * - suitable for fast updates
  28134. * - based on frustum visualization in lightgl.js shadowmap example
  28135. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28136. */
  28137. var _vector$a = new Vector3();
  28138. var _camera = new Camera();
  28139. function CameraHelper( camera ) {
  28140. var geometry = new BufferGeometry();
  28141. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  28142. var vertices = [];
  28143. var colors = [];
  28144. var pointMap = {};
  28145. // colors
  28146. var colorFrustum = new Color( 0xffaa00 );
  28147. var colorCone = new Color( 0xff0000 );
  28148. var colorUp = new Color( 0x00aaff );
  28149. var colorTarget = new Color( 0xffffff );
  28150. var colorCross = new Color( 0x333333 );
  28151. // near
  28152. addLine( 'n1', 'n2', colorFrustum );
  28153. addLine( 'n2', 'n4', colorFrustum );
  28154. addLine( 'n4', 'n3', colorFrustum );
  28155. addLine( 'n3', 'n1', colorFrustum );
  28156. // far
  28157. addLine( 'f1', 'f2', colorFrustum );
  28158. addLine( 'f2', 'f4', colorFrustum );
  28159. addLine( 'f4', 'f3', colorFrustum );
  28160. addLine( 'f3', 'f1', colorFrustum );
  28161. // sides
  28162. addLine( 'n1', 'f1', colorFrustum );
  28163. addLine( 'n2', 'f2', colorFrustum );
  28164. addLine( 'n3', 'f3', colorFrustum );
  28165. addLine( 'n4', 'f4', colorFrustum );
  28166. // cone
  28167. addLine( 'p', 'n1', colorCone );
  28168. addLine( 'p', 'n2', colorCone );
  28169. addLine( 'p', 'n3', colorCone );
  28170. addLine( 'p', 'n4', colorCone );
  28171. // up
  28172. addLine( 'u1', 'u2', colorUp );
  28173. addLine( 'u2', 'u3', colorUp );
  28174. addLine( 'u3', 'u1', colorUp );
  28175. // target
  28176. addLine( 'c', 't', colorTarget );
  28177. addLine( 'p', 'c', colorCross );
  28178. // cross
  28179. addLine( 'cn1', 'cn2', colorCross );
  28180. addLine( 'cn3', 'cn4', colorCross );
  28181. addLine( 'cf1', 'cf2', colorCross );
  28182. addLine( 'cf3', 'cf4', colorCross );
  28183. function addLine( a, b, color ) {
  28184. addPoint( a, color );
  28185. addPoint( b, color );
  28186. }
  28187. function addPoint( id, color ) {
  28188. vertices.push( 0, 0, 0 );
  28189. colors.push( color.r, color.g, color.b );
  28190. if ( pointMap[ id ] === undefined ) {
  28191. pointMap[ id ] = [];
  28192. }
  28193. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  28194. }
  28195. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28196. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28197. LineSegments.call( this, geometry, material );
  28198. this.camera = camera;
  28199. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  28200. this.matrix = camera.matrixWorld;
  28201. this.matrixAutoUpdate = false;
  28202. this.pointMap = pointMap;
  28203. this.update();
  28204. }
  28205. CameraHelper.prototype = Object.create( LineSegments.prototype );
  28206. CameraHelper.prototype.constructor = CameraHelper;
  28207. CameraHelper.prototype.update = function () {
  28208. var geometry = this.geometry;
  28209. var pointMap = this.pointMap;
  28210. var w = 1, h = 1;
  28211. // we need just camera projection matrix inverse
  28212. // world matrix must be identity
  28213. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  28214. // center / target
  28215. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  28216. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  28217. // near
  28218. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  28219. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  28220. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  28221. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  28222. // far
  28223. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  28224. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  28225. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  28226. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  28227. // up
  28228. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  28229. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  28230. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  28231. // cross
  28232. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  28233. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  28234. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  28235. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  28236. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  28237. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  28238. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  28239. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  28240. geometry.getAttribute( 'position' ).needsUpdate = true;
  28241. };
  28242. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  28243. _vector$a.set( x, y, z ).unproject( camera );
  28244. var points = pointMap[ point ];
  28245. if ( points !== undefined ) {
  28246. var position = geometry.getAttribute( 'position' );
  28247. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28248. position.setXYZ( points[ i ], _vector$a.x, _vector$a.y, _vector$a.z );
  28249. }
  28250. }
  28251. }
  28252. /**
  28253. * @author mrdoob / http://mrdoob.com/
  28254. * @author Mugen87 / http://github.com/Mugen87
  28255. */
  28256. var _box$3 = new Box3();
  28257. function BoxHelper( object, color ) {
  28258. this.object = object;
  28259. if ( color === undefined ) color = 0xffff00;
  28260. 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 ] );
  28261. var positions = new Float32Array( 8 * 3 );
  28262. var geometry = new BufferGeometry();
  28263. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28264. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28265. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  28266. this.matrixAutoUpdate = false;
  28267. this.update();
  28268. }
  28269. BoxHelper.prototype = Object.create( LineSegments.prototype );
  28270. BoxHelper.prototype.constructor = BoxHelper;
  28271. BoxHelper.prototype.update = function ( object ) {
  28272. if ( object !== undefined ) {
  28273. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28274. }
  28275. if ( this.object !== undefined ) {
  28276. _box$3.setFromObject( this.object );
  28277. }
  28278. if ( _box$3.isEmpty() ) return;
  28279. var min = _box$3.min;
  28280. var max = _box$3.max;
  28281. /*
  28282. 5____4
  28283. 1/___0/|
  28284. | 6__|_7
  28285. 2/___3/
  28286. 0: max.x, max.y, max.z
  28287. 1: min.x, max.y, max.z
  28288. 2: min.x, min.y, max.z
  28289. 3: max.x, min.y, max.z
  28290. 4: max.x, max.y, min.z
  28291. 5: min.x, max.y, min.z
  28292. 6: min.x, min.y, min.z
  28293. 7: max.x, min.y, min.z
  28294. */
  28295. var position = this.geometry.attributes.position;
  28296. var array = position.array;
  28297. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28298. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28299. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28300. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28301. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28302. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28303. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28304. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28305. position.needsUpdate = true;
  28306. this.geometry.computeBoundingSphere();
  28307. };
  28308. BoxHelper.prototype.setFromObject = function ( object ) {
  28309. this.object = object;
  28310. this.update();
  28311. return this;
  28312. };
  28313. BoxHelper.prototype.copy = function ( source ) {
  28314. LineSegments.prototype.copy.call( this, source );
  28315. this.object = source.object;
  28316. return this;
  28317. };
  28318. BoxHelper.prototype.clone = function () {
  28319. return new this.constructor().copy( this );
  28320. };
  28321. /**
  28322. * @author WestLangley / http://github.com/WestLangley
  28323. */
  28324. function Box3Helper( box, color ) {
  28325. this.type = 'Box3Helper';
  28326. this.box = box;
  28327. color = color || 0xffff00;
  28328. 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 ] );
  28329. 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 ];
  28330. var geometry = new BufferGeometry();
  28331. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28332. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28333. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  28334. this.geometry.computeBoundingSphere();
  28335. }
  28336. Box3Helper.prototype = Object.create( LineSegments.prototype );
  28337. Box3Helper.prototype.constructor = Box3Helper;
  28338. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  28339. var box = this.box;
  28340. if ( box.isEmpty() ) return;
  28341. box.getCenter( this.position );
  28342. box.getSize( this.scale );
  28343. this.scale.multiplyScalar( 0.5 );
  28344. Object3D.prototype.updateMatrixWorld.call( this, force );
  28345. };
  28346. /**
  28347. * @author WestLangley / http://github.com/WestLangley
  28348. */
  28349. function PlaneHelper( plane, size, hex ) {
  28350. this.type = 'PlaneHelper';
  28351. this.plane = plane;
  28352. this.size = ( size === undefined ) ? 1 : size;
  28353. var color = ( hex !== undefined ) ? hex : 0xffff00;
  28354. 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 ];
  28355. var geometry = new BufferGeometry();
  28356. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28357. geometry.computeBoundingSphere();
  28358. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  28359. //
  28360. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28361. var geometry2 = new BufferGeometry();
  28362. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28363. geometry2.computeBoundingSphere();
  28364. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  28365. }
  28366. PlaneHelper.prototype = Object.create( Line.prototype );
  28367. PlaneHelper.prototype.constructor = PlaneHelper;
  28368. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  28369. var scale = - this.plane.constant;
  28370. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28371. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28372. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28373. this.lookAt( this.plane.normal );
  28374. Object3D.prototype.updateMatrixWorld.call( this, force );
  28375. };
  28376. /**
  28377. * @author WestLangley / http://github.com/WestLangley
  28378. * @author zz85 / http://github.com/zz85
  28379. * @author bhouston / http://clara.io
  28380. *
  28381. * Creates an arrow for visualizing directions
  28382. *
  28383. * Parameters:
  28384. * dir - Vector3
  28385. * origin - Vector3
  28386. * length - Number
  28387. * color - color in hex value
  28388. * headLength - Number
  28389. * headWidth - Number
  28390. */
  28391. var _axis = new Vector3();
  28392. var _lineGeometry, _coneGeometry;
  28393. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  28394. // dir is assumed to be normalized
  28395. Object3D.call( this );
  28396. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28397. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28398. if ( length === undefined ) length = 1;
  28399. if ( color === undefined ) color = 0xffff00;
  28400. if ( headLength === undefined ) headLength = 0.2 * length;
  28401. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28402. if ( _lineGeometry === undefined ) {
  28403. _lineGeometry = new BufferGeometry();
  28404. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28405. _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28406. _coneGeometry.translate( 0, - 0.5, 0 );
  28407. }
  28408. this.position.copy( origin );
  28409. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color } ) );
  28410. this.line.matrixAutoUpdate = false;
  28411. this.add( this.line );
  28412. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color } ) );
  28413. this.cone.matrixAutoUpdate = false;
  28414. this.add( this.cone );
  28415. this.setDirection( dir );
  28416. this.setLength( length, headLength, headWidth );
  28417. }
  28418. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28419. ArrowHelper.prototype.constructor = ArrowHelper;
  28420. ArrowHelper.prototype.setDirection = function ( dir ) {
  28421. // dir is assumed to be normalized
  28422. if ( dir.y > 0.99999 ) {
  28423. this.quaternion.set( 0, 0, 0, 1 );
  28424. } else if ( dir.y < - 0.99999 ) {
  28425. this.quaternion.set( 1, 0, 0, 0 );
  28426. } else {
  28427. _axis.set( dir.z, 0, - dir.x ).normalize();
  28428. var radians = Math.acos( dir.y );
  28429. this.quaternion.setFromAxisAngle( _axis, radians );
  28430. }
  28431. };
  28432. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28433. if ( headLength === undefined ) headLength = 0.2 * length;
  28434. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28435. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  28436. this.line.updateMatrix();
  28437. this.cone.scale.set( headWidth, headLength, headWidth );
  28438. this.cone.position.y = length;
  28439. this.cone.updateMatrix();
  28440. };
  28441. ArrowHelper.prototype.setColor = function ( color ) {
  28442. this.line.material.color.set( color );
  28443. this.cone.material.color.set( color );
  28444. };
  28445. ArrowHelper.prototype.copy = function ( source ) {
  28446. Object3D.prototype.copy.call( this, source, false );
  28447. this.line.copy( source.line );
  28448. this.cone.copy( source.cone );
  28449. return this;
  28450. };
  28451. ArrowHelper.prototype.clone = function () {
  28452. return new this.constructor().copy( this );
  28453. };
  28454. /**
  28455. * @author sroucheray / http://sroucheray.org/
  28456. * @author mrdoob / http://mrdoob.com/
  28457. */
  28458. function AxesHelper( size ) {
  28459. size = size || 1;
  28460. var vertices = [
  28461. 0, 0, 0, size, 0, 0,
  28462. 0, 0, 0, 0, size, 0,
  28463. 0, 0, 0, 0, 0, size
  28464. ];
  28465. var colors = [
  28466. 1, 0, 0, 1, 0.6, 0,
  28467. 0, 1, 0, 0.6, 1, 0,
  28468. 0, 0, 1, 0, 0.6, 1
  28469. ];
  28470. var geometry = new BufferGeometry();
  28471. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28472. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28473. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28474. LineSegments.call( this, geometry, material );
  28475. }
  28476. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28477. AxesHelper.prototype.constructor = AxesHelper;
  28478. /**
  28479. * @author mrdoob / http://mrdoob.com/
  28480. */
  28481. function Face4( a, b, c, d, normal, color, materialIndex ) {
  28482. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  28483. return new Face3( a, b, c, normal, color, materialIndex );
  28484. }
  28485. var LineStrip = 0;
  28486. var LinePieces = 1;
  28487. function MeshFaceMaterial( materials ) {
  28488. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28489. return materials;
  28490. }
  28491. function MultiMaterial( materials ) {
  28492. if ( materials === undefined ) materials = [];
  28493. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28494. materials.isMultiMaterial = true;
  28495. materials.materials = materials;
  28496. materials.clone = function () {
  28497. return materials.slice();
  28498. };
  28499. return materials;
  28500. }
  28501. function PointCloud( geometry, material ) {
  28502. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28503. return new Points( geometry, material );
  28504. }
  28505. function Particle( material ) {
  28506. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28507. return new Sprite( material );
  28508. }
  28509. function ParticleSystem( geometry, material ) {
  28510. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28511. return new Points( geometry, material );
  28512. }
  28513. function PointCloudMaterial( parameters ) {
  28514. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28515. return new PointsMaterial( parameters );
  28516. }
  28517. function ParticleBasicMaterial( parameters ) {
  28518. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28519. return new PointsMaterial( parameters );
  28520. }
  28521. function ParticleSystemMaterial( parameters ) {
  28522. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  28523. return new PointsMaterial( parameters );
  28524. }
  28525. function Vertex( x, y, z ) {
  28526. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  28527. return new Vector3( x, y, z );
  28528. }
  28529. //
  28530. function DynamicBufferAttribute( array, itemSize ) {
  28531. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  28532. return new BufferAttribute( array, itemSize ).setDynamic( true );
  28533. }
  28534. function Int8Attribute( array, itemSize ) {
  28535. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  28536. return new Int8BufferAttribute( array, itemSize );
  28537. }
  28538. function Uint8Attribute( array, itemSize ) {
  28539. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  28540. return new Uint8BufferAttribute( array, itemSize );
  28541. }
  28542. function Uint8ClampedAttribute( array, itemSize ) {
  28543. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  28544. return new Uint8ClampedBufferAttribute( array, itemSize );
  28545. }
  28546. function Int16Attribute( array, itemSize ) {
  28547. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  28548. return new Int16BufferAttribute( array, itemSize );
  28549. }
  28550. function Uint16Attribute( array, itemSize ) {
  28551. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  28552. return new Uint16BufferAttribute( array, itemSize );
  28553. }
  28554. function Int32Attribute( array, itemSize ) {
  28555. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28556. return new Int32BufferAttribute( array, itemSize );
  28557. }
  28558. function Uint32Attribute( array, itemSize ) {
  28559. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28560. return new Uint32BufferAttribute( array, itemSize );
  28561. }
  28562. function Float32Attribute( array, itemSize ) {
  28563. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28564. return new Float32BufferAttribute( array, itemSize );
  28565. }
  28566. function Float64Attribute( array, itemSize ) {
  28567. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28568. return new Float64BufferAttribute( array, itemSize );
  28569. }
  28570. //
  28571. Curve.create = function ( construct, getPoint ) {
  28572. console.log( 'THREE.Curve.create() has been deprecated' );
  28573. construct.prototype = Object.create( Curve.prototype );
  28574. construct.prototype.constructor = construct;
  28575. construct.prototype.getPoint = getPoint;
  28576. return construct;
  28577. };
  28578. //
  28579. Object.assign( CurvePath.prototype, {
  28580. createPointsGeometry: function ( divisions ) {
  28581. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28582. // generate geometry from path points (for Line or Points objects)
  28583. var pts = this.getPoints( divisions );
  28584. return this.createGeometry( pts );
  28585. },
  28586. createSpacedPointsGeometry: function ( divisions ) {
  28587. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28588. // generate geometry from equidistant sampling along the path
  28589. var pts = this.getSpacedPoints( divisions );
  28590. return this.createGeometry( pts );
  28591. },
  28592. createGeometry: function ( points ) {
  28593. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28594. var geometry = new Geometry();
  28595. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28596. var point = points[ i ];
  28597. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  28598. }
  28599. return geometry;
  28600. }
  28601. } );
  28602. //
  28603. Object.assign( Path.prototype, {
  28604. fromPoints: function ( points ) {
  28605. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28606. return this.setFromPoints( points );
  28607. }
  28608. } );
  28609. //
  28610. function ClosedSplineCurve3( points ) {
  28611. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28612. CatmullRomCurve3.call( this, points );
  28613. this.type = 'catmullrom';
  28614. this.closed = true;
  28615. }
  28616. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28617. //
  28618. function SplineCurve3( points ) {
  28619. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28620. CatmullRomCurve3.call( this, points );
  28621. this.type = 'catmullrom';
  28622. }
  28623. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28624. //
  28625. function Spline( points ) {
  28626. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28627. CatmullRomCurve3.call( this, points );
  28628. this.type = 'catmullrom';
  28629. }
  28630. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28631. Object.assign( Spline.prototype, {
  28632. initFromArray: function ( /* a */ ) {
  28633. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28634. },
  28635. getControlPointsArray: function ( /* optionalTarget */ ) {
  28636. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28637. },
  28638. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  28639. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  28640. }
  28641. } );
  28642. //
  28643. function AxisHelper( size ) {
  28644. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28645. return new AxesHelper( size );
  28646. }
  28647. function BoundingBoxHelper( object, color ) {
  28648. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28649. return new BoxHelper( object, color );
  28650. }
  28651. function EdgesHelper( object, hex ) {
  28652. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28653. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28654. }
  28655. GridHelper.prototype.setColors = function () {
  28656. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28657. };
  28658. SkeletonHelper.prototype.update = function () {
  28659. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28660. };
  28661. function WireframeHelper( object, hex ) {
  28662. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28663. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28664. }
  28665. //
  28666. Object.assign( Loader.prototype, {
  28667. extractUrlBase: function ( url ) {
  28668. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28669. return LoaderUtils.extractUrlBase( url );
  28670. }
  28671. } );
  28672. Loader.Handlers = {
  28673. add: function ( /* regex, loader */ ) {
  28674. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  28675. },
  28676. get: function ( /* file */ ) {
  28677. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  28678. }
  28679. };
  28680. function XHRLoader( manager ) {
  28681. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28682. return new FileLoader( manager );
  28683. }
  28684. function BinaryTextureLoader( manager ) {
  28685. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28686. return new DataTextureLoader( manager );
  28687. }
  28688. Object.assign( ObjectLoader.prototype, {
  28689. setTexturePath: function ( value ) {
  28690. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  28691. return this.setResourcePath( value );
  28692. }
  28693. } );
  28694. //
  28695. Object.assign( Box2.prototype, {
  28696. center: function ( optionalTarget ) {
  28697. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28698. return this.getCenter( optionalTarget );
  28699. },
  28700. empty: function () {
  28701. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28702. return this.isEmpty();
  28703. },
  28704. isIntersectionBox: function ( box ) {
  28705. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28706. return this.intersectsBox( box );
  28707. },
  28708. size: function ( optionalTarget ) {
  28709. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28710. return this.getSize( optionalTarget );
  28711. }
  28712. } );
  28713. Object.assign( Box3.prototype, {
  28714. center: function ( optionalTarget ) {
  28715. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28716. return this.getCenter( optionalTarget );
  28717. },
  28718. empty: function () {
  28719. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28720. return this.isEmpty();
  28721. },
  28722. isIntersectionBox: function ( box ) {
  28723. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28724. return this.intersectsBox( box );
  28725. },
  28726. isIntersectionSphere: function ( sphere ) {
  28727. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28728. return this.intersectsSphere( sphere );
  28729. },
  28730. size: function ( optionalTarget ) {
  28731. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28732. return this.getSize( optionalTarget );
  28733. }
  28734. } );
  28735. Line3.prototype.center = function ( optionalTarget ) {
  28736. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28737. return this.getCenter( optionalTarget );
  28738. };
  28739. Object.assign( _Math, {
  28740. random16: function () {
  28741. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28742. return Math.random();
  28743. },
  28744. nearestPowerOfTwo: function ( value ) {
  28745. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28746. return _Math.floorPowerOfTwo( value );
  28747. },
  28748. nextPowerOfTwo: function ( value ) {
  28749. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28750. return _Math.ceilPowerOfTwo( value );
  28751. }
  28752. } );
  28753. Object.assign( Matrix3.prototype, {
  28754. flattenToArrayOffset: function ( array, offset ) {
  28755. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28756. return this.toArray( array, offset );
  28757. },
  28758. multiplyVector3: function ( vector ) {
  28759. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28760. return vector.applyMatrix3( this );
  28761. },
  28762. multiplyVector3Array: function ( /* a */ ) {
  28763. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28764. },
  28765. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28766. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28767. return this.applyToBufferAttribute( buffer );
  28768. },
  28769. applyToVector3Array: function ( /* array, offset, length */ ) {
  28770. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28771. }
  28772. } );
  28773. Object.assign( Matrix4.prototype, {
  28774. extractPosition: function ( m ) {
  28775. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28776. return this.copyPosition( m );
  28777. },
  28778. flattenToArrayOffset: function ( array, offset ) {
  28779. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28780. return this.toArray( array, offset );
  28781. },
  28782. getPosition: function () {
  28783. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28784. return new Vector3().setFromMatrixColumn( this, 3 );
  28785. },
  28786. setRotationFromQuaternion: function ( q ) {
  28787. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28788. return this.makeRotationFromQuaternion( q );
  28789. },
  28790. multiplyToArray: function () {
  28791. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28792. },
  28793. multiplyVector3: function ( vector ) {
  28794. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28795. return vector.applyMatrix4( this );
  28796. },
  28797. multiplyVector4: function ( vector ) {
  28798. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28799. return vector.applyMatrix4( this );
  28800. },
  28801. multiplyVector3Array: function ( /* a */ ) {
  28802. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28803. },
  28804. rotateAxis: function ( v ) {
  28805. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28806. v.transformDirection( this );
  28807. },
  28808. crossVector: function ( vector ) {
  28809. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28810. return vector.applyMatrix4( this );
  28811. },
  28812. translate: function () {
  28813. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28814. },
  28815. rotateX: function () {
  28816. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28817. },
  28818. rotateY: function () {
  28819. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28820. },
  28821. rotateZ: function () {
  28822. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28823. },
  28824. rotateByAxis: function () {
  28825. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28826. },
  28827. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28828. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28829. return this.applyToBufferAttribute( buffer );
  28830. },
  28831. applyToVector3Array: function ( /* array, offset, length */ ) {
  28832. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28833. },
  28834. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28835. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28836. return this.makePerspective( left, right, top, bottom, near, far );
  28837. }
  28838. } );
  28839. Plane.prototype.isIntersectionLine = function ( line ) {
  28840. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28841. return this.intersectsLine( line );
  28842. };
  28843. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28844. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28845. return vector.applyQuaternion( this );
  28846. };
  28847. Object.assign( Ray.prototype, {
  28848. isIntersectionBox: function ( box ) {
  28849. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28850. return this.intersectsBox( box );
  28851. },
  28852. isIntersectionPlane: function ( plane ) {
  28853. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28854. return this.intersectsPlane( plane );
  28855. },
  28856. isIntersectionSphere: function ( sphere ) {
  28857. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28858. return this.intersectsSphere( sphere );
  28859. }
  28860. } );
  28861. Object.assign( Triangle.prototype, {
  28862. area: function () {
  28863. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28864. return this.getArea();
  28865. },
  28866. barycoordFromPoint: function ( point, target ) {
  28867. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28868. return this.getBarycoord( point, target );
  28869. },
  28870. midpoint: function ( target ) {
  28871. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28872. return this.getMidpoint( target );
  28873. },
  28874. normal: function ( target ) {
  28875. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28876. return this.getNormal( target );
  28877. },
  28878. plane: function ( target ) {
  28879. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28880. return this.getPlane( target );
  28881. }
  28882. } );
  28883. Object.assign( Triangle, {
  28884. barycoordFromPoint: function ( point, a, b, c, target ) {
  28885. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28886. return Triangle.getBarycoord( point, a, b, c, target );
  28887. },
  28888. normal: function ( a, b, c, target ) {
  28889. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28890. return Triangle.getNormal( a, b, c, target );
  28891. }
  28892. } );
  28893. Object.assign( Shape.prototype, {
  28894. extractAllPoints: function ( divisions ) {
  28895. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28896. return this.extractPoints( divisions );
  28897. },
  28898. extrude: function ( options ) {
  28899. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28900. return new ExtrudeGeometry( this, options );
  28901. },
  28902. makeGeometry: function ( options ) {
  28903. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28904. return new ShapeGeometry( this, options );
  28905. }
  28906. } );
  28907. Object.assign( Vector2.prototype, {
  28908. fromAttribute: function ( attribute, index, offset ) {
  28909. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28910. return this.fromBufferAttribute( attribute, index, offset );
  28911. },
  28912. distanceToManhattan: function ( v ) {
  28913. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28914. return this.manhattanDistanceTo( v );
  28915. },
  28916. lengthManhattan: function () {
  28917. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28918. return this.manhattanLength();
  28919. }
  28920. } );
  28921. Object.assign( Vector3.prototype, {
  28922. setEulerFromRotationMatrix: function () {
  28923. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28924. },
  28925. setEulerFromQuaternion: function () {
  28926. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28927. },
  28928. getPositionFromMatrix: function ( m ) {
  28929. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28930. return this.setFromMatrixPosition( m );
  28931. },
  28932. getScaleFromMatrix: function ( m ) {
  28933. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28934. return this.setFromMatrixScale( m );
  28935. },
  28936. getColumnFromMatrix: function ( index, matrix ) {
  28937. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28938. return this.setFromMatrixColumn( matrix, index );
  28939. },
  28940. applyProjection: function ( m ) {
  28941. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28942. return this.applyMatrix4( m );
  28943. },
  28944. fromAttribute: function ( attribute, index, offset ) {
  28945. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28946. return this.fromBufferAttribute( attribute, index, offset );
  28947. },
  28948. distanceToManhattan: function ( v ) {
  28949. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28950. return this.manhattanDistanceTo( v );
  28951. },
  28952. lengthManhattan: function () {
  28953. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28954. return this.manhattanLength();
  28955. }
  28956. } );
  28957. Object.assign( Vector4.prototype, {
  28958. fromAttribute: function ( attribute, index, offset ) {
  28959. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28960. return this.fromBufferAttribute( attribute, index, offset );
  28961. },
  28962. lengthManhattan: function () {
  28963. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28964. return this.manhattanLength();
  28965. }
  28966. } );
  28967. //
  28968. Object.assign( Geometry.prototype, {
  28969. computeTangents: function () {
  28970. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28971. },
  28972. computeLineDistances: function () {
  28973. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28974. }
  28975. } );
  28976. Object.assign( Object3D.prototype, {
  28977. getChildByName: function ( name ) {
  28978. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28979. return this.getObjectByName( name );
  28980. },
  28981. renderDepth: function () {
  28982. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28983. },
  28984. translate: function ( distance, axis ) {
  28985. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28986. return this.translateOnAxis( axis, distance );
  28987. },
  28988. getWorldRotation: function () {
  28989. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28990. }
  28991. } );
  28992. Object.defineProperties( Object3D.prototype, {
  28993. eulerOrder: {
  28994. get: function () {
  28995. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28996. return this.rotation.order;
  28997. },
  28998. set: function ( value ) {
  28999. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29000. this.rotation.order = value;
  29001. }
  29002. },
  29003. useQuaternion: {
  29004. get: function () {
  29005. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29006. },
  29007. set: function () {
  29008. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29009. }
  29010. }
  29011. } );
  29012. Object.defineProperties( LOD.prototype, {
  29013. objects: {
  29014. get: function () {
  29015. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  29016. return this.levels;
  29017. }
  29018. }
  29019. } );
  29020. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  29021. get: function () {
  29022. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29023. },
  29024. set: function () {
  29025. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29026. }
  29027. } );
  29028. SkinnedMesh.prototype.initBones = function () {
  29029. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  29030. };
  29031. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  29032. get: function () {
  29033. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29034. return this.arcLengthDivisions;
  29035. },
  29036. set: function ( value ) {
  29037. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29038. this.arcLengthDivisions = value;
  29039. }
  29040. } );
  29041. //
  29042. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  29043. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  29044. "Use .setFocalLength and .filmGauge for a photographic setup." );
  29045. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  29046. this.setFocalLength( focalLength );
  29047. };
  29048. //
  29049. Object.defineProperties( Light.prototype, {
  29050. onlyShadow: {
  29051. set: function () {
  29052. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  29053. }
  29054. },
  29055. shadowCameraFov: {
  29056. set: function ( value ) {
  29057. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  29058. this.shadow.camera.fov = value;
  29059. }
  29060. },
  29061. shadowCameraLeft: {
  29062. set: function ( value ) {
  29063. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  29064. this.shadow.camera.left = value;
  29065. }
  29066. },
  29067. shadowCameraRight: {
  29068. set: function ( value ) {
  29069. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  29070. this.shadow.camera.right = value;
  29071. }
  29072. },
  29073. shadowCameraTop: {
  29074. set: function ( value ) {
  29075. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  29076. this.shadow.camera.top = value;
  29077. }
  29078. },
  29079. shadowCameraBottom: {
  29080. set: function ( value ) {
  29081. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  29082. this.shadow.camera.bottom = value;
  29083. }
  29084. },
  29085. shadowCameraNear: {
  29086. set: function ( value ) {
  29087. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  29088. this.shadow.camera.near = value;
  29089. }
  29090. },
  29091. shadowCameraFar: {
  29092. set: function ( value ) {
  29093. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  29094. this.shadow.camera.far = value;
  29095. }
  29096. },
  29097. shadowCameraVisible: {
  29098. set: function () {
  29099. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  29100. }
  29101. },
  29102. shadowBias: {
  29103. set: function ( value ) {
  29104. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  29105. this.shadow.bias = value;
  29106. }
  29107. },
  29108. shadowDarkness: {
  29109. set: function () {
  29110. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  29111. }
  29112. },
  29113. shadowMapWidth: {
  29114. set: function ( value ) {
  29115. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  29116. this.shadow.mapSize.width = value;
  29117. }
  29118. },
  29119. shadowMapHeight: {
  29120. set: function ( value ) {
  29121. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  29122. this.shadow.mapSize.height = value;
  29123. }
  29124. }
  29125. } );
  29126. //
  29127. Object.defineProperties( BufferAttribute.prototype, {
  29128. length: {
  29129. get: function () {
  29130. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  29131. return this.array.length;
  29132. }
  29133. },
  29134. dynamic: {
  29135. get: function () {
  29136. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29137. return this.usage === DynamicDrawUsage;
  29138. },
  29139. set: function ( /* value */ ) {
  29140. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29141. this.setUsage( DynamicDrawUsage );
  29142. }
  29143. }
  29144. } );
  29145. Object.assign( BufferAttribute.prototype, {
  29146. setDynamic: function ( value ) {
  29147. console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  29148. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  29149. return this;
  29150. },
  29151. copyIndicesArray: function ( /* indices */ ) {
  29152. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  29153. },
  29154. setArray: function ( /* array */ ) {
  29155. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  29156. }
  29157. } );
  29158. Object.assign( BufferGeometry.prototype, {
  29159. addIndex: function ( index ) {
  29160. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  29161. this.setIndex( index );
  29162. },
  29163. addAttribute: function ( name, attribute ) {
  29164. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  29165. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  29166. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  29167. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  29168. }
  29169. if ( name === 'index' ) {
  29170. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  29171. this.setIndex( attribute );
  29172. return this;
  29173. }
  29174. return this.setAttribute( name, attribute );
  29175. },
  29176. addDrawCall: function ( start, count, indexOffset ) {
  29177. if ( indexOffset !== undefined ) {
  29178. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  29179. }
  29180. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  29181. this.addGroup( start, count );
  29182. },
  29183. clearDrawCalls: function () {
  29184. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  29185. this.clearGroups();
  29186. },
  29187. computeTangents: function () {
  29188. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  29189. },
  29190. computeOffsets: function () {
  29191. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  29192. },
  29193. removeAttribute: function ( name ) {
  29194. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  29195. return this.deleteAttribute( name );
  29196. }
  29197. } );
  29198. Object.defineProperties( BufferGeometry.prototype, {
  29199. drawcalls: {
  29200. get: function () {
  29201. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  29202. return this.groups;
  29203. }
  29204. },
  29205. offsets: {
  29206. get: function () {
  29207. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  29208. return this.groups;
  29209. }
  29210. }
  29211. } );
  29212. Object.defineProperties( InterleavedBuffer.prototype, {
  29213. dynamic: {
  29214. get: function () {
  29215. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  29216. return this.usage === DynamicDrawUsage;
  29217. },
  29218. set: function ( value ) {
  29219. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  29220. this.setUsage( value );
  29221. }
  29222. }
  29223. } );
  29224. Object.assign( InterleavedBuffer.prototype, {
  29225. setDynamic: function ( value ) {
  29226. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  29227. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  29228. return this;
  29229. },
  29230. setArray: function ( /* array */ ) {
  29231. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  29232. }
  29233. } );
  29234. //
  29235. Object.assign( ExtrudeBufferGeometry.prototype, {
  29236. getArrays: function () {
  29237. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  29238. },
  29239. addShapeList: function () {
  29240. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  29241. },
  29242. addShape: function () {
  29243. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  29244. }
  29245. } );
  29246. //
  29247. Object.defineProperties( Uniform.prototype, {
  29248. dynamic: {
  29249. set: function () {
  29250. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  29251. }
  29252. },
  29253. onUpdate: {
  29254. value: function () {
  29255. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  29256. return this;
  29257. }
  29258. }
  29259. } );
  29260. //
  29261. Object.defineProperties( Material.prototype, {
  29262. wrapAround: {
  29263. get: function () {
  29264. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29265. },
  29266. set: function () {
  29267. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29268. }
  29269. },
  29270. overdraw: {
  29271. get: function () {
  29272. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29273. },
  29274. set: function () {
  29275. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29276. }
  29277. },
  29278. wrapRGB: {
  29279. get: function () {
  29280. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  29281. return new Color();
  29282. }
  29283. },
  29284. shading: {
  29285. get: function () {
  29286. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29287. },
  29288. set: function ( value ) {
  29289. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29290. this.flatShading = ( value === FlatShading );
  29291. }
  29292. },
  29293. stencilMask: {
  29294. get: function () {
  29295. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  29296. return this.stencilFuncMask;
  29297. },
  29298. set: function ( value ) {
  29299. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  29300. this.stencilFuncMask = value;
  29301. }
  29302. }
  29303. } );
  29304. Object.defineProperties( MeshPhongMaterial.prototype, {
  29305. metal: {
  29306. get: function () {
  29307. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  29308. return false;
  29309. },
  29310. set: function () {
  29311. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  29312. }
  29313. }
  29314. } );
  29315. Object.defineProperties( ShaderMaterial.prototype, {
  29316. derivatives: {
  29317. get: function () {
  29318. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29319. return this.extensions.derivatives;
  29320. },
  29321. set: function ( value ) {
  29322. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29323. this.extensions.derivatives = value;
  29324. }
  29325. }
  29326. } );
  29327. //
  29328. Object.assign( WebGLRenderer.prototype, {
  29329. clearTarget: function ( renderTarget, color, depth, stencil ) {
  29330. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  29331. this.setRenderTarget( renderTarget );
  29332. this.clear( color, depth, stencil );
  29333. },
  29334. animate: function ( callback ) {
  29335. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  29336. this.setAnimationLoop( callback );
  29337. },
  29338. getCurrentRenderTarget: function () {
  29339. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  29340. return this.getRenderTarget();
  29341. },
  29342. getMaxAnisotropy: function () {
  29343. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  29344. return this.capabilities.getMaxAnisotropy();
  29345. },
  29346. getPrecision: function () {
  29347. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  29348. return this.capabilities.precision;
  29349. },
  29350. resetGLState: function () {
  29351. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  29352. return this.state.reset();
  29353. },
  29354. supportsFloatTextures: function () {
  29355. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  29356. return this.extensions.get( 'OES_texture_float' );
  29357. },
  29358. supportsHalfFloatTextures: function () {
  29359. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  29360. return this.extensions.get( 'OES_texture_half_float' );
  29361. },
  29362. supportsStandardDerivatives: function () {
  29363. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  29364. return this.extensions.get( 'OES_standard_derivatives' );
  29365. },
  29366. supportsCompressedTextureS3TC: function () {
  29367. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  29368. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  29369. },
  29370. supportsCompressedTexturePVRTC: function () {
  29371. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  29372. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  29373. },
  29374. supportsBlendMinMax: function () {
  29375. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  29376. return this.extensions.get( 'EXT_blend_minmax' );
  29377. },
  29378. supportsVertexTextures: function () {
  29379. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  29380. return this.capabilities.vertexTextures;
  29381. },
  29382. supportsInstancedArrays: function () {
  29383. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  29384. return this.extensions.get( 'ANGLE_instanced_arrays' );
  29385. },
  29386. enableScissorTest: function ( boolean ) {
  29387. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  29388. this.setScissorTest( boolean );
  29389. },
  29390. initMaterial: function () {
  29391. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  29392. },
  29393. addPrePlugin: function () {
  29394. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  29395. },
  29396. addPostPlugin: function () {
  29397. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  29398. },
  29399. updateShadowMap: function () {
  29400. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  29401. },
  29402. setFaceCulling: function () {
  29403. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  29404. },
  29405. allocTextureUnit: function () {
  29406. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  29407. },
  29408. setTexture: function () {
  29409. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  29410. },
  29411. setTexture2D: function () {
  29412. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  29413. },
  29414. setTextureCube: function () {
  29415. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  29416. },
  29417. getActiveMipMapLevel: function () {
  29418. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  29419. return this.getActiveMipmapLevel();
  29420. }
  29421. } );
  29422. Object.defineProperties( WebGLRenderer.prototype, {
  29423. shadowMapEnabled: {
  29424. get: function () {
  29425. return this.shadowMap.enabled;
  29426. },
  29427. set: function ( value ) {
  29428. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  29429. this.shadowMap.enabled = value;
  29430. }
  29431. },
  29432. shadowMapType: {
  29433. get: function () {
  29434. return this.shadowMap.type;
  29435. },
  29436. set: function ( value ) {
  29437. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  29438. this.shadowMap.type = value;
  29439. }
  29440. },
  29441. shadowMapCullFace: {
  29442. get: function () {
  29443. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29444. return undefined;
  29445. },
  29446. set: function ( /* value */ ) {
  29447. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29448. }
  29449. },
  29450. context: {
  29451. get: function () {
  29452. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  29453. return this.getContext();
  29454. }
  29455. }
  29456. } );
  29457. Object.defineProperties( WebGLShadowMap.prototype, {
  29458. cullFace: {
  29459. get: function () {
  29460. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29461. return undefined;
  29462. },
  29463. set: function ( /* cullFace */ ) {
  29464. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29465. }
  29466. },
  29467. renderReverseSided: {
  29468. get: function () {
  29469. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29470. return undefined;
  29471. },
  29472. set: function () {
  29473. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29474. }
  29475. },
  29476. renderSingleSided: {
  29477. get: function () {
  29478. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29479. return undefined;
  29480. },
  29481. set: function () {
  29482. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29483. }
  29484. }
  29485. } );
  29486. //
  29487. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  29488. activeCubeFace: {
  29489. set: function ( /* value */ ) {
  29490. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  29491. }
  29492. },
  29493. activeMipMapLevel: {
  29494. set: function ( /* value */ ) {
  29495. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  29496. }
  29497. }
  29498. } );
  29499. //
  29500. Object.defineProperties( WebGLRenderTarget.prototype, {
  29501. wrapS: {
  29502. get: function () {
  29503. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29504. return this.texture.wrapS;
  29505. },
  29506. set: function ( value ) {
  29507. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29508. this.texture.wrapS = value;
  29509. }
  29510. },
  29511. wrapT: {
  29512. get: function () {
  29513. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29514. return this.texture.wrapT;
  29515. },
  29516. set: function ( value ) {
  29517. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29518. this.texture.wrapT = value;
  29519. }
  29520. },
  29521. magFilter: {
  29522. get: function () {
  29523. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29524. return this.texture.magFilter;
  29525. },
  29526. set: function ( value ) {
  29527. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29528. this.texture.magFilter = value;
  29529. }
  29530. },
  29531. minFilter: {
  29532. get: function () {
  29533. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29534. return this.texture.minFilter;
  29535. },
  29536. set: function ( value ) {
  29537. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29538. this.texture.minFilter = value;
  29539. }
  29540. },
  29541. anisotropy: {
  29542. get: function () {
  29543. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29544. return this.texture.anisotropy;
  29545. },
  29546. set: function ( value ) {
  29547. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29548. this.texture.anisotropy = value;
  29549. }
  29550. },
  29551. offset: {
  29552. get: function () {
  29553. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29554. return this.texture.offset;
  29555. },
  29556. set: function ( value ) {
  29557. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29558. this.texture.offset = value;
  29559. }
  29560. },
  29561. repeat: {
  29562. get: function () {
  29563. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29564. return this.texture.repeat;
  29565. },
  29566. set: function ( value ) {
  29567. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29568. this.texture.repeat = value;
  29569. }
  29570. },
  29571. format: {
  29572. get: function () {
  29573. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29574. return this.texture.format;
  29575. },
  29576. set: function ( value ) {
  29577. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29578. this.texture.format = value;
  29579. }
  29580. },
  29581. type: {
  29582. get: function () {
  29583. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29584. return this.texture.type;
  29585. },
  29586. set: function ( value ) {
  29587. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29588. this.texture.type = value;
  29589. }
  29590. },
  29591. generateMipmaps: {
  29592. get: function () {
  29593. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29594. return this.texture.generateMipmaps;
  29595. },
  29596. set: function ( value ) {
  29597. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29598. this.texture.generateMipmaps = value;
  29599. }
  29600. }
  29601. } );
  29602. //
  29603. Object.defineProperties( WebVRManager.prototype, {
  29604. standing: {
  29605. set: function ( /* value */ ) {
  29606. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  29607. }
  29608. },
  29609. userHeight: {
  29610. set: function ( /* value */ ) {
  29611. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  29612. }
  29613. }
  29614. } );
  29615. //
  29616. Object.defineProperties( Audio.prototype, {
  29617. load: {
  29618. value: function ( file ) {
  29619. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  29620. var scope = this;
  29621. var audioLoader = new AudioLoader();
  29622. audioLoader.load( file, function ( buffer ) {
  29623. scope.setBuffer( buffer );
  29624. } );
  29625. return this;
  29626. }
  29627. },
  29628. startTime: {
  29629. set: function () {
  29630. console.warn( 'THREE.Audio: .startTime is now .play( delay ).' );
  29631. }
  29632. }
  29633. } );
  29634. AudioAnalyser.prototype.getData = function () {
  29635. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  29636. return this.getFrequencyData();
  29637. };
  29638. //
  29639. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  29640. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  29641. return this.update( renderer, scene );
  29642. };
  29643. //
  29644. var GeometryUtils = {
  29645. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  29646. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  29647. var matrix;
  29648. if ( geometry2.isMesh ) {
  29649. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  29650. matrix = geometry2.matrix;
  29651. geometry2 = geometry2.geometry;
  29652. }
  29653. geometry1.merge( geometry2, matrix, materialIndexOffset );
  29654. },
  29655. center: function ( geometry ) {
  29656. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  29657. return geometry.center();
  29658. }
  29659. };
  29660. ImageUtils.crossOrigin = undefined;
  29661. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29662. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29663. var loader = new TextureLoader();
  29664. loader.setCrossOrigin( this.crossOrigin );
  29665. var texture = loader.load( url, onLoad, undefined, onError );
  29666. if ( mapping ) texture.mapping = mapping;
  29667. return texture;
  29668. };
  29669. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29670. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29671. var loader = new CubeTextureLoader();
  29672. loader.setCrossOrigin( this.crossOrigin );
  29673. var texture = loader.load( urls, onLoad, undefined, onError );
  29674. if ( mapping ) texture.mapping = mapping;
  29675. return texture;
  29676. };
  29677. ImageUtils.loadCompressedTexture = function () {
  29678. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29679. };
  29680. ImageUtils.loadCompressedTextureCube = function () {
  29681. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29682. };
  29683. //
  29684. function CanvasRenderer() {
  29685. console.error( 'THREE.CanvasRenderer has been removed' );
  29686. }
  29687. //
  29688. function JSONLoader() {
  29689. console.error( 'THREE.JSONLoader has been removed.' );
  29690. }
  29691. //
  29692. var SceneUtils = {
  29693. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29694. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29695. },
  29696. detach: function ( /* child, parent, scene */ ) {
  29697. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29698. },
  29699. attach: function ( /* child, scene, parent */ ) {
  29700. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29701. }
  29702. };
  29703. //
  29704. function LensFlare() {
  29705. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  29706. }
  29707. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  29708. /* eslint-disable no-undef */
  29709. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  29710. revision: REVISION,
  29711. } } ) );
  29712. /* eslint-enable no-undef */
  29713. }
  29714. export { ACESFilmicToneMapping, AddEquation, AddOperation, 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, FaceNormalsHelper, 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, LightProbeHelper, 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, _Math as Math, 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, NormalBlending, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronBufferGeometry, OctahedronGeometry, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, ParametricBufferGeometry, ParametricGeometry, Particle, ParticleBasicMaterial, ParticleSystem, ParticleSystemMaterial, Path, PerspectiveCamera, Plane, PlaneBufferGeometry, PlaneGeometry, PlaneHelper, PointCloud, PointCloudMaterial, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronBufferGeometry, PolyhedronGeometry, PositionalAudio, PositionalAudioHelper, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, REVISION, RGBADepthPacking, RGBAFormat, 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_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDEncoding, RGBEEncoding, RGBEFormat, RGBFormat, RGBM16Encoding, RGBM7Encoding, RGB_ETC1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RectAreaLightHelper, RedFormat, ReinhardToneMapping, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingBufferGeometry, RingGeometry, 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, VertexNormalsHelper, VideoTexture, WebGLMultisampleRenderTarget, WebGLRenderTarget, WebGLRenderTargetCube, WebGLRenderer, WebGLUtils, WireframeGeometry, WireframeHelper, WrapAroundEnding, XHRLoader, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, sRGBEncoding };