three.module.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485
  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. ( function () {
  32. Object.assign = function ( target ) {
  33. if ( target === undefined || target === null ) {
  34. throw new TypeError( 'Cannot convert undefined or null to object' );
  35. }
  36. var output = Object( target );
  37. for ( var index = 1; index < arguments.length; index ++ ) {
  38. var source = arguments[ index ];
  39. if ( source !== undefined && source !== null ) {
  40. for ( var nextKey in source ) {
  41. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  42. output[ nextKey ] = source[ nextKey ];
  43. }
  44. }
  45. }
  46. }
  47. return output;
  48. };
  49. } )();
  50. }
  51. /**
  52. * https://github.com/mrdoob/eventdispatcher.js/
  53. */
  54. function EventDispatcher() {}
  55. Object.assign( EventDispatcher.prototype, {
  56. addEventListener: function ( type, listener ) {
  57. if ( this._listeners === undefined ) this._listeners = {};
  58. var listeners = this._listeners;
  59. if ( listeners[ type ] === undefined ) {
  60. listeners[ type ] = [];
  61. }
  62. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  63. listeners[ type ].push( listener );
  64. }
  65. },
  66. hasEventListener: function ( type, listener ) {
  67. if ( this._listeners === undefined ) return false;
  68. var listeners = this._listeners;
  69. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  70. },
  71. removeEventListener: function ( type, listener ) {
  72. if ( this._listeners === undefined ) return;
  73. var listeners = this._listeners;
  74. var listenerArray = listeners[ type ];
  75. if ( listenerArray !== undefined ) {
  76. var index = listenerArray.indexOf( listener );
  77. if ( index !== - 1 ) {
  78. listenerArray.splice( index, 1 );
  79. }
  80. }
  81. },
  82. dispatchEvent: function ( event ) {
  83. if ( this._listeners === undefined ) return;
  84. var listeners = this._listeners;
  85. var listenerArray = listeners[ event.type ];
  86. if ( listenerArray !== undefined ) {
  87. event.target = this;
  88. var array = listenerArray.slice( 0 );
  89. for ( var i = 0, l = array.length; i < l; i ++ ) {
  90. array[ i ].call( this, event );
  91. }
  92. }
  93. }
  94. } );
  95. var REVISION = '104dev';
  96. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  97. var CullFaceNone = 0;
  98. var CullFaceBack = 1;
  99. var CullFaceFront = 2;
  100. var CullFaceFrontBack = 3;
  101. var FrontFaceDirectionCW = 0;
  102. var FrontFaceDirectionCCW = 1;
  103. var BasicShadowMap = 0;
  104. var PCFShadowMap = 1;
  105. var PCFSoftShadowMap = 2;
  106. var FrontSide = 0;
  107. var BackSide = 1;
  108. var DoubleSide = 2;
  109. var FlatShading = 1;
  110. var SmoothShading = 2;
  111. var NoColors = 0;
  112. var FaceColors = 1;
  113. var VertexColors = 2;
  114. var NoBlending = 0;
  115. var NormalBlending = 1;
  116. var AdditiveBlending = 2;
  117. var SubtractiveBlending = 3;
  118. var MultiplyBlending = 4;
  119. var CustomBlending = 5;
  120. var AddEquation = 100;
  121. var SubtractEquation = 101;
  122. var ReverseSubtractEquation = 102;
  123. var MinEquation = 103;
  124. var MaxEquation = 104;
  125. var ZeroFactor = 200;
  126. var OneFactor = 201;
  127. var SrcColorFactor = 202;
  128. var OneMinusSrcColorFactor = 203;
  129. var SrcAlphaFactor = 204;
  130. var OneMinusSrcAlphaFactor = 205;
  131. var DstAlphaFactor = 206;
  132. var OneMinusDstAlphaFactor = 207;
  133. var DstColorFactor = 208;
  134. var OneMinusDstColorFactor = 209;
  135. var SrcAlphaSaturateFactor = 210;
  136. var NeverDepth = 0;
  137. var AlwaysDepth = 1;
  138. var LessDepth = 2;
  139. var LessEqualDepth = 3;
  140. var EqualDepth = 4;
  141. var GreaterEqualDepth = 5;
  142. var GreaterDepth = 6;
  143. var NotEqualDepth = 7;
  144. var MultiplyOperation = 0;
  145. var MixOperation = 1;
  146. var AddOperation = 2;
  147. var NoToneMapping = 0;
  148. var LinearToneMapping = 1;
  149. var ReinhardToneMapping = 2;
  150. var Uncharted2ToneMapping = 3;
  151. var CineonToneMapping = 4;
  152. var ACESFilmicToneMapping = 5;
  153. var UVMapping = 300;
  154. var CubeReflectionMapping = 301;
  155. var CubeRefractionMapping = 302;
  156. var EquirectangularReflectionMapping = 303;
  157. var EquirectangularRefractionMapping = 304;
  158. var SphericalReflectionMapping = 305;
  159. var CubeUVReflectionMapping = 306;
  160. var CubeUVRefractionMapping = 307;
  161. var RepeatWrapping = 1000;
  162. var ClampToEdgeWrapping = 1001;
  163. var MirroredRepeatWrapping = 1002;
  164. var NearestFilter = 1003;
  165. var NearestMipMapNearestFilter = 1004;
  166. var NearestMipMapLinearFilter = 1005;
  167. var LinearFilter = 1006;
  168. var LinearMipMapNearestFilter = 1007;
  169. var LinearMipMapLinearFilter = 1008;
  170. var UnsignedByteType = 1009;
  171. var ByteType = 1010;
  172. var ShortType = 1011;
  173. var UnsignedShortType = 1012;
  174. var IntType = 1013;
  175. var UnsignedIntType = 1014;
  176. var FloatType = 1015;
  177. var HalfFloatType = 1016;
  178. var UnsignedShort4444Type = 1017;
  179. var UnsignedShort5551Type = 1018;
  180. var UnsignedShort565Type = 1019;
  181. var UnsignedInt248Type = 1020;
  182. var AlphaFormat = 1021;
  183. var RGBFormat = 1022;
  184. var RGBAFormat = 1023;
  185. var LuminanceFormat = 1024;
  186. var LuminanceAlphaFormat = 1025;
  187. var RGBEFormat = RGBAFormat;
  188. var DepthFormat = 1026;
  189. var DepthStencilFormat = 1027;
  190. var RedFormat = 1028;
  191. var RGB_S3TC_DXT1_Format = 33776;
  192. var RGBA_S3TC_DXT1_Format = 33777;
  193. var RGBA_S3TC_DXT3_Format = 33778;
  194. var RGBA_S3TC_DXT5_Format = 33779;
  195. var RGB_PVRTC_4BPPV1_Format = 35840;
  196. var RGB_PVRTC_2BPPV1_Format = 35841;
  197. var RGBA_PVRTC_4BPPV1_Format = 35842;
  198. var RGBA_PVRTC_2BPPV1_Format = 35843;
  199. var RGB_ETC1_Format = 36196;
  200. var RGBA_ASTC_4x4_Format = 37808;
  201. var RGBA_ASTC_5x4_Format = 37809;
  202. var RGBA_ASTC_5x5_Format = 37810;
  203. var RGBA_ASTC_6x5_Format = 37811;
  204. var RGBA_ASTC_6x6_Format = 37812;
  205. var RGBA_ASTC_8x5_Format = 37813;
  206. var RGBA_ASTC_8x6_Format = 37814;
  207. var RGBA_ASTC_8x8_Format = 37815;
  208. var RGBA_ASTC_10x5_Format = 37816;
  209. var RGBA_ASTC_10x6_Format = 37817;
  210. var RGBA_ASTC_10x8_Format = 37818;
  211. var RGBA_ASTC_10x10_Format = 37819;
  212. var RGBA_ASTC_12x10_Format = 37820;
  213. var RGBA_ASTC_12x12_Format = 37821;
  214. var LoopOnce = 2200;
  215. var LoopRepeat = 2201;
  216. var LoopPingPong = 2202;
  217. var InterpolateDiscrete = 2300;
  218. var InterpolateLinear = 2301;
  219. var InterpolateSmooth = 2302;
  220. var ZeroCurvatureEnding = 2400;
  221. var ZeroSlopeEnding = 2401;
  222. var WrapAroundEnding = 2402;
  223. var TrianglesDrawMode = 0;
  224. var TriangleStripDrawMode = 1;
  225. var TriangleFanDrawMode = 2;
  226. var LinearEncoding = 3000;
  227. var sRGBEncoding = 3001;
  228. var GammaEncoding = 3007;
  229. var RGBEEncoding = 3002;
  230. var LogLuvEncoding = 3003;
  231. var RGBM7Encoding = 3004;
  232. var RGBM16Encoding = 3005;
  233. var RGBDEncoding = 3006;
  234. var BasicDepthPacking = 3200;
  235. var RGBADepthPacking = 3201;
  236. var TangentSpaceNormalMap = 0;
  237. var ObjectSpaceNormalMap = 1;
  238. /**
  239. * @author alteredq / http://alteredqualia.com/
  240. * @author mrdoob / http://mrdoob.com/
  241. */
  242. var _Math = {
  243. DEG2RAD: Math.PI / 180,
  244. RAD2DEG: 180 / Math.PI,
  245. generateUUID: ( function () {
  246. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  247. var lut = [];
  248. for ( var i = 0; i < 256; i ++ ) {
  249. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  250. }
  251. return function generateUUID() {
  252. var d0 = Math.random() * 0xffffffff | 0;
  253. var d1 = Math.random() * 0xffffffff | 0;
  254. var d2 = Math.random() * 0xffffffff | 0;
  255. var d3 = Math.random() * 0xffffffff | 0;
  256. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  257. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  258. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  259. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  260. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  261. return uuid.toUpperCase();
  262. };
  263. } )(),
  264. clamp: function ( value, min, max ) {
  265. return Math.max( min, Math.min( max, value ) );
  266. },
  267. // compute euclidian modulo of m % n
  268. // https://en.wikipedia.org/wiki/Modulo_operation
  269. euclideanModulo: function ( n, m ) {
  270. return ( ( n % m ) + m ) % m;
  271. },
  272. // Linear mapping from range <a1, a2> to range <b1, b2>
  273. mapLinear: function ( x, a1, a2, b1, b2 ) {
  274. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  275. },
  276. // https://en.wikipedia.org/wiki/Linear_interpolation
  277. lerp: function ( x, y, t ) {
  278. return ( 1 - t ) * x + t * y;
  279. },
  280. // http://en.wikipedia.org/wiki/Smoothstep
  281. smoothstep: function ( x, min, max ) {
  282. if ( x <= min ) return 0;
  283. if ( x >= max ) return 1;
  284. x = ( x - min ) / ( max - min );
  285. return x * x * ( 3 - 2 * x );
  286. },
  287. smootherstep: function ( x, min, max ) {
  288. if ( x <= min ) return 0;
  289. if ( x >= max ) return 1;
  290. x = ( x - min ) / ( max - min );
  291. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  292. },
  293. // Random integer from <low, high> interval
  294. randInt: function ( low, high ) {
  295. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  296. },
  297. // Random float from <low, high> interval
  298. randFloat: function ( low, high ) {
  299. return low + Math.random() * ( high - low );
  300. },
  301. // Random float from <-range/2, range/2> interval
  302. randFloatSpread: function ( range ) {
  303. return range * ( 0.5 - Math.random() );
  304. },
  305. degToRad: function ( degrees ) {
  306. return degrees * _Math.DEG2RAD;
  307. },
  308. radToDeg: function ( radians ) {
  309. return radians * _Math.RAD2DEG;
  310. },
  311. isPowerOfTwo: function ( value ) {
  312. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  313. },
  314. ceilPowerOfTwo: function ( value ) {
  315. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  316. },
  317. floorPowerOfTwo: function ( value ) {
  318. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  319. }
  320. };
  321. /**
  322. * @author mrdoob / http://mrdoob.com/
  323. * @author philogb / http://blog.thejit.org/
  324. * @author egraether / http://egraether.com/
  325. * @author zz85 / http://www.lab4games.net/zz85/blog
  326. */
  327. function Vector2( x, y ) {
  328. this.x = x || 0;
  329. this.y = y || 0;
  330. }
  331. Object.defineProperties( Vector2.prototype, {
  332. "width": {
  333. get: function () {
  334. return this.x;
  335. },
  336. set: function ( value ) {
  337. this.x = value;
  338. }
  339. },
  340. "height": {
  341. get: function () {
  342. return this.y;
  343. },
  344. set: function ( value ) {
  345. this.y = value;
  346. }
  347. }
  348. } );
  349. Object.assign( Vector2.prototype, {
  350. isVector2: true,
  351. set: function ( x, y ) {
  352. this.x = x;
  353. this.y = y;
  354. return this;
  355. },
  356. setScalar: function ( scalar ) {
  357. this.x = scalar;
  358. this.y = scalar;
  359. return this;
  360. },
  361. setX: function ( x ) {
  362. this.x = x;
  363. return this;
  364. },
  365. setY: function ( y ) {
  366. this.y = y;
  367. return this;
  368. },
  369. setComponent: function ( index, value ) {
  370. switch ( index ) {
  371. case 0: this.x = value; break;
  372. case 1: this.y = value; break;
  373. default: throw new Error( 'index is out of range: ' + index );
  374. }
  375. return this;
  376. },
  377. getComponent: function ( index ) {
  378. switch ( index ) {
  379. case 0: return this.x;
  380. case 1: return this.y;
  381. default: throw new Error( 'index is out of range: ' + index );
  382. }
  383. },
  384. clone: function () {
  385. return new this.constructor( this.x, this.y );
  386. },
  387. copy: function ( v ) {
  388. this.x = v.x;
  389. this.y = v.y;
  390. return this;
  391. },
  392. add: function ( v, w ) {
  393. if ( w !== undefined ) {
  394. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  395. return this.addVectors( v, w );
  396. }
  397. this.x += v.x;
  398. this.y += v.y;
  399. return this;
  400. },
  401. addScalar: function ( s ) {
  402. this.x += s;
  403. this.y += s;
  404. return this;
  405. },
  406. addVectors: function ( a, b ) {
  407. this.x = a.x + b.x;
  408. this.y = a.y + b.y;
  409. return this;
  410. },
  411. addScaledVector: function ( v, s ) {
  412. this.x += v.x * s;
  413. this.y += v.y * s;
  414. return this;
  415. },
  416. sub: function ( v, w ) {
  417. if ( w !== undefined ) {
  418. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  419. return this.subVectors( v, w );
  420. }
  421. this.x -= v.x;
  422. this.y -= v.y;
  423. return this;
  424. },
  425. subScalar: function ( s ) {
  426. this.x -= s;
  427. this.y -= s;
  428. return this;
  429. },
  430. subVectors: function ( a, b ) {
  431. this.x = a.x - b.x;
  432. this.y = a.y - b.y;
  433. return this;
  434. },
  435. multiply: function ( v ) {
  436. this.x *= v.x;
  437. this.y *= v.y;
  438. return this;
  439. },
  440. multiplyScalar: function ( scalar ) {
  441. this.x *= scalar;
  442. this.y *= scalar;
  443. return this;
  444. },
  445. divide: function ( v ) {
  446. this.x /= v.x;
  447. this.y /= v.y;
  448. return this;
  449. },
  450. divideScalar: function ( scalar ) {
  451. return this.multiplyScalar( 1 / scalar );
  452. },
  453. applyMatrix3: function ( m ) {
  454. var x = this.x, y = this.y;
  455. var e = m.elements;
  456. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  457. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  458. return this;
  459. },
  460. min: function ( v ) {
  461. this.x = Math.min( this.x, v.x );
  462. this.y = Math.min( this.y, v.y );
  463. return this;
  464. },
  465. max: function ( v ) {
  466. this.x = Math.max( this.x, v.x );
  467. this.y = Math.max( this.y, v.y );
  468. return this;
  469. },
  470. clamp: function ( min, max ) {
  471. // assumes min < max, componentwise
  472. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  473. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  474. return this;
  475. },
  476. clampScalar: function ( minVal, maxVal ) {
  477. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  478. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  479. return this;
  480. },
  481. clampLength: function ( min, max ) {
  482. var length = this.length();
  483. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  484. },
  485. floor: function () {
  486. this.x = Math.floor( this.x );
  487. this.y = Math.floor( this.y );
  488. return this;
  489. },
  490. ceil: function () {
  491. this.x = Math.ceil( this.x );
  492. this.y = Math.ceil( this.y );
  493. return this;
  494. },
  495. round: function () {
  496. this.x = Math.round( this.x );
  497. this.y = Math.round( this.y );
  498. return this;
  499. },
  500. roundToZero: function () {
  501. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  502. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  503. return this;
  504. },
  505. negate: function () {
  506. this.x = - this.x;
  507. this.y = - this.y;
  508. return this;
  509. },
  510. dot: function ( v ) {
  511. return this.x * v.x + this.y * v.y;
  512. },
  513. cross: function ( v ) {
  514. return this.x * v.y - this.y * v.x;
  515. },
  516. lengthSq: function () {
  517. return this.x * this.x + this.y * this.y;
  518. },
  519. length: function () {
  520. return Math.sqrt( this.x * this.x + this.y * this.y );
  521. },
  522. manhattanLength: function () {
  523. return Math.abs( this.x ) + Math.abs( this.y );
  524. },
  525. normalize: function () {
  526. return this.divideScalar( this.length() || 1 );
  527. },
  528. angle: function () {
  529. // computes the angle in radians with respect to the positive x-axis
  530. var angle = Math.atan2( this.y, this.x );
  531. if ( angle < 0 ) angle += 2 * Math.PI;
  532. return angle;
  533. },
  534. distanceTo: function ( v ) {
  535. return Math.sqrt( this.distanceToSquared( v ) );
  536. },
  537. distanceToSquared: function ( v ) {
  538. var dx = this.x - v.x, dy = this.y - v.y;
  539. return dx * dx + dy * dy;
  540. },
  541. manhattanDistanceTo: function ( v ) {
  542. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  543. },
  544. setLength: function ( length ) {
  545. return this.normalize().multiplyScalar( length );
  546. },
  547. lerp: function ( v, alpha ) {
  548. this.x += ( v.x - this.x ) * alpha;
  549. this.y += ( v.y - this.y ) * alpha;
  550. return this;
  551. },
  552. lerpVectors: function ( v1, v2, alpha ) {
  553. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  554. },
  555. equals: function ( v ) {
  556. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  557. },
  558. fromArray: function ( array, offset ) {
  559. if ( offset === undefined ) offset = 0;
  560. this.x = array[ offset ];
  561. this.y = array[ offset + 1 ];
  562. return this;
  563. },
  564. toArray: function ( array, offset ) {
  565. if ( array === undefined ) array = [];
  566. if ( offset === undefined ) offset = 0;
  567. array[ offset ] = this.x;
  568. array[ offset + 1 ] = this.y;
  569. return array;
  570. },
  571. fromBufferAttribute: function ( attribute, index, offset ) {
  572. if ( offset !== undefined ) {
  573. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  574. }
  575. this.x = attribute.getX( index );
  576. this.y = attribute.getY( index );
  577. return this;
  578. },
  579. rotateAround: function ( center, angle ) {
  580. var c = Math.cos( angle ), s = Math.sin( angle );
  581. var x = this.x - center.x;
  582. var y = this.y - center.y;
  583. this.x = x * c - y * s + center.x;
  584. this.y = x * s + y * c + center.y;
  585. return this;
  586. }
  587. } );
  588. /**
  589. * @author mikael emtinger / http://gomo.se/
  590. * @author alteredq / http://alteredqualia.com/
  591. * @author WestLangley / http://github.com/WestLangley
  592. * @author bhouston / http://clara.io
  593. */
  594. function Quaternion( x, y, z, w ) {
  595. this._x = x || 0;
  596. this._y = y || 0;
  597. this._z = z || 0;
  598. this._w = ( w !== undefined ) ? w : 1;
  599. }
  600. Object.assign( Quaternion, {
  601. slerp: function ( qa, qb, qm, t ) {
  602. return qm.copy( qa ).slerp( qb, t );
  603. },
  604. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  605. // fuzz-free, array-based Quaternion SLERP operation
  606. var x0 = src0[ srcOffset0 + 0 ],
  607. y0 = src0[ srcOffset0 + 1 ],
  608. z0 = src0[ srcOffset0 + 2 ],
  609. w0 = src0[ srcOffset0 + 3 ],
  610. x1 = src1[ srcOffset1 + 0 ],
  611. y1 = src1[ srcOffset1 + 1 ],
  612. z1 = src1[ srcOffset1 + 2 ],
  613. w1 = src1[ srcOffset1 + 3 ];
  614. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  615. var s = 1 - t,
  616. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  617. dir = ( cos >= 0 ? 1 : - 1 ),
  618. sqrSin = 1 - cos * cos;
  619. // Skip the Slerp for tiny steps to avoid numeric problems:
  620. if ( sqrSin > Number.EPSILON ) {
  621. var sin = Math.sqrt( sqrSin ),
  622. len = Math.atan2( sin, cos * dir );
  623. s = Math.sin( s * len ) / sin;
  624. t = Math.sin( t * len ) / sin;
  625. }
  626. var tDir = t * dir;
  627. x0 = x0 * s + x1 * tDir;
  628. y0 = y0 * s + y1 * tDir;
  629. z0 = z0 * s + z1 * tDir;
  630. w0 = w0 * s + w1 * tDir;
  631. // Normalize in case we just did a lerp:
  632. if ( s === 1 - t ) {
  633. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  634. x0 *= f;
  635. y0 *= f;
  636. z0 *= f;
  637. w0 *= f;
  638. }
  639. }
  640. dst[ dstOffset ] = x0;
  641. dst[ dstOffset + 1 ] = y0;
  642. dst[ dstOffset + 2 ] = z0;
  643. dst[ dstOffset + 3 ] = w0;
  644. }
  645. } );
  646. Object.defineProperties( Quaternion.prototype, {
  647. x: {
  648. get: function () {
  649. return this._x;
  650. },
  651. set: function ( value ) {
  652. this._x = value;
  653. this.onChangeCallback();
  654. }
  655. },
  656. y: {
  657. get: function () {
  658. return this._y;
  659. },
  660. set: function ( value ) {
  661. this._y = value;
  662. this.onChangeCallback();
  663. }
  664. },
  665. z: {
  666. get: function () {
  667. return this._z;
  668. },
  669. set: function ( value ) {
  670. this._z = value;
  671. this.onChangeCallback();
  672. }
  673. },
  674. w: {
  675. get: function () {
  676. return this._w;
  677. },
  678. set: function ( value ) {
  679. this._w = value;
  680. this.onChangeCallback();
  681. }
  682. }
  683. } );
  684. Object.assign( Quaternion.prototype, {
  685. isQuaternion: true,
  686. set: function ( x, y, z, w ) {
  687. this._x = x;
  688. this._y = y;
  689. this._z = z;
  690. this._w = w;
  691. this.onChangeCallback();
  692. return this;
  693. },
  694. clone: function () {
  695. return new this.constructor( this._x, this._y, this._z, this._w );
  696. },
  697. copy: function ( quaternion ) {
  698. this._x = quaternion.x;
  699. this._y = quaternion.y;
  700. this._z = quaternion.z;
  701. this._w = quaternion.w;
  702. this.onChangeCallback();
  703. return this;
  704. },
  705. setFromEuler: function ( euler, update ) {
  706. if ( ! ( euler && euler.isEuler ) ) {
  707. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  708. }
  709. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  710. // http://www.mathworks.com/matlabcentral/fileexchange/
  711. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  712. // content/SpinCalc.m
  713. var cos = Math.cos;
  714. var sin = Math.sin;
  715. var c1 = cos( x / 2 );
  716. var c2 = cos( y / 2 );
  717. var c3 = cos( z / 2 );
  718. var s1 = sin( x / 2 );
  719. var s2 = sin( y / 2 );
  720. var s3 = sin( z / 2 );
  721. if ( order === 'XYZ' ) {
  722. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  723. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  724. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  725. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  726. } else if ( order === 'YXZ' ) {
  727. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  728. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  729. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  730. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  731. } else if ( order === 'ZXY' ) {
  732. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  733. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  734. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  735. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  736. } else if ( order === 'ZYX' ) {
  737. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  738. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  739. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  740. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  741. } else if ( order === 'YZX' ) {
  742. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  743. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  744. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  745. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  746. } else if ( order === 'XZY' ) {
  747. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  748. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  749. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  750. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  751. }
  752. if ( update !== false ) this.onChangeCallback();
  753. return this;
  754. },
  755. setFromAxisAngle: function ( axis, angle ) {
  756. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  757. // assumes axis is normalized
  758. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  759. this._x = axis.x * s;
  760. this._y = axis.y * s;
  761. this._z = axis.z * s;
  762. this._w = Math.cos( halfAngle );
  763. this.onChangeCallback();
  764. return this;
  765. },
  766. setFromRotationMatrix: function ( m ) {
  767. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  768. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  769. var te = m.elements,
  770. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  771. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  772. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  773. trace = m11 + m22 + m33,
  774. s;
  775. if ( trace > 0 ) {
  776. s = 0.5 / Math.sqrt( trace + 1.0 );
  777. this._w = 0.25 / s;
  778. this._x = ( m32 - m23 ) * s;
  779. this._y = ( m13 - m31 ) * s;
  780. this._z = ( m21 - m12 ) * s;
  781. } else if ( m11 > m22 && m11 > m33 ) {
  782. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  783. this._w = ( m32 - m23 ) / s;
  784. this._x = 0.25 * s;
  785. this._y = ( m12 + m21 ) / s;
  786. this._z = ( m13 + m31 ) / s;
  787. } else if ( m22 > m33 ) {
  788. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  789. this._w = ( m13 - m31 ) / s;
  790. this._x = ( m12 + m21 ) / s;
  791. this._y = 0.25 * s;
  792. this._z = ( m23 + m32 ) / s;
  793. } else {
  794. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  795. this._w = ( m21 - m12 ) / s;
  796. this._x = ( m13 + m31 ) / s;
  797. this._y = ( m23 + m32 ) / s;
  798. this._z = 0.25 * s;
  799. }
  800. this.onChangeCallback();
  801. return this;
  802. },
  803. setFromUnitVectors: function ( vFrom, vTo ) {
  804. // assumes direction vectors vFrom and vTo are normalized
  805. var EPS = 0.000001;
  806. var r = vFrom.dot( vTo ) + 1;
  807. if ( r < EPS ) {
  808. r = 0;
  809. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  810. this._x = - vFrom.y;
  811. this._y = vFrom.x;
  812. this._z = 0;
  813. this._w = r;
  814. } else {
  815. this._x = 0;
  816. this._y = - vFrom.z;
  817. this._z = vFrom.y;
  818. this._w = r;
  819. }
  820. } else {
  821. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  822. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  823. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  824. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  825. this._w = r;
  826. }
  827. return this.normalize();
  828. },
  829. angleTo: function ( q ) {
  830. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  831. },
  832. rotateTowards: function ( q, step ) {
  833. var angle = this.angleTo( q );
  834. if ( angle === 0 ) return this;
  835. var t = Math.min( 1, step / angle );
  836. this.slerp( q, t );
  837. return this;
  838. },
  839. inverse: function () {
  840. // quaternion is assumed to have unit length
  841. return this.conjugate();
  842. },
  843. conjugate: function () {
  844. this._x *= - 1;
  845. this._y *= - 1;
  846. this._z *= - 1;
  847. this.onChangeCallback();
  848. return this;
  849. },
  850. dot: function ( v ) {
  851. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  852. },
  853. lengthSq: function () {
  854. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  855. },
  856. length: function () {
  857. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  858. },
  859. normalize: function () {
  860. var l = this.length();
  861. if ( l === 0 ) {
  862. this._x = 0;
  863. this._y = 0;
  864. this._z = 0;
  865. this._w = 1;
  866. } else {
  867. l = 1 / l;
  868. this._x = this._x * l;
  869. this._y = this._y * l;
  870. this._z = this._z * l;
  871. this._w = this._w * l;
  872. }
  873. this.onChangeCallback();
  874. return this;
  875. },
  876. multiply: function ( q, p ) {
  877. if ( p !== undefined ) {
  878. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  879. return this.multiplyQuaternions( q, p );
  880. }
  881. return this.multiplyQuaternions( this, q );
  882. },
  883. premultiply: function ( q ) {
  884. return this.multiplyQuaternions( q, this );
  885. },
  886. multiplyQuaternions: function ( a, b ) {
  887. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  888. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  889. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  890. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  891. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  892. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  893. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  894. this.onChangeCallback();
  895. return this;
  896. },
  897. slerp: function ( qb, t ) {
  898. if ( t === 0 ) return this;
  899. if ( t === 1 ) return this.copy( qb );
  900. var x = this._x, y = this._y, z = this._z, w = this._w;
  901. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  902. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  903. if ( cosHalfTheta < 0 ) {
  904. this._w = - qb._w;
  905. this._x = - qb._x;
  906. this._y = - qb._y;
  907. this._z = - qb._z;
  908. cosHalfTheta = - cosHalfTheta;
  909. } else {
  910. this.copy( qb );
  911. }
  912. if ( cosHalfTheta >= 1.0 ) {
  913. this._w = w;
  914. this._x = x;
  915. this._y = y;
  916. this._z = z;
  917. return this;
  918. }
  919. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  920. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  921. var s = 1 - t;
  922. this._w = s * w + t * this._w;
  923. this._x = s * x + t * this._x;
  924. this._y = s * y + t * this._y;
  925. this._z = s * z + t * this._z;
  926. return this.normalize();
  927. }
  928. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  929. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  930. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  931. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  932. this._w = ( w * ratioA + this._w * ratioB );
  933. this._x = ( x * ratioA + this._x * ratioB );
  934. this._y = ( y * ratioA + this._y * ratioB );
  935. this._z = ( z * ratioA + this._z * ratioB );
  936. this.onChangeCallback();
  937. return this;
  938. },
  939. equals: function ( quaternion ) {
  940. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  941. },
  942. fromArray: function ( array, offset ) {
  943. if ( offset === undefined ) offset = 0;
  944. this._x = array[ offset ];
  945. this._y = array[ offset + 1 ];
  946. this._z = array[ offset + 2 ];
  947. this._w = array[ offset + 3 ];
  948. this.onChangeCallback();
  949. return this;
  950. },
  951. toArray: function ( array, offset ) {
  952. if ( array === undefined ) array = [];
  953. if ( offset === undefined ) offset = 0;
  954. array[ offset ] = this._x;
  955. array[ offset + 1 ] = this._y;
  956. array[ offset + 2 ] = this._z;
  957. array[ offset + 3 ] = this._w;
  958. return array;
  959. },
  960. onChange: function ( callback ) {
  961. this.onChangeCallback = callback;
  962. return this;
  963. },
  964. onChangeCallback: function () {}
  965. } );
  966. /**
  967. * @author mrdoob / http://mrdoob.com/
  968. * @author kile / http://kile.stravaganza.org/
  969. * @author philogb / http://blog.thejit.org/
  970. * @author mikael emtinger / http://gomo.se/
  971. * @author egraether / http://egraether.com/
  972. * @author WestLangley / http://github.com/WestLangley
  973. */
  974. function Vector3( x, y, z ) {
  975. this.x = x || 0;
  976. this.y = y || 0;
  977. this.z = z || 0;
  978. }
  979. Object.assign( Vector3.prototype, {
  980. isVector3: true,
  981. set: function ( x, y, z ) {
  982. this.x = x;
  983. this.y = y;
  984. this.z = z;
  985. return this;
  986. },
  987. setScalar: function ( scalar ) {
  988. this.x = scalar;
  989. this.y = scalar;
  990. this.z = scalar;
  991. return this;
  992. },
  993. setX: function ( x ) {
  994. this.x = x;
  995. return this;
  996. },
  997. setY: function ( y ) {
  998. this.y = y;
  999. return this;
  1000. },
  1001. setZ: function ( z ) {
  1002. this.z = z;
  1003. return this;
  1004. },
  1005. setComponent: function ( index, value ) {
  1006. switch ( index ) {
  1007. case 0: this.x = value; break;
  1008. case 1: this.y = value; break;
  1009. case 2: this.z = value; break;
  1010. default: throw new Error( 'index is out of range: ' + index );
  1011. }
  1012. return this;
  1013. },
  1014. getComponent: function ( index ) {
  1015. switch ( index ) {
  1016. case 0: return this.x;
  1017. case 1: return this.y;
  1018. case 2: return this.z;
  1019. default: throw new Error( 'index is out of range: ' + index );
  1020. }
  1021. },
  1022. clone: function () {
  1023. return new this.constructor( this.x, this.y, this.z );
  1024. },
  1025. copy: function ( v ) {
  1026. this.x = v.x;
  1027. this.y = v.y;
  1028. this.z = v.z;
  1029. return this;
  1030. },
  1031. add: function ( v, w ) {
  1032. if ( w !== undefined ) {
  1033. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1034. return this.addVectors( v, w );
  1035. }
  1036. this.x += v.x;
  1037. this.y += v.y;
  1038. this.z += v.z;
  1039. return this;
  1040. },
  1041. addScalar: function ( s ) {
  1042. this.x += s;
  1043. this.y += s;
  1044. this.z += s;
  1045. return this;
  1046. },
  1047. addVectors: function ( a, b ) {
  1048. this.x = a.x + b.x;
  1049. this.y = a.y + b.y;
  1050. this.z = a.z + b.z;
  1051. return this;
  1052. },
  1053. addScaledVector: function ( v, s ) {
  1054. this.x += v.x * s;
  1055. this.y += v.y * s;
  1056. this.z += v.z * s;
  1057. return this;
  1058. },
  1059. sub: function ( v, w ) {
  1060. if ( w !== undefined ) {
  1061. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1062. return this.subVectors( v, w );
  1063. }
  1064. this.x -= v.x;
  1065. this.y -= v.y;
  1066. this.z -= v.z;
  1067. return this;
  1068. },
  1069. subScalar: function ( s ) {
  1070. this.x -= s;
  1071. this.y -= s;
  1072. this.z -= s;
  1073. return this;
  1074. },
  1075. subVectors: function ( a, b ) {
  1076. this.x = a.x - b.x;
  1077. this.y = a.y - b.y;
  1078. this.z = a.z - b.z;
  1079. return this;
  1080. },
  1081. multiply: function ( v, w ) {
  1082. if ( w !== undefined ) {
  1083. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1084. return this.multiplyVectors( v, w );
  1085. }
  1086. this.x *= v.x;
  1087. this.y *= v.y;
  1088. this.z *= v.z;
  1089. return this;
  1090. },
  1091. multiplyScalar: function ( scalar ) {
  1092. this.x *= scalar;
  1093. this.y *= scalar;
  1094. this.z *= scalar;
  1095. return this;
  1096. },
  1097. multiplyVectors: function ( a, b ) {
  1098. this.x = a.x * b.x;
  1099. this.y = a.y * b.y;
  1100. this.z = a.z * b.z;
  1101. return this;
  1102. },
  1103. applyEuler: function () {
  1104. var quaternion = new Quaternion();
  1105. return function applyEuler( euler ) {
  1106. if ( ! ( euler && euler.isEuler ) ) {
  1107. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1108. }
  1109. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1110. };
  1111. }(),
  1112. applyAxisAngle: function () {
  1113. var quaternion = new Quaternion();
  1114. return function applyAxisAngle( axis, angle ) {
  1115. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1116. };
  1117. }(),
  1118. applyMatrix3: function ( m ) {
  1119. var x = this.x, y = this.y, z = this.z;
  1120. var e = m.elements;
  1121. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1122. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1123. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1124. return this;
  1125. },
  1126. applyMatrix4: function ( m ) {
  1127. var x = this.x, y = this.y, z = this.z;
  1128. var e = m.elements;
  1129. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1130. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1131. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1132. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1133. return this;
  1134. },
  1135. applyQuaternion: function ( q ) {
  1136. var x = this.x, y = this.y, z = this.z;
  1137. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1138. // calculate quat * vector
  1139. var ix = qw * x + qy * z - qz * y;
  1140. var iy = qw * y + qz * x - qx * z;
  1141. var iz = qw * z + qx * y - qy * x;
  1142. var iw = - qx * x - qy * y - qz * z;
  1143. // calculate result * inverse quat
  1144. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1145. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1146. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1147. return this;
  1148. },
  1149. project: function ( camera ) {
  1150. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1151. },
  1152. unproject: function ( camera ) {
  1153. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1154. },
  1155. transformDirection: function ( m ) {
  1156. // input: THREE.Matrix4 affine matrix
  1157. // vector interpreted as a direction
  1158. var x = this.x, y = this.y, z = this.z;
  1159. var e = m.elements;
  1160. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1161. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1162. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1163. return this.normalize();
  1164. },
  1165. divide: function ( v ) {
  1166. this.x /= v.x;
  1167. this.y /= v.y;
  1168. this.z /= v.z;
  1169. return this;
  1170. },
  1171. divideScalar: function ( scalar ) {
  1172. return this.multiplyScalar( 1 / scalar );
  1173. },
  1174. min: function ( v ) {
  1175. this.x = Math.min( this.x, v.x );
  1176. this.y = Math.min( this.y, v.y );
  1177. this.z = Math.min( this.z, v.z );
  1178. return this;
  1179. },
  1180. max: function ( v ) {
  1181. this.x = Math.max( this.x, v.x );
  1182. this.y = Math.max( this.y, v.y );
  1183. this.z = Math.max( this.z, v.z );
  1184. return this;
  1185. },
  1186. clamp: function ( min, max ) {
  1187. // assumes min < max, componentwise
  1188. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1189. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1190. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1191. return this;
  1192. },
  1193. clampScalar: function ( minVal, maxVal ) {
  1194. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1195. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1196. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1197. return this;
  1198. },
  1199. clampLength: function ( min, max ) {
  1200. var length = this.length();
  1201. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1202. },
  1203. floor: function () {
  1204. this.x = Math.floor( this.x );
  1205. this.y = Math.floor( this.y );
  1206. this.z = Math.floor( this.z );
  1207. return this;
  1208. },
  1209. ceil: function () {
  1210. this.x = Math.ceil( this.x );
  1211. this.y = Math.ceil( this.y );
  1212. this.z = Math.ceil( this.z );
  1213. return this;
  1214. },
  1215. round: function () {
  1216. this.x = Math.round( this.x );
  1217. this.y = Math.round( this.y );
  1218. this.z = Math.round( this.z );
  1219. return this;
  1220. },
  1221. roundToZero: function () {
  1222. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1223. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1224. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1225. return this;
  1226. },
  1227. negate: function () {
  1228. this.x = - this.x;
  1229. this.y = - this.y;
  1230. this.z = - this.z;
  1231. return this;
  1232. },
  1233. dot: function ( v ) {
  1234. return this.x * v.x + this.y * v.y + this.z * v.z;
  1235. },
  1236. // TODO lengthSquared?
  1237. lengthSq: function () {
  1238. return this.x * this.x + this.y * this.y + this.z * this.z;
  1239. },
  1240. length: function () {
  1241. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1242. },
  1243. manhattanLength: function () {
  1244. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1245. },
  1246. normalize: function () {
  1247. return this.divideScalar( this.length() || 1 );
  1248. },
  1249. setLength: function ( length ) {
  1250. return this.normalize().multiplyScalar( length );
  1251. },
  1252. lerp: function ( v, alpha ) {
  1253. this.x += ( v.x - this.x ) * alpha;
  1254. this.y += ( v.y - this.y ) * alpha;
  1255. this.z += ( v.z - this.z ) * alpha;
  1256. return this;
  1257. },
  1258. lerpVectors: function ( v1, v2, alpha ) {
  1259. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1260. },
  1261. cross: function ( v, w ) {
  1262. if ( w !== undefined ) {
  1263. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1264. return this.crossVectors( v, w );
  1265. }
  1266. return this.crossVectors( this, v );
  1267. },
  1268. crossVectors: function ( a, b ) {
  1269. var ax = a.x, ay = a.y, az = a.z;
  1270. var bx = b.x, by = b.y, bz = b.z;
  1271. this.x = ay * bz - az * by;
  1272. this.y = az * bx - ax * bz;
  1273. this.z = ax * by - ay * bx;
  1274. return this;
  1275. },
  1276. projectOnVector: function ( vector ) {
  1277. var scalar = vector.dot( this ) / vector.lengthSq();
  1278. return this.copy( vector ).multiplyScalar( scalar );
  1279. },
  1280. projectOnPlane: function () {
  1281. var v1 = new Vector3();
  1282. return function projectOnPlane( planeNormal ) {
  1283. v1.copy( this ).projectOnVector( planeNormal );
  1284. return this.sub( v1 );
  1285. };
  1286. }(),
  1287. reflect: function () {
  1288. // reflect incident vector off plane orthogonal to normal
  1289. // normal is assumed to have unit length
  1290. var v1 = new Vector3();
  1291. return function reflect( normal ) {
  1292. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1293. };
  1294. }(),
  1295. angleTo: function ( v ) {
  1296. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1297. // clamp, to handle numerical problems
  1298. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1299. },
  1300. distanceTo: function ( v ) {
  1301. return Math.sqrt( this.distanceToSquared( v ) );
  1302. },
  1303. distanceToSquared: function ( v ) {
  1304. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1305. return dx * dx + dy * dy + dz * dz;
  1306. },
  1307. manhattanDistanceTo: function ( v ) {
  1308. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1309. },
  1310. setFromSpherical: function ( s ) {
  1311. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1312. },
  1313. setFromSphericalCoords: function ( radius, phi, theta ) {
  1314. var sinPhiRadius = Math.sin( phi ) * radius;
  1315. this.x = sinPhiRadius * Math.sin( theta );
  1316. this.y = Math.cos( phi ) * radius;
  1317. this.z = sinPhiRadius * Math.cos( theta );
  1318. return this;
  1319. },
  1320. setFromCylindrical: function ( c ) {
  1321. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1322. },
  1323. setFromCylindricalCoords: function ( radius, theta, y ) {
  1324. this.x = radius * Math.sin( theta );
  1325. this.y = y;
  1326. this.z = radius * Math.cos( theta );
  1327. return this;
  1328. },
  1329. setFromMatrixPosition: function ( m ) {
  1330. var e = m.elements;
  1331. this.x = e[ 12 ];
  1332. this.y = e[ 13 ];
  1333. this.z = e[ 14 ];
  1334. return this;
  1335. },
  1336. setFromMatrixScale: function ( m ) {
  1337. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1338. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1339. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1340. this.x = sx;
  1341. this.y = sy;
  1342. this.z = sz;
  1343. return this;
  1344. },
  1345. setFromMatrixColumn: function ( m, index ) {
  1346. return this.fromArray( m.elements, index * 4 );
  1347. },
  1348. equals: function ( v ) {
  1349. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1350. },
  1351. fromArray: function ( array, offset ) {
  1352. if ( offset === undefined ) offset = 0;
  1353. this.x = array[ offset ];
  1354. this.y = array[ offset + 1 ];
  1355. this.z = array[ offset + 2 ];
  1356. return this;
  1357. },
  1358. toArray: function ( array, offset ) {
  1359. if ( array === undefined ) array = [];
  1360. if ( offset === undefined ) offset = 0;
  1361. array[ offset ] = this.x;
  1362. array[ offset + 1 ] = this.y;
  1363. array[ offset + 2 ] = this.z;
  1364. return array;
  1365. },
  1366. fromBufferAttribute: function ( attribute, index, offset ) {
  1367. if ( offset !== undefined ) {
  1368. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1369. }
  1370. this.x = attribute.getX( index );
  1371. this.y = attribute.getY( index );
  1372. this.z = attribute.getZ( index );
  1373. return this;
  1374. }
  1375. } );
  1376. /**
  1377. * @author alteredq / http://alteredqualia.com/
  1378. * @author WestLangley / http://github.com/WestLangley
  1379. * @author bhouston / http://clara.io
  1380. * @author tschw
  1381. */
  1382. function Matrix3() {
  1383. this.elements = [
  1384. 1, 0, 0,
  1385. 0, 1, 0,
  1386. 0, 0, 1
  1387. ];
  1388. if ( arguments.length > 0 ) {
  1389. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1390. }
  1391. }
  1392. Object.assign( Matrix3.prototype, {
  1393. isMatrix3: true,
  1394. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1395. var te = this.elements;
  1396. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1397. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1398. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1399. return this;
  1400. },
  1401. identity: function () {
  1402. this.set(
  1403. 1, 0, 0,
  1404. 0, 1, 0,
  1405. 0, 0, 1
  1406. );
  1407. return this;
  1408. },
  1409. clone: function () {
  1410. return new this.constructor().fromArray( this.elements );
  1411. },
  1412. copy: function ( m ) {
  1413. var te = this.elements;
  1414. var me = m.elements;
  1415. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1416. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1417. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1418. return this;
  1419. },
  1420. setFromMatrix4: function ( m ) {
  1421. var me = m.elements;
  1422. this.set(
  1423. me[ 0 ], me[ 4 ], me[ 8 ],
  1424. me[ 1 ], me[ 5 ], me[ 9 ],
  1425. me[ 2 ], me[ 6 ], me[ 10 ]
  1426. );
  1427. return this;
  1428. },
  1429. applyToBufferAttribute: function () {
  1430. var v1 = new Vector3();
  1431. return function applyToBufferAttribute( attribute ) {
  1432. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1433. v1.x = attribute.getX( i );
  1434. v1.y = attribute.getY( i );
  1435. v1.z = attribute.getZ( i );
  1436. v1.applyMatrix3( this );
  1437. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  1438. }
  1439. return attribute;
  1440. };
  1441. }(),
  1442. multiply: function ( m ) {
  1443. return this.multiplyMatrices( this, m );
  1444. },
  1445. premultiply: function ( m ) {
  1446. return this.multiplyMatrices( m, this );
  1447. },
  1448. multiplyMatrices: function ( a, b ) {
  1449. var ae = a.elements;
  1450. var be = b.elements;
  1451. var te = this.elements;
  1452. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1453. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1454. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1455. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1456. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1457. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1458. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1459. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1460. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1461. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1462. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1463. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1464. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1465. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1466. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1467. return this;
  1468. },
  1469. multiplyScalar: function ( s ) {
  1470. var te = this.elements;
  1471. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1472. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1473. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1474. return this;
  1475. },
  1476. determinant: function () {
  1477. var te = this.elements;
  1478. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1479. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1480. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1481. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1482. },
  1483. getInverse: function ( matrix, throwOnDegenerate ) {
  1484. if ( matrix && matrix.isMatrix4 ) {
  1485. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1486. }
  1487. var me = matrix.elements,
  1488. te = this.elements,
  1489. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1490. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1491. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1492. t11 = n33 * n22 - n32 * n23,
  1493. t12 = n32 * n13 - n33 * n12,
  1494. t13 = n23 * n12 - n22 * n13,
  1495. det = n11 * t11 + n21 * t12 + n31 * t13;
  1496. if ( det === 0 ) {
  1497. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1498. if ( throwOnDegenerate === true ) {
  1499. throw new Error( msg );
  1500. } else {
  1501. console.warn( msg );
  1502. }
  1503. return this.identity();
  1504. }
  1505. var detInv = 1 / det;
  1506. te[ 0 ] = t11 * detInv;
  1507. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1508. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1509. te[ 3 ] = t12 * detInv;
  1510. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1511. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1512. te[ 6 ] = t13 * detInv;
  1513. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1514. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1515. return this;
  1516. },
  1517. transpose: function () {
  1518. var tmp, m = this.elements;
  1519. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1520. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1521. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1522. return this;
  1523. },
  1524. getNormalMatrix: function ( matrix4 ) {
  1525. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1526. },
  1527. transposeIntoArray: function ( r ) {
  1528. var m = this.elements;
  1529. r[ 0 ] = m[ 0 ];
  1530. r[ 1 ] = m[ 3 ];
  1531. r[ 2 ] = m[ 6 ];
  1532. r[ 3 ] = m[ 1 ];
  1533. r[ 4 ] = m[ 4 ];
  1534. r[ 5 ] = m[ 7 ];
  1535. r[ 6 ] = m[ 2 ];
  1536. r[ 7 ] = m[ 5 ];
  1537. r[ 8 ] = m[ 8 ];
  1538. return this;
  1539. },
  1540. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1541. var c = Math.cos( rotation );
  1542. var s = Math.sin( rotation );
  1543. this.set(
  1544. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1545. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1546. 0, 0, 1
  1547. );
  1548. },
  1549. scale: function ( sx, sy ) {
  1550. var te = this.elements;
  1551. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1552. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1553. return this;
  1554. },
  1555. rotate: function ( theta ) {
  1556. var c = Math.cos( theta );
  1557. var s = Math.sin( theta );
  1558. var te = this.elements;
  1559. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1560. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1561. te[ 0 ] = c * a11 + s * a21;
  1562. te[ 3 ] = c * a12 + s * a22;
  1563. te[ 6 ] = c * a13 + s * a23;
  1564. te[ 1 ] = - s * a11 + c * a21;
  1565. te[ 4 ] = - s * a12 + c * a22;
  1566. te[ 7 ] = - s * a13 + c * a23;
  1567. return this;
  1568. },
  1569. translate: function ( tx, ty ) {
  1570. var te = this.elements;
  1571. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1572. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1573. return this;
  1574. },
  1575. equals: function ( matrix ) {
  1576. var te = this.elements;
  1577. var me = matrix.elements;
  1578. for ( var i = 0; i < 9; i ++ ) {
  1579. if ( te[ i ] !== me[ i ] ) return false;
  1580. }
  1581. return true;
  1582. },
  1583. fromArray: function ( array, offset ) {
  1584. if ( offset === undefined ) offset = 0;
  1585. for ( var i = 0; i < 9; i ++ ) {
  1586. this.elements[ i ] = array[ i + offset ];
  1587. }
  1588. return this;
  1589. },
  1590. toArray: function ( array, offset ) {
  1591. if ( array === undefined ) array = [];
  1592. if ( offset === undefined ) offset = 0;
  1593. var te = this.elements;
  1594. array[ offset ] = te[ 0 ];
  1595. array[ offset + 1 ] = te[ 1 ];
  1596. array[ offset + 2 ] = te[ 2 ];
  1597. array[ offset + 3 ] = te[ 3 ];
  1598. array[ offset + 4 ] = te[ 4 ];
  1599. array[ offset + 5 ] = te[ 5 ];
  1600. array[ offset + 6 ] = te[ 6 ];
  1601. array[ offset + 7 ] = te[ 7 ];
  1602. array[ offset + 8 ] = te[ 8 ];
  1603. return array;
  1604. }
  1605. } );
  1606. /**
  1607. * @author mrdoob / http://mrdoob.com/
  1608. * @author alteredq / http://alteredqualia.com/
  1609. * @author szimek / https://github.com/szimek/
  1610. */
  1611. var _canvas;
  1612. var ImageUtils = {
  1613. getDataURL: function ( image ) {
  1614. var canvas;
  1615. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1616. return image.src;
  1617. } else if ( image instanceof HTMLCanvasElement ) {
  1618. canvas = image;
  1619. } else {
  1620. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1621. _canvas.width = image.width;
  1622. _canvas.height = image.height;
  1623. var context = _canvas.getContext( '2d' );
  1624. if ( image instanceof ImageData ) {
  1625. context.putImageData( image, 0, 0 );
  1626. } else {
  1627. context.drawImage( image, 0, 0, image.width, image.height );
  1628. }
  1629. canvas = _canvas;
  1630. }
  1631. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1632. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1633. } else {
  1634. return canvas.toDataURL( 'image/png' );
  1635. }
  1636. }
  1637. };
  1638. /**
  1639. * @author mrdoob / http://mrdoob.com/
  1640. * @author alteredq / http://alteredqualia.com/
  1641. * @author szimek / https://github.com/szimek/
  1642. */
  1643. var textureId = 0;
  1644. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1645. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1646. this.uuid = _Math.generateUUID();
  1647. this.name = '';
  1648. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1649. this.mipmaps = [];
  1650. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1651. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1652. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1653. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1654. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  1655. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1656. this.format = format !== undefined ? format : RGBAFormat;
  1657. this.type = type !== undefined ? type : UnsignedByteType;
  1658. this.offset = new Vector2( 0, 0 );
  1659. this.repeat = new Vector2( 1, 1 );
  1660. this.center = new Vector2( 0, 0 );
  1661. this.rotation = 0;
  1662. this.matrixAutoUpdate = true;
  1663. this.matrix = new Matrix3();
  1664. this.generateMipmaps = true;
  1665. this.premultiplyAlpha = false;
  1666. this.flipY = true;
  1667. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1668. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1669. //
  1670. // Also changing the encoding after already used by a Material will not automatically make the Material
  1671. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1672. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1673. this.version = 0;
  1674. this.onUpdate = null;
  1675. }
  1676. Texture.DEFAULT_IMAGE = undefined;
  1677. Texture.DEFAULT_MAPPING = UVMapping;
  1678. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1679. constructor: Texture,
  1680. isTexture: true,
  1681. updateMatrix: function () {
  1682. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1683. },
  1684. clone: function () {
  1685. return new this.constructor().copy( this );
  1686. },
  1687. copy: function ( source ) {
  1688. this.name = source.name;
  1689. this.image = source.image;
  1690. this.mipmaps = source.mipmaps.slice( 0 );
  1691. this.mapping = source.mapping;
  1692. this.wrapS = source.wrapS;
  1693. this.wrapT = source.wrapT;
  1694. this.magFilter = source.magFilter;
  1695. this.minFilter = source.minFilter;
  1696. this.anisotropy = source.anisotropy;
  1697. this.format = source.format;
  1698. this.type = source.type;
  1699. this.offset.copy( source.offset );
  1700. this.repeat.copy( source.repeat );
  1701. this.center.copy( source.center );
  1702. this.rotation = source.rotation;
  1703. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1704. this.matrix.copy( source.matrix );
  1705. this.generateMipmaps = source.generateMipmaps;
  1706. this.premultiplyAlpha = source.premultiplyAlpha;
  1707. this.flipY = source.flipY;
  1708. this.unpackAlignment = source.unpackAlignment;
  1709. this.encoding = source.encoding;
  1710. return this;
  1711. },
  1712. toJSON: function ( meta ) {
  1713. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1714. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1715. return meta.textures[ this.uuid ];
  1716. }
  1717. var output = {
  1718. metadata: {
  1719. version: 4.5,
  1720. type: 'Texture',
  1721. generator: 'Texture.toJSON'
  1722. },
  1723. uuid: this.uuid,
  1724. name: this.name,
  1725. mapping: this.mapping,
  1726. repeat: [ this.repeat.x, this.repeat.y ],
  1727. offset: [ this.offset.x, this.offset.y ],
  1728. center: [ this.center.x, this.center.y ],
  1729. rotation: this.rotation,
  1730. wrap: [ this.wrapS, this.wrapT ],
  1731. format: this.format,
  1732. type: this.type,
  1733. encoding: this.encoding,
  1734. minFilter: this.minFilter,
  1735. magFilter: this.magFilter,
  1736. anisotropy: this.anisotropy,
  1737. flipY: this.flipY,
  1738. premultiplyAlpha: this.premultiplyAlpha,
  1739. unpackAlignment: this.unpackAlignment
  1740. };
  1741. if ( this.image !== undefined ) {
  1742. // TODO: Move to THREE.Image
  1743. var image = this.image;
  1744. if ( image.uuid === undefined ) {
  1745. image.uuid = _Math.generateUUID(); // UGH
  1746. }
  1747. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1748. var url;
  1749. if ( Array.isArray( image ) ) {
  1750. // process array of images e.g. CubeTexture
  1751. url = [];
  1752. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1753. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1754. }
  1755. } else {
  1756. // process single image
  1757. url = ImageUtils.getDataURL( image );
  1758. }
  1759. meta.images[ image.uuid ] = {
  1760. uuid: image.uuid,
  1761. url: url
  1762. };
  1763. }
  1764. output.image = image.uuid;
  1765. }
  1766. if ( ! isRootObject ) {
  1767. meta.textures[ this.uuid ] = output;
  1768. }
  1769. return output;
  1770. },
  1771. dispose: function () {
  1772. this.dispatchEvent( { type: 'dispose' } );
  1773. },
  1774. transformUv: function ( uv ) {
  1775. if ( this.mapping !== UVMapping ) return uv;
  1776. uv.applyMatrix3( this.matrix );
  1777. if ( uv.x < 0 || uv.x > 1 ) {
  1778. switch ( this.wrapS ) {
  1779. case RepeatWrapping:
  1780. uv.x = uv.x - Math.floor( uv.x );
  1781. break;
  1782. case ClampToEdgeWrapping:
  1783. uv.x = uv.x < 0 ? 0 : 1;
  1784. break;
  1785. case MirroredRepeatWrapping:
  1786. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1787. uv.x = Math.ceil( uv.x ) - uv.x;
  1788. } else {
  1789. uv.x = uv.x - Math.floor( uv.x );
  1790. }
  1791. break;
  1792. }
  1793. }
  1794. if ( uv.y < 0 || uv.y > 1 ) {
  1795. switch ( this.wrapT ) {
  1796. case RepeatWrapping:
  1797. uv.y = uv.y - Math.floor( uv.y );
  1798. break;
  1799. case ClampToEdgeWrapping:
  1800. uv.y = uv.y < 0 ? 0 : 1;
  1801. break;
  1802. case MirroredRepeatWrapping:
  1803. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1804. uv.y = Math.ceil( uv.y ) - uv.y;
  1805. } else {
  1806. uv.y = uv.y - Math.floor( uv.y );
  1807. }
  1808. break;
  1809. }
  1810. }
  1811. if ( this.flipY ) {
  1812. uv.y = 1 - uv.y;
  1813. }
  1814. return uv;
  1815. }
  1816. } );
  1817. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1818. set: function ( value ) {
  1819. if ( value === true ) this.version ++;
  1820. }
  1821. } );
  1822. /**
  1823. * @author supereggbert / http://www.paulbrunt.co.uk/
  1824. * @author philogb / http://blog.thejit.org/
  1825. * @author mikael emtinger / http://gomo.se/
  1826. * @author egraether / http://egraether.com/
  1827. * @author WestLangley / http://github.com/WestLangley
  1828. */
  1829. function Vector4( x, y, z, w ) {
  1830. this.x = x || 0;
  1831. this.y = y || 0;
  1832. this.z = z || 0;
  1833. this.w = ( w !== undefined ) ? w : 1;
  1834. }
  1835. Object.assign( Vector4.prototype, {
  1836. isVector4: true,
  1837. set: function ( x, y, z, w ) {
  1838. this.x = x;
  1839. this.y = y;
  1840. this.z = z;
  1841. this.w = w;
  1842. return this;
  1843. },
  1844. setScalar: function ( scalar ) {
  1845. this.x = scalar;
  1846. this.y = scalar;
  1847. this.z = scalar;
  1848. this.w = scalar;
  1849. return this;
  1850. },
  1851. setX: function ( x ) {
  1852. this.x = x;
  1853. return this;
  1854. },
  1855. setY: function ( y ) {
  1856. this.y = y;
  1857. return this;
  1858. },
  1859. setZ: function ( z ) {
  1860. this.z = z;
  1861. return this;
  1862. },
  1863. setW: function ( w ) {
  1864. this.w = w;
  1865. return this;
  1866. },
  1867. setComponent: function ( index, value ) {
  1868. switch ( index ) {
  1869. case 0: this.x = value; break;
  1870. case 1: this.y = value; break;
  1871. case 2: this.z = value; break;
  1872. case 3: this.w = value; break;
  1873. default: throw new Error( 'index is out of range: ' + index );
  1874. }
  1875. return this;
  1876. },
  1877. getComponent: function ( index ) {
  1878. switch ( index ) {
  1879. case 0: return this.x;
  1880. case 1: return this.y;
  1881. case 2: return this.z;
  1882. case 3: return this.w;
  1883. default: throw new Error( 'index is out of range: ' + index );
  1884. }
  1885. },
  1886. clone: function () {
  1887. return new this.constructor( this.x, this.y, this.z, this.w );
  1888. },
  1889. copy: function ( v ) {
  1890. this.x = v.x;
  1891. this.y = v.y;
  1892. this.z = v.z;
  1893. this.w = ( v.w !== undefined ) ? v.w : 1;
  1894. return this;
  1895. },
  1896. add: function ( v, w ) {
  1897. if ( w !== undefined ) {
  1898. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1899. return this.addVectors( v, w );
  1900. }
  1901. this.x += v.x;
  1902. this.y += v.y;
  1903. this.z += v.z;
  1904. this.w += v.w;
  1905. return this;
  1906. },
  1907. addScalar: function ( s ) {
  1908. this.x += s;
  1909. this.y += s;
  1910. this.z += s;
  1911. this.w += s;
  1912. return this;
  1913. },
  1914. addVectors: function ( a, b ) {
  1915. this.x = a.x + b.x;
  1916. this.y = a.y + b.y;
  1917. this.z = a.z + b.z;
  1918. this.w = a.w + b.w;
  1919. return this;
  1920. },
  1921. addScaledVector: function ( v, s ) {
  1922. this.x += v.x * s;
  1923. this.y += v.y * s;
  1924. this.z += v.z * s;
  1925. this.w += v.w * s;
  1926. return this;
  1927. },
  1928. sub: function ( v, w ) {
  1929. if ( w !== undefined ) {
  1930. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1931. return this.subVectors( v, w );
  1932. }
  1933. this.x -= v.x;
  1934. this.y -= v.y;
  1935. this.z -= v.z;
  1936. this.w -= v.w;
  1937. return this;
  1938. },
  1939. subScalar: function ( s ) {
  1940. this.x -= s;
  1941. this.y -= s;
  1942. this.z -= s;
  1943. this.w -= s;
  1944. return this;
  1945. },
  1946. subVectors: function ( a, b ) {
  1947. this.x = a.x - b.x;
  1948. this.y = a.y - b.y;
  1949. this.z = a.z - b.z;
  1950. this.w = a.w - b.w;
  1951. return this;
  1952. },
  1953. multiplyScalar: function ( scalar ) {
  1954. this.x *= scalar;
  1955. this.y *= scalar;
  1956. this.z *= scalar;
  1957. this.w *= scalar;
  1958. return this;
  1959. },
  1960. applyMatrix4: function ( m ) {
  1961. var x = this.x, y = this.y, z = this.z, w = this.w;
  1962. var e = m.elements;
  1963. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1964. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1965. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1966. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1967. return this;
  1968. },
  1969. divideScalar: function ( scalar ) {
  1970. return this.multiplyScalar( 1 / scalar );
  1971. },
  1972. setAxisAngleFromQuaternion: function ( q ) {
  1973. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1974. // q is assumed to be normalized
  1975. this.w = 2 * Math.acos( q.w );
  1976. var s = Math.sqrt( 1 - q.w * q.w );
  1977. if ( s < 0.0001 ) {
  1978. this.x = 1;
  1979. this.y = 0;
  1980. this.z = 0;
  1981. } else {
  1982. this.x = q.x / s;
  1983. this.y = q.y / s;
  1984. this.z = q.z / s;
  1985. }
  1986. return this;
  1987. },
  1988. setAxisAngleFromRotationMatrix: function ( m ) {
  1989. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1990. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1991. var angle, x, y, z, // variables for result
  1992. epsilon = 0.01, // margin to allow for rounding errors
  1993. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1994. te = m.elements,
  1995. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1996. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1997. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1998. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1999. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2000. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2001. // singularity found
  2002. // first check for identity matrix which must have +1 for all terms
  2003. // in leading diagonal and zero in other terms
  2004. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2005. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2006. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2007. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2008. // this singularity is identity matrix so angle = 0
  2009. this.set( 1, 0, 0, 0 );
  2010. return this; // zero angle, arbitrary axis
  2011. }
  2012. // otherwise this singularity is angle = 180
  2013. angle = Math.PI;
  2014. var xx = ( m11 + 1 ) / 2;
  2015. var yy = ( m22 + 1 ) / 2;
  2016. var zz = ( m33 + 1 ) / 2;
  2017. var xy = ( m12 + m21 ) / 4;
  2018. var xz = ( m13 + m31 ) / 4;
  2019. var yz = ( m23 + m32 ) / 4;
  2020. if ( ( xx > yy ) && ( xx > zz ) ) {
  2021. // m11 is the largest diagonal term
  2022. if ( xx < epsilon ) {
  2023. x = 0;
  2024. y = 0.707106781;
  2025. z = 0.707106781;
  2026. } else {
  2027. x = Math.sqrt( xx );
  2028. y = xy / x;
  2029. z = xz / x;
  2030. }
  2031. } else if ( yy > zz ) {
  2032. // m22 is the largest diagonal term
  2033. if ( yy < epsilon ) {
  2034. x = 0.707106781;
  2035. y = 0;
  2036. z = 0.707106781;
  2037. } else {
  2038. y = Math.sqrt( yy );
  2039. x = xy / y;
  2040. z = yz / y;
  2041. }
  2042. } else {
  2043. // m33 is the largest diagonal term so base result on this
  2044. if ( zz < epsilon ) {
  2045. x = 0.707106781;
  2046. y = 0.707106781;
  2047. z = 0;
  2048. } else {
  2049. z = Math.sqrt( zz );
  2050. x = xz / z;
  2051. y = yz / z;
  2052. }
  2053. }
  2054. this.set( x, y, z, angle );
  2055. return this; // return 180 deg rotation
  2056. }
  2057. // as we have reached here there are no singularities so we can handle normally
  2058. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2059. ( m13 - m31 ) * ( m13 - m31 ) +
  2060. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2061. if ( Math.abs( s ) < 0.001 ) s = 1;
  2062. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2063. // caught by singularity test above, but I've left it in just in case
  2064. this.x = ( m32 - m23 ) / s;
  2065. this.y = ( m13 - m31 ) / s;
  2066. this.z = ( m21 - m12 ) / s;
  2067. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2068. return this;
  2069. },
  2070. min: function ( v ) {
  2071. this.x = Math.min( this.x, v.x );
  2072. this.y = Math.min( this.y, v.y );
  2073. this.z = Math.min( this.z, v.z );
  2074. this.w = Math.min( this.w, v.w );
  2075. return this;
  2076. },
  2077. max: function ( v ) {
  2078. this.x = Math.max( this.x, v.x );
  2079. this.y = Math.max( this.y, v.y );
  2080. this.z = Math.max( this.z, v.z );
  2081. this.w = Math.max( this.w, v.w );
  2082. return this;
  2083. },
  2084. clamp: function ( min, max ) {
  2085. // assumes min < max, componentwise
  2086. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2087. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2088. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2089. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2090. return this;
  2091. },
  2092. clampScalar: function () {
  2093. var min, max;
  2094. return function clampScalar( minVal, maxVal ) {
  2095. if ( min === undefined ) {
  2096. min = new Vector4();
  2097. max = new Vector4();
  2098. }
  2099. min.set( minVal, minVal, minVal, minVal );
  2100. max.set( maxVal, maxVal, maxVal, maxVal );
  2101. return this.clamp( min, max );
  2102. };
  2103. }(),
  2104. clampLength: function ( min, max ) {
  2105. var length = this.length();
  2106. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2107. },
  2108. floor: function () {
  2109. this.x = Math.floor( this.x );
  2110. this.y = Math.floor( this.y );
  2111. this.z = Math.floor( this.z );
  2112. this.w = Math.floor( this.w );
  2113. return this;
  2114. },
  2115. ceil: function () {
  2116. this.x = Math.ceil( this.x );
  2117. this.y = Math.ceil( this.y );
  2118. this.z = Math.ceil( this.z );
  2119. this.w = Math.ceil( this.w );
  2120. return this;
  2121. },
  2122. round: function () {
  2123. this.x = Math.round( this.x );
  2124. this.y = Math.round( this.y );
  2125. this.z = Math.round( this.z );
  2126. this.w = Math.round( this.w );
  2127. return this;
  2128. },
  2129. roundToZero: function () {
  2130. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2131. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2132. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2133. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2134. return this;
  2135. },
  2136. negate: function () {
  2137. this.x = - this.x;
  2138. this.y = - this.y;
  2139. this.z = - this.z;
  2140. this.w = - this.w;
  2141. return this;
  2142. },
  2143. dot: function ( v ) {
  2144. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2145. },
  2146. lengthSq: function () {
  2147. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2148. },
  2149. length: function () {
  2150. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2151. },
  2152. manhattanLength: function () {
  2153. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2154. },
  2155. normalize: function () {
  2156. return this.divideScalar( this.length() || 1 );
  2157. },
  2158. setLength: function ( length ) {
  2159. return this.normalize().multiplyScalar( length );
  2160. },
  2161. lerp: function ( v, alpha ) {
  2162. this.x += ( v.x - this.x ) * alpha;
  2163. this.y += ( v.y - this.y ) * alpha;
  2164. this.z += ( v.z - this.z ) * alpha;
  2165. this.w += ( v.w - this.w ) * alpha;
  2166. return this;
  2167. },
  2168. lerpVectors: function ( v1, v2, alpha ) {
  2169. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2170. },
  2171. equals: function ( v ) {
  2172. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2173. },
  2174. fromArray: function ( array, offset ) {
  2175. if ( offset === undefined ) offset = 0;
  2176. this.x = array[ offset ];
  2177. this.y = array[ offset + 1 ];
  2178. this.z = array[ offset + 2 ];
  2179. this.w = array[ offset + 3 ];
  2180. return this;
  2181. },
  2182. toArray: function ( array, offset ) {
  2183. if ( array === undefined ) array = [];
  2184. if ( offset === undefined ) offset = 0;
  2185. array[ offset ] = this.x;
  2186. array[ offset + 1 ] = this.y;
  2187. array[ offset + 2 ] = this.z;
  2188. array[ offset + 3 ] = this.w;
  2189. return array;
  2190. },
  2191. fromBufferAttribute: function ( attribute, index, offset ) {
  2192. if ( offset !== undefined ) {
  2193. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2194. }
  2195. this.x = attribute.getX( index );
  2196. this.y = attribute.getY( index );
  2197. this.z = attribute.getZ( index );
  2198. this.w = attribute.getW( index );
  2199. return this;
  2200. }
  2201. } );
  2202. /**
  2203. * @author szimek / https://github.com/szimek/
  2204. * @author alteredq / http://alteredqualia.com/
  2205. * @author Marius Kintel / https://github.com/kintel
  2206. */
  2207. /*
  2208. In options, we can specify:
  2209. * Texture parameters for an auto-generated target texture
  2210. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2211. */
  2212. function WebGLRenderTarget( width, height, options ) {
  2213. this.width = width;
  2214. this.height = height;
  2215. this.scissor = new Vector4( 0, 0, width, height );
  2216. this.scissorTest = false;
  2217. this.viewport = new Vector4( 0, 0, width, height );
  2218. options = options || {};
  2219. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2220. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2221. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2222. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2223. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2224. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2225. }
  2226. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2227. constructor: WebGLRenderTarget,
  2228. isWebGLRenderTarget: true,
  2229. setSize: function ( width, height ) {
  2230. if ( this.width !== width || this.height !== height ) {
  2231. this.width = width;
  2232. this.height = height;
  2233. this.dispose();
  2234. }
  2235. this.viewport.set( 0, 0, width, height );
  2236. this.scissor.set( 0, 0, width, height );
  2237. },
  2238. clone: function () {
  2239. return new this.constructor().copy( this );
  2240. },
  2241. copy: function ( source ) {
  2242. this.width = source.width;
  2243. this.height = source.height;
  2244. this.viewport.copy( source.viewport );
  2245. this.texture = source.texture.clone();
  2246. this.depthBuffer = source.depthBuffer;
  2247. this.stencilBuffer = source.stencilBuffer;
  2248. this.depthTexture = source.depthTexture;
  2249. return this;
  2250. },
  2251. dispose: function () {
  2252. this.dispatchEvent( { type: 'dispose' } );
  2253. }
  2254. } );
  2255. /**
  2256. * @author Mugen87 / https://github.com/Mugen87
  2257. * @author Matt DesLauriers / @mattdesl
  2258. */
  2259. function WebGLMultisampleRenderTarget( width, height, options ) {
  2260. WebGLRenderTarget.call( this, width, height, options );
  2261. this.samples = 4;
  2262. }
  2263. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2264. constructor: WebGLMultisampleRenderTarget,
  2265. isWebGLMultisampleRenderTarget: true,
  2266. copy: function ( source ) {
  2267. WebGLRenderTarget.prototype.copy.call( this, source );
  2268. this.samples = source.samples;
  2269. return this;
  2270. }
  2271. } );
  2272. /**
  2273. * @author alteredq / http://alteredqualia.com
  2274. */
  2275. function WebGLRenderTargetCube( width, height, options ) {
  2276. WebGLRenderTarget.call( this, width, height, options );
  2277. }
  2278. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2279. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2280. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2281. /**
  2282. * @author alteredq / http://alteredqualia.com/
  2283. */
  2284. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2285. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2286. this.image = { data: data, width: width, height: height };
  2287. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2288. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2289. this.generateMipmaps = false;
  2290. this.flipY = false;
  2291. this.unpackAlignment = 1;
  2292. }
  2293. DataTexture.prototype = Object.create( Texture.prototype );
  2294. DataTexture.prototype.constructor = DataTexture;
  2295. DataTexture.prototype.isDataTexture = true;
  2296. /**
  2297. * @author bhouston / http://clara.io
  2298. * @author WestLangley / http://github.com/WestLangley
  2299. */
  2300. function Box3( min, max ) {
  2301. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2302. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2303. }
  2304. Object.assign( Box3.prototype, {
  2305. isBox3: true,
  2306. set: function ( min, max ) {
  2307. this.min.copy( min );
  2308. this.max.copy( max );
  2309. return this;
  2310. },
  2311. setFromArray: function ( array ) {
  2312. var minX = + Infinity;
  2313. var minY = + Infinity;
  2314. var minZ = + Infinity;
  2315. var maxX = - Infinity;
  2316. var maxY = - Infinity;
  2317. var maxZ = - Infinity;
  2318. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2319. var x = array[ i ];
  2320. var y = array[ i + 1 ];
  2321. var z = array[ i + 2 ];
  2322. if ( x < minX ) minX = x;
  2323. if ( y < minY ) minY = y;
  2324. if ( z < minZ ) minZ = z;
  2325. if ( x > maxX ) maxX = x;
  2326. if ( y > maxY ) maxY = y;
  2327. if ( z > maxZ ) maxZ = z;
  2328. }
  2329. this.min.set( minX, minY, minZ );
  2330. this.max.set( maxX, maxY, maxZ );
  2331. return this;
  2332. },
  2333. setFromBufferAttribute: function ( attribute ) {
  2334. var minX = + Infinity;
  2335. var minY = + Infinity;
  2336. var minZ = + Infinity;
  2337. var maxX = - Infinity;
  2338. var maxY = - Infinity;
  2339. var maxZ = - Infinity;
  2340. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2341. var x = attribute.getX( i );
  2342. var y = attribute.getY( i );
  2343. var z = attribute.getZ( i );
  2344. if ( x < minX ) minX = x;
  2345. if ( y < minY ) minY = y;
  2346. if ( z < minZ ) minZ = z;
  2347. if ( x > maxX ) maxX = x;
  2348. if ( y > maxY ) maxY = y;
  2349. if ( z > maxZ ) maxZ = z;
  2350. }
  2351. this.min.set( minX, minY, minZ );
  2352. this.max.set( maxX, maxY, maxZ );
  2353. return this;
  2354. },
  2355. setFromPoints: function ( points ) {
  2356. this.makeEmpty();
  2357. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2358. this.expandByPoint( points[ i ] );
  2359. }
  2360. return this;
  2361. },
  2362. setFromCenterAndSize: function () {
  2363. var v1 = new Vector3();
  2364. return function setFromCenterAndSize( center, size ) {
  2365. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2366. this.min.copy( center ).sub( halfSize );
  2367. this.max.copy( center ).add( halfSize );
  2368. return this;
  2369. };
  2370. }(),
  2371. setFromObject: function ( object ) {
  2372. this.makeEmpty();
  2373. return this.expandByObject( object );
  2374. },
  2375. clone: function () {
  2376. return new this.constructor().copy( this );
  2377. },
  2378. copy: function ( box ) {
  2379. this.min.copy( box.min );
  2380. this.max.copy( box.max );
  2381. return this;
  2382. },
  2383. makeEmpty: function () {
  2384. this.min.x = this.min.y = this.min.z = + Infinity;
  2385. this.max.x = this.max.y = this.max.z = - Infinity;
  2386. return this;
  2387. },
  2388. isEmpty: function () {
  2389. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2390. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2391. },
  2392. getCenter: function ( target ) {
  2393. if ( target === undefined ) {
  2394. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2395. target = new Vector3();
  2396. }
  2397. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2398. },
  2399. getSize: function ( target ) {
  2400. if ( target === undefined ) {
  2401. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2402. target = new Vector3();
  2403. }
  2404. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2405. },
  2406. expandByPoint: function ( point ) {
  2407. this.min.min( point );
  2408. this.max.max( point );
  2409. return this;
  2410. },
  2411. expandByVector: function ( vector ) {
  2412. this.min.sub( vector );
  2413. this.max.add( vector );
  2414. return this;
  2415. },
  2416. expandByScalar: function ( scalar ) {
  2417. this.min.addScalar( - scalar );
  2418. this.max.addScalar( scalar );
  2419. return this;
  2420. },
  2421. expandByObject: function () {
  2422. // Computes the world-axis-aligned bounding box of an object (including its children),
  2423. // accounting for both the object's, and children's, world transforms
  2424. var scope, i, l;
  2425. var v1 = new Vector3();
  2426. function traverse( node ) {
  2427. var geometry = node.geometry;
  2428. if ( geometry !== undefined ) {
  2429. if ( geometry.isGeometry ) {
  2430. var vertices = geometry.vertices;
  2431. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  2432. v1.copy( vertices[ i ] );
  2433. v1.applyMatrix4( node.matrixWorld );
  2434. scope.expandByPoint( v1 );
  2435. }
  2436. } else if ( geometry.isBufferGeometry ) {
  2437. var attribute = geometry.attributes.position;
  2438. if ( attribute !== undefined ) {
  2439. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  2440. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  2441. scope.expandByPoint( v1 );
  2442. }
  2443. }
  2444. }
  2445. }
  2446. }
  2447. return function expandByObject( object ) {
  2448. scope = this;
  2449. object.updateMatrixWorld( true );
  2450. object.traverse( traverse );
  2451. return this;
  2452. };
  2453. }(),
  2454. containsPoint: function ( point ) {
  2455. return point.x < this.min.x || point.x > this.max.x ||
  2456. point.y < this.min.y || point.y > this.max.y ||
  2457. point.z < this.min.z || point.z > this.max.z ? false : true;
  2458. },
  2459. containsBox: function ( box ) {
  2460. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2461. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2462. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2463. },
  2464. getParameter: function ( point, target ) {
  2465. // This can potentially have a divide by zero if the box
  2466. // has a size dimension of 0.
  2467. if ( target === undefined ) {
  2468. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  2469. target = new Vector3();
  2470. }
  2471. return target.set(
  2472. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2473. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2474. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2475. );
  2476. },
  2477. intersectsBox: function ( box ) {
  2478. // using 6 splitting planes to rule out intersections.
  2479. return box.max.x < this.min.x || box.min.x > this.max.x ||
  2480. box.max.y < this.min.y || box.min.y > this.max.y ||
  2481. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2482. },
  2483. intersectsSphere: ( function () {
  2484. var closestPoint = new Vector3();
  2485. return function intersectsSphere( sphere ) {
  2486. // Find the point on the AABB closest to the sphere center.
  2487. this.clampPoint( sphere.center, closestPoint );
  2488. // If that point is inside the sphere, the AABB and sphere intersect.
  2489. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2490. };
  2491. } )(),
  2492. intersectsPlane: function ( plane ) {
  2493. // We compute the minimum and maximum dot product values. If those values
  2494. // are on the same side (back or front) of the plane, then there is no intersection.
  2495. var min, max;
  2496. if ( plane.normal.x > 0 ) {
  2497. min = plane.normal.x * this.min.x;
  2498. max = plane.normal.x * this.max.x;
  2499. } else {
  2500. min = plane.normal.x * this.max.x;
  2501. max = plane.normal.x * this.min.x;
  2502. }
  2503. if ( plane.normal.y > 0 ) {
  2504. min += plane.normal.y * this.min.y;
  2505. max += plane.normal.y * this.max.y;
  2506. } else {
  2507. min += plane.normal.y * this.max.y;
  2508. max += plane.normal.y * this.min.y;
  2509. }
  2510. if ( plane.normal.z > 0 ) {
  2511. min += plane.normal.z * this.min.z;
  2512. max += plane.normal.z * this.max.z;
  2513. } else {
  2514. min += plane.normal.z * this.max.z;
  2515. max += plane.normal.z * this.min.z;
  2516. }
  2517. return ( min <= - plane.constant && max >= - plane.constant );
  2518. },
  2519. intersectsTriangle: ( function () {
  2520. // triangle centered vertices
  2521. var v0 = new Vector3();
  2522. var v1 = new Vector3();
  2523. var v2 = new Vector3();
  2524. // triangle edge vectors
  2525. var f0 = new Vector3();
  2526. var f1 = new Vector3();
  2527. var f2 = new Vector3();
  2528. var testAxis = new Vector3();
  2529. var center = new Vector3();
  2530. var extents = new Vector3();
  2531. var triangleNormal = new Vector3();
  2532. function satForAxes( axes ) {
  2533. var i, j;
  2534. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  2535. testAxis.fromArray( axes, i );
  2536. // project the aabb onto the seperating axis
  2537. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  2538. // project all 3 vertices of the triangle onto the seperating axis
  2539. var p0 = v0.dot( testAxis );
  2540. var p1 = v1.dot( testAxis );
  2541. var p2 = v2.dot( testAxis );
  2542. // actual test, basically see if either of the most extreme of the triangle points intersects r
  2543. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  2544. // points of the projected triangle are outside the projected half-length of the aabb
  2545. // the axis is seperating and we can exit
  2546. return false;
  2547. }
  2548. }
  2549. return true;
  2550. }
  2551. return function intersectsTriangle( triangle ) {
  2552. if ( this.isEmpty() ) {
  2553. return false;
  2554. }
  2555. // compute box center and extents
  2556. this.getCenter( center );
  2557. extents.subVectors( this.max, center );
  2558. // translate triangle to aabb origin
  2559. v0.subVectors( triangle.a, center );
  2560. v1.subVectors( triangle.b, center );
  2561. v2.subVectors( triangle.c, center );
  2562. // compute edge vectors for triangle
  2563. f0.subVectors( v1, v0 );
  2564. f1.subVectors( v2, v1 );
  2565. f2.subVectors( v0, v2 );
  2566. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2567. // 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
  2568. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2569. var axes = [
  2570. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  2571. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  2572. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  2573. ];
  2574. if ( ! satForAxes( axes ) ) {
  2575. return false;
  2576. }
  2577. // test 3 face normals from the aabb
  2578. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  2579. if ( ! satForAxes( axes ) ) {
  2580. return false;
  2581. }
  2582. // finally testing the face normal of the triangle
  2583. // use already existing triangle edge vectors here
  2584. triangleNormal.crossVectors( f0, f1 );
  2585. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  2586. return satForAxes( axes );
  2587. };
  2588. } )(),
  2589. clampPoint: function ( point, target ) {
  2590. if ( target === undefined ) {
  2591. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  2592. target = new Vector3();
  2593. }
  2594. return target.copy( point ).clamp( this.min, this.max );
  2595. },
  2596. distanceToPoint: function () {
  2597. var v1 = new Vector3();
  2598. return function distanceToPoint( point ) {
  2599. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2600. return clampedPoint.sub( point ).length();
  2601. };
  2602. }(),
  2603. getBoundingSphere: function () {
  2604. var v1 = new Vector3();
  2605. return function getBoundingSphere( target ) {
  2606. if ( target === undefined ) {
  2607. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  2608. //target = new Sphere(); // removed to avoid cyclic dependency
  2609. }
  2610. this.getCenter( target.center );
  2611. target.radius = this.getSize( v1 ).length() * 0.5;
  2612. return target;
  2613. };
  2614. }(),
  2615. intersect: function ( box ) {
  2616. this.min.max( box.min );
  2617. this.max.min( box.max );
  2618. // 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.
  2619. if ( this.isEmpty() ) this.makeEmpty();
  2620. return this;
  2621. },
  2622. union: function ( box ) {
  2623. this.min.min( box.min );
  2624. this.max.max( box.max );
  2625. return this;
  2626. },
  2627. applyMatrix4: function () {
  2628. var points = [
  2629. new Vector3(),
  2630. new Vector3(),
  2631. new Vector3(),
  2632. new Vector3(),
  2633. new Vector3(),
  2634. new Vector3(),
  2635. new Vector3(),
  2636. new Vector3()
  2637. ];
  2638. return function applyMatrix4( matrix ) {
  2639. // transform of empty box is an empty box.
  2640. if ( this.isEmpty() ) return this;
  2641. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2642. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2643. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2644. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2645. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2646. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2647. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2648. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2649. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2650. this.setFromPoints( points );
  2651. return this;
  2652. };
  2653. }(),
  2654. translate: function ( offset ) {
  2655. this.min.add( offset );
  2656. this.max.add( offset );
  2657. return this;
  2658. },
  2659. equals: function ( box ) {
  2660. return box.min.equals( this.min ) && box.max.equals( this.max );
  2661. }
  2662. } );
  2663. /**
  2664. * @author bhouston / http://clara.io
  2665. * @author mrdoob / http://mrdoob.com/
  2666. */
  2667. function Sphere( center, radius ) {
  2668. this.center = ( center !== undefined ) ? center : new Vector3();
  2669. this.radius = ( radius !== undefined ) ? radius : 0;
  2670. }
  2671. Object.assign( Sphere.prototype, {
  2672. set: function ( center, radius ) {
  2673. this.center.copy( center );
  2674. this.radius = radius;
  2675. return this;
  2676. },
  2677. setFromPoints: function () {
  2678. var box = new Box3();
  2679. return function setFromPoints( points, optionalCenter ) {
  2680. var center = this.center;
  2681. if ( optionalCenter !== undefined ) {
  2682. center.copy( optionalCenter );
  2683. } else {
  2684. box.setFromPoints( points ).getCenter( center );
  2685. }
  2686. var maxRadiusSq = 0;
  2687. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2688. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  2689. }
  2690. this.radius = Math.sqrt( maxRadiusSq );
  2691. return this;
  2692. };
  2693. }(),
  2694. clone: function () {
  2695. return new this.constructor().copy( this );
  2696. },
  2697. copy: function ( sphere ) {
  2698. this.center.copy( sphere.center );
  2699. this.radius = sphere.radius;
  2700. return this;
  2701. },
  2702. empty: function () {
  2703. return ( this.radius <= 0 );
  2704. },
  2705. containsPoint: function ( point ) {
  2706. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  2707. },
  2708. distanceToPoint: function ( point ) {
  2709. return ( point.distanceTo( this.center ) - this.radius );
  2710. },
  2711. intersectsSphere: function ( sphere ) {
  2712. var radiusSum = this.radius + sphere.radius;
  2713. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  2714. },
  2715. intersectsBox: function ( box ) {
  2716. return box.intersectsSphere( this );
  2717. },
  2718. intersectsPlane: function ( plane ) {
  2719. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  2720. },
  2721. clampPoint: function ( point, target ) {
  2722. var deltaLengthSq = this.center.distanceToSquared( point );
  2723. if ( target === undefined ) {
  2724. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  2725. target = new Vector3();
  2726. }
  2727. target.copy( point );
  2728. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  2729. target.sub( this.center ).normalize();
  2730. target.multiplyScalar( this.radius ).add( this.center );
  2731. }
  2732. return target;
  2733. },
  2734. getBoundingBox: function ( target ) {
  2735. if ( target === undefined ) {
  2736. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  2737. target = new Box3();
  2738. }
  2739. target.set( this.center, this.center );
  2740. target.expandByScalar( this.radius );
  2741. return target;
  2742. },
  2743. applyMatrix4: function ( matrix ) {
  2744. this.center.applyMatrix4( matrix );
  2745. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2746. return this;
  2747. },
  2748. translate: function ( offset ) {
  2749. this.center.add( offset );
  2750. return this;
  2751. },
  2752. equals: function ( sphere ) {
  2753. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  2754. }
  2755. } );
  2756. /**
  2757. * @author bhouston / http://clara.io
  2758. */
  2759. function Plane( normal, constant ) {
  2760. // normal is assumed to be normalized
  2761. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  2762. this.constant = ( constant !== undefined ) ? constant : 0;
  2763. }
  2764. Object.assign( Plane.prototype, {
  2765. set: function ( normal, constant ) {
  2766. this.normal.copy( normal );
  2767. this.constant = constant;
  2768. return this;
  2769. },
  2770. setComponents: function ( x, y, z, w ) {
  2771. this.normal.set( x, y, z );
  2772. this.constant = w;
  2773. return this;
  2774. },
  2775. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  2776. this.normal.copy( normal );
  2777. this.constant = - point.dot( this.normal );
  2778. return this;
  2779. },
  2780. setFromCoplanarPoints: function () {
  2781. var v1 = new Vector3();
  2782. var v2 = new Vector3();
  2783. return function setFromCoplanarPoints( a, b, c ) {
  2784. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  2785. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  2786. this.setFromNormalAndCoplanarPoint( normal, a );
  2787. return this;
  2788. };
  2789. }(),
  2790. clone: function () {
  2791. return new this.constructor().copy( this );
  2792. },
  2793. copy: function ( plane ) {
  2794. this.normal.copy( plane.normal );
  2795. this.constant = plane.constant;
  2796. return this;
  2797. },
  2798. normalize: function () {
  2799. // Note: will lead to a divide by zero if the plane is invalid.
  2800. var inverseNormalLength = 1.0 / this.normal.length();
  2801. this.normal.multiplyScalar( inverseNormalLength );
  2802. this.constant *= inverseNormalLength;
  2803. return this;
  2804. },
  2805. negate: function () {
  2806. this.constant *= - 1;
  2807. this.normal.negate();
  2808. return this;
  2809. },
  2810. distanceToPoint: function ( point ) {
  2811. return this.normal.dot( point ) + this.constant;
  2812. },
  2813. distanceToSphere: function ( sphere ) {
  2814. return this.distanceToPoint( sphere.center ) - sphere.radius;
  2815. },
  2816. projectPoint: function ( point, target ) {
  2817. if ( target === undefined ) {
  2818. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  2819. target = new Vector3();
  2820. }
  2821. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  2822. },
  2823. intersectLine: function () {
  2824. var v1 = new Vector3();
  2825. return function intersectLine( line, target ) {
  2826. if ( target === undefined ) {
  2827. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  2828. target = new Vector3();
  2829. }
  2830. var direction = line.delta( v1 );
  2831. var denominator = this.normal.dot( direction );
  2832. if ( denominator === 0 ) {
  2833. // line is coplanar, return origin
  2834. if ( this.distanceToPoint( line.start ) === 0 ) {
  2835. return target.copy( line.start );
  2836. }
  2837. // Unsure if this is the correct method to handle this case.
  2838. return undefined;
  2839. }
  2840. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  2841. if ( t < 0 || t > 1 ) {
  2842. return undefined;
  2843. }
  2844. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  2845. };
  2846. }(),
  2847. intersectsLine: function ( line ) {
  2848. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  2849. var startSign = this.distanceToPoint( line.start );
  2850. var endSign = this.distanceToPoint( line.end );
  2851. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  2852. },
  2853. intersectsBox: function ( box ) {
  2854. return box.intersectsPlane( this );
  2855. },
  2856. intersectsSphere: function ( sphere ) {
  2857. return sphere.intersectsPlane( this );
  2858. },
  2859. coplanarPoint: function ( target ) {
  2860. if ( target === undefined ) {
  2861. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  2862. target = new Vector3();
  2863. }
  2864. return target.copy( this.normal ).multiplyScalar( - this.constant );
  2865. },
  2866. applyMatrix4: function () {
  2867. var v1 = new Vector3();
  2868. var m1 = new Matrix3();
  2869. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  2870. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  2871. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  2872. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  2873. this.constant = - referencePoint.dot( normal );
  2874. return this;
  2875. };
  2876. }(),
  2877. translate: function ( offset ) {
  2878. this.constant -= offset.dot( this.normal );
  2879. return this;
  2880. },
  2881. equals: function ( plane ) {
  2882. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  2883. }
  2884. } );
  2885. /**
  2886. * @author mrdoob / http://mrdoob.com/
  2887. * @author alteredq / http://alteredqualia.com/
  2888. * @author bhouston / http://clara.io
  2889. */
  2890. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  2891. this.planes = [
  2892. ( p0 !== undefined ) ? p0 : new Plane(),
  2893. ( p1 !== undefined ) ? p1 : new Plane(),
  2894. ( p2 !== undefined ) ? p2 : new Plane(),
  2895. ( p3 !== undefined ) ? p3 : new Plane(),
  2896. ( p4 !== undefined ) ? p4 : new Plane(),
  2897. ( p5 !== undefined ) ? p5 : new Plane()
  2898. ];
  2899. }
  2900. Object.assign( Frustum.prototype, {
  2901. set: function ( p0, p1, p2, p3, p4, p5 ) {
  2902. var planes = this.planes;
  2903. planes[ 0 ].copy( p0 );
  2904. planes[ 1 ].copy( p1 );
  2905. planes[ 2 ].copy( p2 );
  2906. planes[ 3 ].copy( p3 );
  2907. planes[ 4 ].copy( p4 );
  2908. planes[ 5 ].copy( p5 );
  2909. return this;
  2910. },
  2911. clone: function () {
  2912. return new this.constructor().copy( this );
  2913. },
  2914. copy: function ( frustum ) {
  2915. var planes = this.planes;
  2916. for ( var i = 0; i < 6; i ++ ) {
  2917. planes[ i ].copy( frustum.planes[ i ] );
  2918. }
  2919. return this;
  2920. },
  2921. setFromMatrix: function ( m ) {
  2922. var planes = this.planes;
  2923. var me = m.elements;
  2924. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  2925. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  2926. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  2927. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  2928. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  2929. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  2930. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  2931. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  2932. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  2933. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  2934. return this;
  2935. },
  2936. intersectsObject: function () {
  2937. var sphere = new Sphere();
  2938. return function intersectsObject( object ) {
  2939. var geometry = object.geometry;
  2940. if ( geometry.boundingSphere === null )
  2941. geometry.computeBoundingSphere();
  2942. sphere.copy( geometry.boundingSphere )
  2943. .applyMatrix4( object.matrixWorld );
  2944. return this.intersectsSphere( sphere );
  2945. };
  2946. }(),
  2947. intersectsSprite: function () {
  2948. var sphere = new Sphere();
  2949. return function intersectsSprite( sprite ) {
  2950. sphere.center.set( 0, 0, 0 );
  2951. sphere.radius = 0.7071067811865476;
  2952. sphere.applyMatrix4( sprite.matrixWorld );
  2953. return this.intersectsSphere( sphere );
  2954. };
  2955. }(),
  2956. intersectsSphere: function ( sphere ) {
  2957. var planes = this.planes;
  2958. var center = sphere.center;
  2959. var negRadius = - sphere.radius;
  2960. for ( var i = 0; i < 6; i ++ ) {
  2961. var distance = planes[ i ].distanceToPoint( center );
  2962. if ( distance < negRadius ) {
  2963. return false;
  2964. }
  2965. }
  2966. return true;
  2967. },
  2968. intersectsBox: function () {
  2969. var p = new Vector3();
  2970. return function intersectsBox( box ) {
  2971. var planes = this.planes;
  2972. for ( var i = 0; i < 6; i ++ ) {
  2973. var plane = planes[ i ];
  2974. // corner at max distance
  2975. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  2976. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  2977. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  2978. if ( plane.distanceToPoint( p ) < 0 ) {
  2979. return false;
  2980. }
  2981. }
  2982. return true;
  2983. };
  2984. }(),
  2985. containsPoint: function ( point ) {
  2986. var planes = this.planes;
  2987. for ( var i = 0; i < 6; i ++ ) {
  2988. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  2989. return false;
  2990. }
  2991. }
  2992. return true;
  2993. }
  2994. } );
  2995. /**
  2996. * @author mrdoob / http://mrdoob.com/
  2997. * @author supereggbert / http://www.paulbrunt.co.uk/
  2998. * @author philogb / http://blog.thejit.org/
  2999. * @author jordi_ros / http://plattsoft.com
  3000. * @author D1plo1d / http://github.com/D1plo1d
  3001. * @author alteredq / http://alteredqualia.com/
  3002. * @author mikael emtinger / http://gomo.se/
  3003. * @author timknip / http://www.floorplanner.com/
  3004. * @author bhouston / http://clara.io
  3005. * @author WestLangley / http://github.com/WestLangley
  3006. */
  3007. function Matrix4() {
  3008. this.elements = [
  3009. 1, 0, 0, 0,
  3010. 0, 1, 0, 0,
  3011. 0, 0, 1, 0,
  3012. 0, 0, 0, 1
  3013. ];
  3014. if ( arguments.length > 0 ) {
  3015. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  3016. }
  3017. }
  3018. Object.assign( Matrix4.prototype, {
  3019. isMatrix4: true,
  3020. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3021. var te = this.elements;
  3022. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3023. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3024. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3025. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3026. return this;
  3027. },
  3028. identity: function () {
  3029. this.set(
  3030. 1, 0, 0, 0,
  3031. 0, 1, 0, 0,
  3032. 0, 0, 1, 0,
  3033. 0, 0, 0, 1
  3034. );
  3035. return this;
  3036. },
  3037. clone: function () {
  3038. return new Matrix4().fromArray( this.elements );
  3039. },
  3040. copy: function ( m ) {
  3041. var te = this.elements;
  3042. var me = m.elements;
  3043. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3044. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3045. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3046. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3047. return this;
  3048. },
  3049. copyPosition: function ( m ) {
  3050. var te = this.elements, me = m.elements;
  3051. te[ 12 ] = me[ 12 ];
  3052. te[ 13 ] = me[ 13 ];
  3053. te[ 14 ] = me[ 14 ];
  3054. return this;
  3055. },
  3056. extractBasis: function ( xAxis, yAxis, zAxis ) {
  3057. xAxis.setFromMatrixColumn( this, 0 );
  3058. yAxis.setFromMatrixColumn( this, 1 );
  3059. zAxis.setFromMatrixColumn( this, 2 );
  3060. return this;
  3061. },
  3062. makeBasis: function ( xAxis, yAxis, zAxis ) {
  3063. this.set(
  3064. xAxis.x, yAxis.x, zAxis.x, 0,
  3065. xAxis.y, yAxis.y, zAxis.y, 0,
  3066. xAxis.z, yAxis.z, zAxis.z, 0,
  3067. 0, 0, 0, 1
  3068. );
  3069. return this;
  3070. },
  3071. extractRotation: function () {
  3072. var v1 = new Vector3();
  3073. return function extractRotation( m ) {
  3074. // this method does not support reflection matrices
  3075. var te = this.elements;
  3076. var me = m.elements;
  3077. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  3078. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  3079. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  3080. te[ 0 ] = me[ 0 ] * scaleX;
  3081. te[ 1 ] = me[ 1 ] * scaleX;
  3082. te[ 2 ] = me[ 2 ] * scaleX;
  3083. te[ 3 ] = 0;
  3084. te[ 4 ] = me[ 4 ] * scaleY;
  3085. te[ 5 ] = me[ 5 ] * scaleY;
  3086. te[ 6 ] = me[ 6 ] * scaleY;
  3087. te[ 7 ] = 0;
  3088. te[ 8 ] = me[ 8 ] * scaleZ;
  3089. te[ 9 ] = me[ 9 ] * scaleZ;
  3090. te[ 10 ] = me[ 10 ] * scaleZ;
  3091. te[ 11 ] = 0;
  3092. te[ 12 ] = 0;
  3093. te[ 13 ] = 0;
  3094. te[ 14 ] = 0;
  3095. te[ 15 ] = 1;
  3096. return this;
  3097. };
  3098. }(),
  3099. makeRotationFromEuler: function ( euler ) {
  3100. if ( ! ( euler && euler.isEuler ) ) {
  3101. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  3102. }
  3103. var te = this.elements;
  3104. var x = euler.x, y = euler.y, z = euler.z;
  3105. var a = Math.cos( x ), b = Math.sin( x );
  3106. var c = Math.cos( y ), d = Math.sin( y );
  3107. var e = Math.cos( z ), f = Math.sin( z );
  3108. if ( euler.order === 'XYZ' ) {
  3109. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  3110. te[ 0 ] = c * e;
  3111. te[ 4 ] = - c * f;
  3112. te[ 8 ] = d;
  3113. te[ 1 ] = af + be * d;
  3114. te[ 5 ] = ae - bf * d;
  3115. te[ 9 ] = - b * c;
  3116. te[ 2 ] = bf - ae * d;
  3117. te[ 6 ] = be + af * d;
  3118. te[ 10 ] = a * c;
  3119. } else if ( euler.order === 'YXZ' ) {
  3120. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  3121. te[ 0 ] = ce + df * b;
  3122. te[ 4 ] = de * b - cf;
  3123. te[ 8 ] = a * d;
  3124. te[ 1 ] = a * f;
  3125. te[ 5 ] = a * e;
  3126. te[ 9 ] = - b;
  3127. te[ 2 ] = cf * b - de;
  3128. te[ 6 ] = df + ce * b;
  3129. te[ 10 ] = a * c;
  3130. } else if ( euler.order === 'ZXY' ) {
  3131. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  3132. te[ 0 ] = ce - df * b;
  3133. te[ 4 ] = - a * f;
  3134. te[ 8 ] = de + cf * b;
  3135. te[ 1 ] = cf + de * b;
  3136. te[ 5 ] = a * e;
  3137. te[ 9 ] = df - ce * b;
  3138. te[ 2 ] = - a * d;
  3139. te[ 6 ] = b;
  3140. te[ 10 ] = a * c;
  3141. } else if ( euler.order === 'ZYX' ) {
  3142. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  3143. te[ 0 ] = c * e;
  3144. te[ 4 ] = be * d - af;
  3145. te[ 8 ] = ae * d + bf;
  3146. te[ 1 ] = c * f;
  3147. te[ 5 ] = bf * d + ae;
  3148. te[ 9 ] = af * d - be;
  3149. te[ 2 ] = - d;
  3150. te[ 6 ] = b * c;
  3151. te[ 10 ] = a * c;
  3152. } else if ( euler.order === 'YZX' ) {
  3153. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3154. te[ 0 ] = c * e;
  3155. te[ 4 ] = bd - ac * f;
  3156. te[ 8 ] = bc * f + ad;
  3157. te[ 1 ] = f;
  3158. te[ 5 ] = a * e;
  3159. te[ 9 ] = - b * e;
  3160. te[ 2 ] = - d * e;
  3161. te[ 6 ] = ad * f + bc;
  3162. te[ 10 ] = ac - bd * f;
  3163. } else if ( euler.order === 'XZY' ) {
  3164. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3165. te[ 0 ] = c * e;
  3166. te[ 4 ] = - f;
  3167. te[ 8 ] = d * e;
  3168. te[ 1 ] = ac * f + bd;
  3169. te[ 5 ] = a * e;
  3170. te[ 9 ] = ad * f - bc;
  3171. te[ 2 ] = bc * f - ad;
  3172. te[ 6 ] = b * e;
  3173. te[ 10 ] = bd * f + ac;
  3174. }
  3175. // bottom row
  3176. te[ 3 ] = 0;
  3177. te[ 7 ] = 0;
  3178. te[ 11 ] = 0;
  3179. // last column
  3180. te[ 12 ] = 0;
  3181. te[ 13 ] = 0;
  3182. te[ 14 ] = 0;
  3183. te[ 15 ] = 1;
  3184. return this;
  3185. },
  3186. makeRotationFromQuaternion: function () {
  3187. var zero = new Vector3( 0, 0, 0 );
  3188. var one = new Vector3( 1, 1, 1 );
  3189. return function makeRotationFromQuaternion( q ) {
  3190. return this.compose( zero, q, one );
  3191. };
  3192. }(),
  3193. lookAt: function () {
  3194. var x = new Vector3();
  3195. var y = new Vector3();
  3196. var z = new Vector3();
  3197. return function lookAt( eye, target, up ) {
  3198. var te = this.elements;
  3199. z.subVectors( eye, target );
  3200. if ( z.lengthSq() === 0 ) {
  3201. // eye and target are in the same position
  3202. z.z = 1;
  3203. }
  3204. z.normalize();
  3205. x.crossVectors( up, z );
  3206. if ( x.lengthSq() === 0 ) {
  3207. // up and z are parallel
  3208. if ( Math.abs( up.z ) === 1 ) {
  3209. z.x += 0.0001;
  3210. } else {
  3211. z.z += 0.0001;
  3212. }
  3213. z.normalize();
  3214. x.crossVectors( up, z );
  3215. }
  3216. x.normalize();
  3217. y.crossVectors( z, x );
  3218. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3219. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3220. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3221. return this;
  3222. };
  3223. }(),
  3224. multiply: function ( m, n ) {
  3225. if ( n !== undefined ) {
  3226. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3227. return this.multiplyMatrices( m, n );
  3228. }
  3229. return this.multiplyMatrices( this, m );
  3230. },
  3231. premultiply: function ( m ) {
  3232. return this.multiplyMatrices( m, this );
  3233. },
  3234. multiplyMatrices: function ( a, b ) {
  3235. var ae = a.elements;
  3236. var be = b.elements;
  3237. var te = this.elements;
  3238. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3239. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3240. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3241. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3242. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3243. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3244. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3245. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3246. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3247. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3248. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3249. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3250. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3251. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3252. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3253. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3254. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3255. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3256. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3257. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3258. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3259. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3260. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3261. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3262. return this;
  3263. },
  3264. multiplyScalar: function ( s ) {
  3265. var te = this.elements;
  3266. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3267. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3268. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3269. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3270. return this;
  3271. },
  3272. applyToBufferAttribute: function () {
  3273. var v1 = new Vector3();
  3274. return function applyToBufferAttribute( attribute ) {
  3275. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3276. v1.x = attribute.getX( i );
  3277. v1.y = attribute.getY( i );
  3278. v1.z = attribute.getZ( i );
  3279. v1.applyMatrix4( this );
  3280. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  3281. }
  3282. return attribute;
  3283. };
  3284. }(),
  3285. determinant: function () {
  3286. var te = this.elements;
  3287. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3288. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3289. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3290. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3291. //TODO: make this more efficient
  3292. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3293. return (
  3294. n41 * (
  3295. + n14 * n23 * n32
  3296. - n13 * n24 * n32
  3297. - n14 * n22 * n33
  3298. + n12 * n24 * n33
  3299. + n13 * n22 * n34
  3300. - n12 * n23 * n34
  3301. ) +
  3302. n42 * (
  3303. + n11 * n23 * n34
  3304. - n11 * n24 * n33
  3305. + n14 * n21 * n33
  3306. - n13 * n21 * n34
  3307. + n13 * n24 * n31
  3308. - n14 * n23 * n31
  3309. ) +
  3310. n43 * (
  3311. + n11 * n24 * n32
  3312. - n11 * n22 * n34
  3313. - n14 * n21 * n32
  3314. + n12 * n21 * n34
  3315. + n14 * n22 * n31
  3316. - n12 * n24 * n31
  3317. ) +
  3318. n44 * (
  3319. - n13 * n22 * n31
  3320. - n11 * n23 * n32
  3321. + n11 * n22 * n33
  3322. + n13 * n21 * n32
  3323. - n12 * n21 * n33
  3324. + n12 * n23 * n31
  3325. )
  3326. );
  3327. },
  3328. transpose: function () {
  3329. var te = this.elements;
  3330. var tmp;
  3331. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3332. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3333. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3334. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3335. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3336. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3337. return this;
  3338. },
  3339. setPosition: function ( v ) {
  3340. var te = this.elements;
  3341. te[ 12 ] = v.x;
  3342. te[ 13 ] = v.y;
  3343. te[ 14 ] = v.z;
  3344. return this;
  3345. },
  3346. getInverse: function ( m, throwOnDegenerate ) {
  3347. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3348. var te = this.elements,
  3349. me = m.elements,
  3350. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3351. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3352. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3353. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3354. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3355. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3356. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3357. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3358. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3359. if ( det === 0 ) {
  3360. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  3361. if ( throwOnDegenerate === true ) {
  3362. throw new Error( msg );
  3363. } else {
  3364. console.warn( msg );
  3365. }
  3366. return this.identity();
  3367. }
  3368. var detInv = 1 / det;
  3369. te[ 0 ] = t11 * detInv;
  3370. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3371. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3372. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3373. te[ 4 ] = t12 * detInv;
  3374. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3375. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3376. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3377. te[ 8 ] = t13 * detInv;
  3378. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3379. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3380. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3381. te[ 12 ] = t14 * detInv;
  3382. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3383. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3384. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3385. return this;
  3386. },
  3387. scale: function ( v ) {
  3388. var te = this.elements;
  3389. var x = v.x, y = v.y, z = v.z;
  3390. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3391. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3392. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3393. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3394. return this;
  3395. },
  3396. getMaxScaleOnAxis: function () {
  3397. var te = this.elements;
  3398. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3399. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3400. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3401. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3402. },
  3403. makeTranslation: function ( x, y, z ) {
  3404. this.set(
  3405. 1, 0, 0, x,
  3406. 0, 1, 0, y,
  3407. 0, 0, 1, z,
  3408. 0, 0, 0, 1
  3409. );
  3410. return this;
  3411. },
  3412. makeRotationX: function ( theta ) {
  3413. var c = Math.cos( theta ), s = Math.sin( theta );
  3414. this.set(
  3415. 1, 0, 0, 0,
  3416. 0, c, - s, 0,
  3417. 0, s, c, 0,
  3418. 0, 0, 0, 1
  3419. );
  3420. return this;
  3421. },
  3422. makeRotationY: function ( theta ) {
  3423. var c = Math.cos( theta ), s = Math.sin( theta );
  3424. this.set(
  3425. c, 0, s, 0,
  3426. 0, 1, 0, 0,
  3427. - s, 0, c, 0,
  3428. 0, 0, 0, 1
  3429. );
  3430. return this;
  3431. },
  3432. makeRotationZ: function ( theta ) {
  3433. var c = Math.cos( theta ), s = Math.sin( theta );
  3434. this.set(
  3435. c, - s, 0, 0,
  3436. s, c, 0, 0,
  3437. 0, 0, 1, 0,
  3438. 0, 0, 0, 1
  3439. );
  3440. return this;
  3441. },
  3442. makeRotationAxis: function ( axis, angle ) {
  3443. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3444. var c = Math.cos( angle );
  3445. var s = Math.sin( angle );
  3446. var t = 1 - c;
  3447. var x = axis.x, y = axis.y, z = axis.z;
  3448. var tx = t * x, ty = t * y;
  3449. this.set(
  3450. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3451. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3452. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3453. 0, 0, 0, 1
  3454. );
  3455. return this;
  3456. },
  3457. makeScale: function ( x, y, z ) {
  3458. this.set(
  3459. x, 0, 0, 0,
  3460. 0, y, 0, 0,
  3461. 0, 0, z, 0,
  3462. 0, 0, 0, 1
  3463. );
  3464. return this;
  3465. },
  3466. makeShear: function ( x, y, z ) {
  3467. this.set(
  3468. 1, y, z, 0,
  3469. x, 1, z, 0,
  3470. x, y, 1, 0,
  3471. 0, 0, 0, 1
  3472. );
  3473. return this;
  3474. },
  3475. compose: function ( position, quaternion, scale ) {
  3476. var te = this.elements;
  3477. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3478. var x2 = x + x, y2 = y + y, z2 = z + z;
  3479. var xx = x * x2, xy = x * y2, xz = x * z2;
  3480. var yy = y * y2, yz = y * z2, zz = z * z2;
  3481. var wx = w * x2, wy = w * y2, wz = w * z2;
  3482. var sx = scale.x, sy = scale.y, sz = scale.z;
  3483. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3484. te[ 1 ] = ( xy + wz ) * sx;
  3485. te[ 2 ] = ( xz - wy ) * sx;
  3486. te[ 3 ] = 0;
  3487. te[ 4 ] = ( xy - wz ) * sy;
  3488. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3489. te[ 6 ] = ( yz + wx ) * sy;
  3490. te[ 7 ] = 0;
  3491. te[ 8 ] = ( xz + wy ) * sz;
  3492. te[ 9 ] = ( yz - wx ) * sz;
  3493. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3494. te[ 11 ] = 0;
  3495. te[ 12 ] = position.x;
  3496. te[ 13 ] = position.y;
  3497. te[ 14 ] = position.z;
  3498. te[ 15 ] = 1;
  3499. return this;
  3500. },
  3501. decompose: function () {
  3502. var vector = new Vector3();
  3503. var matrix = new Matrix4();
  3504. return function decompose( position, quaternion, scale ) {
  3505. var te = this.elements;
  3506. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3507. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3508. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3509. // if determine is negative, we need to invert one scale
  3510. var det = this.determinant();
  3511. if ( det < 0 ) sx = - sx;
  3512. position.x = te[ 12 ];
  3513. position.y = te[ 13 ];
  3514. position.z = te[ 14 ];
  3515. // scale the rotation part
  3516. matrix.copy( this );
  3517. var invSX = 1 / sx;
  3518. var invSY = 1 / sy;
  3519. var invSZ = 1 / sz;
  3520. matrix.elements[ 0 ] *= invSX;
  3521. matrix.elements[ 1 ] *= invSX;
  3522. matrix.elements[ 2 ] *= invSX;
  3523. matrix.elements[ 4 ] *= invSY;
  3524. matrix.elements[ 5 ] *= invSY;
  3525. matrix.elements[ 6 ] *= invSY;
  3526. matrix.elements[ 8 ] *= invSZ;
  3527. matrix.elements[ 9 ] *= invSZ;
  3528. matrix.elements[ 10 ] *= invSZ;
  3529. quaternion.setFromRotationMatrix( matrix );
  3530. scale.x = sx;
  3531. scale.y = sy;
  3532. scale.z = sz;
  3533. return this;
  3534. };
  3535. }(),
  3536. makePerspective: function ( left, right, top, bottom, near, far ) {
  3537. if ( far === undefined ) {
  3538. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3539. }
  3540. var te = this.elements;
  3541. var x = 2 * near / ( right - left );
  3542. var y = 2 * near / ( top - bottom );
  3543. var a = ( right + left ) / ( right - left );
  3544. var b = ( top + bottom ) / ( top - bottom );
  3545. var c = - ( far + near ) / ( far - near );
  3546. var d = - 2 * far * near / ( far - near );
  3547. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3548. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3549. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3550. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3551. return this;
  3552. },
  3553. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3554. var te = this.elements;
  3555. var w = 1.0 / ( right - left );
  3556. var h = 1.0 / ( top - bottom );
  3557. var p = 1.0 / ( far - near );
  3558. var x = ( right + left ) * w;
  3559. var y = ( top + bottom ) * h;
  3560. var z = ( far + near ) * p;
  3561. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3562. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3563. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3564. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3565. return this;
  3566. },
  3567. equals: function ( matrix ) {
  3568. var te = this.elements;
  3569. var me = matrix.elements;
  3570. for ( var i = 0; i < 16; i ++ ) {
  3571. if ( te[ i ] !== me[ i ] ) return false;
  3572. }
  3573. return true;
  3574. },
  3575. fromArray: function ( array, offset ) {
  3576. if ( offset === undefined ) offset = 0;
  3577. for ( var i = 0; i < 16; i ++ ) {
  3578. this.elements[ i ] = array[ i + offset ];
  3579. }
  3580. return this;
  3581. },
  3582. toArray: function ( array, offset ) {
  3583. if ( array === undefined ) array = [];
  3584. if ( offset === undefined ) offset = 0;
  3585. var te = this.elements;
  3586. array[ offset ] = te[ 0 ];
  3587. array[ offset + 1 ] = te[ 1 ];
  3588. array[ offset + 2 ] = te[ 2 ];
  3589. array[ offset + 3 ] = te[ 3 ];
  3590. array[ offset + 4 ] = te[ 4 ];
  3591. array[ offset + 5 ] = te[ 5 ];
  3592. array[ offset + 6 ] = te[ 6 ];
  3593. array[ offset + 7 ] = te[ 7 ];
  3594. array[ offset + 8 ] = te[ 8 ];
  3595. array[ offset + 9 ] = te[ 9 ];
  3596. array[ offset + 10 ] = te[ 10 ];
  3597. array[ offset + 11 ] = te[ 11 ];
  3598. array[ offset + 12 ] = te[ 12 ];
  3599. array[ offset + 13 ] = te[ 13 ];
  3600. array[ offset + 14 ] = te[ 14 ];
  3601. array[ offset + 15 ] = te[ 15 ];
  3602. return array;
  3603. }
  3604. } );
  3605. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  3606. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  3607. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  3608. 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( PHYSICAL )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";
  3609. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3610. var begin_vertex = "vec3 transformed = vec3( position );";
  3611. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  3612. 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}\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 GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, 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_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 GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.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( specularColor, dotNV );\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}";
  3613. 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";
  3614. 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";
  3615. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  3616. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  3617. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  3618. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3619. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3620. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3621. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3622. 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#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(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}\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};\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}";
  3623. 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";
  3624. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\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";
  3625. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  3626. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  3627. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  3628. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  3629. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  3630. 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}";
  3631. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToVertex, 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";
  3632. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n\tuniform float reflectivity;\n\tuniform float envMapIntensity;\n#endif\n#ifdef USE_ENVMAP\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n\t\tvarying vec3 vWorldPosition;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  3633. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
  3634. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\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";
  3635. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  3636. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  3637. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 ) );\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";
  3638. 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";
  3639. 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";
  3640. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  3641. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3642. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = 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";
  3643. var lights_pars_begin = "uniform 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";
  3644. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP ) && defined( PHYSICAL )\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 blinnShininessExponent, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, 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, BlinnExponentToGGXRoughness(blinnShininessExponent ));\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";
  3645. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  3646. 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)";
  3647. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\n#ifdef STANDARD\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.clearCoat = saturate( clearCoat );\tmaterial.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\n#endif";
  3648. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#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#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#endif\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#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\tfloat clearCoatInv = 1.0 - clearCoatDHR;\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 singleScattering = vec3( 0.0 );\n\t\tvec3 multiScattering = vec3( 0.0 );\n\t\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\t\tvec3 diffuse = material.diffuseColor;\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;\n\t\treflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;\n\t\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\t#else\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#endif\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\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\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\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}";
  3649. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\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#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? 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#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? 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#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? 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 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";
  3650. 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( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), maxMipLevel );\n\t#ifndef STANDARD\n\t\tclearCoatRadiance += getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );\n\t#endif\n#endif";
  3651. 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, irradiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif";
  3652. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3653. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  3654. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  3655. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t#else\n\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\tgl_Position.z *= gl_Position.w;\n\t#endif\n#endif";
  3656. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  3657. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  3658. var map_particle_fragment = "#ifdef USE_MAP\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif";
  3659. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  3660. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  3661. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3662. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n\tobjectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n\tobjectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n\tobjectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n#endif";
  3663. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  3664. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n\ttransformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n\ttransformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n\ttransformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\ttransformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n\ttransformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n\ttransformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n\ttransformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  3665. 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#endif\n#endif";
  3666. var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t#ifdef FLIP_SIDED\n\t\t\tnormal = - normal;\n\t\t#endif\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\tnormal = normalize( normalMatrix * normal );\n\t#else\n\t\t#ifdef USE_TANGENT\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy = normalScale * mapN.xy;\n\t\t\tnormal = normalize( vTBN * mapN );\n\t\t#else\n\t\t\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n\t\t#endif\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  3667. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tuniform mat3 normalMatrix;\n\t#else\n\t\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\t\tvec2 st0 = dFdx( vUv.st );\n\t\t\tvec2 st1 = dFdy( vUv.st );\n\t\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\t\tvec3 N = normalize( surf_norm );\n\t\t\tmat3 tsn = mat3( S, T, N );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy *= normalScale;\n\t\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\treturn normalize( tsn * mapN );\n\t\t}\n\t#endif\n#endif";
  3668. 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}\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}";
  3669. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  3670. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  3671. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  3672. var dithering_pars_fragment = "#if defined( 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";
  3673. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  3674. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3675. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\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 ) / size;\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\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( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, 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( 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 / 9.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#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 )\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";
  3676. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n#endif";
  3677. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif";
  3678. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\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\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\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\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\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\tshadow *= bool( pointLight.shadow ) ? 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}";
  3679. 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";
  3680. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform 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";
  3681. 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";
  3682. 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";
  3683. 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";
  3684. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3685. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  3686. var tonemapping_pars_fragment = "#ifndef saturate\n\t#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}";
  3687. var uv_pars_fragment = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n#endif";
  3688. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif";
  3689. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  3690. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3691. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3692. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3693. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  3694. 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}";
  3695. 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}";
  3696. 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}";
  3697. 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}";
  3698. 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}";
  3699. 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}";
  3700. 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}";
  3701. 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}";
  3702. 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}";
  3703. 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}";
  3704. 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}";
  3705. 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}";
  3706. 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_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}";
  3707. 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}";
  3708. 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_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}";
  3709. 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}";
  3710. 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}";
  3711. 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}";
  3712. 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_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}";
  3713. 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}";
  3714. var meshphysical_frag = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifndef STANDARD\n\tuniform float clearCoat;\n\tuniform float clearCoatRoughness;\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_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 <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 <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\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}";
  3715. var meshphysical_vert = "#define PHYSICAL\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}";
  3716. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_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>\nvoid main() {\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}";
  3717. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_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 <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_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#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  3718. 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}";
  3719. 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 = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\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}";
  3720. 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}";
  3721. 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}";
  3722. var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_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 <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}";
  3723. 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 = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\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}";
  3724. var ShaderChunk = {
  3725. alphamap_fragment: alphamap_fragment,
  3726. alphamap_pars_fragment: alphamap_pars_fragment,
  3727. alphatest_fragment: alphatest_fragment,
  3728. aomap_fragment: aomap_fragment,
  3729. aomap_pars_fragment: aomap_pars_fragment,
  3730. begin_vertex: begin_vertex,
  3731. beginnormal_vertex: beginnormal_vertex,
  3732. bsdfs: bsdfs,
  3733. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3734. clipping_planes_fragment: clipping_planes_fragment,
  3735. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3736. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3737. clipping_planes_vertex: clipping_planes_vertex,
  3738. color_fragment: color_fragment,
  3739. color_pars_fragment: color_pars_fragment,
  3740. color_pars_vertex: color_pars_vertex,
  3741. color_vertex: color_vertex,
  3742. common: common,
  3743. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3744. defaultnormal_vertex: defaultnormal_vertex,
  3745. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3746. displacementmap_vertex: displacementmap_vertex,
  3747. emissivemap_fragment: emissivemap_fragment,
  3748. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3749. encodings_fragment: encodings_fragment,
  3750. encodings_pars_fragment: encodings_pars_fragment,
  3751. envmap_fragment: envmap_fragment,
  3752. envmap_pars_fragment: envmap_pars_fragment,
  3753. envmap_pars_vertex: envmap_pars_vertex,
  3754. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  3755. envmap_vertex: envmap_vertex,
  3756. fog_vertex: fog_vertex,
  3757. fog_pars_vertex: fog_pars_vertex,
  3758. fog_fragment: fog_fragment,
  3759. fog_pars_fragment: fog_pars_fragment,
  3760. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3761. lightmap_fragment: lightmap_fragment,
  3762. lightmap_pars_fragment: lightmap_pars_fragment,
  3763. lights_lambert_vertex: lights_lambert_vertex,
  3764. lights_pars_begin: lights_pars_begin,
  3765. lights_phong_fragment: lights_phong_fragment,
  3766. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3767. lights_physical_fragment: lights_physical_fragment,
  3768. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3769. lights_fragment_begin: lights_fragment_begin,
  3770. lights_fragment_maps: lights_fragment_maps,
  3771. lights_fragment_end: lights_fragment_end,
  3772. logdepthbuf_fragment: logdepthbuf_fragment,
  3773. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3774. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3775. logdepthbuf_vertex: logdepthbuf_vertex,
  3776. map_fragment: map_fragment,
  3777. map_pars_fragment: map_pars_fragment,
  3778. map_particle_fragment: map_particle_fragment,
  3779. map_particle_pars_fragment: map_particle_pars_fragment,
  3780. metalnessmap_fragment: metalnessmap_fragment,
  3781. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3782. morphnormal_vertex: morphnormal_vertex,
  3783. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3784. morphtarget_vertex: morphtarget_vertex,
  3785. normal_fragment_begin: normal_fragment_begin,
  3786. normal_fragment_maps: normal_fragment_maps,
  3787. normalmap_pars_fragment: normalmap_pars_fragment,
  3788. packing: packing,
  3789. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3790. project_vertex: project_vertex,
  3791. dithering_fragment: dithering_fragment,
  3792. dithering_pars_fragment: dithering_pars_fragment,
  3793. roughnessmap_fragment: roughnessmap_fragment,
  3794. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3795. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3796. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3797. shadowmap_vertex: shadowmap_vertex,
  3798. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3799. skinbase_vertex: skinbase_vertex,
  3800. skinning_pars_vertex: skinning_pars_vertex,
  3801. skinning_vertex: skinning_vertex,
  3802. skinnormal_vertex: skinnormal_vertex,
  3803. specularmap_fragment: specularmap_fragment,
  3804. specularmap_pars_fragment: specularmap_pars_fragment,
  3805. tonemapping_fragment: tonemapping_fragment,
  3806. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3807. uv_pars_fragment: uv_pars_fragment,
  3808. uv_pars_vertex: uv_pars_vertex,
  3809. uv_vertex: uv_vertex,
  3810. uv2_pars_fragment: uv2_pars_fragment,
  3811. uv2_pars_vertex: uv2_pars_vertex,
  3812. uv2_vertex: uv2_vertex,
  3813. worldpos_vertex: worldpos_vertex,
  3814. background_frag: background_frag,
  3815. background_vert: background_vert,
  3816. cube_frag: cube_frag,
  3817. cube_vert: cube_vert,
  3818. depth_frag: depth_frag,
  3819. depth_vert: depth_vert,
  3820. distanceRGBA_frag: distanceRGBA_frag,
  3821. distanceRGBA_vert: distanceRGBA_vert,
  3822. equirect_frag: equirect_frag,
  3823. equirect_vert: equirect_vert,
  3824. linedashed_frag: linedashed_frag,
  3825. linedashed_vert: linedashed_vert,
  3826. meshbasic_frag: meshbasic_frag,
  3827. meshbasic_vert: meshbasic_vert,
  3828. meshlambert_frag: meshlambert_frag,
  3829. meshlambert_vert: meshlambert_vert,
  3830. meshmatcap_frag: meshmatcap_frag,
  3831. meshmatcap_vert: meshmatcap_vert,
  3832. meshphong_frag: meshphong_frag,
  3833. meshphong_vert: meshphong_vert,
  3834. meshphysical_frag: meshphysical_frag,
  3835. meshphysical_vert: meshphysical_vert,
  3836. normal_frag: normal_frag,
  3837. normal_vert: normal_vert,
  3838. points_frag: points_frag,
  3839. points_vert: points_vert,
  3840. shadow_frag: shadow_frag,
  3841. shadow_vert: shadow_vert,
  3842. sprite_frag: sprite_frag,
  3843. sprite_vert: sprite_vert
  3844. };
  3845. /**
  3846. * Uniform Utilities
  3847. */
  3848. function cloneUniforms( src ) {
  3849. var dst = {};
  3850. for ( var u in src ) {
  3851. dst[ u ] = {};
  3852. for ( var p in src[ u ] ) {
  3853. var property = src[ u ][ p ];
  3854. if ( property && ( property.isColor ||
  3855. property.isMatrix3 || property.isMatrix4 ||
  3856. property.isVector2 || property.isVector3 || property.isVector4 ||
  3857. property.isTexture ) ) {
  3858. dst[ u ][ p ] = property.clone();
  3859. } else if ( Array.isArray( property ) ) {
  3860. dst[ u ][ p ] = property.slice();
  3861. } else {
  3862. dst[ u ][ p ] = property;
  3863. }
  3864. }
  3865. }
  3866. return dst;
  3867. }
  3868. function mergeUniforms( uniforms ) {
  3869. var merged = {};
  3870. for ( var u = 0; u < uniforms.length; u ++ ) {
  3871. var tmp = cloneUniforms( uniforms[ u ] );
  3872. for ( var p in tmp ) {
  3873. merged[ p ] = tmp[ p ];
  3874. }
  3875. }
  3876. return merged;
  3877. }
  3878. // Legacy
  3879. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  3880. /**
  3881. * @author mrdoob / http://mrdoob.com/
  3882. */
  3883. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3884. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3885. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3886. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3887. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3888. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3889. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3890. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3891. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3892. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3893. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3894. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3895. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3896. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3897. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3898. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3899. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3900. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3901. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3902. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3903. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3904. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3905. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3906. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3907. function Color( r, g, b ) {
  3908. if ( g === undefined && b === undefined ) {
  3909. // r is THREE.Color, hex or string
  3910. return this.set( r );
  3911. }
  3912. return this.setRGB( r, g, b );
  3913. }
  3914. Object.assign( Color.prototype, {
  3915. isColor: true,
  3916. r: 1, g: 1, b: 1,
  3917. set: function ( value ) {
  3918. if ( value && value.isColor ) {
  3919. this.copy( value );
  3920. } else if ( typeof value === 'number' ) {
  3921. this.setHex( value );
  3922. } else if ( typeof value === 'string' ) {
  3923. this.setStyle( value );
  3924. }
  3925. return this;
  3926. },
  3927. setScalar: function ( scalar ) {
  3928. this.r = scalar;
  3929. this.g = scalar;
  3930. this.b = scalar;
  3931. return this;
  3932. },
  3933. setHex: function ( hex ) {
  3934. hex = Math.floor( hex );
  3935. this.r = ( hex >> 16 & 255 ) / 255;
  3936. this.g = ( hex >> 8 & 255 ) / 255;
  3937. this.b = ( hex & 255 ) / 255;
  3938. return this;
  3939. },
  3940. setRGB: function ( r, g, b ) {
  3941. this.r = r;
  3942. this.g = g;
  3943. this.b = b;
  3944. return this;
  3945. },
  3946. setHSL: function () {
  3947. function hue2rgb( p, q, t ) {
  3948. if ( t < 0 ) t += 1;
  3949. if ( t > 1 ) t -= 1;
  3950. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3951. if ( t < 1 / 2 ) return q;
  3952. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3953. return p;
  3954. }
  3955. return function setHSL( h, s, l ) {
  3956. // h,s,l ranges are in 0.0 - 1.0
  3957. h = _Math.euclideanModulo( h, 1 );
  3958. s = _Math.clamp( s, 0, 1 );
  3959. l = _Math.clamp( l, 0, 1 );
  3960. if ( s === 0 ) {
  3961. this.r = this.g = this.b = l;
  3962. } else {
  3963. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3964. var q = ( 2 * l ) - p;
  3965. this.r = hue2rgb( q, p, h + 1 / 3 );
  3966. this.g = hue2rgb( q, p, h );
  3967. this.b = hue2rgb( q, p, h - 1 / 3 );
  3968. }
  3969. return this;
  3970. };
  3971. }(),
  3972. setStyle: function ( style ) {
  3973. function handleAlpha( string ) {
  3974. if ( string === undefined ) return;
  3975. if ( parseFloat( string ) < 1 ) {
  3976. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3977. }
  3978. }
  3979. var m;
  3980. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3981. // rgb / hsl
  3982. var color;
  3983. var name = m[ 1 ];
  3984. var components = m[ 2 ];
  3985. switch ( name ) {
  3986. case 'rgb':
  3987. case 'rgba':
  3988. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3989. // rgb(255,0,0) rgba(255,0,0,0.5)
  3990. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3991. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3992. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3993. handleAlpha( color[ 5 ] );
  3994. return this;
  3995. }
  3996. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3997. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  3998. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  3999. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4000. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4001. handleAlpha( color[ 5 ] );
  4002. return this;
  4003. }
  4004. break;
  4005. case 'hsl':
  4006. case 'hsla':
  4007. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4008. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4009. var h = parseFloat( color[ 1 ] ) / 360;
  4010. var s = parseInt( color[ 2 ], 10 ) / 100;
  4011. var l = parseInt( color[ 3 ], 10 ) / 100;
  4012. handleAlpha( color[ 5 ] );
  4013. return this.setHSL( h, s, l );
  4014. }
  4015. break;
  4016. }
  4017. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4018. // hex color
  4019. var hex = m[ 1 ];
  4020. var size = hex.length;
  4021. if ( size === 3 ) {
  4022. // #ff0
  4023. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4024. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4025. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4026. return this;
  4027. } else if ( size === 6 ) {
  4028. // #ff0000
  4029. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4030. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4031. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4032. return this;
  4033. }
  4034. }
  4035. if ( style && style.length > 0 ) {
  4036. // color keywords
  4037. var hex = ColorKeywords[ style ];
  4038. if ( hex !== undefined ) {
  4039. // red
  4040. this.setHex( hex );
  4041. } else {
  4042. // unknown color
  4043. console.warn( 'THREE.Color: Unknown color ' + style );
  4044. }
  4045. }
  4046. return this;
  4047. },
  4048. clone: function () {
  4049. return new this.constructor( this.r, this.g, this.b );
  4050. },
  4051. copy: function ( color ) {
  4052. this.r = color.r;
  4053. this.g = color.g;
  4054. this.b = color.b;
  4055. return this;
  4056. },
  4057. copyGammaToLinear: function ( color, gammaFactor ) {
  4058. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4059. this.r = Math.pow( color.r, gammaFactor );
  4060. this.g = Math.pow( color.g, gammaFactor );
  4061. this.b = Math.pow( color.b, gammaFactor );
  4062. return this;
  4063. },
  4064. copyLinearToGamma: function ( color, gammaFactor ) {
  4065. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4066. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4067. this.r = Math.pow( color.r, safeInverse );
  4068. this.g = Math.pow( color.g, safeInverse );
  4069. this.b = Math.pow( color.b, safeInverse );
  4070. return this;
  4071. },
  4072. convertGammaToLinear: function ( gammaFactor ) {
  4073. this.copyGammaToLinear( this, gammaFactor );
  4074. return this;
  4075. },
  4076. convertLinearToGamma: function ( gammaFactor ) {
  4077. this.copyLinearToGamma( this, gammaFactor );
  4078. return this;
  4079. },
  4080. copySRGBToLinear: function () {
  4081. function SRGBToLinear( c ) {
  4082. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4083. }
  4084. return function copySRGBToLinear( color ) {
  4085. this.r = SRGBToLinear( color.r );
  4086. this.g = SRGBToLinear( color.g );
  4087. this.b = SRGBToLinear( color.b );
  4088. return this;
  4089. };
  4090. }(),
  4091. copyLinearToSRGB: function () {
  4092. function LinearToSRGB( c ) {
  4093. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4094. }
  4095. return function copyLinearToSRGB( color ) {
  4096. this.r = LinearToSRGB( color.r );
  4097. this.g = LinearToSRGB( color.g );
  4098. this.b = LinearToSRGB( color.b );
  4099. return this;
  4100. };
  4101. }(),
  4102. convertSRGBToLinear: function () {
  4103. this.copySRGBToLinear( this );
  4104. return this;
  4105. },
  4106. convertLinearToSRGB: function () {
  4107. this.copyLinearToSRGB( this );
  4108. return this;
  4109. },
  4110. getHex: function () {
  4111. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4112. },
  4113. getHexString: function () {
  4114. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4115. },
  4116. getHSL: function ( target ) {
  4117. // h,s,l ranges are in 0.0 - 1.0
  4118. if ( target === undefined ) {
  4119. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4120. target = { h: 0, s: 0, l: 0 };
  4121. }
  4122. var r = this.r, g = this.g, b = this.b;
  4123. var max = Math.max( r, g, b );
  4124. var min = Math.min( r, g, b );
  4125. var hue, saturation;
  4126. var lightness = ( min + max ) / 2.0;
  4127. if ( min === max ) {
  4128. hue = 0;
  4129. saturation = 0;
  4130. } else {
  4131. var delta = max - min;
  4132. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4133. switch ( max ) {
  4134. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4135. case g: hue = ( b - r ) / delta + 2; break;
  4136. case b: hue = ( r - g ) / delta + 4; break;
  4137. }
  4138. hue /= 6;
  4139. }
  4140. target.h = hue;
  4141. target.s = saturation;
  4142. target.l = lightness;
  4143. return target;
  4144. },
  4145. getStyle: function () {
  4146. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4147. },
  4148. offsetHSL: function () {
  4149. var hsl = {};
  4150. return function ( h, s, l ) {
  4151. this.getHSL( hsl );
  4152. hsl.h += h; hsl.s += s; hsl.l += l;
  4153. this.setHSL( hsl.h, hsl.s, hsl.l );
  4154. return this;
  4155. };
  4156. }(),
  4157. add: function ( color ) {
  4158. this.r += color.r;
  4159. this.g += color.g;
  4160. this.b += color.b;
  4161. return this;
  4162. },
  4163. addColors: function ( color1, color2 ) {
  4164. this.r = color1.r + color2.r;
  4165. this.g = color1.g + color2.g;
  4166. this.b = color1.b + color2.b;
  4167. return this;
  4168. },
  4169. addScalar: function ( s ) {
  4170. this.r += s;
  4171. this.g += s;
  4172. this.b += s;
  4173. return this;
  4174. },
  4175. sub: function ( color ) {
  4176. this.r = Math.max( 0, this.r - color.r );
  4177. this.g = Math.max( 0, this.g - color.g );
  4178. this.b = Math.max( 0, this.b - color.b );
  4179. return this;
  4180. },
  4181. multiply: function ( color ) {
  4182. this.r *= color.r;
  4183. this.g *= color.g;
  4184. this.b *= color.b;
  4185. return this;
  4186. },
  4187. multiplyScalar: function ( s ) {
  4188. this.r *= s;
  4189. this.g *= s;
  4190. this.b *= s;
  4191. return this;
  4192. },
  4193. lerp: function ( color, alpha ) {
  4194. this.r += ( color.r - this.r ) * alpha;
  4195. this.g += ( color.g - this.g ) * alpha;
  4196. this.b += ( color.b - this.b ) * alpha;
  4197. return this;
  4198. },
  4199. lerpHSL: function () {
  4200. var hslA = { h: 0, s: 0, l: 0 };
  4201. var hslB = { h: 0, s: 0, l: 0 };
  4202. return function lerpHSL( color, alpha ) {
  4203. this.getHSL( hslA );
  4204. color.getHSL( hslB );
  4205. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  4206. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  4207. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  4208. this.setHSL( h, s, l );
  4209. return this;
  4210. };
  4211. }(),
  4212. equals: function ( c ) {
  4213. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4214. },
  4215. fromArray: function ( array, offset ) {
  4216. if ( offset === undefined ) offset = 0;
  4217. this.r = array[ offset ];
  4218. this.g = array[ offset + 1 ];
  4219. this.b = array[ offset + 2 ];
  4220. return this;
  4221. },
  4222. toArray: function ( array, offset ) {
  4223. if ( array === undefined ) array = [];
  4224. if ( offset === undefined ) offset = 0;
  4225. array[ offset ] = this.r;
  4226. array[ offset + 1 ] = this.g;
  4227. array[ offset + 2 ] = this.b;
  4228. return array;
  4229. },
  4230. toJSON: function () {
  4231. return this.getHex();
  4232. }
  4233. } );
  4234. /**
  4235. * Uniforms library for shared webgl shaders
  4236. */
  4237. var UniformsLib = {
  4238. common: {
  4239. diffuse: { value: new Color( 0xeeeeee ) },
  4240. opacity: { value: 1.0 },
  4241. map: { value: null },
  4242. uvTransform: { value: new Matrix3() },
  4243. alphaMap: { value: null },
  4244. },
  4245. specularmap: {
  4246. specularMap: { value: null },
  4247. },
  4248. envmap: {
  4249. envMap: { value: null },
  4250. flipEnvMap: { value: - 1 },
  4251. reflectivity: { value: 1.0 },
  4252. refractionRatio: { value: 0.98 },
  4253. maxMipLevel: { value: 0 }
  4254. },
  4255. aomap: {
  4256. aoMap: { value: null },
  4257. aoMapIntensity: { value: 1 }
  4258. },
  4259. lightmap: {
  4260. lightMap: { value: null },
  4261. lightMapIntensity: { value: 1 }
  4262. },
  4263. emissivemap: {
  4264. emissiveMap: { value: null }
  4265. },
  4266. bumpmap: {
  4267. bumpMap: { value: null },
  4268. bumpScale: { value: 1 }
  4269. },
  4270. normalmap: {
  4271. normalMap: { value: null },
  4272. normalScale: { value: new Vector2( 1, 1 ) }
  4273. },
  4274. displacementmap: {
  4275. displacementMap: { value: null },
  4276. displacementScale: { value: 1 },
  4277. displacementBias: { value: 0 }
  4278. },
  4279. roughnessmap: {
  4280. roughnessMap: { value: null }
  4281. },
  4282. metalnessmap: {
  4283. metalnessMap: { value: null }
  4284. },
  4285. gradientmap: {
  4286. gradientMap: { value: null }
  4287. },
  4288. fog: {
  4289. fogDensity: { value: 0.00025 },
  4290. fogNear: { value: 1 },
  4291. fogFar: { value: 2000 },
  4292. fogColor: { value: new Color( 0xffffff ) }
  4293. },
  4294. lights: {
  4295. ambientLightColor: { value: [] },
  4296. lightProbe: { value: [] },
  4297. directionalLights: { value: [], properties: {
  4298. direction: {},
  4299. color: {},
  4300. shadow: {},
  4301. shadowBias: {},
  4302. shadowRadius: {},
  4303. shadowMapSize: {}
  4304. } },
  4305. directionalShadowMap: { value: [] },
  4306. directionalShadowMatrix: { value: [] },
  4307. spotLights: { value: [], properties: {
  4308. color: {},
  4309. position: {},
  4310. direction: {},
  4311. distance: {},
  4312. coneCos: {},
  4313. penumbraCos: {},
  4314. decay: {},
  4315. shadow: {},
  4316. shadowBias: {},
  4317. shadowRadius: {},
  4318. shadowMapSize: {}
  4319. } },
  4320. spotShadowMap: { value: [] },
  4321. spotShadowMatrix: { value: [] },
  4322. pointLights: { value: [], properties: {
  4323. color: {},
  4324. position: {},
  4325. decay: {},
  4326. distance: {},
  4327. shadow: {},
  4328. shadowBias: {},
  4329. shadowRadius: {},
  4330. shadowMapSize: {},
  4331. shadowCameraNear: {},
  4332. shadowCameraFar: {}
  4333. } },
  4334. pointShadowMap: { value: [] },
  4335. pointShadowMatrix: { value: [] },
  4336. hemisphereLights: { value: [], properties: {
  4337. direction: {},
  4338. skyColor: {},
  4339. groundColor: {}
  4340. } },
  4341. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4342. rectAreaLights: { value: [], properties: {
  4343. color: {},
  4344. position: {},
  4345. width: {},
  4346. height: {}
  4347. } }
  4348. },
  4349. points: {
  4350. diffuse: { value: new Color( 0xeeeeee ) },
  4351. opacity: { value: 1.0 },
  4352. size: { value: 1.0 },
  4353. scale: { value: 1.0 },
  4354. map: { value: null },
  4355. uvTransform: { value: new Matrix3() }
  4356. },
  4357. sprite: {
  4358. diffuse: { value: new Color( 0xeeeeee ) },
  4359. opacity: { value: 1.0 },
  4360. center: { value: new Vector2( 0.5, 0.5 ) },
  4361. rotation: { value: 0.0 },
  4362. map: { value: null },
  4363. uvTransform: { value: new Matrix3() }
  4364. }
  4365. };
  4366. /**
  4367. * @author alteredq / http://alteredqualia.com/
  4368. * @author mrdoob / http://mrdoob.com/
  4369. * @author mikael emtinger / http://gomo.se/
  4370. */
  4371. var ShaderLib = {
  4372. basic: {
  4373. uniforms: mergeUniforms( [
  4374. UniformsLib.common,
  4375. UniformsLib.specularmap,
  4376. UniformsLib.envmap,
  4377. UniformsLib.aomap,
  4378. UniformsLib.lightmap,
  4379. UniformsLib.fog
  4380. ] ),
  4381. vertexShader: ShaderChunk.meshbasic_vert,
  4382. fragmentShader: ShaderChunk.meshbasic_frag
  4383. },
  4384. lambert: {
  4385. uniforms: mergeUniforms( [
  4386. UniformsLib.common,
  4387. UniformsLib.specularmap,
  4388. UniformsLib.envmap,
  4389. UniformsLib.aomap,
  4390. UniformsLib.lightmap,
  4391. UniformsLib.emissivemap,
  4392. UniformsLib.fog,
  4393. UniformsLib.lights,
  4394. {
  4395. emissive: { value: new Color( 0x000000 ) }
  4396. }
  4397. ] ),
  4398. vertexShader: ShaderChunk.meshlambert_vert,
  4399. fragmentShader: ShaderChunk.meshlambert_frag
  4400. },
  4401. phong: {
  4402. uniforms: mergeUniforms( [
  4403. UniformsLib.common,
  4404. UniformsLib.specularmap,
  4405. UniformsLib.envmap,
  4406. UniformsLib.aomap,
  4407. UniformsLib.lightmap,
  4408. UniformsLib.emissivemap,
  4409. UniformsLib.bumpmap,
  4410. UniformsLib.normalmap,
  4411. UniformsLib.displacementmap,
  4412. UniformsLib.gradientmap,
  4413. UniformsLib.fog,
  4414. UniformsLib.lights,
  4415. {
  4416. emissive: { value: new Color( 0x000000 ) },
  4417. specular: { value: new Color( 0x111111 ) },
  4418. shininess: { value: 30 }
  4419. }
  4420. ] ),
  4421. vertexShader: ShaderChunk.meshphong_vert,
  4422. fragmentShader: ShaderChunk.meshphong_frag
  4423. },
  4424. standard: {
  4425. uniforms: mergeUniforms( [
  4426. UniformsLib.common,
  4427. UniformsLib.envmap,
  4428. UniformsLib.aomap,
  4429. UniformsLib.lightmap,
  4430. UniformsLib.emissivemap,
  4431. UniformsLib.bumpmap,
  4432. UniformsLib.normalmap,
  4433. UniformsLib.displacementmap,
  4434. UniformsLib.roughnessmap,
  4435. UniformsLib.metalnessmap,
  4436. UniformsLib.fog,
  4437. UniformsLib.lights,
  4438. {
  4439. emissive: { value: new Color( 0x000000 ) },
  4440. roughness: { value: 0.5 },
  4441. metalness: { value: 0.5 },
  4442. envMapIntensity: { value: 1 } // temporary
  4443. }
  4444. ] ),
  4445. vertexShader: ShaderChunk.meshphysical_vert,
  4446. fragmentShader: ShaderChunk.meshphysical_frag
  4447. },
  4448. matcap: {
  4449. uniforms: mergeUniforms( [
  4450. UniformsLib.common,
  4451. UniformsLib.bumpmap,
  4452. UniformsLib.normalmap,
  4453. UniformsLib.displacementmap,
  4454. UniformsLib.fog,
  4455. {
  4456. matcap: { value: null }
  4457. }
  4458. ] ),
  4459. vertexShader: ShaderChunk.meshmatcap_vert,
  4460. fragmentShader: ShaderChunk.meshmatcap_frag
  4461. },
  4462. points: {
  4463. uniforms: mergeUniforms( [
  4464. UniformsLib.points,
  4465. UniformsLib.fog
  4466. ] ),
  4467. vertexShader: ShaderChunk.points_vert,
  4468. fragmentShader: ShaderChunk.points_frag
  4469. },
  4470. dashed: {
  4471. uniforms: mergeUniforms( [
  4472. UniformsLib.common,
  4473. UniformsLib.fog,
  4474. {
  4475. scale: { value: 1 },
  4476. dashSize: { value: 1 },
  4477. totalSize: { value: 2 }
  4478. }
  4479. ] ),
  4480. vertexShader: ShaderChunk.linedashed_vert,
  4481. fragmentShader: ShaderChunk.linedashed_frag
  4482. },
  4483. depth: {
  4484. uniforms: mergeUniforms( [
  4485. UniformsLib.common,
  4486. UniformsLib.displacementmap
  4487. ] ),
  4488. vertexShader: ShaderChunk.depth_vert,
  4489. fragmentShader: ShaderChunk.depth_frag
  4490. },
  4491. normal: {
  4492. uniforms: mergeUniforms( [
  4493. UniformsLib.common,
  4494. UniformsLib.bumpmap,
  4495. UniformsLib.normalmap,
  4496. UniformsLib.displacementmap,
  4497. {
  4498. opacity: { value: 1.0 }
  4499. }
  4500. ] ),
  4501. vertexShader: ShaderChunk.normal_vert,
  4502. fragmentShader: ShaderChunk.normal_frag
  4503. },
  4504. sprite: {
  4505. uniforms: mergeUniforms( [
  4506. UniformsLib.sprite,
  4507. UniformsLib.fog
  4508. ] ),
  4509. vertexShader: ShaderChunk.sprite_vert,
  4510. fragmentShader: ShaderChunk.sprite_frag
  4511. },
  4512. background: {
  4513. uniforms: {
  4514. uvTransform: { value: new Matrix3() },
  4515. t2D: { value: null },
  4516. },
  4517. vertexShader: ShaderChunk.background_vert,
  4518. fragmentShader: ShaderChunk.background_frag
  4519. },
  4520. /* -------------------------------------------------------------------------
  4521. // Cube map shader
  4522. ------------------------------------------------------------------------- */
  4523. cube: {
  4524. uniforms: {
  4525. tCube: { value: null },
  4526. tFlip: { value: - 1 },
  4527. opacity: { value: 1.0 }
  4528. },
  4529. vertexShader: ShaderChunk.cube_vert,
  4530. fragmentShader: ShaderChunk.cube_frag
  4531. },
  4532. equirect: {
  4533. uniforms: {
  4534. tEquirect: { value: null },
  4535. },
  4536. vertexShader: ShaderChunk.equirect_vert,
  4537. fragmentShader: ShaderChunk.equirect_frag
  4538. },
  4539. distanceRGBA: {
  4540. uniforms: mergeUniforms( [
  4541. UniformsLib.common,
  4542. UniformsLib.displacementmap,
  4543. {
  4544. referencePosition: { value: new Vector3() },
  4545. nearDistance: { value: 1 },
  4546. farDistance: { value: 1000 }
  4547. }
  4548. ] ),
  4549. vertexShader: ShaderChunk.distanceRGBA_vert,
  4550. fragmentShader: ShaderChunk.distanceRGBA_frag
  4551. },
  4552. shadow: {
  4553. uniforms: mergeUniforms( [
  4554. UniformsLib.lights,
  4555. UniformsLib.fog,
  4556. {
  4557. color: { value: new Color( 0x00000 ) },
  4558. opacity: { value: 1.0 }
  4559. },
  4560. ] ),
  4561. vertexShader: ShaderChunk.shadow_vert,
  4562. fragmentShader: ShaderChunk.shadow_frag
  4563. }
  4564. };
  4565. ShaderLib.physical = {
  4566. uniforms: mergeUniforms( [
  4567. ShaderLib.standard.uniforms,
  4568. {
  4569. clearCoat: { value: 0 },
  4570. clearCoatRoughness: { value: 0 }
  4571. }
  4572. ] ),
  4573. vertexShader: ShaderChunk.meshphysical_vert,
  4574. fragmentShader: ShaderChunk.meshphysical_frag
  4575. };
  4576. /**
  4577. * @author mrdoob / http://mrdoob.com/
  4578. */
  4579. function WebGLAnimation() {
  4580. var context = null;
  4581. var isAnimating = false;
  4582. var animationLoop = null;
  4583. function onAnimationFrame( time, frame ) {
  4584. if ( isAnimating === false ) return;
  4585. animationLoop( time, frame );
  4586. context.requestAnimationFrame( onAnimationFrame );
  4587. }
  4588. return {
  4589. start: function () {
  4590. if ( isAnimating === true ) return;
  4591. if ( animationLoop === null ) return;
  4592. context.requestAnimationFrame( onAnimationFrame );
  4593. isAnimating = true;
  4594. },
  4595. stop: function () {
  4596. isAnimating = false;
  4597. },
  4598. setAnimationLoop: function ( callback ) {
  4599. animationLoop = callback;
  4600. },
  4601. setContext: function ( value ) {
  4602. context = value;
  4603. }
  4604. };
  4605. }
  4606. /**
  4607. * @author mrdoob / http://mrdoob.com/
  4608. */
  4609. function WebGLAttributes( gl ) {
  4610. var buffers = new WeakMap();
  4611. function createBuffer( attribute, bufferType ) {
  4612. var array = attribute.array;
  4613. var usage = attribute.dynamic ? 35048 : 35044;
  4614. var buffer = gl.createBuffer();
  4615. gl.bindBuffer( bufferType, buffer );
  4616. gl.bufferData( bufferType, array, usage );
  4617. attribute.onUploadCallback();
  4618. var type = 5126;
  4619. if ( array instanceof Float32Array ) {
  4620. type = 5126;
  4621. } else if ( array instanceof Float64Array ) {
  4622. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4623. } else if ( array instanceof Uint16Array ) {
  4624. type = 5123;
  4625. } else if ( array instanceof Int16Array ) {
  4626. type = 5122;
  4627. } else if ( array instanceof Uint32Array ) {
  4628. type = 5125;
  4629. } else if ( array instanceof Int32Array ) {
  4630. type = 5124;
  4631. } else if ( array instanceof Int8Array ) {
  4632. type = 5120;
  4633. } else if ( array instanceof Uint8Array ) {
  4634. type = 5121;
  4635. }
  4636. return {
  4637. buffer: buffer,
  4638. type: type,
  4639. bytesPerElement: array.BYTES_PER_ELEMENT,
  4640. version: attribute.version
  4641. };
  4642. }
  4643. function updateBuffer( buffer, attribute, bufferType ) {
  4644. var array = attribute.array;
  4645. var updateRange = attribute.updateRange;
  4646. gl.bindBuffer( bufferType, buffer );
  4647. if ( attribute.dynamic === false ) {
  4648. gl.bufferData( bufferType, array, 35044 );
  4649. } else if ( updateRange.count === - 1 ) {
  4650. // Not using update ranges
  4651. gl.bufferSubData( bufferType, 0, array );
  4652. } else if ( updateRange.count === 0 ) {
  4653. console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
  4654. } else {
  4655. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4656. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4657. updateRange.count = - 1; // reset range
  4658. }
  4659. }
  4660. //
  4661. function get( attribute ) {
  4662. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4663. return buffers.get( attribute );
  4664. }
  4665. function remove( attribute ) {
  4666. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4667. var data = buffers.get( attribute );
  4668. if ( data ) {
  4669. gl.deleteBuffer( data.buffer );
  4670. buffers.delete( attribute );
  4671. }
  4672. }
  4673. function update( attribute, bufferType ) {
  4674. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4675. var data = buffers.get( attribute );
  4676. if ( data === undefined ) {
  4677. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4678. } else if ( data.version < attribute.version ) {
  4679. updateBuffer( data.buffer, attribute, bufferType );
  4680. data.version = attribute.version;
  4681. }
  4682. }
  4683. return {
  4684. get: get,
  4685. remove: remove,
  4686. update: update
  4687. };
  4688. }
  4689. /**
  4690. * @author mrdoob / http://mrdoob.com/
  4691. * @author alteredq / http://alteredqualia.com/
  4692. */
  4693. function Face3( a, b, c, normal, color, materialIndex ) {
  4694. this.a = a;
  4695. this.b = b;
  4696. this.c = c;
  4697. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4698. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4699. this.color = ( color && color.isColor ) ? color : new Color();
  4700. this.vertexColors = Array.isArray( color ) ? color : [];
  4701. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4702. }
  4703. Object.assign( Face3.prototype, {
  4704. clone: function () {
  4705. return new this.constructor().copy( this );
  4706. },
  4707. copy: function ( source ) {
  4708. this.a = source.a;
  4709. this.b = source.b;
  4710. this.c = source.c;
  4711. this.normal.copy( source.normal );
  4712. this.color.copy( source.color );
  4713. this.materialIndex = source.materialIndex;
  4714. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4715. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4716. }
  4717. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4718. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4719. }
  4720. return this;
  4721. }
  4722. } );
  4723. /**
  4724. * @author mrdoob / http://mrdoob.com/
  4725. * @author WestLangley / http://github.com/WestLangley
  4726. * @author bhouston / http://clara.io
  4727. */
  4728. function Euler( x, y, z, order ) {
  4729. this._x = x || 0;
  4730. this._y = y || 0;
  4731. this._z = z || 0;
  4732. this._order = order || Euler.DefaultOrder;
  4733. }
  4734. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4735. Euler.DefaultOrder = 'XYZ';
  4736. Object.defineProperties( Euler.prototype, {
  4737. x: {
  4738. get: function () {
  4739. return this._x;
  4740. },
  4741. set: function ( value ) {
  4742. this._x = value;
  4743. this.onChangeCallback();
  4744. }
  4745. },
  4746. y: {
  4747. get: function () {
  4748. return this._y;
  4749. },
  4750. set: function ( value ) {
  4751. this._y = value;
  4752. this.onChangeCallback();
  4753. }
  4754. },
  4755. z: {
  4756. get: function () {
  4757. return this._z;
  4758. },
  4759. set: function ( value ) {
  4760. this._z = value;
  4761. this.onChangeCallback();
  4762. }
  4763. },
  4764. order: {
  4765. get: function () {
  4766. return this._order;
  4767. },
  4768. set: function ( value ) {
  4769. this._order = value;
  4770. this.onChangeCallback();
  4771. }
  4772. }
  4773. } );
  4774. Object.assign( Euler.prototype, {
  4775. isEuler: true,
  4776. set: function ( x, y, z, order ) {
  4777. this._x = x;
  4778. this._y = y;
  4779. this._z = z;
  4780. this._order = order || this._order;
  4781. this.onChangeCallback();
  4782. return this;
  4783. },
  4784. clone: function () {
  4785. return new this.constructor( this._x, this._y, this._z, this._order );
  4786. },
  4787. copy: function ( euler ) {
  4788. this._x = euler._x;
  4789. this._y = euler._y;
  4790. this._z = euler._z;
  4791. this._order = euler._order;
  4792. this.onChangeCallback();
  4793. return this;
  4794. },
  4795. setFromRotationMatrix: function ( m, order, update ) {
  4796. var clamp = _Math.clamp;
  4797. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4798. var te = m.elements;
  4799. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4800. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4801. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4802. order = order || this._order;
  4803. if ( order === 'XYZ' ) {
  4804. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4805. if ( Math.abs( m13 ) < 0.99999 ) {
  4806. this._x = Math.atan2( - m23, m33 );
  4807. this._z = Math.atan2( - m12, m11 );
  4808. } else {
  4809. this._x = Math.atan2( m32, m22 );
  4810. this._z = 0;
  4811. }
  4812. } else if ( order === 'YXZ' ) {
  4813. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4814. if ( Math.abs( m23 ) < 0.99999 ) {
  4815. this._y = Math.atan2( m13, m33 );
  4816. this._z = Math.atan2( m21, m22 );
  4817. } else {
  4818. this._y = Math.atan2( - m31, m11 );
  4819. this._z = 0;
  4820. }
  4821. } else if ( order === 'ZXY' ) {
  4822. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4823. if ( Math.abs( m32 ) < 0.99999 ) {
  4824. this._y = Math.atan2( - m31, m33 );
  4825. this._z = Math.atan2( - m12, m22 );
  4826. } else {
  4827. this._y = 0;
  4828. this._z = Math.atan2( m21, m11 );
  4829. }
  4830. } else if ( order === 'ZYX' ) {
  4831. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4832. if ( Math.abs( m31 ) < 0.99999 ) {
  4833. this._x = Math.atan2( m32, m33 );
  4834. this._z = Math.atan2( m21, m11 );
  4835. } else {
  4836. this._x = 0;
  4837. this._z = Math.atan2( - m12, m22 );
  4838. }
  4839. } else if ( order === 'YZX' ) {
  4840. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4841. if ( Math.abs( m21 ) < 0.99999 ) {
  4842. this._x = Math.atan2( - m23, m22 );
  4843. this._y = Math.atan2( - m31, m11 );
  4844. } else {
  4845. this._x = 0;
  4846. this._y = Math.atan2( m13, m33 );
  4847. }
  4848. } else if ( order === 'XZY' ) {
  4849. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4850. if ( Math.abs( m12 ) < 0.99999 ) {
  4851. this._x = Math.atan2( m32, m22 );
  4852. this._y = Math.atan2( m13, m11 );
  4853. } else {
  4854. this._x = Math.atan2( - m23, m33 );
  4855. this._y = 0;
  4856. }
  4857. } else {
  4858. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4859. }
  4860. this._order = order;
  4861. if ( update !== false ) this.onChangeCallback();
  4862. return this;
  4863. },
  4864. setFromQuaternion: function () {
  4865. var matrix = new Matrix4();
  4866. return function setFromQuaternion( q, order, update ) {
  4867. matrix.makeRotationFromQuaternion( q );
  4868. return this.setFromRotationMatrix( matrix, order, update );
  4869. };
  4870. }(),
  4871. setFromVector3: function ( v, order ) {
  4872. return this.set( v.x, v.y, v.z, order || this._order );
  4873. },
  4874. reorder: function () {
  4875. // WARNING: this discards revolution information -bhouston
  4876. var q = new Quaternion();
  4877. return function reorder( newOrder ) {
  4878. q.setFromEuler( this );
  4879. return this.setFromQuaternion( q, newOrder );
  4880. };
  4881. }(),
  4882. equals: function ( euler ) {
  4883. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4884. },
  4885. fromArray: function ( array ) {
  4886. this._x = array[ 0 ];
  4887. this._y = array[ 1 ];
  4888. this._z = array[ 2 ];
  4889. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4890. this.onChangeCallback();
  4891. return this;
  4892. },
  4893. toArray: function ( array, offset ) {
  4894. if ( array === undefined ) array = [];
  4895. if ( offset === undefined ) offset = 0;
  4896. array[ offset ] = this._x;
  4897. array[ offset + 1 ] = this._y;
  4898. array[ offset + 2 ] = this._z;
  4899. array[ offset + 3 ] = this._order;
  4900. return array;
  4901. },
  4902. toVector3: function ( optionalResult ) {
  4903. if ( optionalResult ) {
  4904. return optionalResult.set( this._x, this._y, this._z );
  4905. } else {
  4906. return new Vector3( this._x, this._y, this._z );
  4907. }
  4908. },
  4909. onChange: function ( callback ) {
  4910. this.onChangeCallback = callback;
  4911. return this;
  4912. },
  4913. onChangeCallback: function () {}
  4914. } );
  4915. /**
  4916. * @author mrdoob / http://mrdoob.com/
  4917. */
  4918. function Layers() {
  4919. this.mask = 1 | 0;
  4920. }
  4921. Object.assign( Layers.prototype, {
  4922. set: function ( channel ) {
  4923. this.mask = 1 << channel | 0;
  4924. },
  4925. enable: function ( channel ) {
  4926. this.mask |= 1 << channel | 0;
  4927. },
  4928. toggle: function ( channel ) {
  4929. this.mask ^= 1 << channel | 0;
  4930. },
  4931. disable: function ( channel ) {
  4932. this.mask &= ~ ( 1 << channel | 0 );
  4933. },
  4934. test: function ( layers ) {
  4935. return ( this.mask & layers.mask ) !== 0;
  4936. }
  4937. } );
  4938. /**
  4939. * @author mrdoob / http://mrdoob.com/
  4940. * @author mikael emtinger / http://gomo.se/
  4941. * @author alteredq / http://alteredqualia.com/
  4942. * @author WestLangley / http://github.com/WestLangley
  4943. * @author elephantatwork / www.elephantatwork.ch
  4944. */
  4945. var object3DId = 0;
  4946. function Object3D() {
  4947. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4948. this.uuid = _Math.generateUUID();
  4949. this.name = '';
  4950. this.type = 'Object3D';
  4951. this.parent = null;
  4952. this.children = [];
  4953. this.up = Object3D.DefaultUp.clone();
  4954. var position = new Vector3();
  4955. var rotation = new Euler();
  4956. var quaternion = new Quaternion();
  4957. var scale = new Vector3( 1, 1, 1 );
  4958. function onRotationChange() {
  4959. quaternion.setFromEuler( rotation, false );
  4960. }
  4961. function onQuaternionChange() {
  4962. rotation.setFromQuaternion( quaternion, undefined, false );
  4963. }
  4964. rotation.onChange( onRotationChange );
  4965. quaternion.onChange( onQuaternionChange );
  4966. Object.defineProperties( this, {
  4967. position: {
  4968. configurable: true,
  4969. enumerable: true,
  4970. value: position
  4971. },
  4972. rotation: {
  4973. configurable: true,
  4974. enumerable: true,
  4975. value: rotation
  4976. },
  4977. quaternion: {
  4978. configurable: true,
  4979. enumerable: true,
  4980. value: quaternion
  4981. },
  4982. scale: {
  4983. configurable: true,
  4984. enumerable: true,
  4985. value: scale
  4986. },
  4987. modelViewMatrix: {
  4988. value: new Matrix4()
  4989. },
  4990. normalMatrix: {
  4991. value: new Matrix3()
  4992. }
  4993. } );
  4994. this.matrix = new Matrix4();
  4995. this.matrixWorld = new Matrix4();
  4996. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4997. this.matrixWorldNeedsUpdate = false;
  4998. this.layers = new Layers();
  4999. this.visible = true;
  5000. this.castShadow = false;
  5001. this.receiveShadow = false;
  5002. this.frustumCulled = true;
  5003. this.renderOrder = 0;
  5004. this.userData = {};
  5005. }
  5006. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5007. Object3D.DefaultMatrixAutoUpdate = true;
  5008. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5009. constructor: Object3D,
  5010. isObject3D: true,
  5011. onBeforeRender: function () {},
  5012. onAfterRender: function () {},
  5013. applyMatrix: function ( matrix ) {
  5014. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5015. this.matrix.premultiply( matrix );
  5016. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5017. },
  5018. applyQuaternion: function ( q ) {
  5019. this.quaternion.premultiply( q );
  5020. return this;
  5021. },
  5022. setRotationFromAxisAngle: function ( axis, angle ) {
  5023. // assumes axis is normalized
  5024. this.quaternion.setFromAxisAngle( axis, angle );
  5025. },
  5026. setRotationFromEuler: function ( euler ) {
  5027. this.quaternion.setFromEuler( euler, true );
  5028. },
  5029. setRotationFromMatrix: function ( m ) {
  5030. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5031. this.quaternion.setFromRotationMatrix( m );
  5032. },
  5033. setRotationFromQuaternion: function ( q ) {
  5034. // assumes q is normalized
  5035. this.quaternion.copy( q );
  5036. },
  5037. rotateOnAxis: function () {
  5038. // rotate object on axis in object space
  5039. // axis is assumed to be normalized
  5040. var q1 = new Quaternion();
  5041. return function rotateOnAxis( axis, angle ) {
  5042. q1.setFromAxisAngle( axis, angle );
  5043. this.quaternion.multiply( q1 );
  5044. return this;
  5045. };
  5046. }(),
  5047. rotateOnWorldAxis: function () {
  5048. // rotate object on axis in world space
  5049. // axis is assumed to be normalized
  5050. // method assumes no rotated parent
  5051. var q1 = new Quaternion();
  5052. return function rotateOnWorldAxis( axis, angle ) {
  5053. q1.setFromAxisAngle( axis, angle );
  5054. this.quaternion.premultiply( q1 );
  5055. return this;
  5056. };
  5057. }(),
  5058. rotateX: function () {
  5059. var v1 = new Vector3( 1, 0, 0 );
  5060. return function rotateX( angle ) {
  5061. return this.rotateOnAxis( v1, angle );
  5062. };
  5063. }(),
  5064. rotateY: function () {
  5065. var v1 = new Vector3( 0, 1, 0 );
  5066. return function rotateY( angle ) {
  5067. return this.rotateOnAxis( v1, angle );
  5068. };
  5069. }(),
  5070. rotateZ: function () {
  5071. var v1 = new Vector3( 0, 0, 1 );
  5072. return function rotateZ( angle ) {
  5073. return this.rotateOnAxis( v1, angle );
  5074. };
  5075. }(),
  5076. translateOnAxis: function () {
  5077. // translate object by distance along axis in object space
  5078. // axis is assumed to be normalized
  5079. var v1 = new Vector3();
  5080. return function translateOnAxis( axis, distance ) {
  5081. v1.copy( axis ).applyQuaternion( this.quaternion );
  5082. this.position.add( v1.multiplyScalar( distance ) );
  5083. return this;
  5084. };
  5085. }(),
  5086. translateX: function () {
  5087. var v1 = new Vector3( 1, 0, 0 );
  5088. return function translateX( distance ) {
  5089. return this.translateOnAxis( v1, distance );
  5090. };
  5091. }(),
  5092. translateY: function () {
  5093. var v1 = new Vector3( 0, 1, 0 );
  5094. return function translateY( distance ) {
  5095. return this.translateOnAxis( v1, distance );
  5096. };
  5097. }(),
  5098. translateZ: function () {
  5099. var v1 = new Vector3( 0, 0, 1 );
  5100. return function translateZ( distance ) {
  5101. return this.translateOnAxis( v1, distance );
  5102. };
  5103. }(),
  5104. localToWorld: function ( vector ) {
  5105. return vector.applyMatrix4( this.matrixWorld );
  5106. },
  5107. worldToLocal: function () {
  5108. var m1 = new Matrix4();
  5109. return function worldToLocal( vector ) {
  5110. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5111. };
  5112. }(),
  5113. lookAt: function () {
  5114. // This method does not support objects having non-uniformly-scaled parent(s)
  5115. var q1 = new Quaternion();
  5116. var m1 = new Matrix4();
  5117. var target = new Vector3();
  5118. var position = new Vector3();
  5119. return function lookAt( x, y, z ) {
  5120. if ( x.isVector3 ) {
  5121. target.copy( x );
  5122. } else {
  5123. target.set( x, y, z );
  5124. }
  5125. var parent = this.parent;
  5126. this.updateWorldMatrix( true, false );
  5127. position.setFromMatrixPosition( this.matrixWorld );
  5128. if ( this.isCamera || this.isLight ) {
  5129. m1.lookAt( position, target, this.up );
  5130. } else {
  5131. m1.lookAt( target, position, this.up );
  5132. }
  5133. this.quaternion.setFromRotationMatrix( m1 );
  5134. if ( parent ) {
  5135. m1.extractRotation( parent.matrixWorld );
  5136. q1.setFromRotationMatrix( m1 );
  5137. this.quaternion.premultiply( q1.inverse() );
  5138. }
  5139. };
  5140. }(),
  5141. add: function ( object ) {
  5142. if ( arguments.length > 1 ) {
  5143. for ( var i = 0; i < arguments.length; i ++ ) {
  5144. this.add( arguments[ i ] );
  5145. }
  5146. return this;
  5147. }
  5148. if ( object === this ) {
  5149. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5150. return this;
  5151. }
  5152. if ( ( object && object.isObject3D ) ) {
  5153. if ( object.parent !== null ) {
  5154. object.parent.remove( object );
  5155. }
  5156. object.parent = this;
  5157. object.dispatchEvent( { type: 'added' } );
  5158. this.children.push( object );
  5159. } else {
  5160. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5161. }
  5162. return this;
  5163. },
  5164. remove: function ( object ) {
  5165. if ( arguments.length > 1 ) {
  5166. for ( var i = 0; i < arguments.length; i ++ ) {
  5167. this.remove( arguments[ i ] );
  5168. }
  5169. return this;
  5170. }
  5171. var index = this.children.indexOf( object );
  5172. if ( index !== - 1 ) {
  5173. object.parent = null;
  5174. object.dispatchEvent( { type: 'removed' } );
  5175. this.children.splice( index, 1 );
  5176. }
  5177. return this;
  5178. },
  5179. getObjectById: function ( id ) {
  5180. return this.getObjectByProperty( 'id', id );
  5181. },
  5182. getObjectByName: function ( name ) {
  5183. return this.getObjectByProperty( 'name', name );
  5184. },
  5185. getObjectByProperty: function ( name, value ) {
  5186. if ( this[ name ] === value ) return this;
  5187. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5188. var child = this.children[ i ];
  5189. var object = child.getObjectByProperty( name, value );
  5190. if ( object !== undefined ) {
  5191. return object;
  5192. }
  5193. }
  5194. return undefined;
  5195. },
  5196. getWorldPosition: function ( target ) {
  5197. if ( target === undefined ) {
  5198. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  5199. target = new Vector3();
  5200. }
  5201. this.updateMatrixWorld( true );
  5202. return target.setFromMatrixPosition( this.matrixWorld );
  5203. },
  5204. getWorldQuaternion: function () {
  5205. var position = new Vector3();
  5206. var scale = new Vector3();
  5207. return function getWorldQuaternion( target ) {
  5208. if ( target === undefined ) {
  5209. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5210. target = new Quaternion();
  5211. }
  5212. this.updateMatrixWorld( true );
  5213. this.matrixWorld.decompose( position, target, scale );
  5214. return target;
  5215. };
  5216. }(),
  5217. getWorldScale: function () {
  5218. var position = new Vector3();
  5219. var quaternion = new Quaternion();
  5220. return function getWorldScale( target ) {
  5221. if ( target === undefined ) {
  5222. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5223. target = new Vector3();
  5224. }
  5225. this.updateMatrixWorld( true );
  5226. this.matrixWorld.decompose( position, quaternion, target );
  5227. return target;
  5228. };
  5229. }(),
  5230. getWorldDirection: function ( target ) {
  5231. if ( target === undefined ) {
  5232. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5233. target = new Vector3();
  5234. }
  5235. this.updateMatrixWorld( true );
  5236. var e = this.matrixWorld.elements;
  5237. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  5238. },
  5239. raycast: function () {},
  5240. traverse: function ( callback ) {
  5241. callback( this );
  5242. var children = this.children;
  5243. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5244. children[ i ].traverse( callback );
  5245. }
  5246. },
  5247. traverseVisible: function ( callback ) {
  5248. if ( this.visible === false ) return;
  5249. callback( this );
  5250. var children = this.children;
  5251. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5252. children[ i ].traverseVisible( callback );
  5253. }
  5254. },
  5255. traverseAncestors: function ( callback ) {
  5256. var parent = this.parent;
  5257. if ( parent !== null ) {
  5258. callback( parent );
  5259. parent.traverseAncestors( callback );
  5260. }
  5261. },
  5262. updateMatrix: function () {
  5263. this.matrix.compose( this.position, this.quaternion, this.scale );
  5264. this.matrixWorldNeedsUpdate = true;
  5265. },
  5266. updateMatrixWorld: function ( force ) {
  5267. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5268. if ( this.matrixWorldNeedsUpdate || force ) {
  5269. if ( this.parent === null ) {
  5270. this.matrixWorld.copy( this.matrix );
  5271. } else {
  5272. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5273. }
  5274. this.matrixWorldNeedsUpdate = false;
  5275. force = true;
  5276. }
  5277. // update children
  5278. var children = this.children;
  5279. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5280. children[ i ].updateMatrixWorld( force );
  5281. }
  5282. },
  5283. updateWorldMatrix: function ( updateParents, updateChildren ) {
  5284. var parent = this.parent;
  5285. if ( updateParents === true && parent !== null ) {
  5286. parent.updateWorldMatrix( true, false );
  5287. }
  5288. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5289. if ( this.parent === null ) {
  5290. this.matrixWorld.copy( this.matrix );
  5291. } else {
  5292. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5293. }
  5294. // update children
  5295. if ( updateChildren === true ) {
  5296. var children = this.children;
  5297. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5298. children[ i ].updateWorldMatrix( false, true );
  5299. }
  5300. }
  5301. },
  5302. toJSON: function ( meta ) {
  5303. // meta is a string when called from JSON.stringify
  5304. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5305. var output = {};
  5306. // meta is a hash used to collect geometries, materials.
  5307. // not providing it implies that this is the root object
  5308. // being serialized.
  5309. if ( isRootObject ) {
  5310. // initialize meta obj
  5311. meta = {
  5312. geometries: {},
  5313. materials: {},
  5314. textures: {},
  5315. images: {},
  5316. shapes: {}
  5317. };
  5318. output.metadata = {
  5319. version: 4.5,
  5320. type: 'Object',
  5321. generator: 'Object3D.toJSON'
  5322. };
  5323. }
  5324. // standard Object3D serialization
  5325. var object = {};
  5326. object.uuid = this.uuid;
  5327. object.type = this.type;
  5328. if ( this.name !== '' ) object.name = this.name;
  5329. if ( this.castShadow === true ) object.castShadow = true;
  5330. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5331. if ( this.visible === false ) object.visible = false;
  5332. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5333. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5334. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5335. object.layers = this.layers.mask;
  5336. object.matrix = this.matrix.toArray();
  5337. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5338. // object specific properties
  5339. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  5340. //
  5341. function serialize( library, element ) {
  5342. if ( library[ element.uuid ] === undefined ) {
  5343. library[ element.uuid ] = element.toJSON( meta );
  5344. }
  5345. return element.uuid;
  5346. }
  5347. if ( this.isMesh || this.isLine || this.isPoints ) {
  5348. object.geometry = serialize( meta.geometries, this.geometry );
  5349. var parameters = this.geometry.parameters;
  5350. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5351. var shapes = parameters.shapes;
  5352. if ( Array.isArray( shapes ) ) {
  5353. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5354. var shape = shapes[ i ];
  5355. serialize( meta.shapes, shape );
  5356. }
  5357. } else {
  5358. serialize( meta.shapes, shapes );
  5359. }
  5360. }
  5361. }
  5362. if ( this.material !== undefined ) {
  5363. if ( Array.isArray( this.material ) ) {
  5364. var uuids = [];
  5365. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5366. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5367. }
  5368. object.material = uuids;
  5369. } else {
  5370. object.material = serialize( meta.materials, this.material );
  5371. }
  5372. }
  5373. //
  5374. if ( this.children.length > 0 ) {
  5375. object.children = [];
  5376. for ( var i = 0; i < this.children.length; i ++ ) {
  5377. object.children.push( this.children[ i ].toJSON( meta ).object );
  5378. }
  5379. }
  5380. if ( isRootObject ) {
  5381. var geometries = extractFromCache( meta.geometries );
  5382. var materials = extractFromCache( meta.materials );
  5383. var textures = extractFromCache( meta.textures );
  5384. var images = extractFromCache( meta.images );
  5385. var shapes = extractFromCache( meta.shapes );
  5386. if ( geometries.length > 0 ) output.geometries = geometries;
  5387. if ( materials.length > 0 ) output.materials = materials;
  5388. if ( textures.length > 0 ) output.textures = textures;
  5389. if ( images.length > 0 ) output.images = images;
  5390. if ( shapes.length > 0 ) output.shapes = shapes;
  5391. }
  5392. output.object = object;
  5393. return output;
  5394. // extract data from the cache hash
  5395. // remove metadata on each item
  5396. // and return as array
  5397. function extractFromCache( cache ) {
  5398. var values = [];
  5399. for ( var key in cache ) {
  5400. var data = cache[ key ];
  5401. delete data.metadata;
  5402. values.push( data );
  5403. }
  5404. return values;
  5405. }
  5406. },
  5407. clone: function ( recursive ) {
  5408. return new this.constructor().copy( this, recursive );
  5409. },
  5410. copy: function ( source, recursive ) {
  5411. if ( recursive === undefined ) recursive = true;
  5412. this.name = source.name;
  5413. this.up.copy( source.up );
  5414. this.position.copy( source.position );
  5415. this.quaternion.copy( source.quaternion );
  5416. this.scale.copy( source.scale );
  5417. this.matrix.copy( source.matrix );
  5418. this.matrixWorld.copy( source.matrixWorld );
  5419. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5420. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5421. this.layers.mask = source.layers.mask;
  5422. this.visible = source.visible;
  5423. this.castShadow = source.castShadow;
  5424. this.receiveShadow = source.receiveShadow;
  5425. this.frustumCulled = source.frustumCulled;
  5426. this.renderOrder = source.renderOrder;
  5427. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5428. if ( recursive === true ) {
  5429. for ( var i = 0; i < source.children.length; i ++ ) {
  5430. var child = source.children[ i ];
  5431. this.add( child.clone() );
  5432. }
  5433. }
  5434. return this;
  5435. }
  5436. } );
  5437. /**
  5438. * @author mrdoob / http://mrdoob.com/
  5439. * @author kile / http://kile.stravaganza.org/
  5440. * @author alteredq / http://alteredqualia.com/
  5441. * @author mikael emtinger / http://gomo.se/
  5442. * @author zz85 / http://www.lab4games.net/zz85/blog
  5443. * @author bhouston / http://clara.io
  5444. */
  5445. var geometryId = 0; // Geometry uses even numbers as Id
  5446. function Geometry() {
  5447. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5448. this.uuid = _Math.generateUUID();
  5449. this.name = '';
  5450. this.type = 'Geometry';
  5451. this.vertices = [];
  5452. this.colors = [];
  5453. this.faces = [];
  5454. this.faceVertexUvs = [[]];
  5455. this.morphTargets = [];
  5456. this.morphNormals = [];
  5457. this.skinWeights = [];
  5458. this.skinIndices = [];
  5459. this.lineDistances = [];
  5460. this.boundingBox = null;
  5461. this.boundingSphere = null;
  5462. // update flags
  5463. this.elementsNeedUpdate = false;
  5464. this.verticesNeedUpdate = false;
  5465. this.uvsNeedUpdate = false;
  5466. this.normalsNeedUpdate = false;
  5467. this.colorsNeedUpdate = false;
  5468. this.lineDistancesNeedUpdate = false;
  5469. this.groupsNeedUpdate = false;
  5470. }
  5471. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5472. constructor: Geometry,
  5473. isGeometry: true,
  5474. applyMatrix: function ( matrix ) {
  5475. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5476. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5477. var vertex = this.vertices[ i ];
  5478. vertex.applyMatrix4( matrix );
  5479. }
  5480. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5481. var face = this.faces[ i ];
  5482. face.normal.applyMatrix3( normalMatrix ).normalize();
  5483. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5484. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5485. }
  5486. }
  5487. if ( this.boundingBox !== null ) {
  5488. this.computeBoundingBox();
  5489. }
  5490. if ( this.boundingSphere !== null ) {
  5491. this.computeBoundingSphere();
  5492. }
  5493. this.verticesNeedUpdate = true;
  5494. this.normalsNeedUpdate = true;
  5495. return this;
  5496. },
  5497. rotateX: function () {
  5498. // rotate geometry around world x-axis
  5499. var m1 = new Matrix4();
  5500. return function rotateX( angle ) {
  5501. m1.makeRotationX( angle );
  5502. this.applyMatrix( m1 );
  5503. return this;
  5504. };
  5505. }(),
  5506. rotateY: function () {
  5507. // rotate geometry around world y-axis
  5508. var m1 = new Matrix4();
  5509. return function rotateY( angle ) {
  5510. m1.makeRotationY( angle );
  5511. this.applyMatrix( m1 );
  5512. return this;
  5513. };
  5514. }(),
  5515. rotateZ: function () {
  5516. // rotate geometry around world z-axis
  5517. var m1 = new Matrix4();
  5518. return function rotateZ( angle ) {
  5519. m1.makeRotationZ( angle );
  5520. this.applyMatrix( m1 );
  5521. return this;
  5522. };
  5523. }(),
  5524. translate: function () {
  5525. // translate geometry
  5526. var m1 = new Matrix4();
  5527. return function translate( x, y, z ) {
  5528. m1.makeTranslation( x, y, z );
  5529. this.applyMatrix( m1 );
  5530. return this;
  5531. };
  5532. }(),
  5533. scale: function () {
  5534. // scale geometry
  5535. var m1 = new Matrix4();
  5536. return function scale( x, y, z ) {
  5537. m1.makeScale( x, y, z );
  5538. this.applyMatrix( m1 );
  5539. return this;
  5540. };
  5541. }(),
  5542. lookAt: function () {
  5543. var obj = new Object3D();
  5544. return function lookAt( vector ) {
  5545. obj.lookAt( vector );
  5546. obj.updateMatrix();
  5547. this.applyMatrix( obj.matrix );
  5548. };
  5549. }(),
  5550. fromBufferGeometry: function ( geometry ) {
  5551. var scope = this;
  5552. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5553. var attributes = geometry.attributes;
  5554. var positions = attributes.position.array;
  5555. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5556. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5557. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5558. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5559. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5560. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5561. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  5562. if ( colors !== undefined ) {
  5563. scope.colors.push( new Color().fromArray( colors, i ) );
  5564. }
  5565. }
  5566. function addFace( a, b, c, materialIndex ) {
  5567. var vertexColors = ( colors === undefined ) ? [] : [
  5568. scope.colors[ a ].clone(),
  5569. scope.colors[ b ].clone(),
  5570. scope.colors[ c ].clone() ];
  5571. var vertexNormals = ( normals === undefined ) ? [] : [
  5572. new Vector3().fromArray( normals, a * 3 ),
  5573. new Vector3().fromArray( normals, b * 3 ),
  5574. new Vector3().fromArray( normals, c * 3 )
  5575. ];
  5576. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5577. scope.faces.push( face );
  5578. if ( uvs !== undefined ) {
  5579. scope.faceVertexUvs[ 0 ].push( [
  5580. new Vector2().fromArray( uvs, a * 2 ),
  5581. new Vector2().fromArray( uvs, b * 2 ),
  5582. new Vector2().fromArray( uvs, c * 2 )
  5583. ] );
  5584. }
  5585. if ( uvs2 !== undefined ) {
  5586. scope.faceVertexUvs[ 1 ].push( [
  5587. new Vector2().fromArray( uvs2, a * 2 ),
  5588. new Vector2().fromArray( uvs2, b * 2 ),
  5589. new Vector2().fromArray( uvs2, c * 2 )
  5590. ] );
  5591. }
  5592. }
  5593. var groups = geometry.groups;
  5594. if ( groups.length > 0 ) {
  5595. for ( var i = 0; i < groups.length; i ++ ) {
  5596. var group = groups[ i ];
  5597. var start = group.start;
  5598. var count = group.count;
  5599. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5600. if ( indices !== undefined ) {
  5601. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5602. } else {
  5603. addFace( j, j + 1, j + 2, group.materialIndex );
  5604. }
  5605. }
  5606. }
  5607. } else {
  5608. if ( indices !== undefined ) {
  5609. for ( var i = 0; i < indices.length; i += 3 ) {
  5610. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5611. }
  5612. } else {
  5613. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5614. addFace( i, i + 1, i + 2 );
  5615. }
  5616. }
  5617. }
  5618. this.computeFaceNormals();
  5619. if ( geometry.boundingBox !== null ) {
  5620. this.boundingBox = geometry.boundingBox.clone();
  5621. }
  5622. if ( geometry.boundingSphere !== null ) {
  5623. this.boundingSphere = geometry.boundingSphere.clone();
  5624. }
  5625. return this;
  5626. },
  5627. center: function () {
  5628. var offset = new Vector3();
  5629. return function center() {
  5630. this.computeBoundingBox();
  5631. this.boundingBox.getCenter( offset ).negate();
  5632. this.translate( offset.x, offset.y, offset.z );
  5633. return this;
  5634. };
  5635. }(),
  5636. normalize: function () {
  5637. this.computeBoundingSphere();
  5638. var center = this.boundingSphere.center;
  5639. var radius = this.boundingSphere.radius;
  5640. var s = radius === 0 ? 1 : 1.0 / radius;
  5641. var matrix = new Matrix4();
  5642. matrix.set(
  5643. s, 0, 0, - s * center.x,
  5644. 0, s, 0, - s * center.y,
  5645. 0, 0, s, - s * center.z,
  5646. 0, 0, 0, 1
  5647. );
  5648. this.applyMatrix( matrix );
  5649. return this;
  5650. },
  5651. computeFaceNormals: function () {
  5652. var cb = new Vector3(), ab = new Vector3();
  5653. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5654. var face = this.faces[ f ];
  5655. var vA = this.vertices[ face.a ];
  5656. var vB = this.vertices[ face.b ];
  5657. var vC = this.vertices[ face.c ];
  5658. cb.subVectors( vC, vB );
  5659. ab.subVectors( vA, vB );
  5660. cb.cross( ab );
  5661. cb.normalize();
  5662. face.normal.copy( cb );
  5663. }
  5664. },
  5665. computeVertexNormals: function ( areaWeighted ) {
  5666. if ( areaWeighted === undefined ) areaWeighted = true;
  5667. var v, vl, f, fl, face, vertices;
  5668. vertices = new Array( this.vertices.length );
  5669. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5670. vertices[ v ] = new Vector3();
  5671. }
  5672. if ( areaWeighted ) {
  5673. // vertex normals weighted by triangle areas
  5674. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5675. var vA, vB, vC;
  5676. var cb = new Vector3(), ab = new Vector3();
  5677. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5678. face = this.faces[ f ];
  5679. vA = this.vertices[ face.a ];
  5680. vB = this.vertices[ face.b ];
  5681. vC = this.vertices[ face.c ];
  5682. cb.subVectors( vC, vB );
  5683. ab.subVectors( vA, vB );
  5684. cb.cross( ab );
  5685. vertices[ face.a ].add( cb );
  5686. vertices[ face.b ].add( cb );
  5687. vertices[ face.c ].add( cb );
  5688. }
  5689. } else {
  5690. this.computeFaceNormals();
  5691. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5692. face = this.faces[ f ];
  5693. vertices[ face.a ].add( face.normal );
  5694. vertices[ face.b ].add( face.normal );
  5695. vertices[ face.c ].add( face.normal );
  5696. }
  5697. }
  5698. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5699. vertices[ v ].normalize();
  5700. }
  5701. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5702. face = this.faces[ f ];
  5703. var vertexNormals = face.vertexNormals;
  5704. if ( vertexNormals.length === 3 ) {
  5705. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5706. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5707. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5708. } else {
  5709. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5710. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5711. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5712. }
  5713. }
  5714. if ( this.faces.length > 0 ) {
  5715. this.normalsNeedUpdate = true;
  5716. }
  5717. },
  5718. computeFlatVertexNormals: function () {
  5719. var f, fl, face;
  5720. this.computeFaceNormals();
  5721. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5722. face = this.faces[ f ];
  5723. var vertexNormals = face.vertexNormals;
  5724. if ( vertexNormals.length === 3 ) {
  5725. vertexNormals[ 0 ].copy( face.normal );
  5726. vertexNormals[ 1 ].copy( face.normal );
  5727. vertexNormals[ 2 ].copy( face.normal );
  5728. } else {
  5729. vertexNormals[ 0 ] = face.normal.clone();
  5730. vertexNormals[ 1 ] = face.normal.clone();
  5731. vertexNormals[ 2 ] = face.normal.clone();
  5732. }
  5733. }
  5734. if ( this.faces.length > 0 ) {
  5735. this.normalsNeedUpdate = true;
  5736. }
  5737. },
  5738. computeMorphNormals: function () {
  5739. var i, il, f, fl, face;
  5740. // save original normals
  5741. // - create temp variables on first access
  5742. // otherwise just copy (for faster repeated calls)
  5743. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5744. face = this.faces[ f ];
  5745. if ( ! face.__originalFaceNormal ) {
  5746. face.__originalFaceNormal = face.normal.clone();
  5747. } else {
  5748. face.__originalFaceNormal.copy( face.normal );
  5749. }
  5750. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5751. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5752. if ( ! face.__originalVertexNormals[ i ] ) {
  5753. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5754. } else {
  5755. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5756. }
  5757. }
  5758. }
  5759. // use temp geometry to compute face and vertex normals for each morph
  5760. var tmpGeo = new Geometry();
  5761. tmpGeo.faces = this.faces;
  5762. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5763. // create on first access
  5764. if ( ! this.morphNormals[ i ] ) {
  5765. this.morphNormals[ i ] = {};
  5766. this.morphNormals[ i ].faceNormals = [];
  5767. this.morphNormals[ i ].vertexNormals = [];
  5768. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5769. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5770. var faceNormal, vertexNormals;
  5771. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5772. faceNormal = new Vector3();
  5773. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5774. dstNormalsFace.push( faceNormal );
  5775. dstNormalsVertex.push( vertexNormals );
  5776. }
  5777. }
  5778. var morphNormals = this.morphNormals[ i ];
  5779. // set vertices to morph target
  5780. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5781. // compute morph normals
  5782. tmpGeo.computeFaceNormals();
  5783. tmpGeo.computeVertexNormals();
  5784. // store morph normals
  5785. var faceNormal, vertexNormals;
  5786. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5787. face = this.faces[ f ];
  5788. faceNormal = morphNormals.faceNormals[ f ];
  5789. vertexNormals = morphNormals.vertexNormals[ f ];
  5790. faceNormal.copy( face.normal );
  5791. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5792. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5793. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5794. }
  5795. }
  5796. // restore original normals
  5797. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5798. face = this.faces[ f ];
  5799. face.normal = face.__originalFaceNormal;
  5800. face.vertexNormals = face.__originalVertexNormals;
  5801. }
  5802. },
  5803. computeBoundingBox: function () {
  5804. if ( this.boundingBox === null ) {
  5805. this.boundingBox = new Box3();
  5806. }
  5807. this.boundingBox.setFromPoints( this.vertices );
  5808. },
  5809. computeBoundingSphere: function () {
  5810. if ( this.boundingSphere === null ) {
  5811. this.boundingSphere = new Sphere();
  5812. }
  5813. this.boundingSphere.setFromPoints( this.vertices );
  5814. },
  5815. merge: function ( geometry, matrix, materialIndexOffset ) {
  5816. if ( ! ( geometry && geometry.isGeometry ) ) {
  5817. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5818. return;
  5819. }
  5820. var normalMatrix,
  5821. vertexOffset = this.vertices.length,
  5822. vertices1 = this.vertices,
  5823. vertices2 = geometry.vertices,
  5824. faces1 = this.faces,
  5825. faces2 = geometry.faces,
  5826. uvs1 = this.faceVertexUvs[ 0 ],
  5827. uvs2 = geometry.faceVertexUvs[ 0 ],
  5828. colors1 = this.colors,
  5829. colors2 = geometry.colors;
  5830. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5831. if ( matrix !== undefined ) {
  5832. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5833. }
  5834. // vertices
  5835. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5836. var vertex = vertices2[ i ];
  5837. var vertexCopy = vertex.clone();
  5838. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5839. vertices1.push( vertexCopy );
  5840. }
  5841. // colors
  5842. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5843. colors1.push( colors2[ i ].clone() );
  5844. }
  5845. // faces
  5846. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5847. var face = faces2[ i ], faceCopy, normal, color,
  5848. faceVertexNormals = face.vertexNormals,
  5849. faceVertexColors = face.vertexColors;
  5850. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5851. faceCopy.normal.copy( face.normal );
  5852. if ( normalMatrix !== undefined ) {
  5853. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5854. }
  5855. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5856. normal = faceVertexNormals[ j ].clone();
  5857. if ( normalMatrix !== undefined ) {
  5858. normal.applyMatrix3( normalMatrix ).normalize();
  5859. }
  5860. faceCopy.vertexNormals.push( normal );
  5861. }
  5862. faceCopy.color.copy( face.color );
  5863. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5864. color = faceVertexColors[ j ];
  5865. faceCopy.vertexColors.push( color.clone() );
  5866. }
  5867. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5868. faces1.push( faceCopy );
  5869. }
  5870. // uvs
  5871. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5872. var uv = uvs2[ i ], uvCopy = [];
  5873. if ( uv === undefined ) {
  5874. continue;
  5875. }
  5876. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5877. uvCopy.push( uv[ j ].clone() );
  5878. }
  5879. uvs1.push( uvCopy );
  5880. }
  5881. },
  5882. mergeMesh: function ( mesh ) {
  5883. if ( ! ( mesh && mesh.isMesh ) ) {
  5884. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5885. return;
  5886. }
  5887. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5888. this.merge( mesh.geometry, mesh.matrix );
  5889. },
  5890. /*
  5891. * Checks for duplicate vertices with hashmap.
  5892. * Duplicated vertices are removed
  5893. * and faces' vertices are updated.
  5894. */
  5895. mergeVertices: function () {
  5896. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5897. var unique = [], changes = [];
  5898. var v, key;
  5899. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5900. var precision = Math.pow( 10, precisionPoints );
  5901. var i, il, face;
  5902. var indices, j, jl;
  5903. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5904. v = this.vertices[ i ];
  5905. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5906. if ( verticesMap[ key ] === undefined ) {
  5907. verticesMap[ key ] = i;
  5908. unique.push( this.vertices[ i ] );
  5909. changes[ i ] = unique.length - 1;
  5910. } else {
  5911. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5912. changes[ i ] = changes[ verticesMap[ key ] ];
  5913. }
  5914. }
  5915. // if faces are completely degenerate after merging vertices, we
  5916. // have to remove them from the geometry.
  5917. var faceIndicesToRemove = [];
  5918. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5919. face = this.faces[ i ];
  5920. face.a = changes[ face.a ];
  5921. face.b = changes[ face.b ];
  5922. face.c = changes[ face.c ];
  5923. indices = [ face.a, face.b, face.c ];
  5924. // if any duplicate vertices are found in a Face3
  5925. // we have to remove the face as nothing can be saved
  5926. for ( var n = 0; n < 3; n ++ ) {
  5927. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5928. faceIndicesToRemove.push( i );
  5929. break;
  5930. }
  5931. }
  5932. }
  5933. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5934. var idx = faceIndicesToRemove[ i ];
  5935. this.faces.splice( idx, 1 );
  5936. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5937. this.faceVertexUvs[ j ].splice( idx, 1 );
  5938. }
  5939. }
  5940. // Use unique set of vertices
  5941. var diff = this.vertices.length - unique.length;
  5942. this.vertices = unique;
  5943. return diff;
  5944. },
  5945. setFromPoints: function ( points ) {
  5946. this.vertices = [];
  5947. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5948. var point = points[ i ];
  5949. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5950. }
  5951. return this;
  5952. },
  5953. sortFacesByMaterialIndex: function () {
  5954. var faces = this.faces;
  5955. var length = faces.length;
  5956. // tag faces
  5957. for ( var i = 0; i < length; i ++ ) {
  5958. faces[ i ]._id = i;
  5959. }
  5960. // sort faces
  5961. function materialIndexSort( a, b ) {
  5962. return a.materialIndex - b.materialIndex;
  5963. }
  5964. faces.sort( materialIndexSort );
  5965. // sort uvs
  5966. var uvs1 = this.faceVertexUvs[ 0 ];
  5967. var uvs2 = this.faceVertexUvs[ 1 ];
  5968. var newUvs1, newUvs2;
  5969. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5970. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5971. for ( var i = 0; i < length; i ++ ) {
  5972. var id = faces[ i ]._id;
  5973. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5974. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5975. }
  5976. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5977. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5978. },
  5979. toJSON: function () {
  5980. var data = {
  5981. metadata: {
  5982. version: 4.5,
  5983. type: 'Geometry',
  5984. generator: 'Geometry.toJSON'
  5985. }
  5986. };
  5987. // standard Geometry serialization
  5988. data.uuid = this.uuid;
  5989. data.type = this.type;
  5990. if ( this.name !== '' ) data.name = this.name;
  5991. if ( this.parameters !== undefined ) {
  5992. var parameters = this.parameters;
  5993. for ( var key in parameters ) {
  5994. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5995. }
  5996. return data;
  5997. }
  5998. var vertices = [];
  5999. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6000. var vertex = this.vertices[ i ];
  6001. vertices.push( vertex.x, vertex.y, vertex.z );
  6002. }
  6003. var faces = [];
  6004. var normals = [];
  6005. var normalsHash = {};
  6006. var colors = [];
  6007. var colorsHash = {};
  6008. var uvs = [];
  6009. var uvsHash = {};
  6010. for ( var i = 0; i < this.faces.length; i ++ ) {
  6011. var face = this.faces[ i ];
  6012. var hasMaterial = true;
  6013. var hasFaceUv = false; // deprecated
  6014. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6015. var hasFaceNormal = face.normal.length() > 0;
  6016. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6017. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6018. var hasFaceVertexColor = face.vertexColors.length > 0;
  6019. var faceType = 0;
  6020. faceType = setBit( faceType, 0, 0 ); // isQuad
  6021. faceType = setBit( faceType, 1, hasMaterial );
  6022. faceType = setBit( faceType, 2, hasFaceUv );
  6023. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6024. faceType = setBit( faceType, 4, hasFaceNormal );
  6025. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6026. faceType = setBit( faceType, 6, hasFaceColor );
  6027. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6028. faces.push( faceType );
  6029. faces.push( face.a, face.b, face.c );
  6030. faces.push( face.materialIndex );
  6031. if ( hasFaceVertexUv ) {
  6032. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6033. faces.push(
  6034. getUvIndex( faceVertexUvs[ 0 ] ),
  6035. getUvIndex( faceVertexUvs[ 1 ] ),
  6036. getUvIndex( faceVertexUvs[ 2 ] )
  6037. );
  6038. }
  6039. if ( hasFaceNormal ) {
  6040. faces.push( getNormalIndex( face.normal ) );
  6041. }
  6042. if ( hasFaceVertexNormal ) {
  6043. var vertexNormals = face.vertexNormals;
  6044. faces.push(
  6045. getNormalIndex( vertexNormals[ 0 ] ),
  6046. getNormalIndex( vertexNormals[ 1 ] ),
  6047. getNormalIndex( vertexNormals[ 2 ] )
  6048. );
  6049. }
  6050. if ( hasFaceColor ) {
  6051. faces.push( getColorIndex( face.color ) );
  6052. }
  6053. if ( hasFaceVertexColor ) {
  6054. var vertexColors = face.vertexColors;
  6055. faces.push(
  6056. getColorIndex( vertexColors[ 0 ] ),
  6057. getColorIndex( vertexColors[ 1 ] ),
  6058. getColorIndex( vertexColors[ 2 ] )
  6059. );
  6060. }
  6061. }
  6062. function setBit( value, position, enabled ) {
  6063. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6064. }
  6065. function getNormalIndex( normal ) {
  6066. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6067. if ( normalsHash[ hash ] !== undefined ) {
  6068. return normalsHash[ hash ];
  6069. }
  6070. normalsHash[ hash ] = normals.length / 3;
  6071. normals.push( normal.x, normal.y, normal.z );
  6072. return normalsHash[ hash ];
  6073. }
  6074. function getColorIndex( color ) {
  6075. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6076. if ( colorsHash[ hash ] !== undefined ) {
  6077. return colorsHash[ hash ];
  6078. }
  6079. colorsHash[ hash ] = colors.length;
  6080. colors.push( color.getHex() );
  6081. return colorsHash[ hash ];
  6082. }
  6083. function getUvIndex( uv ) {
  6084. var hash = uv.x.toString() + uv.y.toString();
  6085. if ( uvsHash[ hash ] !== undefined ) {
  6086. return uvsHash[ hash ];
  6087. }
  6088. uvsHash[ hash ] = uvs.length / 2;
  6089. uvs.push( uv.x, uv.y );
  6090. return uvsHash[ hash ];
  6091. }
  6092. data.data = {};
  6093. data.data.vertices = vertices;
  6094. data.data.normals = normals;
  6095. if ( colors.length > 0 ) data.data.colors = colors;
  6096. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6097. data.data.faces = faces;
  6098. return data;
  6099. },
  6100. clone: function () {
  6101. /*
  6102. // Handle primitives
  6103. var parameters = this.parameters;
  6104. if ( parameters !== undefined ) {
  6105. var values = [];
  6106. for ( var key in parameters ) {
  6107. values.push( parameters[ key ] );
  6108. }
  6109. var geometry = Object.create( this.constructor.prototype );
  6110. this.constructor.apply( geometry, values );
  6111. return geometry;
  6112. }
  6113. return new this.constructor().copy( this );
  6114. */
  6115. return new Geometry().copy( this );
  6116. },
  6117. copy: function ( source ) {
  6118. var i, il, j, jl, k, kl;
  6119. // reset
  6120. this.vertices = [];
  6121. this.colors = [];
  6122. this.faces = [];
  6123. this.faceVertexUvs = [[]];
  6124. this.morphTargets = [];
  6125. this.morphNormals = [];
  6126. this.skinWeights = [];
  6127. this.skinIndices = [];
  6128. this.lineDistances = [];
  6129. this.boundingBox = null;
  6130. this.boundingSphere = null;
  6131. // name
  6132. this.name = source.name;
  6133. // vertices
  6134. var vertices = source.vertices;
  6135. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6136. this.vertices.push( vertices[ i ].clone() );
  6137. }
  6138. // colors
  6139. var colors = source.colors;
  6140. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6141. this.colors.push( colors[ i ].clone() );
  6142. }
  6143. // faces
  6144. var faces = source.faces;
  6145. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6146. this.faces.push( faces[ i ].clone() );
  6147. }
  6148. // face vertex uvs
  6149. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6150. var faceVertexUvs = source.faceVertexUvs[ i ];
  6151. if ( this.faceVertexUvs[ i ] === undefined ) {
  6152. this.faceVertexUvs[ i ] = [];
  6153. }
  6154. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6155. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6156. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6157. var uv = uvs[ k ];
  6158. uvsCopy.push( uv.clone() );
  6159. }
  6160. this.faceVertexUvs[ i ].push( uvsCopy );
  6161. }
  6162. }
  6163. // morph targets
  6164. var morphTargets = source.morphTargets;
  6165. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6166. var morphTarget = {};
  6167. morphTarget.name = morphTargets[ i ].name;
  6168. // vertices
  6169. if ( morphTargets[ i ].vertices !== undefined ) {
  6170. morphTarget.vertices = [];
  6171. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6172. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6173. }
  6174. }
  6175. // normals
  6176. if ( morphTargets[ i ].normals !== undefined ) {
  6177. morphTarget.normals = [];
  6178. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6179. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6180. }
  6181. }
  6182. this.morphTargets.push( morphTarget );
  6183. }
  6184. // morph normals
  6185. var morphNormals = source.morphNormals;
  6186. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6187. var morphNormal = {};
  6188. // vertex normals
  6189. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6190. morphNormal.vertexNormals = [];
  6191. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6192. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6193. var destVertexNormal = {};
  6194. destVertexNormal.a = srcVertexNormal.a.clone();
  6195. destVertexNormal.b = srcVertexNormal.b.clone();
  6196. destVertexNormal.c = srcVertexNormal.c.clone();
  6197. morphNormal.vertexNormals.push( destVertexNormal );
  6198. }
  6199. }
  6200. // face normals
  6201. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6202. morphNormal.faceNormals = [];
  6203. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6204. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6205. }
  6206. }
  6207. this.morphNormals.push( morphNormal );
  6208. }
  6209. // skin weights
  6210. var skinWeights = source.skinWeights;
  6211. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6212. this.skinWeights.push( skinWeights[ i ].clone() );
  6213. }
  6214. // skin indices
  6215. var skinIndices = source.skinIndices;
  6216. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6217. this.skinIndices.push( skinIndices[ i ].clone() );
  6218. }
  6219. // line distances
  6220. var lineDistances = source.lineDistances;
  6221. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6222. this.lineDistances.push( lineDistances[ i ] );
  6223. }
  6224. // bounding box
  6225. var boundingBox = source.boundingBox;
  6226. if ( boundingBox !== null ) {
  6227. this.boundingBox = boundingBox.clone();
  6228. }
  6229. // bounding sphere
  6230. var boundingSphere = source.boundingSphere;
  6231. if ( boundingSphere !== null ) {
  6232. this.boundingSphere = boundingSphere.clone();
  6233. }
  6234. // update flags
  6235. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6236. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6237. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6238. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6239. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6240. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6241. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6242. return this;
  6243. },
  6244. dispose: function () {
  6245. this.dispatchEvent( { type: 'dispose' } );
  6246. }
  6247. } );
  6248. /**
  6249. * @author mrdoob / http://mrdoob.com/
  6250. */
  6251. function BufferAttribute( array, itemSize, normalized ) {
  6252. if ( Array.isArray( array ) ) {
  6253. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6254. }
  6255. this.name = '';
  6256. this.array = array;
  6257. this.itemSize = itemSize;
  6258. this.count = array !== undefined ? array.length / itemSize : 0;
  6259. this.normalized = normalized === true;
  6260. this.dynamic = false;
  6261. this.updateRange = { offset: 0, count: - 1 };
  6262. this.version = 0;
  6263. }
  6264. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6265. set: function ( value ) {
  6266. if ( value === true ) this.version ++;
  6267. }
  6268. } );
  6269. Object.assign( BufferAttribute.prototype, {
  6270. isBufferAttribute: true,
  6271. onUploadCallback: function () {},
  6272. setArray: function ( array ) {
  6273. if ( Array.isArray( array ) ) {
  6274. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6275. }
  6276. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6277. this.array = array;
  6278. return this;
  6279. },
  6280. setDynamic: function ( value ) {
  6281. this.dynamic = value;
  6282. return this;
  6283. },
  6284. copy: function ( source ) {
  6285. this.name = source.name;
  6286. this.array = new source.array.constructor( source.array );
  6287. this.itemSize = source.itemSize;
  6288. this.count = source.count;
  6289. this.normalized = source.normalized;
  6290. this.dynamic = source.dynamic;
  6291. return this;
  6292. },
  6293. copyAt: function ( index1, attribute, index2 ) {
  6294. index1 *= this.itemSize;
  6295. index2 *= attribute.itemSize;
  6296. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6297. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6298. }
  6299. return this;
  6300. },
  6301. copyArray: function ( array ) {
  6302. this.array.set( array );
  6303. return this;
  6304. },
  6305. copyColorsArray: function ( colors ) {
  6306. var array = this.array, offset = 0;
  6307. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6308. var color = colors[ i ];
  6309. if ( color === undefined ) {
  6310. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6311. color = new Color();
  6312. }
  6313. array[ offset ++ ] = color.r;
  6314. array[ offset ++ ] = color.g;
  6315. array[ offset ++ ] = color.b;
  6316. }
  6317. return this;
  6318. },
  6319. copyVector2sArray: function ( vectors ) {
  6320. var array = this.array, offset = 0;
  6321. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6322. var vector = vectors[ i ];
  6323. if ( vector === undefined ) {
  6324. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6325. vector = new Vector2();
  6326. }
  6327. array[ offset ++ ] = vector.x;
  6328. array[ offset ++ ] = vector.y;
  6329. }
  6330. return this;
  6331. },
  6332. copyVector3sArray: function ( vectors ) {
  6333. var array = this.array, offset = 0;
  6334. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6335. var vector = vectors[ i ];
  6336. if ( vector === undefined ) {
  6337. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6338. vector = new Vector3();
  6339. }
  6340. array[ offset ++ ] = vector.x;
  6341. array[ offset ++ ] = vector.y;
  6342. array[ offset ++ ] = vector.z;
  6343. }
  6344. return this;
  6345. },
  6346. copyVector4sArray: function ( vectors ) {
  6347. var array = this.array, offset = 0;
  6348. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6349. var vector = vectors[ i ];
  6350. if ( vector === undefined ) {
  6351. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6352. vector = new Vector4();
  6353. }
  6354. array[ offset ++ ] = vector.x;
  6355. array[ offset ++ ] = vector.y;
  6356. array[ offset ++ ] = vector.z;
  6357. array[ offset ++ ] = vector.w;
  6358. }
  6359. return this;
  6360. },
  6361. set: function ( value, offset ) {
  6362. if ( offset === undefined ) offset = 0;
  6363. this.array.set( value, offset );
  6364. return this;
  6365. },
  6366. getX: function ( index ) {
  6367. return this.array[ index * this.itemSize ];
  6368. },
  6369. setX: function ( index, x ) {
  6370. this.array[ index * this.itemSize ] = x;
  6371. return this;
  6372. },
  6373. getY: function ( index ) {
  6374. return this.array[ index * this.itemSize + 1 ];
  6375. },
  6376. setY: function ( index, y ) {
  6377. this.array[ index * this.itemSize + 1 ] = y;
  6378. return this;
  6379. },
  6380. getZ: function ( index ) {
  6381. return this.array[ index * this.itemSize + 2 ];
  6382. },
  6383. setZ: function ( index, z ) {
  6384. this.array[ index * this.itemSize + 2 ] = z;
  6385. return this;
  6386. },
  6387. getW: function ( index ) {
  6388. return this.array[ index * this.itemSize + 3 ];
  6389. },
  6390. setW: function ( index, w ) {
  6391. this.array[ index * this.itemSize + 3 ] = w;
  6392. return this;
  6393. },
  6394. setXY: function ( index, x, y ) {
  6395. index *= this.itemSize;
  6396. this.array[ index + 0 ] = x;
  6397. this.array[ index + 1 ] = y;
  6398. return this;
  6399. },
  6400. setXYZ: function ( index, x, y, z ) {
  6401. index *= this.itemSize;
  6402. this.array[ index + 0 ] = x;
  6403. this.array[ index + 1 ] = y;
  6404. this.array[ index + 2 ] = z;
  6405. return this;
  6406. },
  6407. setXYZW: function ( index, x, y, z, w ) {
  6408. index *= this.itemSize;
  6409. this.array[ index + 0 ] = x;
  6410. this.array[ index + 1 ] = y;
  6411. this.array[ index + 2 ] = z;
  6412. this.array[ index + 3 ] = w;
  6413. return this;
  6414. },
  6415. onUpload: function ( callback ) {
  6416. this.onUploadCallback = callback;
  6417. return this;
  6418. },
  6419. clone: function () {
  6420. return new this.constructor( this.array, this.itemSize ).copy( this );
  6421. }
  6422. } );
  6423. //
  6424. function Int8BufferAttribute( array, itemSize, normalized ) {
  6425. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6426. }
  6427. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6428. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6429. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6430. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6431. }
  6432. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6433. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6434. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6435. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6436. }
  6437. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6438. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6439. function Int16BufferAttribute( array, itemSize, normalized ) {
  6440. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6441. }
  6442. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6443. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6444. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6445. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6446. }
  6447. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6448. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6449. function Int32BufferAttribute( array, itemSize, normalized ) {
  6450. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6451. }
  6452. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6453. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6454. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6455. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6456. }
  6457. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6458. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6459. function Float32BufferAttribute( array, itemSize, normalized ) {
  6460. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6461. }
  6462. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6463. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6464. function Float64BufferAttribute( array, itemSize, normalized ) {
  6465. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6466. }
  6467. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6468. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6469. /**
  6470. * @author mrdoob / http://mrdoob.com/
  6471. */
  6472. function DirectGeometry() {
  6473. this.vertices = [];
  6474. this.normals = [];
  6475. this.colors = [];
  6476. this.uvs = [];
  6477. this.uvs2 = [];
  6478. this.groups = [];
  6479. this.morphTargets = {};
  6480. this.skinWeights = [];
  6481. this.skinIndices = [];
  6482. // this.lineDistances = [];
  6483. this.boundingBox = null;
  6484. this.boundingSphere = null;
  6485. // update flags
  6486. this.verticesNeedUpdate = false;
  6487. this.normalsNeedUpdate = false;
  6488. this.colorsNeedUpdate = false;
  6489. this.uvsNeedUpdate = false;
  6490. this.groupsNeedUpdate = false;
  6491. }
  6492. Object.assign( DirectGeometry.prototype, {
  6493. computeGroups: function ( geometry ) {
  6494. var group;
  6495. var groups = [];
  6496. var materialIndex = undefined;
  6497. var faces = geometry.faces;
  6498. for ( var i = 0; i < faces.length; i ++ ) {
  6499. var face = faces[ i ];
  6500. // materials
  6501. if ( face.materialIndex !== materialIndex ) {
  6502. materialIndex = face.materialIndex;
  6503. if ( group !== undefined ) {
  6504. group.count = ( i * 3 ) - group.start;
  6505. groups.push( group );
  6506. }
  6507. group = {
  6508. start: i * 3,
  6509. materialIndex: materialIndex
  6510. };
  6511. }
  6512. }
  6513. if ( group !== undefined ) {
  6514. group.count = ( i * 3 ) - group.start;
  6515. groups.push( group );
  6516. }
  6517. this.groups = groups;
  6518. },
  6519. fromGeometry: function ( geometry ) {
  6520. var faces = geometry.faces;
  6521. var vertices = geometry.vertices;
  6522. var faceVertexUvs = geometry.faceVertexUvs;
  6523. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6524. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6525. // morphs
  6526. var morphTargets = geometry.morphTargets;
  6527. var morphTargetsLength = morphTargets.length;
  6528. var morphTargetsPosition;
  6529. if ( morphTargetsLength > 0 ) {
  6530. morphTargetsPosition = [];
  6531. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6532. morphTargetsPosition[ i ] = {
  6533. name: morphTargets[ i ].name,
  6534. data: []
  6535. };
  6536. }
  6537. this.morphTargets.position = morphTargetsPosition;
  6538. }
  6539. var morphNormals = geometry.morphNormals;
  6540. var morphNormalsLength = morphNormals.length;
  6541. var morphTargetsNormal;
  6542. if ( morphNormalsLength > 0 ) {
  6543. morphTargetsNormal = [];
  6544. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6545. morphTargetsNormal[ i ] = {
  6546. name: morphNormals[ i ].name,
  6547. data: []
  6548. };
  6549. }
  6550. this.morphTargets.normal = morphTargetsNormal;
  6551. }
  6552. // skins
  6553. var skinIndices = geometry.skinIndices;
  6554. var skinWeights = geometry.skinWeights;
  6555. var hasSkinIndices = skinIndices.length === vertices.length;
  6556. var hasSkinWeights = skinWeights.length === vertices.length;
  6557. //
  6558. if ( vertices.length > 0 && faces.length === 0 ) {
  6559. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6560. }
  6561. for ( var i = 0; i < faces.length; i ++ ) {
  6562. var face = faces[ i ];
  6563. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6564. var vertexNormals = face.vertexNormals;
  6565. if ( vertexNormals.length === 3 ) {
  6566. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6567. } else {
  6568. var normal = face.normal;
  6569. this.normals.push( normal, normal, normal );
  6570. }
  6571. var vertexColors = face.vertexColors;
  6572. if ( vertexColors.length === 3 ) {
  6573. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6574. } else {
  6575. var color = face.color;
  6576. this.colors.push( color, color, color );
  6577. }
  6578. if ( hasFaceVertexUv === true ) {
  6579. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6580. if ( vertexUvs !== undefined ) {
  6581. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6582. } else {
  6583. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6584. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6585. }
  6586. }
  6587. if ( hasFaceVertexUv2 === true ) {
  6588. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6589. if ( vertexUvs !== undefined ) {
  6590. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6591. } else {
  6592. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6593. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6594. }
  6595. }
  6596. // morphs
  6597. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6598. var morphTarget = morphTargets[ j ].vertices;
  6599. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6600. }
  6601. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6602. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6603. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6604. }
  6605. // skins
  6606. if ( hasSkinIndices ) {
  6607. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6608. }
  6609. if ( hasSkinWeights ) {
  6610. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6611. }
  6612. }
  6613. this.computeGroups( geometry );
  6614. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6615. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6616. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6617. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6618. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6619. return this;
  6620. }
  6621. } );
  6622. /**
  6623. * @author mrdoob / http://mrdoob.com/
  6624. */
  6625. function arrayMax( array ) {
  6626. if ( array.length === 0 ) return - Infinity;
  6627. var max = array[ 0 ];
  6628. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6629. if ( array[ i ] > max ) max = array[ i ];
  6630. }
  6631. return max;
  6632. }
  6633. /**
  6634. * @author alteredq / http://alteredqualia.com/
  6635. * @author mrdoob / http://mrdoob.com/
  6636. */
  6637. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6638. function BufferGeometry() {
  6639. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6640. this.uuid = _Math.generateUUID();
  6641. this.name = '';
  6642. this.type = 'BufferGeometry';
  6643. this.index = null;
  6644. this.attributes = {};
  6645. this.morphAttributes = {};
  6646. this.groups = [];
  6647. this.boundingBox = null;
  6648. this.boundingSphere = null;
  6649. this.drawRange = { start: 0, count: Infinity };
  6650. this.userData = {};
  6651. }
  6652. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6653. constructor: BufferGeometry,
  6654. isBufferGeometry: true,
  6655. getIndex: function () {
  6656. return this.index;
  6657. },
  6658. setIndex: function ( index ) {
  6659. if ( Array.isArray( index ) ) {
  6660. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6661. } else {
  6662. this.index = index;
  6663. }
  6664. },
  6665. addAttribute: function ( name, attribute ) {
  6666. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6667. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6668. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6669. }
  6670. if ( name === 'index' ) {
  6671. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6672. this.setIndex( attribute );
  6673. return this;
  6674. }
  6675. this.attributes[ name ] = attribute;
  6676. return this;
  6677. },
  6678. getAttribute: function ( name ) {
  6679. return this.attributes[ name ];
  6680. },
  6681. removeAttribute: function ( name ) {
  6682. delete this.attributes[ name ];
  6683. return this;
  6684. },
  6685. addGroup: function ( start, count, materialIndex ) {
  6686. this.groups.push( {
  6687. start: start,
  6688. count: count,
  6689. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6690. } );
  6691. },
  6692. clearGroups: function () {
  6693. this.groups = [];
  6694. },
  6695. setDrawRange: function ( start, count ) {
  6696. this.drawRange.start = start;
  6697. this.drawRange.count = count;
  6698. },
  6699. applyMatrix: function ( matrix ) {
  6700. var position = this.attributes.position;
  6701. if ( position !== undefined ) {
  6702. matrix.applyToBufferAttribute( position );
  6703. position.needsUpdate = true;
  6704. }
  6705. var normal = this.attributes.normal;
  6706. if ( normal !== undefined ) {
  6707. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6708. normalMatrix.applyToBufferAttribute( normal );
  6709. normal.needsUpdate = true;
  6710. }
  6711. var tangent = this.attributes.tangent;
  6712. if ( tangent !== undefined ) {
  6713. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6714. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  6715. normalMatrix.applyToBufferAttribute( tangent );
  6716. tangent.needsUpdate = true;
  6717. }
  6718. if ( this.boundingBox !== null ) {
  6719. this.computeBoundingBox();
  6720. }
  6721. if ( this.boundingSphere !== null ) {
  6722. this.computeBoundingSphere();
  6723. }
  6724. return this;
  6725. },
  6726. rotateX: function () {
  6727. // rotate geometry around world x-axis
  6728. var m1 = new Matrix4();
  6729. return function rotateX( angle ) {
  6730. m1.makeRotationX( angle );
  6731. this.applyMatrix( m1 );
  6732. return this;
  6733. };
  6734. }(),
  6735. rotateY: function () {
  6736. // rotate geometry around world y-axis
  6737. var m1 = new Matrix4();
  6738. return function rotateY( angle ) {
  6739. m1.makeRotationY( angle );
  6740. this.applyMatrix( m1 );
  6741. return this;
  6742. };
  6743. }(),
  6744. rotateZ: function () {
  6745. // rotate geometry around world z-axis
  6746. var m1 = new Matrix4();
  6747. return function rotateZ( angle ) {
  6748. m1.makeRotationZ( angle );
  6749. this.applyMatrix( m1 );
  6750. return this;
  6751. };
  6752. }(),
  6753. translate: function () {
  6754. // translate geometry
  6755. var m1 = new Matrix4();
  6756. return function translate( x, y, z ) {
  6757. m1.makeTranslation( x, y, z );
  6758. this.applyMatrix( m1 );
  6759. return this;
  6760. };
  6761. }(),
  6762. scale: function () {
  6763. // scale geometry
  6764. var m1 = new Matrix4();
  6765. return function scale( x, y, z ) {
  6766. m1.makeScale( x, y, z );
  6767. this.applyMatrix( m1 );
  6768. return this;
  6769. };
  6770. }(),
  6771. lookAt: function () {
  6772. var obj = new Object3D();
  6773. return function lookAt( vector ) {
  6774. obj.lookAt( vector );
  6775. obj.updateMatrix();
  6776. this.applyMatrix( obj.matrix );
  6777. };
  6778. }(),
  6779. center: function () {
  6780. var offset = new Vector3();
  6781. return function center() {
  6782. this.computeBoundingBox();
  6783. this.boundingBox.getCenter( offset ).negate();
  6784. this.translate( offset.x, offset.y, offset.z );
  6785. return this;
  6786. };
  6787. }(),
  6788. setFromObject: function ( object ) {
  6789. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6790. var geometry = object.geometry;
  6791. if ( object.isPoints || object.isLine ) {
  6792. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6793. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6794. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6795. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6796. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6797. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6798. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6799. }
  6800. if ( geometry.boundingSphere !== null ) {
  6801. this.boundingSphere = geometry.boundingSphere.clone();
  6802. }
  6803. if ( geometry.boundingBox !== null ) {
  6804. this.boundingBox = geometry.boundingBox.clone();
  6805. }
  6806. } else if ( object.isMesh ) {
  6807. if ( geometry && geometry.isGeometry ) {
  6808. this.fromGeometry( geometry );
  6809. }
  6810. }
  6811. return this;
  6812. },
  6813. setFromPoints: function ( points ) {
  6814. var position = [];
  6815. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6816. var point = points[ i ];
  6817. position.push( point.x, point.y, point.z || 0 );
  6818. }
  6819. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6820. return this;
  6821. },
  6822. updateFromObject: function ( object ) {
  6823. var geometry = object.geometry;
  6824. if ( object.isMesh ) {
  6825. var direct = geometry.__directGeometry;
  6826. if ( geometry.elementsNeedUpdate === true ) {
  6827. direct = undefined;
  6828. geometry.elementsNeedUpdate = false;
  6829. }
  6830. if ( direct === undefined ) {
  6831. return this.fromGeometry( geometry );
  6832. }
  6833. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6834. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6835. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6836. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6837. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6838. geometry.verticesNeedUpdate = false;
  6839. geometry.normalsNeedUpdate = false;
  6840. geometry.colorsNeedUpdate = false;
  6841. geometry.uvsNeedUpdate = false;
  6842. geometry.groupsNeedUpdate = false;
  6843. geometry = direct;
  6844. }
  6845. var attribute;
  6846. if ( geometry.verticesNeedUpdate === true ) {
  6847. attribute = this.attributes.position;
  6848. if ( attribute !== undefined ) {
  6849. attribute.copyVector3sArray( geometry.vertices );
  6850. attribute.needsUpdate = true;
  6851. }
  6852. geometry.verticesNeedUpdate = false;
  6853. }
  6854. if ( geometry.normalsNeedUpdate === true ) {
  6855. attribute = this.attributes.normal;
  6856. if ( attribute !== undefined ) {
  6857. attribute.copyVector3sArray( geometry.normals );
  6858. attribute.needsUpdate = true;
  6859. }
  6860. geometry.normalsNeedUpdate = false;
  6861. }
  6862. if ( geometry.colorsNeedUpdate === true ) {
  6863. attribute = this.attributes.color;
  6864. if ( attribute !== undefined ) {
  6865. attribute.copyColorsArray( geometry.colors );
  6866. attribute.needsUpdate = true;
  6867. }
  6868. geometry.colorsNeedUpdate = false;
  6869. }
  6870. if ( geometry.uvsNeedUpdate ) {
  6871. attribute = this.attributes.uv;
  6872. if ( attribute !== undefined ) {
  6873. attribute.copyVector2sArray( geometry.uvs );
  6874. attribute.needsUpdate = true;
  6875. }
  6876. geometry.uvsNeedUpdate = false;
  6877. }
  6878. if ( geometry.lineDistancesNeedUpdate ) {
  6879. attribute = this.attributes.lineDistance;
  6880. if ( attribute !== undefined ) {
  6881. attribute.copyArray( geometry.lineDistances );
  6882. attribute.needsUpdate = true;
  6883. }
  6884. geometry.lineDistancesNeedUpdate = false;
  6885. }
  6886. if ( geometry.groupsNeedUpdate ) {
  6887. geometry.computeGroups( object.geometry );
  6888. this.groups = geometry.groups;
  6889. geometry.groupsNeedUpdate = false;
  6890. }
  6891. return this;
  6892. },
  6893. fromGeometry: function ( geometry ) {
  6894. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6895. return this.fromDirectGeometry( geometry.__directGeometry );
  6896. },
  6897. fromDirectGeometry: function ( geometry ) {
  6898. var positions = new Float32Array( geometry.vertices.length * 3 );
  6899. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6900. if ( geometry.normals.length > 0 ) {
  6901. var normals = new Float32Array( geometry.normals.length * 3 );
  6902. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6903. }
  6904. if ( geometry.colors.length > 0 ) {
  6905. var colors = new Float32Array( geometry.colors.length * 3 );
  6906. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6907. }
  6908. if ( geometry.uvs.length > 0 ) {
  6909. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6910. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6911. }
  6912. if ( geometry.uvs2.length > 0 ) {
  6913. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6914. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6915. }
  6916. // groups
  6917. this.groups = geometry.groups;
  6918. // morphs
  6919. for ( var name in geometry.morphTargets ) {
  6920. var array = [];
  6921. var morphTargets = geometry.morphTargets[ name ];
  6922. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6923. var morphTarget = morphTargets[ i ];
  6924. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6925. attribute.name = morphTarget.name;
  6926. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6927. }
  6928. this.morphAttributes[ name ] = array;
  6929. }
  6930. // skinning
  6931. if ( geometry.skinIndices.length > 0 ) {
  6932. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6933. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6934. }
  6935. if ( geometry.skinWeights.length > 0 ) {
  6936. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6937. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6938. }
  6939. //
  6940. if ( geometry.boundingSphere !== null ) {
  6941. this.boundingSphere = geometry.boundingSphere.clone();
  6942. }
  6943. if ( geometry.boundingBox !== null ) {
  6944. this.boundingBox = geometry.boundingBox.clone();
  6945. }
  6946. return this;
  6947. },
  6948. computeBoundingBox: function () {
  6949. var box = new Box3();
  6950. return function computeBoundingBox() {
  6951. if ( this.boundingBox === null ) {
  6952. this.boundingBox = new Box3();
  6953. }
  6954. var position = this.attributes.position;
  6955. var morphAttributesPosition = this.morphAttributes.position;
  6956. if ( position !== undefined ) {
  6957. this.boundingBox.setFromBufferAttribute( position );
  6958. // process morph attributes if present
  6959. if ( morphAttributesPosition ) {
  6960. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6961. var morphAttribute = morphAttributesPosition[ i ];
  6962. box.setFromBufferAttribute( morphAttribute );
  6963. this.boundingBox.expandByPoint( box.min );
  6964. this.boundingBox.expandByPoint( box.max );
  6965. }
  6966. }
  6967. } else {
  6968. this.boundingBox.makeEmpty();
  6969. }
  6970. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6971. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6972. }
  6973. };
  6974. }(),
  6975. computeBoundingSphere: function () {
  6976. var box = new Box3();
  6977. var boxMorphTargets = new Box3();
  6978. var vector = new Vector3();
  6979. return function computeBoundingSphere() {
  6980. if ( this.boundingSphere === null ) {
  6981. this.boundingSphere = new Sphere();
  6982. }
  6983. var position = this.attributes.position;
  6984. var morphAttributesPosition = this.morphAttributes.position;
  6985. if ( position ) {
  6986. // first, find the center of the bounding sphere
  6987. var center = this.boundingSphere.center;
  6988. box.setFromBufferAttribute( position );
  6989. // process morph attributes if present
  6990. if ( morphAttributesPosition ) {
  6991. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6992. var morphAttribute = morphAttributesPosition[ i ];
  6993. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6994. box.expandByPoint( boxMorphTargets.min );
  6995. box.expandByPoint( boxMorphTargets.max );
  6996. }
  6997. }
  6998. box.getCenter( center );
  6999. // second, try to find a boundingSphere with a radius smaller than the
  7000. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7001. var maxRadiusSq = 0;
  7002. for ( var i = 0, il = position.count; i < il; i ++ ) {
  7003. vector.fromBufferAttribute( position, i );
  7004. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7005. }
  7006. // process morph attributes if present
  7007. if ( morphAttributesPosition ) {
  7008. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  7009. var morphAttribute = morphAttributesPosition[ i ];
  7010. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  7011. vector.fromBufferAttribute( morphAttribute, j );
  7012. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7013. }
  7014. }
  7015. }
  7016. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  7017. if ( isNaN( this.boundingSphere.radius ) ) {
  7018. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  7019. }
  7020. }
  7021. };
  7022. }(),
  7023. computeFaceNormals: function () {
  7024. // backwards compatibility
  7025. },
  7026. computeVertexNormals: function () {
  7027. var index = this.index;
  7028. var attributes = this.attributes;
  7029. if ( attributes.position ) {
  7030. var positions = attributes.position.array;
  7031. if ( attributes.normal === undefined ) {
  7032. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7033. } else {
  7034. // reset existing normals to zero
  7035. var array = attributes.normal.array;
  7036. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7037. array[ i ] = 0;
  7038. }
  7039. }
  7040. var normals = attributes.normal.array;
  7041. var vA, vB, vC;
  7042. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  7043. var cb = new Vector3(), ab = new Vector3();
  7044. // indexed elements
  7045. if ( index ) {
  7046. var indices = index.array;
  7047. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  7048. vA = indices[ i + 0 ] * 3;
  7049. vB = indices[ i + 1 ] * 3;
  7050. vC = indices[ i + 2 ] * 3;
  7051. pA.fromArray( positions, vA );
  7052. pB.fromArray( positions, vB );
  7053. pC.fromArray( positions, vC );
  7054. cb.subVectors( pC, pB );
  7055. ab.subVectors( pA, pB );
  7056. cb.cross( ab );
  7057. normals[ vA ] += cb.x;
  7058. normals[ vA + 1 ] += cb.y;
  7059. normals[ vA + 2 ] += cb.z;
  7060. normals[ vB ] += cb.x;
  7061. normals[ vB + 1 ] += cb.y;
  7062. normals[ vB + 2 ] += cb.z;
  7063. normals[ vC ] += cb.x;
  7064. normals[ vC + 1 ] += cb.y;
  7065. normals[ vC + 2 ] += cb.z;
  7066. }
  7067. } else {
  7068. // non-indexed elements (unconnected triangle soup)
  7069. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7070. pA.fromArray( positions, i );
  7071. pB.fromArray( positions, i + 3 );
  7072. pC.fromArray( positions, i + 6 );
  7073. cb.subVectors( pC, pB );
  7074. ab.subVectors( pA, pB );
  7075. cb.cross( ab );
  7076. normals[ i ] = cb.x;
  7077. normals[ i + 1 ] = cb.y;
  7078. normals[ i + 2 ] = cb.z;
  7079. normals[ i + 3 ] = cb.x;
  7080. normals[ i + 4 ] = cb.y;
  7081. normals[ i + 5 ] = cb.z;
  7082. normals[ i + 6 ] = cb.x;
  7083. normals[ i + 7 ] = cb.y;
  7084. normals[ i + 8 ] = cb.z;
  7085. }
  7086. }
  7087. this.normalizeNormals();
  7088. attributes.normal.needsUpdate = true;
  7089. }
  7090. },
  7091. merge: function ( geometry, offset ) {
  7092. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  7093. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7094. return;
  7095. }
  7096. if ( offset === undefined ) {
  7097. offset = 0;
  7098. console.warn(
  7099. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7100. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7101. );
  7102. }
  7103. var attributes = this.attributes;
  7104. for ( var key in attributes ) {
  7105. if ( geometry.attributes[ key ] === undefined ) continue;
  7106. var attribute1 = attributes[ key ];
  7107. var attributeArray1 = attribute1.array;
  7108. var attribute2 = geometry.attributes[ key ];
  7109. var attributeArray2 = attribute2.array;
  7110. var attributeSize = attribute2.itemSize;
  7111. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7112. attributeArray1[ j ] = attributeArray2[ i ];
  7113. }
  7114. }
  7115. return this;
  7116. },
  7117. normalizeNormals: function () {
  7118. var vector = new Vector3();
  7119. return function normalizeNormals() {
  7120. var normals = this.attributes.normal;
  7121. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7122. vector.x = normals.getX( i );
  7123. vector.y = normals.getY( i );
  7124. vector.z = normals.getZ( i );
  7125. vector.normalize();
  7126. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7127. }
  7128. };
  7129. }(),
  7130. toNonIndexed: function () {
  7131. function convertBufferAttribute( attribute, indices ) {
  7132. var array = attribute.array;
  7133. var itemSize = attribute.itemSize;
  7134. var array2 = new array.constructor( indices.length * itemSize );
  7135. var index = 0, index2 = 0;
  7136. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7137. index = indices[ i ] * itemSize;
  7138. for ( var j = 0; j < itemSize; j ++ ) {
  7139. array2[ index2 ++ ] = array[ index ++ ];
  7140. }
  7141. }
  7142. return new BufferAttribute( array2, itemSize );
  7143. }
  7144. //
  7145. if ( this.index === null ) {
  7146. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7147. return this;
  7148. }
  7149. var geometry2 = new BufferGeometry();
  7150. var indices = this.index.array;
  7151. var attributes = this.attributes;
  7152. // attributes
  7153. for ( var name in attributes ) {
  7154. var attribute = attributes[ name ];
  7155. var newAttribute = convertBufferAttribute( attribute, indices );
  7156. geometry2.addAttribute( name, newAttribute );
  7157. }
  7158. // morph attributes
  7159. var morphAttributes = this.morphAttributes;
  7160. for ( name in morphAttributes ) {
  7161. var morphArray = [];
  7162. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7163. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  7164. var attribute = morphAttribute[ i ];
  7165. var newAttribute = convertBufferAttribute( attribute, indices );
  7166. morphArray.push( newAttribute );
  7167. }
  7168. geometry2.morphAttributes[ name ] = morphArray;
  7169. }
  7170. // groups
  7171. var groups = this.groups;
  7172. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7173. var group = groups[ i ];
  7174. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7175. }
  7176. return geometry2;
  7177. },
  7178. toJSON: function () {
  7179. var data = {
  7180. metadata: {
  7181. version: 4.5,
  7182. type: 'BufferGeometry',
  7183. generator: 'BufferGeometry.toJSON'
  7184. }
  7185. };
  7186. // standard BufferGeometry serialization
  7187. data.uuid = this.uuid;
  7188. data.type = this.type;
  7189. if ( this.name !== '' ) data.name = this.name;
  7190. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7191. if ( this.parameters !== undefined ) {
  7192. var parameters = this.parameters;
  7193. for ( var key in parameters ) {
  7194. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7195. }
  7196. return data;
  7197. }
  7198. data.data = { attributes: {} };
  7199. var index = this.index;
  7200. if ( index !== null ) {
  7201. data.data.index = {
  7202. type: index.array.constructor.name,
  7203. array: Array.prototype.slice.call( index.array )
  7204. };
  7205. }
  7206. var attributes = this.attributes;
  7207. for ( var key in attributes ) {
  7208. var attribute = attributes[ key ];
  7209. var attributeData = {
  7210. itemSize: attribute.itemSize,
  7211. type: attribute.array.constructor.name,
  7212. array: Array.prototype.slice.call( attribute.array ),
  7213. normalized: attribute.normalized
  7214. };
  7215. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7216. data.data.attributes[ key ] = attributeData;
  7217. }
  7218. var morphAttributes = {};
  7219. var hasMorphAttributes = false;
  7220. for ( var key in this.morphAttributes ) {
  7221. var attributeArray = this.morphAttributes[ key ];
  7222. var array = [];
  7223. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  7224. var attribute = attributeArray[ i ];
  7225. var attributeData = {
  7226. itemSize: attribute.itemSize,
  7227. type: attribute.array.constructor.name,
  7228. array: Array.prototype.slice.call( attribute.array ),
  7229. normalized: attribute.normalized
  7230. };
  7231. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7232. array.push( attributeData );
  7233. }
  7234. if ( array.length > 0 ) {
  7235. morphAttributes[ key ] = array;
  7236. hasMorphAttributes = true;
  7237. }
  7238. }
  7239. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  7240. var groups = this.groups;
  7241. if ( groups.length > 0 ) {
  7242. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7243. }
  7244. var boundingSphere = this.boundingSphere;
  7245. if ( boundingSphere !== null ) {
  7246. data.data.boundingSphere = {
  7247. center: boundingSphere.center.toArray(),
  7248. radius: boundingSphere.radius
  7249. };
  7250. }
  7251. return data;
  7252. },
  7253. clone: function () {
  7254. /*
  7255. // Handle primitives
  7256. var parameters = this.parameters;
  7257. if ( parameters !== undefined ) {
  7258. var values = [];
  7259. for ( var key in parameters ) {
  7260. values.push( parameters[ key ] );
  7261. }
  7262. var geometry = Object.create( this.constructor.prototype );
  7263. this.constructor.apply( geometry, values );
  7264. return geometry;
  7265. }
  7266. return new this.constructor().copy( this );
  7267. */
  7268. return new BufferGeometry().copy( this );
  7269. },
  7270. copy: function ( source ) {
  7271. var name, i, l;
  7272. // reset
  7273. this.index = null;
  7274. this.attributes = {};
  7275. this.morphAttributes = {};
  7276. this.groups = [];
  7277. this.boundingBox = null;
  7278. this.boundingSphere = null;
  7279. // name
  7280. this.name = source.name;
  7281. // index
  7282. var index = source.index;
  7283. if ( index !== null ) {
  7284. this.setIndex( index.clone() );
  7285. }
  7286. // attributes
  7287. var attributes = source.attributes;
  7288. for ( name in attributes ) {
  7289. var attribute = attributes[ name ];
  7290. this.addAttribute( name, attribute.clone() );
  7291. }
  7292. // morph attributes
  7293. var morphAttributes = source.morphAttributes;
  7294. for ( name in morphAttributes ) {
  7295. var array = [];
  7296. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7297. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7298. array.push( morphAttribute[ i ].clone() );
  7299. }
  7300. this.morphAttributes[ name ] = array;
  7301. }
  7302. // groups
  7303. var groups = source.groups;
  7304. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7305. var group = groups[ i ];
  7306. this.addGroup( group.start, group.count, group.materialIndex );
  7307. }
  7308. // bounding box
  7309. var boundingBox = source.boundingBox;
  7310. if ( boundingBox !== null ) {
  7311. this.boundingBox = boundingBox.clone();
  7312. }
  7313. // bounding sphere
  7314. var boundingSphere = source.boundingSphere;
  7315. if ( boundingSphere !== null ) {
  7316. this.boundingSphere = boundingSphere.clone();
  7317. }
  7318. // draw range
  7319. this.drawRange.start = source.drawRange.start;
  7320. this.drawRange.count = source.drawRange.count;
  7321. // user data
  7322. this.userData = source.userData;
  7323. return this;
  7324. },
  7325. dispose: function () {
  7326. this.dispatchEvent( { type: 'dispose' } );
  7327. }
  7328. } );
  7329. /**
  7330. * @author mrdoob / http://mrdoob.com/
  7331. * @author Mugen87 / https://github.com/Mugen87
  7332. */
  7333. // BoxGeometry
  7334. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7335. Geometry.call( this );
  7336. this.type = 'BoxGeometry';
  7337. this.parameters = {
  7338. width: width,
  7339. height: height,
  7340. depth: depth,
  7341. widthSegments: widthSegments,
  7342. heightSegments: heightSegments,
  7343. depthSegments: depthSegments
  7344. };
  7345. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7346. this.mergeVertices();
  7347. }
  7348. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7349. BoxGeometry.prototype.constructor = BoxGeometry;
  7350. // BoxBufferGeometry
  7351. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7352. BufferGeometry.call( this );
  7353. this.type = 'BoxBufferGeometry';
  7354. this.parameters = {
  7355. width: width,
  7356. height: height,
  7357. depth: depth,
  7358. widthSegments: widthSegments,
  7359. heightSegments: heightSegments,
  7360. depthSegments: depthSegments
  7361. };
  7362. var scope = this;
  7363. width = width || 1;
  7364. height = height || 1;
  7365. depth = depth || 1;
  7366. // segments
  7367. widthSegments = Math.floor( widthSegments ) || 1;
  7368. heightSegments = Math.floor( heightSegments ) || 1;
  7369. depthSegments = Math.floor( depthSegments ) || 1;
  7370. // buffers
  7371. var indices = [];
  7372. var vertices = [];
  7373. var normals = [];
  7374. var uvs = [];
  7375. // helper variables
  7376. var numberOfVertices = 0;
  7377. var groupStart = 0;
  7378. // build each side of the box geometry
  7379. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7380. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7381. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7382. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7383. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7384. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7385. // build geometry
  7386. this.setIndex( indices );
  7387. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7388. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7389. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7390. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7391. var segmentWidth = width / gridX;
  7392. var segmentHeight = height / gridY;
  7393. var widthHalf = width / 2;
  7394. var heightHalf = height / 2;
  7395. var depthHalf = depth / 2;
  7396. var gridX1 = gridX + 1;
  7397. var gridY1 = gridY + 1;
  7398. var vertexCounter = 0;
  7399. var groupCount = 0;
  7400. var ix, iy;
  7401. var vector = new Vector3();
  7402. // generate vertices, normals and uvs
  7403. for ( iy = 0; iy < gridY1; iy ++ ) {
  7404. var y = iy * segmentHeight - heightHalf;
  7405. for ( ix = 0; ix < gridX1; ix ++ ) {
  7406. var x = ix * segmentWidth - widthHalf;
  7407. // set values to correct vector component
  7408. vector[ u ] = x * udir;
  7409. vector[ v ] = y * vdir;
  7410. vector[ w ] = depthHalf;
  7411. // now apply vector to vertex buffer
  7412. vertices.push( vector.x, vector.y, vector.z );
  7413. // set values to correct vector component
  7414. vector[ u ] = 0;
  7415. vector[ v ] = 0;
  7416. vector[ w ] = depth > 0 ? 1 : - 1;
  7417. // now apply vector to normal buffer
  7418. normals.push( vector.x, vector.y, vector.z );
  7419. // uvs
  7420. uvs.push( ix / gridX );
  7421. uvs.push( 1 - ( iy / gridY ) );
  7422. // counters
  7423. vertexCounter += 1;
  7424. }
  7425. }
  7426. // indices
  7427. // 1. you need three indices to draw a single face
  7428. // 2. a single segment consists of two faces
  7429. // 3. so we need to generate six (2*3) indices per segment
  7430. for ( iy = 0; iy < gridY; iy ++ ) {
  7431. for ( ix = 0; ix < gridX; ix ++ ) {
  7432. var a = numberOfVertices + ix + gridX1 * iy;
  7433. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7434. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7435. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7436. // faces
  7437. indices.push( a, b, d );
  7438. indices.push( b, c, d );
  7439. // increase counter
  7440. groupCount += 6;
  7441. }
  7442. }
  7443. // add a group to the geometry. this will ensure multi material support
  7444. scope.addGroup( groupStart, groupCount, materialIndex );
  7445. // calculate new start value for groups
  7446. groupStart += groupCount;
  7447. // update total number of vertices
  7448. numberOfVertices += vertexCounter;
  7449. }
  7450. }
  7451. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7452. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7453. /**
  7454. * @author mrdoob / http://mrdoob.com/
  7455. * @author Mugen87 / https://github.com/Mugen87
  7456. */
  7457. // PlaneGeometry
  7458. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7459. Geometry.call( this );
  7460. this.type = 'PlaneGeometry';
  7461. this.parameters = {
  7462. width: width,
  7463. height: height,
  7464. widthSegments: widthSegments,
  7465. heightSegments: heightSegments
  7466. };
  7467. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7468. this.mergeVertices();
  7469. }
  7470. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7471. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7472. // PlaneBufferGeometry
  7473. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7474. BufferGeometry.call( this );
  7475. this.type = 'PlaneBufferGeometry';
  7476. this.parameters = {
  7477. width: width,
  7478. height: height,
  7479. widthSegments: widthSegments,
  7480. heightSegments: heightSegments
  7481. };
  7482. width = width || 1;
  7483. height = height || 1;
  7484. var width_half = width / 2;
  7485. var height_half = height / 2;
  7486. var gridX = Math.floor( widthSegments ) || 1;
  7487. var gridY = Math.floor( heightSegments ) || 1;
  7488. var gridX1 = gridX + 1;
  7489. var gridY1 = gridY + 1;
  7490. var segment_width = width / gridX;
  7491. var segment_height = height / gridY;
  7492. var ix, iy;
  7493. // buffers
  7494. var indices = [];
  7495. var vertices = [];
  7496. var normals = [];
  7497. var uvs = [];
  7498. // generate vertices, normals and uvs
  7499. for ( iy = 0; iy < gridY1; iy ++ ) {
  7500. var y = iy * segment_height - height_half;
  7501. for ( ix = 0; ix < gridX1; ix ++ ) {
  7502. var x = ix * segment_width - width_half;
  7503. vertices.push( x, - y, 0 );
  7504. normals.push( 0, 0, 1 );
  7505. uvs.push( ix / gridX );
  7506. uvs.push( 1 - ( iy / gridY ) );
  7507. }
  7508. }
  7509. // indices
  7510. for ( iy = 0; iy < gridY; iy ++ ) {
  7511. for ( ix = 0; ix < gridX; ix ++ ) {
  7512. var a = ix + gridX1 * iy;
  7513. var b = ix + gridX1 * ( iy + 1 );
  7514. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7515. var d = ( ix + 1 ) + gridX1 * iy;
  7516. // faces
  7517. indices.push( a, b, d );
  7518. indices.push( b, c, d );
  7519. }
  7520. }
  7521. // build geometry
  7522. this.setIndex( indices );
  7523. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7524. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7525. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7526. }
  7527. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7528. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7529. /**
  7530. * @author mrdoob / http://mrdoob.com/
  7531. * @author alteredq / http://alteredqualia.com/
  7532. */
  7533. var materialId = 0;
  7534. function Material() {
  7535. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7536. this.uuid = _Math.generateUUID();
  7537. this.name = '';
  7538. this.type = 'Material';
  7539. this.fog = true;
  7540. this.lights = true;
  7541. this.blending = NormalBlending;
  7542. this.side = FrontSide;
  7543. this.flatShading = false;
  7544. this.vertexTangents = false;
  7545. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7546. this.opacity = 1;
  7547. this.transparent = false;
  7548. this.blendSrc = SrcAlphaFactor;
  7549. this.blendDst = OneMinusSrcAlphaFactor;
  7550. this.blendEquation = AddEquation;
  7551. this.blendSrcAlpha = null;
  7552. this.blendDstAlpha = null;
  7553. this.blendEquationAlpha = null;
  7554. this.depthFunc = LessEqualDepth;
  7555. this.depthTest = true;
  7556. this.depthWrite = true;
  7557. this.clippingPlanes = null;
  7558. this.clipIntersection = false;
  7559. this.clipShadows = false;
  7560. this.shadowSide = null;
  7561. this.colorWrite = true;
  7562. this.precision = null; // override the renderer's default precision for this material
  7563. this.polygonOffset = false;
  7564. this.polygonOffsetFactor = 0;
  7565. this.polygonOffsetUnits = 0;
  7566. this.dithering = false;
  7567. this.alphaTest = 0;
  7568. this.premultipliedAlpha = false;
  7569. this.visible = true;
  7570. this.userData = {};
  7571. this.needsUpdate = true;
  7572. }
  7573. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7574. constructor: Material,
  7575. isMaterial: true,
  7576. onBeforeCompile: function () {},
  7577. setValues: function ( values ) {
  7578. if ( values === undefined ) return;
  7579. for ( var key in values ) {
  7580. var newValue = values[ key ];
  7581. if ( newValue === undefined ) {
  7582. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7583. continue;
  7584. }
  7585. // for backward compatability if shading is set in the constructor
  7586. if ( key === 'shading' ) {
  7587. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7588. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7589. continue;
  7590. }
  7591. var currentValue = this[ key ];
  7592. if ( currentValue === undefined ) {
  7593. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7594. continue;
  7595. }
  7596. if ( currentValue && currentValue.isColor ) {
  7597. currentValue.set( newValue );
  7598. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7599. currentValue.copy( newValue );
  7600. } else {
  7601. this[ key ] = newValue;
  7602. }
  7603. }
  7604. },
  7605. toJSON: function ( meta ) {
  7606. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7607. if ( isRoot ) {
  7608. meta = {
  7609. textures: {},
  7610. images: {}
  7611. };
  7612. }
  7613. var data = {
  7614. metadata: {
  7615. version: 4.5,
  7616. type: 'Material',
  7617. generator: 'Material.toJSON'
  7618. }
  7619. };
  7620. // standard Material serialization
  7621. data.uuid = this.uuid;
  7622. data.type = this.type;
  7623. if ( this.name !== '' ) data.name = this.name;
  7624. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7625. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7626. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7627. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7628. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7629. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7630. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7631. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7632. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7633. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7634. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  7635. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7636. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7637. if ( this.aoMap && this.aoMap.isTexture ) {
  7638. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7639. data.aoMapIntensity = this.aoMapIntensity;
  7640. }
  7641. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7642. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7643. data.bumpScale = this.bumpScale;
  7644. }
  7645. if ( this.normalMap && this.normalMap.isTexture ) {
  7646. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7647. data.normalMapType = this.normalMapType;
  7648. data.normalScale = this.normalScale.toArray();
  7649. }
  7650. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7651. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7652. data.displacementScale = this.displacementScale;
  7653. data.displacementBias = this.displacementBias;
  7654. }
  7655. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7656. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7657. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7658. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7659. if ( this.envMap && this.envMap.isTexture ) {
  7660. data.envMap = this.envMap.toJSON( meta ).uuid;
  7661. data.reflectivity = this.reflectivity; // Scale behind envMap
  7662. if ( this.combine !== undefined ) data.combine = this.combine;
  7663. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  7664. }
  7665. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7666. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7667. }
  7668. if ( this.size !== undefined ) data.size = this.size;
  7669. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7670. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7671. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7672. if ( this.side !== FrontSide ) data.side = this.side;
  7673. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7674. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7675. if ( this.transparent === true ) data.transparent = this.transparent;
  7676. data.depthFunc = this.depthFunc;
  7677. data.depthTest = this.depthTest;
  7678. data.depthWrite = this.depthWrite;
  7679. // rotation (SpriteMaterial)
  7680. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7681. if ( this.polygonOffset === true ) data.polygonOffset = true;
  7682. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  7683. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  7684. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7685. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7686. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7687. if ( this.scale !== undefined ) data.scale = this.scale;
  7688. if ( this.dithering === true ) data.dithering = true;
  7689. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7690. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7691. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7692. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7693. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7694. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7695. if ( this.morphTargets === true ) data.morphTargets = true;
  7696. if ( this.skinning === true ) data.skinning = true;
  7697. if ( this.visible === false ) data.visible = false;
  7698. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7699. // TODO: Copied from Object3D.toJSON
  7700. function extractFromCache( cache ) {
  7701. var values = [];
  7702. for ( var key in cache ) {
  7703. var data = cache[ key ];
  7704. delete data.metadata;
  7705. values.push( data );
  7706. }
  7707. return values;
  7708. }
  7709. if ( isRoot ) {
  7710. var textures = extractFromCache( meta.textures );
  7711. var images = extractFromCache( meta.images );
  7712. if ( textures.length > 0 ) data.textures = textures;
  7713. if ( images.length > 0 ) data.images = images;
  7714. }
  7715. return data;
  7716. },
  7717. clone: function () {
  7718. return new this.constructor().copy( this );
  7719. },
  7720. copy: function ( source ) {
  7721. this.name = source.name;
  7722. this.fog = source.fog;
  7723. this.lights = source.lights;
  7724. this.blending = source.blending;
  7725. this.side = source.side;
  7726. this.flatShading = source.flatShading;
  7727. this.vertexColors = source.vertexColors;
  7728. this.opacity = source.opacity;
  7729. this.transparent = source.transparent;
  7730. this.blendSrc = source.blendSrc;
  7731. this.blendDst = source.blendDst;
  7732. this.blendEquation = source.blendEquation;
  7733. this.blendSrcAlpha = source.blendSrcAlpha;
  7734. this.blendDstAlpha = source.blendDstAlpha;
  7735. this.blendEquationAlpha = source.blendEquationAlpha;
  7736. this.depthFunc = source.depthFunc;
  7737. this.depthTest = source.depthTest;
  7738. this.depthWrite = source.depthWrite;
  7739. this.colorWrite = source.colorWrite;
  7740. this.precision = source.precision;
  7741. this.polygonOffset = source.polygonOffset;
  7742. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7743. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7744. this.dithering = source.dithering;
  7745. this.alphaTest = source.alphaTest;
  7746. this.premultipliedAlpha = source.premultipliedAlpha;
  7747. this.visible = source.visible;
  7748. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7749. this.clipShadows = source.clipShadows;
  7750. this.clipIntersection = source.clipIntersection;
  7751. var srcPlanes = source.clippingPlanes,
  7752. dstPlanes = null;
  7753. if ( srcPlanes !== null ) {
  7754. var n = srcPlanes.length;
  7755. dstPlanes = new Array( n );
  7756. for ( var i = 0; i !== n; ++ i )
  7757. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7758. }
  7759. this.clippingPlanes = dstPlanes;
  7760. this.shadowSide = source.shadowSide;
  7761. return this;
  7762. },
  7763. dispose: function () {
  7764. this.dispatchEvent( { type: 'dispose' } );
  7765. }
  7766. } );
  7767. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7768. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7769. /**
  7770. * @author alteredq / http://alteredqualia.com/
  7771. *
  7772. * parameters = {
  7773. * defines: { "label" : "value" },
  7774. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7775. *
  7776. * fragmentShader: <string>,
  7777. * vertexShader: <string>,
  7778. *
  7779. * wireframe: <boolean>,
  7780. * wireframeLinewidth: <float>,
  7781. *
  7782. * lights: <bool>,
  7783. *
  7784. * skinning: <bool>,
  7785. * morphTargets: <bool>,
  7786. * morphNormals: <bool>
  7787. * }
  7788. */
  7789. function ShaderMaterial( parameters ) {
  7790. Material.call( this );
  7791. this.type = 'ShaderMaterial';
  7792. this.defines = {};
  7793. this.uniforms = {};
  7794. this.vertexShader = default_vertex;
  7795. this.fragmentShader = default_fragment;
  7796. this.linewidth = 1;
  7797. this.wireframe = false;
  7798. this.wireframeLinewidth = 1;
  7799. this.fog = false; // set to use scene fog
  7800. this.lights = false; // set to use scene lights
  7801. this.clipping = false; // set to use user-defined clipping planes
  7802. this.skinning = false; // set to use skinning attribute streams
  7803. this.morphTargets = false; // set to use morph targets
  7804. this.morphNormals = false; // set to use morph normals
  7805. this.extensions = {
  7806. derivatives: false, // set to use derivatives
  7807. fragDepth: false, // set to use fragment depth values
  7808. drawBuffers: false, // set to use draw buffers
  7809. shaderTextureLOD: false // set to use shader texture LOD
  7810. };
  7811. // When rendered geometry doesn't include these attributes but the material does,
  7812. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7813. this.defaultAttributeValues = {
  7814. 'color': [ 1, 1, 1 ],
  7815. 'uv': [ 0, 0 ],
  7816. 'uv2': [ 0, 0 ]
  7817. };
  7818. this.index0AttributeName = undefined;
  7819. this.uniformsNeedUpdate = false;
  7820. if ( parameters !== undefined ) {
  7821. if ( parameters.attributes !== undefined ) {
  7822. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7823. }
  7824. this.setValues( parameters );
  7825. }
  7826. }
  7827. ShaderMaterial.prototype = Object.create( Material.prototype );
  7828. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7829. ShaderMaterial.prototype.isShaderMaterial = true;
  7830. ShaderMaterial.prototype.copy = function ( source ) {
  7831. Material.prototype.copy.call( this, source );
  7832. this.fragmentShader = source.fragmentShader;
  7833. this.vertexShader = source.vertexShader;
  7834. this.uniforms = cloneUniforms( source.uniforms );
  7835. this.defines = Object.assign( {}, source.defines );
  7836. this.wireframe = source.wireframe;
  7837. this.wireframeLinewidth = source.wireframeLinewidth;
  7838. this.lights = source.lights;
  7839. this.clipping = source.clipping;
  7840. this.skinning = source.skinning;
  7841. this.morphTargets = source.morphTargets;
  7842. this.morphNormals = source.morphNormals;
  7843. this.extensions = source.extensions;
  7844. return this;
  7845. };
  7846. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7847. var data = Material.prototype.toJSON.call( this, meta );
  7848. data.uniforms = {};
  7849. for ( var name in this.uniforms ) {
  7850. var uniform = this.uniforms[ name ];
  7851. var value = uniform.value;
  7852. if ( value && value.isTexture ) {
  7853. data.uniforms[ name ] = {
  7854. type: 't',
  7855. value: value.toJSON( meta ).uuid
  7856. };
  7857. } else if ( value && value.isColor ) {
  7858. data.uniforms[ name ] = {
  7859. type: 'c',
  7860. value: value.getHex()
  7861. };
  7862. } else if ( value && value.isVector2 ) {
  7863. data.uniforms[ name ] = {
  7864. type: 'v2',
  7865. value: value.toArray()
  7866. };
  7867. } else if ( value && value.isVector3 ) {
  7868. data.uniforms[ name ] = {
  7869. type: 'v3',
  7870. value: value.toArray()
  7871. };
  7872. } else if ( value && value.isVector4 ) {
  7873. data.uniforms[ name ] = {
  7874. type: 'v4',
  7875. value: value.toArray()
  7876. };
  7877. } else if ( value && value.isMatrix3 ) {
  7878. data.uniforms[ name ] = {
  7879. type: 'm3',
  7880. value: value.toArray()
  7881. };
  7882. } else if ( value && value.isMatrix4 ) {
  7883. data.uniforms[ name ] = {
  7884. type: 'm4',
  7885. value: value.toArray()
  7886. };
  7887. } else {
  7888. data.uniforms[ name ] = {
  7889. value: value
  7890. };
  7891. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7892. }
  7893. }
  7894. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7895. data.vertexShader = this.vertexShader;
  7896. data.fragmentShader = this.fragmentShader;
  7897. var extensions = {};
  7898. for ( var key in this.extensions ) {
  7899. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7900. }
  7901. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7902. return data;
  7903. };
  7904. /**
  7905. * @author bhouston / http://clara.io
  7906. */
  7907. function Ray( origin, direction ) {
  7908. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7909. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7910. }
  7911. Object.assign( Ray.prototype, {
  7912. set: function ( origin, direction ) {
  7913. this.origin.copy( origin );
  7914. this.direction.copy( direction );
  7915. return this;
  7916. },
  7917. clone: function () {
  7918. return new this.constructor().copy( this );
  7919. },
  7920. copy: function ( ray ) {
  7921. this.origin.copy( ray.origin );
  7922. this.direction.copy( ray.direction );
  7923. return this;
  7924. },
  7925. at: function ( t, target ) {
  7926. if ( target === undefined ) {
  7927. console.warn( 'THREE.Ray: .at() target is now required' );
  7928. target = new Vector3();
  7929. }
  7930. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7931. },
  7932. lookAt: function ( v ) {
  7933. this.direction.copy( v ).sub( this.origin ).normalize();
  7934. return this;
  7935. },
  7936. recast: function () {
  7937. var v1 = new Vector3();
  7938. return function recast( t ) {
  7939. this.origin.copy( this.at( t, v1 ) );
  7940. return this;
  7941. };
  7942. }(),
  7943. closestPointToPoint: function ( point, target ) {
  7944. if ( target === undefined ) {
  7945. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7946. target = new Vector3();
  7947. }
  7948. target.subVectors( point, this.origin );
  7949. var directionDistance = target.dot( this.direction );
  7950. if ( directionDistance < 0 ) {
  7951. return target.copy( this.origin );
  7952. }
  7953. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7954. },
  7955. distanceToPoint: function ( point ) {
  7956. return Math.sqrt( this.distanceSqToPoint( point ) );
  7957. },
  7958. distanceSqToPoint: function () {
  7959. var v1 = new Vector3();
  7960. return function distanceSqToPoint( point ) {
  7961. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7962. // point behind the ray
  7963. if ( directionDistance < 0 ) {
  7964. return this.origin.distanceToSquared( point );
  7965. }
  7966. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7967. return v1.distanceToSquared( point );
  7968. };
  7969. }(),
  7970. distanceSqToSegment: function () {
  7971. var segCenter = new Vector3();
  7972. var segDir = new Vector3();
  7973. var diff = new Vector3();
  7974. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7975. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7976. // It returns the min distance between the ray and the segment
  7977. // defined by v0 and v1
  7978. // It can also set two optional targets :
  7979. // - The closest point on the ray
  7980. // - The closest point on the segment
  7981. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7982. segDir.copy( v1 ).sub( v0 ).normalize();
  7983. diff.copy( this.origin ).sub( segCenter );
  7984. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7985. var a01 = - this.direction.dot( segDir );
  7986. var b0 = diff.dot( this.direction );
  7987. var b1 = - diff.dot( segDir );
  7988. var c = diff.lengthSq();
  7989. var det = Math.abs( 1 - a01 * a01 );
  7990. var s0, s1, sqrDist, extDet;
  7991. if ( det > 0 ) {
  7992. // The ray and segment are not parallel.
  7993. s0 = a01 * b1 - b0;
  7994. s1 = a01 * b0 - b1;
  7995. extDet = segExtent * det;
  7996. if ( s0 >= 0 ) {
  7997. if ( s1 >= - extDet ) {
  7998. if ( s1 <= extDet ) {
  7999. // region 0
  8000. // Minimum at interior points of ray and segment.
  8001. var invDet = 1 / det;
  8002. s0 *= invDet;
  8003. s1 *= invDet;
  8004. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  8005. } else {
  8006. // region 1
  8007. s1 = segExtent;
  8008. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8009. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8010. }
  8011. } else {
  8012. // region 5
  8013. s1 = - segExtent;
  8014. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8015. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8016. }
  8017. } else {
  8018. if ( s1 <= - extDet ) {
  8019. // region 4
  8020. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  8021. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8022. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8023. } else if ( s1 <= extDet ) {
  8024. // region 3
  8025. s0 = 0;
  8026. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8027. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  8028. } else {
  8029. // region 2
  8030. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  8031. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8032. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8033. }
  8034. }
  8035. } else {
  8036. // Ray and segment are parallel.
  8037. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  8038. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8039. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8040. }
  8041. if ( optionalPointOnRay ) {
  8042. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  8043. }
  8044. if ( optionalPointOnSegment ) {
  8045. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  8046. }
  8047. return sqrDist;
  8048. };
  8049. }(),
  8050. intersectSphere: function () {
  8051. var v1 = new Vector3();
  8052. return function intersectSphere( sphere, target ) {
  8053. v1.subVectors( sphere.center, this.origin );
  8054. var tca = v1.dot( this.direction );
  8055. var d2 = v1.dot( v1 ) - tca * tca;
  8056. var radius2 = sphere.radius * sphere.radius;
  8057. if ( d2 > radius2 ) return null;
  8058. var thc = Math.sqrt( radius2 - d2 );
  8059. // t0 = first intersect point - entrance on front of sphere
  8060. var t0 = tca - thc;
  8061. // t1 = second intersect point - exit point on back of sphere
  8062. var t1 = tca + thc;
  8063. // test to see if both t0 and t1 are behind the ray - if so, return null
  8064. if ( t0 < 0 && t1 < 0 ) return null;
  8065. // test to see if t0 is behind the ray:
  8066. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  8067. // in order to always return an intersect point that is in front of the ray.
  8068. if ( t0 < 0 ) return this.at( t1, target );
  8069. // else t0 is in front of the ray, so return the first collision point scaled by t0
  8070. return this.at( t0, target );
  8071. };
  8072. }(),
  8073. intersectsSphere: function ( sphere ) {
  8074. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  8075. },
  8076. distanceToPlane: function ( plane ) {
  8077. var denominator = plane.normal.dot( this.direction );
  8078. if ( denominator === 0 ) {
  8079. // line is coplanar, return origin
  8080. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8081. return 0;
  8082. }
  8083. // Null is preferable to undefined since undefined means.... it is undefined
  8084. return null;
  8085. }
  8086. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8087. // Return if the ray never intersects the plane
  8088. return t >= 0 ? t : null;
  8089. },
  8090. intersectPlane: function ( plane, target ) {
  8091. var t = this.distanceToPlane( plane );
  8092. if ( t === null ) {
  8093. return null;
  8094. }
  8095. return this.at( t, target );
  8096. },
  8097. intersectsPlane: function ( plane ) {
  8098. // check if the ray lies on the plane first
  8099. var distToPoint = plane.distanceToPoint( this.origin );
  8100. if ( distToPoint === 0 ) {
  8101. return true;
  8102. }
  8103. var denominator = plane.normal.dot( this.direction );
  8104. if ( denominator * distToPoint < 0 ) {
  8105. return true;
  8106. }
  8107. // ray origin is behind the plane (and is pointing behind it)
  8108. return false;
  8109. },
  8110. intersectBox: function ( box, target ) {
  8111. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8112. var invdirx = 1 / this.direction.x,
  8113. invdiry = 1 / this.direction.y,
  8114. invdirz = 1 / this.direction.z;
  8115. var origin = this.origin;
  8116. if ( invdirx >= 0 ) {
  8117. tmin = ( box.min.x - origin.x ) * invdirx;
  8118. tmax = ( box.max.x - origin.x ) * invdirx;
  8119. } else {
  8120. tmin = ( box.max.x - origin.x ) * invdirx;
  8121. tmax = ( box.min.x - origin.x ) * invdirx;
  8122. }
  8123. if ( invdiry >= 0 ) {
  8124. tymin = ( box.min.y - origin.y ) * invdiry;
  8125. tymax = ( box.max.y - origin.y ) * invdiry;
  8126. } else {
  8127. tymin = ( box.max.y - origin.y ) * invdiry;
  8128. tymax = ( box.min.y - origin.y ) * invdiry;
  8129. }
  8130. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8131. // These lines also handle the case where tmin or tmax is NaN
  8132. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8133. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8134. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8135. if ( invdirz >= 0 ) {
  8136. tzmin = ( box.min.z - origin.z ) * invdirz;
  8137. tzmax = ( box.max.z - origin.z ) * invdirz;
  8138. } else {
  8139. tzmin = ( box.max.z - origin.z ) * invdirz;
  8140. tzmax = ( box.min.z - origin.z ) * invdirz;
  8141. }
  8142. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8143. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8144. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8145. //return point closest to the ray (positive side)
  8146. if ( tmax < 0 ) return null;
  8147. return this.at( tmin >= 0 ? tmin : tmax, target );
  8148. },
  8149. intersectsBox: ( function () {
  8150. var v = new Vector3();
  8151. return function intersectsBox( box ) {
  8152. return this.intersectBox( box, v ) !== null;
  8153. };
  8154. } )(),
  8155. intersectTriangle: function () {
  8156. // Compute the offset origin, edges, and normal.
  8157. var diff = new Vector3();
  8158. var edge1 = new Vector3();
  8159. var edge2 = new Vector3();
  8160. var normal = new Vector3();
  8161. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8162. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8163. edge1.subVectors( b, a );
  8164. edge2.subVectors( c, a );
  8165. normal.crossVectors( edge1, edge2 );
  8166. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8167. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8168. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8169. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8170. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8171. var DdN = this.direction.dot( normal );
  8172. var sign;
  8173. if ( DdN > 0 ) {
  8174. if ( backfaceCulling ) return null;
  8175. sign = 1;
  8176. } else if ( DdN < 0 ) {
  8177. sign = - 1;
  8178. DdN = - DdN;
  8179. } else {
  8180. return null;
  8181. }
  8182. diff.subVectors( this.origin, a );
  8183. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8184. // b1 < 0, no intersection
  8185. if ( DdQxE2 < 0 ) {
  8186. return null;
  8187. }
  8188. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8189. // b2 < 0, no intersection
  8190. if ( DdE1xQ < 0 ) {
  8191. return null;
  8192. }
  8193. // b1+b2 > 1, no intersection
  8194. if ( DdQxE2 + DdE1xQ > DdN ) {
  8195. return null;
  8196. }
  8197. // Line intersects triangle, check if ray does.
  8198. var QdN = - sign * diff.dot( normal );
  8199. // t < 0, no intersection
  8200. if ( QdN < 0 ) {
  8201. return null;
  8202. }
  8203. // Ray intersects triangle.
  8204. return this.at( QdN / DdN, target );
  8205. };
  8206. }(),
  8207. applyMatrix4: function ( matrix4 ) {
  8208. this.origin.applyMatrix4( matrix4 );
  8209. this.direction.transformDirection( matrix4 );
  8210. return this;
  8211. },
  8212. equals: function ( ray ) {
  8213. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8214. }
  8215. } );
  8216. /**
  8217. * @author bhouston / http://clara.io
  8218. * @author mrdoob / http://mrdoob.com/
  8219. */
  8220. function Triangle( a, b, c ) {
  8221. this.a = ( a !== undefined ) ? a : new Vector3();
  8222. this.b = ( b !== undefined ) ? b : new Vector3();
  8223. this.c = ( c !== undefined ) ? c : new Vector3();
  8224. }
  8225. Object.assign( Triangle, {
  8226. getNormal: function () {
  8227. var v0 = new Vector3();
  8228. return function getNormal( a, b, c, target ) {
  8229. if ( target === undefined ) {
  8230. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8231. target = new Vector3();
  8232. }
  8233. target.subVectors( c, b );
  8234. v0.subVectors( a, b );
  8235. target.cross( v0 );
  8236. var targetLengthSq = target.lengthSq();
  8237. if ( targetLengthSq > 0 ) {
  8238. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8239. }
  8240. return target.set( 0, 0, 0 );
  8241. };
  8242. }(),
  8243. // static/instance method to calculate barycentric coordinates
  8244. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8245. getBarycoord: function () {
  8246. var v0 = new Vector3();
  8247. var v1 = new Vector3();
  8248. var v2 = new Vector3();
  8249. return function getBarycoord( point, a, b, c, target ) {
  8250. v0.subVectors( c, a );
  8251. v1.subVectors( b, a );
  8252. v2.subVectors( point, a );
  8253. var dot00 = v0.dot( v0 );
  8254. var dot01 = v0.dot( v1 );
  8255. var dot02 = v0.dot( v2 );
  8256. var dot11 = v1.dot( v1 );
  8257. var dot12 = v1.dot( v2 );
  8258. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8259. if ( target === undefined ) {
  8260. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8261. target = new Vector3();
  8262. }
  8263. // collinear or singular triangle
  8264. if ( denom === 0 ) {
  8265. // arbitrary location outside of triangle?
  8266. // not sure if this is the best idea, maybe should be returning undefined
  8267. return target.set( - 2, - 1, - 1 );
  8268. }
  8269. var invDenom = 1 / denom;
  8270. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8271. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8272. // barycentric coordinates must always sum to 1
  8273. return target.set( 1 - u - v, v, u );
  8274. };
  8275. }(),
  8276. containsPoint: function () {
  8277. var v1 = new Vector3();
  8278. return function containsPoint( point, a, b, c ) {
  8279. Triangle.getBarycoord( point, a, b, c, v1 );
  8280. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8281. };
  8282. }(),
  8283. getUV: function () {
  8284. var barycoord = new Vector3();
  8285. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  8286. this.getBarycoord( point, p1, p2, p3, barycoord );
  8287. target.set( 0, 0 );
  8288. target.addScaledVector( uv1, barycoord.x );
  8289. target.addScaledVector( uv2, barycoord.y );
  8290. target.addScaledVector( uv3, barycoord.z );
  8291. return target;
  8292. };
  8293. }()
  8294. } );
  8295. Object.assign( Triangle.prototype, {
  8296. set: function ( a, b, c ) {
  8297. this.a.copy( a );
  8298. this.b.copy( b );
  8299. this.c.copy( c );
  8300. return this;
  8301. },
  8302. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8303. this.a.copy( points[ i0 ] );
  8304. this.b.copy( points[ i1 ] );
  8305. this.c.copy( points[ i2 ] );
  8306. return this;
  8307. },
  8308. clone: function () {
  8309. return new this.constructor().copy( this );
  8310. },
  8311. copy: function ( triangle ) {
  8312. this.a.copy( triangle.a );
  8313. this.b.copy( triangle.b );
  8314. this.c.copy( triangle.c );
  8315. return this;
  8316. },
  8317. getArea: function () {
  8318. var v0 = new Vector3();
  8319. var v1 = new Vector3();
  8320. return function getArea() {
  8321. v0.subVectors( this.c, this.b );
  8322. v1.subVectors( this.a, this.b );
  8323. return v0.cross( v1 ).length() * 0.5;
  8324. };
  8325. }(),
  8326. getMidpoint: function ( target ) {
  8327. if ( target === undefined ) {
  8328. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8329. target = new Vector3();
  8330. }
  8331. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8332. },
  8333. getNormal: function ( target ) {
  8334. return Triangle.getNormal( this.a, this.b, this.c, target );
  8335. },
  8336. getPlane: function ( target ) {
  8337. if ( target === undefined ) {
  8338. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8339. target = new Vector3();
  8340. }
  8341. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8342. },
  8343. getBarycoord: function ( point, target ) {
  8344. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8345. },
  8346. containsPoint: function ( point ) {
  8347. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8348. },
  8349. getUV: function ( point, uv1, uv2, uv3, result ) {
  8350. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
  8351. },
  8352. intersectsBox: function ( box ) {
  8353. return box.intersectsTriangle( this );
  8354. },
  8355. closestPointToPoint: function () {
  8356. var vab = new Vector3();
  8357. var vac = new Vector3();
  8358. var vbc = new Vector3();
  8359. var vap = new Vector3();
  8360. var vbp = new Vector3();
  8361. var vcp = new Vector3();
  8362. return function closestPointToPoint( p, target ) {
  8363. if ( target === undefined ) {
  8364. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8365. target = new Vector3();
  8366. }
  8367. var a = this.a, b = this.b, c = this.c;
  8368. var v, w;
  8369. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  8370. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  8371. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  8372. // basically, we're distinguishing which of the voronoi regions of the triangle
  8373. // the point lies in with the minimum amount of redundant computation.
  8374. vab.subVectors( b, a );
  8375. vac.subVectors( c, a );
  8376. vap.subVectors( p, a );
  8377. var d1 = vab.dot( vap );
  8378. var d2 = vac.dot( vap );
  8379. if ( d1 <= 0 && d2 <= 0 ) {
  8380. // vertex region of A; barycentric coords (1, 0, 0)
  8381. return target.copy( a );
  8382. }
  8383. vbp.subVectors( p, b );
  8384. var d3 = vab.dot( vbp );
  8385. var d4 = vac.dot( vbp );
  8386. if ( d3 >= 0 && d4 <= d3 ) {
  8387. // vertex region of B; barycentric coords (0, 1, 0)
  8388. return target.copy( b );
  8389. }
  8390. var vc = d1 * d4 - d3 * d2;
  8391. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  8392. v = d1 / ( d1 - d3 );
  8393. // edge region of AB; barycentric coords (1-v, v, 0)
  8394. return target.copy( a ).addScaledVector( vab, v );
  8395. }
  8396. vcp.subVectors( p, c );
  8397. var d5 = vab.dot( vcp );
  8398. var d6 = vac.dot( vcp );
  8399. if ( d6 >= 0 && d5 <= d6 ) {
  8400. // vertex region of C; barycentric coords (0, 0, 1)
  8401. return target.copy( c );
  8402. }
  8403. var vb = d5 * d2 - d1 * d6;
  8404. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  8405. w = d2 / ( d2 - d6 );
  8406. // edge region of AC; barycentric coords (1-w, 0, w)
  8407. return target.copy( a ).addScaledVector( vac, w );
  8408. }
  8409. var va = d3 * d6 - d5 * d4;
  8410. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  8411. vbc.subVectors( c, b );
  8412. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  8413. // edge region of BC; barycentric coords (0, 1-w, w)
  8414. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  8415. }
  8416. // face region
  8417. var denom = 1 / ( va + vb + vc );
  8418. // u = va * denom
  8419. v = vb * denom;
  8420. w = vc * denom;
  8421. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  8422. };
  8423. }(),
  8424. equals: function ( triangle ) {
  8425. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8426. }
  8427. } );
  8428. /**
  8429. * @author mrdoob / http://mrdoob.com/
  8430. * @author alteredq / http://alteredqualia.com/
  8431. *
  8432. * parameters = {
  8433. * color: <hex>,
  8434. * opacity: <float>,
  8435. * map: new THREE.Texture( <Image> ),
  8436. *
  8437. * lightMap: new THREE.Texture( <Image> ),
  8438. * lightMapIntensity: <float>
  8439. *
  8440. * aoMap: new THREE.Texture( <Image> ),
  8441. * aoMapIntensity: <float>
  8442. *
  8443. * specularMap: new THREE.Texture( <Image> ),
  8444. *
  8445. * alphaMap: new THREE.Texture( <Image> ),
  8446. *
  8447. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  8448. * combine: THREE.Multiply,
  8449. * reflectivity: <float>,
  8450. * refractionRatio: <float>,
  8451. *
  8452. * depthTest: <bool>,
  8453. * depthWrite: <bool>,
  8454. *
  8455. * wireframe: <boolean>,
  8456. * wireframeLinewidth: <float>,
  8457. *
  8458. * skinning: <bool>,
  8459. * morphTargets: <bool>
  8460. * }
  8461. */
  8462. function MeshBasicMaterial( parameters ) {
  8463. Material.call( this );
  8464. this.type = 'MeshBasicMaterial';
  8465. this.color = new Color( 0xffffff ); // emissive
  8466. this.map = null;
  8467. this.lightMap = null;
  8468. this.lightMapIntensity = 1.0;
  8469. this.aoMap = null;
  8470. this.aoMapIntensity = 1.0;
  8471. this.specularMap = null;
  8472. this.alphaMap = null;
  8473. this.envMap = null;
  8474. this.combine = MultiplyOperation;
  8475. this.reflectivity = 1;
  8476. this.refractionRatio = 0.98;
  8477. this.wireframe = false;
  8478. this.wireframeLinewidth = 1;
  8479. this.wireframeLinecap = 'round';
  8480. this.wireframeLinejoin = 'round';
  8481. this.skinning = false;
  8482. this.morphTargets = false;
  8483. this.lights = false;
  8484. this.setValues( parameters );
  8485. }
  8486. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8487. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8488. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8489. MeshBasicMaterial.prototype.copy = function ( source ) {
  8490. Material.prototype.copy.call( this, source );
  8491. this.color.copy( source.color );
  8492. this.map = source.map;
  8493. this.lightMap = source.lightMap;
  8494. this.lightMapIntensity = source.lightMapIntensity;
  8495. this.aoMap = source.aoMap;
  8496. this.aoMapIntensity = source.aoMapIntensity;
  8497. this.specularMap = source.specularMap;
  8498. this.alphaMap = source.alphaMap;
  8499. this.envMap = source.envMap;
  8500. this.combine = source.combine;
  8501. this.reflectivity = source.reflectivity;
  8502. this.refractionRatio = source.refractionRatio;
  8503. this.wireframe = source.wireframe;
  8504. this.wireframeLinewidth = source.wireframeLinewidth;
  8505. this.wireframeLinecap = source.wireframeLinecap;
  8506. this.wireframeLinejoin = source.wireframeLinejoin;
  8507. this.skinning = source.skinning;
  8508. this.morphTargets = source.morphTargets;
  8509. return this;
  8510. };
  8511. /**
  8512. * @author mrdoob / http://mrdoob.com/
  8513. * @author alteredq / http://alteredqualia.com/
  8514. * @author mikael emtinger / http://gomo.se/
  8515. * @author jonobr1 / http://jonobr1.com/
  8516. */
  8517. function Mesh( geometry, material ) {
  8518. Object3D.call( this );
  8519. this.type = 'Mesh';
  8520. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8521. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8522. this.drawMode = TrianglesDrawMode;
  8523. this.updateMorphTargets();
  8524. }
  8525. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8526. constructor: Mesh,
  8527. isMesh: true,
  8528. setDrawMode: function ( value ) {
  8529. this.drawMode = value;
  8530. },
  8531. copy: function ( source ) {
  8532. Object3D.prototype.copy.call( this, source );
  8533. this.drawMode = source.drawMode;
  8534. if ( source.morphTargetInfluences !== undefined ) {
  8535. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8536. }
  8537. if ( source.morphTargetDictionary !== undefined ) {
  8538. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8539. }
  8540. return this;
  8541. },
  8542. updateMorphTargets: function () {
  8543. var geometry = this.geometry;
  8544. var m, ml, name;
  8545. if ( geometry.isBufferGeometry ) {
  8546. var morphAttributes = geometry.morphAttributes;
  8547. var keys = Object.keys( morphAttributes );
  8548. if ( keys.length > 0 ) {
  8549. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8550. if ( morphAttribute !== undefined ) {
  8551. this.morphTargetInfluences = [];
  8552. this.morphTargetDictionary = {};
  8553. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8554. name = morphAttribute[ m ].name || String( m );
  8555. this.morphTargetInfluences.push( 0 );
  8556. this.morphTargetDictionary[ name ] = m;
  8557. }
  8558. }
  8559. }
  8560. } else {
  8561. var morphTargets = geometry.morphTargets;
  8562. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8563. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  8564. }
  8565. }
  8566. },
  8567. raycast: ( function () {
  8568. var inverseMatrix = new Matrix4();
  8569. var ray = new Ray();
  8570. var sphere = new Sphere();
  8571. var vA = new Vector3();
  8572. var vB = new Vector3();
  8573. var vC = new Vector3();
  8574. var tempA = new Vector3();
  8575. var tempB = new Vector3();
  8576. var tempC = new Vector3();
  8577. var morphA = new Vector3();
  8578. var morphB = new Vector3();
  8579. var morphC = new Vector3();
  8580. var uvA = new Vector2();
  8581. var uvB = new Vector2();
  8582. var uvC = new Vector2();
  8583. var intersectionPoint = new Vector3();
  8584. var intersectionPointWorld = new Vector3();
  8585. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8586. var intersect;
  8587. if ( material.side === BackSide ) {
  8588. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8589. } else {
  8590. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8591. }
  8592. if ( intersect === null ) return null;
  8593. intersectionPointWorld.copy( point );
  8594. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8595. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8596. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8597. return {
  8598. distance: distance,
  8599. point: intersectionPointWorld.clone(),
  8600. object: object
  8601. };
  8602. }
  8603. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, a, b, c ) {
  8604. vA.fromBufferAttribute( position, a );
  8605. vB.fromBufferAttribute( position, b );
  8606. vC.fromBufferAttribute( position, c );
  8607. var morphInfluences = object.morphTargetInfluences;
  8608. if ( material.morphTargets && morphPosition && morphInfluences ) {
  8609. morphA.set( 0, 0, 0 );
  8610. morphB.set( 0, 0, 0 );
  8611. morphC.set( 0, 0, 0 );
  8612. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  8613. var influence = morphInfluences[ i ];
  8614. var morphAttribute = morphPosition[ i ];
  8615. if ( influence === 0 ) continue;
  8616. tempA.fromBufferAttribute( morphAttribute, a );
  8617. tempB.fromBufferAttribute( morphAttribute, b );
  8618. tempC.fromBufferAttribute( morphAttribute, c );
  8619. morphA.addScaledVector( tempA.sub( vA ), influence );
  8620. morphB.addScaledVector( tempB.sub( vB ), influence );
  8621. morphC.addScaledVector( tempC.sub( vC ), influence );
  8622. }
  8623. vA.add( morphA );
  8624. vB.add( morphB );
  8625. vC.add( morphC );
  8626. }
  8627. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8628. if ( intersection ) {
  8629. if ( uv ) {
  8630. uvA.fromBufferAttribute( uv, a );
  8631. uvB.fromBufferAttribute( uv, b );
  8632. uvC.fromBufferAttribute( uv, c );
  8633. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  8634. }
  8635. var face = new Face3( a, b, c );
  8636. Triangle.getNormal( vA, vB, vC, face.normal );
  8637. intersection.face = face;
  8638. }
  8639. return intersection;
  8640. }
  8641. return function raycast( raycaster, intersects ) {
  8642. var geometry = this.geometry;
  8643. var material = this.material;
  8644. var matrixWorld = this.matrixWorld;
  8645. if ( material === undefined ) return;
  8646. // Checking boundingSphere distance to ray
  8647. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8648. sphere.copy( geometry.boundingSphere );
  8649. sphere.applyMatrix4( matrixWorld );
  8650. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8651. //
  8652. inverseMatrix.getInverse( matrixWorld );
  8653. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8654. // Check boundingBox before continuing
  8655. if ( geometry.boundingBox !== null ) {
  8656. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8657. }
  8658. var intersection;
  8659. if ( geometry.isBufferGeometry ) {
  8660. var a, b, c;
  8661. var index = geometry.index;
  8662. var position = geometry.attributes.position;
  8663. var morphPosition = geometry.morphAttributes.position;
  8664. var uv = geometry.attributes.uv;
  8665. var groups = geometry.groups;
  8666. var drawRange = geometry.drawRange;
  8667. var i, j, il, jl;
  8668. var group, groupMaterial;
  8669. var start, end;
  8670. if ( index !== null ) {
  8671. // indexed buffer geometry
  8672. if ( Array.isArray( material ) ) {
  8673. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8674. group = groups[ i ];
  8675. groupMaterial = material[ group.materialIndex ];
  8676. start = Math.max( group.start, drawRange.start );
  8677. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8678. for ( j = start, jl = end; j < jl; j += 3 ) {
  8679. a = index.getX( j );
  8680. b = index.getX( j + 1 );
  8681. c = index.getX( j + 2 );
  8682. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  8683. if ( intersection ) {
  8684. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  8685. intersection.face.materialIndex = group.materialIndex;
  8686. intersects.push( intersection );
  8687. }
  8688. }
  8689. }
  8690. } else {
  8691. start = Math.max( 0, drawRange.start );
  8692. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  8693. for ( i = start, il = end; i < il; i += 3 ) {
  8694. a = index.getX( i );
  8695. b = index.getX( i + 1 );
  8696. c = index.getX( i + 2 );
  8697. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  8698. if ( intersection ) {
  8699. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8700. intersects.push( intersection );
  8701. }
  8702. }
  8703. }
  8704. } else if ( position !== undefined ) {
  8705. // non-indexed buffer geometry
  8706. if ( Array.isArray( material ) ) {
  8707. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8708. group = groups[ i ];
  8709. groupMaterial = material[ group.materialIndex ];
  8710. start = Math.max( group.start, drawRange.start );
  8711. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8712. for ( j = start, jl = end; j < jl; j += 3 ) {
  8713. a = j;
  8714. b = j + 1;
  8715. c = j + 2;
  8716. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  8717. if ( intersection ) {
  8718. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  8719. intersection.face.materialIndex = group.materialIndex;
  8720. intersects.push( intersection );
  8721. }
  8722. }
  8723. }
  8724. } else {
  8725. start = Math.max( 0, drawRange.start );
  8726. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  8727. for ( i = start, il = end; i < il; i += 3 ) {
  8728. a = i;
  8729. b = i + 1;
  8730. c = i + 2;
  8731. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  8732. if ( intersection ) {
  8733. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8734. intersects.push( intersection );
  8735. }
  8736. }
  8737. }
  8738. }
  8739. } else if ( geometry.isGeometry ) {
  8740. var fvA, fvB, fvC;
  8741. var isMultiMaterial = Array.isArray( material );
  8742. var vertices = geometry.vertices;
  8743. var faces = geometry.faces;
  8744. var uvs;
  8745. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8746. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8747. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8748. var face = faces[ f ];
  8749. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8750. if ( faceMaterial === undefined ) continue;
  8751. fvA = vertices[ face.a ];
  8752. fvB = vertices[ face.b ];
  8753. fvC = vertices[ face.c ];
  8754. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8755. if ( intersection ) {
  8756. if ( uvs && uvs[ f ] ) {
  8757. var uvs_f = uvs[ f ];
  8758. uvA.copy( uvs_f[ 0 ] );
  8759. uvB.copy( uvs_f[ 1 ] );
  8760. uvC.copy( uvs_f[ 2 ] );
  8761. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  8762. }
  8763. intersection.face = face;
  8764. intersection.faceIndex = f;
  8765. intersects.push( intersection );
  8766. }
  8767. }
  8768. }
  8769. };
  8770. }() ),
  8771. clone: function () {
  8772. return new this.constructor( this.geometry, this.material ).copy( this );
  8773. }
  8774. } );
  8775. /**
  8776. * @author mrdoob / http://mrdoob.com/
  8777. */
  8778. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8779. var clearColor = new Color( 0x000000 );
  8780. var clearAlpha = 0;
  8781. var planeMesh;
  8782. var boxMesh;
  8783. // Store the current background texture and its `version`
  8784. // so we can recompile the material accordingly.
  8785. var currentBackground = null;
  8786. var currentBackgroundVersion = 0;
  8787. function render( renderList, scene, camera, forceClear ) {
  8788. var background = scene.background;
  8789. // Ignore background in AR
  8790. // TODO: Reconsider this.
  8791. var vr = renderer.vr;
  8792. var session = vr.getSession && vr.getSession();
  8793. if ( session && session.environmentBlendMode === 'additive' ) {
  8794. background = null;
  8795. }
  8796. if ( background === null ) {
  8797. setClear( clearColor, clearAlpha );
  8798. currentBackground = null;
  8799. currentBackgroundVersion = 0;
  8800. } else if ( background && background.isColor ) {
  8801. setClear( background, 1 );
  8802. forceClear = true;
  8803. currentBackground = null;
  8804. currentBackgroundVersion = 0;
  8805. }
  8806. if ( renderer.autoClear || forceClear ) {
  8807. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8808. }
  8809. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  8810. if ( boxMesh === undefined ) {
  8811. boxMesh = new Mesh(
  8812. new BoxBufferGeometry( 1, 1, 1 ),
  8813. new ShaderMaterial( {
  8814. type: 'BackgroundCubeMaterial',
  8815. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8816. vertexShader: ShaderLib.cube.vertexShader,
  8817. fragmentShader: ShaderLib.cube.fragmentShader,
  8818. side: BackSide,
  8819. depthTest: false,
  8820. depthWrite: false,
  8821. fog: false
  8822. } )
  8823. );
  8824. boxMesh.geometry.removeAttribute( 'normal' );
  8825. boxMesh.geometry.removeAttribute( 'uv' );
  8826. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8827. this.matrixWorld.copyPosition( camera.matrixWorld );
  8828. };
  8829. // enable code injection for non-built-in material
  8830. Object.defineProperty( boxMesh.material, 'map', {
  8831. get: function () {
  8832. return this.uniforms.tCube.value;
  8833. }
  8834. } );
  8835. objects.update( boxMesh );
  8836. }
  8837. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  8838. boxMesh.material.uniforms.tCube.value = texture;
  8839. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  8840. if ( currentBackground !== background ||
  8841. currentBackgroundVersion !== texture.version ) {
  8842. boxMesh.material.needsUpdate = true;
  8843. currentBackground = background;
  8844. currentBackgroundVersion = texture.version;
  8845. }
  8846. // push to the pre-sorted opaque render list
  8847. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8848. } else if ( background && background.isTexture ) {
  8849. if ( planeMesh === undefined ) {
  8850. planeMesh = new Mesh(
  8851. new PlaneBufferGeometry( 2, 2 ),
  8852. new ShaderMaterial( {
  8853. type: 'BackgroundMaterial',
  8854. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8855. vertexShader: ShaderLib.background.vertexShader,
  8856. fragmentShader: ShaderLib.background.fragmentShader,
  8857. side: FrontSide,
  8858. depthTest: false,
  8859. depthWrite: false,
  8860. fog: false
  8861. } )
  8862. );
  8863. planeMesh.geometry.removeAttribute( 'normal' );
  8864. // enable code injection for non-built-in material
  8865. Object.defineProperty( planeMesh.material, 'map', {
  8866. get: function () {
  8867. return this.uniforms.t2D.value;
  8868. }
  8869. } );
  8870. objects.update( planeMesh );
  8871. }
  8872. planeMesh.material.uniforms.t2D.value = background;
  8873. if ( background.matrixAutoUpdate === true ) {
  8874. background.updateMatrix();
  8875. }
  8876. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8877. if ( currentBackground !== background ||
  8878. currentBackgroundVersion !== background.version ) {
  8879. planeMesh.material.needsUpdate = true;
  8880. currentBackground = background;
  8881. currentBackgroundVersion = background.version;
  8882. }
  8883. // push to the pre-sorted opaque render list
  8884. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8885. }
  8886. }
  8887. function setClear( color, alpha ) {
  8888. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8889. }
  8890. return {
  8891. getClearColor: function () {
  8892. return clearColor;
  8893. },
  8894. setClearColor: function ( color, alpha ) {
  8895. clearColor.set( color );
  8896. clearAlpha = alpha !== undefined ? alpha : 1;
  8897. setClear( clearColor, clearAlpha );
  8898. },
  8899. getClearAlpha: function () {
  8900. return clearAlpha;
  8901. },
  8902. setClearAlpha: function ( alpha ) {
  8903. clearAlpha = alpha;
  8904. setClear( clearColor, clearAlpha );
  8905. },
  8906. render: render
  8907. };
  8908. }
  8909. /**
  8910. * @author mrdoob / http://mrdoob.com/
  8911. */
  8912. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8913. var mode;
  8914. function setMode( value ) {
  8915. mode = value;
  8916. }
  8917. function render( start, count ) {
  8918. gl.drawArrays( mode, start, count );
  8919. info.update( count, mode );
  8920. }
  8921. function renderInstances( geometry, start, count ) {
  8922. var extension;
  8923. if ( capabilities.isWebGL2 ) {
  8924. extension = gl;
  8925. } else {
  8926. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8927. if ( extension === null ) {
  8928. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8929. return;
  8930. }
  8931. }
  8932. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  8933. info.update( count, mode, geometry.maxInstancedCount );
  8934. }
  8935. //
  8936. this.setMode = setMode;
  8937. this.render = render;
  8938. this.renderInstances = renderInstances;
  8939. }
  8940. /**
  8941. * @author mrdoob / http://mrdoob.com/
  8942. */
  8943. function WebGLCapabilities( gl, extensions, parameters ) {
  8944. var maxAnisotropy;
  8945. function getMaxAnisotropy() {
  8946. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8947. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8948. if ( extension !== null ) {
  8949. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8950. } else {
  8951. maxAnisotropy = 0;
  8952. }
  8953. return maxAnisotropy;
  8954. }
  8955. function getMaxPrecision( precision ) {
  8956. if ( precision === 'highp' ) {
  8957. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8958. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8959. return 'highp';
  8960. }
  8961. precision = 'mediump';
  8962. }
  8963. if ( precision === 'mediump' ) {
  8964. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8965. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8966. return 'mediump';
  8967. }
  8968. }
  8969. return 'lowp';
  8970. }
  8971. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  8972. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8973. var maxPrecision = getMaxPrecision( precision );
  8974. if ( maxPrecision !== precision ) {
  8975. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8976. precision = maxPrecision;
  8977. }
  8978. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8979. var maxTextures = gl.getParameter( 34930 );
  8980. var maxVertexTextures = gl.getParameter( 35660 );
  8981. var maxTextureSize = gl.getParameter( 3379 );
  8982. var maxCubemapSize = gl.getParameter( 34076 );
  8983. var maxAttributes = gl.getParameter( 34921 );
  8984. var maxVertexUniforms = gl.getParameter( 36347 );
  8985. var maxVaryings = gl.getParameter( 36348 );
  8986. var maxFragmentUniforms = gl.getParameter( 36349 );
  8987. var vertexTextures = maxVertexTextures > 0;
  8988. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8989. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8990. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8991. return {
  8992. isWebGL2: isWebGL2,
  8993. getMaxAnisotropy: getMaxAnisotropy,
  8994. getMaxPrecision: getMaxPrecision,
  8995. precision: precision,
  8996. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8997. maxTextures: maxTextures,
  8998. maxVertexTextures: maxVertexTextures,
  8999. maxTextureSize: maxTextureSize,
  9000. maxCubemapSize: maxCubemapSize,
  9001. maxAttributes: maxAttributes,
  9002. maxVertexUniforms: maxVertexUniforms,
  9003. maxVaryings: maxVaryings,
  9004. maxFragmentUniforms: maxFragmentUniforms,
  9005. vertexTextures: vertexTextures,
  9006. floatFragmentTextures: floatFragmentTextures,
  9007. floatVertexTextures: floatVertexTextures,
  9008. maxSamples: maxSamples
  9009. };
  9010. }
  9011. /**
  9012. * @author tschw
  9013. */
  9014. function WebGLClipping() {
  9015. var scope = this,
  9016. globalState = null,
  9017. numGlobalPlanes = 0,
  9018. localClippingEnabled = false,
  9019. renderingShadows = false,
  9020. plane = new Plane(),
  9021. viewNormalMatrix = new Matrix3(),
  9022. uniform = { value: null, needsUpdate: false };
  9023. this.uniform = uniform;
  9024. this.numPlanes = 0;
  9025. this.numIntersection = 0;
  9026. this.init = function ( planes, enableLocalClipping, camera ) {
  9027. var enabled =
  9028. planes.length !== 0 ||
  9029. enableLocalClipping ||
  9030. // enable state of previous frame - the clipping code has to
  9031. // run another frame in order to reset the state:
  9032. numGlobalPlanes !== 0 ||
  9033. localClippingEnabled;
  9034. localClippingEnabled = enableLocalClipping;
  9035. globalState = projectPlanes( planes, camera, 0 );
  9036. numGlobalPlanes = planes.length;
  9037. return enabled;
  9038. };
  9039. this.beginShadows = function () {
  9040. renderingShadows = true;
  9041. projectPlanes( null );
  9042. };
  9043. this.endShadows = function () {
  9044. renderingShadows = false;
  9045. resetGlobalState();
  9046. };
  9047. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9048. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9049. // there's no local clipping
  9050. if ( renderingShadows ) {
  9051. // there's no global clipping
  9052. projectPlanes( null );
  9053. } else {
  9054. resetGlobalState();
  9055. }
  9056. } else {
  9057. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9058. lGlobal = nGlobal * 4,
  9059. dstArray = cache.clippingState || null;
  9060. uniform.value = dstArray; // ensure unique state
  9061. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9062. for ( var i = 0; i !== lGlobal; ++ i ) {
  9063. dstArray[ i ] = globalState[ i ];
  9064. }
  9065. cache.clippingState = dstArray;
  9066. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9067. this.numPlanes += nGlobal;
  9068. }
  9069. };
  9070. function resetGlobalState() {
  9071. if ( uniform.value !== globalState ) {
  9072. uniform.value = globalState;
  9073. uniform.needsUpdate = numGlobalPlanes > 0;
  9074. }
  9075. scope.numPlanes = numGlobalPlanes;
  9076. scope.numIntersection = 0;
  9077. }
  9078. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9079. var nPlanes = planes !== null ? planes.length : 0,
  9080. dstArray = null;
  9081. if ( nPlanes !== 0 ) {
  9082. dstArray = uniform.value;
  9083. if ( skipTransform !== true || dstArray === null ) {
  9084. var flatSize = dstOffset + nPlanes * 4,
  9085. viewMatrix = camera.matrixWorldInverse;
  9086. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9087. if ( dstArray === null || dstArray.length < flatSize ) {
  9088. dstArray = new Float32Array( flatSize );
  9089. }
  9090. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9091. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9092. plane.normal.toArray( dstArray, i4 );
  9093. dstArray[ i4 + 3 ] = plane.constant;
  9094. }
  9095. }
  9096. uniform.value = dstArray;
  9097. uniform.needsUpdate = true;
  9098. }
  9099. scope.numPlanes = nPlanes;
  9100. return dstArray;
  9101. }
  9102. }
  9103. /**
  9104. * @author mrdoob / http://mrdoob.com/
  9105. */
  9106. function WebGLExtensions( gl ) {
  9107. var extensions = {};
  9108. return {
  9109. get: function ( name ) {
  9110. if ( extensions[ name ] !== undefined ) {
  9111. return extensions[ name ];
  9112. }
  9113. var extension;
  9114. switch ( name ) {
  9115. case 'WEBGL_depth_texture':
  9116. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9117. break;
  9118. case 'EXT_texture_filter_anisotropic':
  9119. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9120. break;
  9121. case 'WEBGL_compressed_texture_s3tc':
  9122. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9123. break;
  9124. case 'WEBGL_compressed_texture_pvrtc':
  9125. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9126. break;
  9127. default:
  9128. extension = gl.getExtension( name );
  9129. }
  9130. if ( extension === null ) {
  9131. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9132. }
  9133. extensions[ name ] = extension;
  9134. return extension;
  9135. }
  9136. };
  9137. }
  9138. /**
  9139. * @author mrdoob / http://mrdoob.com/
  9140. */
  9141. function WebGLGeometries( gl, attributes, info ) {
  9142. var geometries = {};
  9143. var wireframeAttributes = {};
  9144. function onGeometryDispose( event ) {
  9145. var geometry = event.target;
  9146. var buffergeometry = geometries[ geometry.id ];
  9147. if ( buffergeometry.index !== null ) {
  9148. attributes.remove( buffergeometry.index );
  9149. }
  9150. for ( var name in buffergeometry.attributes ) {
  9151. attributes.remove( buffergeometry.attributes[ name ] );
  9152. }
  9153. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9154. delete geometries[ geometry.id ];
  9155. var attribute = wireframeAttributes[ buffergeometry.id ];
  9156. if ( attribute ) {
  9157. attributes.remove( attribute );
  9158. delete wireframeAttributes[ buffergeometry.id ];
  9159. }
  9160. //
  9161. info.memory.geometries --;
  9162. }
  9163. function get( object, geometry ) {
  9164. var buffergeometry = geometries[ geometry.id ];
  9165. if ( buffergeometry ) return buffergeometry;
  9166. geometry.addEventListener( 'dispose', onGeometryDispose );
  9167. if ( geometry.isBufferGeometry ) {
  9168. buffergeometry = geometry;
  9169. } else if ( geometry.isGeometry ) {
  9170. if ( geometry._bufferGeometry === undefined ) {
  9171. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9172. }
  9173. buffergeometry = geometry._bufferGeometry;
  9174. }
  9175. geometries[ geometry.id ] = buffergeometry;
  9176. info.memory.geometries ++;
  9177. return buffergeometry;
  9178. }
  9179. function update( geometry ) {
  9180. var index = geometry.index;
  9181. var geometryAttributes = geometry.attributes;
  9182. if ( index !== null ) {
  9183. attributes.update( index, 34963 );
  9184. }
  9185. for ( var name in geometryAttributes ) {
  9186. attributes.update( geometryAttributes[ name ], 34962 );
  9187. }
  9188. // morph targets
  9189. var morphAttributes = geometry.morphAttributes;
  9190. for ( var name in morphAttributes ) {
  9191. var array = morphAttributes[ name ];
  9192. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9193. attributes.update( array[ i ], 34962 );
  9194. }
  9195. }
  9196. }
  9197. function getWireframeAttribute( geometry ) {
  9198. var attribute = wireframeAttributes[ geometry.id ];
  9199. if ( attribute ) return attribute;
  9200. var indices = [];
  9201. var geometryIndex = geometry.index;
  9202. var geometryAttributes = geometry.attributes;
  9203. // console.time( 'wireframe' );
  9204. if ( geometryIndex !== null ) {
  9205. var array = geometryIndex.array;
  9206. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9207. var a = array[ i + 0 ];
  9208. var b = array[ i + 1 ];
  9209. var c = array[ i + 2 ];
  9210. indices.push( a, b, b, c, c, a );
  9211. }
  9212. } else {
  9213. var array = geometryAttributes.position.array;
  9214. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9215. var a = i + 0;
  9216. var b = i + 1;
  9217. var c = i + 2;
  9218. indices.push( a, b, b, c, c, a );
  9219. }
  9220. }
  9221. // console.timeEnd( 'wireframe' );
  9222. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9223. attributes.update( attribute, 34963 );
  9224. wireframeAttributes[ geometry.id ] = attribute;
  9225. return attribute;
  9226. }
  9227. return {
  9228. get: get,
  9229. update: update,
  9230. getWireframeAttribute: getWireframeAttribute
  9231. };
  9232. }
  9233. /**
  9234. * @author mrdoob / http://mrdoob.com/
  9235. */
  9236. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9237. var mode;
  9238. function setMode( value ) {
  9239. mode = value;
  9240. }
  9241. var type, bytesPerElement;
  9242. function setIndex( value ) {
  9243. type = value.type;
  9244. bytesPerElement = value.bytesPerElement;
  9245. }
  9246. function render( start, count ) {
  9247. gl.drawElements( mode, count, type, start * bytesPerElement );
  9248. info.update( count, mode );
  9249. }
  9250. function renderInstances( geometry, start, count ) {
  9251. var extension;
  9252. if ( capabilities.isWebGL2 ) {
  9253. extension = gl;
  9254. } else {
  9255. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9256. if ( extension === null ) {
  9257. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9258. return;
  9259. }
  9260. }
  9261. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9262. info.update( count, mode, geometry.maxInstancedCount );
  9263. }
  9264. //
  9265. this.setMode = setMode;
  9266. this.setIndex = setIndex;
  9267. this.render = render;
  9268. this.renderInstances = renderInstances;
  9269. }
  9270. /**
  9271. * @author Mugen87 / https://github.com/Mugen87
  9272. */
  9273. function WebGLInfo( gl ) {
  9274. var memory = {
  9275. geometries: 0,
  9276. textures: 0
  9277. };
  9278. var render = {
  9279. frame: 0,
  9280. calls: 0,
  9281. triangles: 0,
  9282. points: 0,
  9283. lines: 0
  9284. };
  9285. function update( count, mode, instanceCount ) {
  9286. instanceCount = instanceCount || 1;
  9287. render.calls ++;
  9288. switch ( mode ) {
  9289. case 4:
  9290. render.triangles += instanceCount * ( count / 3 );
  9291. break;
  9292. case 5:
  9293. case 6:
  9294. render.triangles += instanceCount * ( count - 2 );
  9295. break;
  9296. case 1:
  9297. render.lines += instanceCount * ( count / 2 );
  9298. break;
  9299. case 3:
  9300. render.lines += instanceCount * ( count - 1 );
  9301. break;
  9302. case 2:
  9303. render.lines += instanceCount * count;
  9304. break;
  9305. case 0:
  9306. render.points += instanceCount * count;
  9307. break;
  9308. default:
  9309. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9310. break;
  9311. }
  9312. }
  9313. function reset() {
  9314. render.frame ++;
  9315. render.calls = 0;
  9316. render.triangles = 0;
  9317. render.points = 0;
  9318. render.lines = 0;
  9319. }
  9320. return {
  9321. memory: memory,
  9322. render: render,
  9323. programs: null,
  9324. autoReset: true,
  9325. reset: reset,
  9326. update: update
  9327. };
  9328. }
  9329. /**
  9330. * @author mrdoob / http://mrdoob.com/
  9331. */
  9332. function absNumericalSort( a, b ) {
  9333. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9334. }
  9335. function WebGLMorphtargets( gl ) {
  9336. var influencesList = {};
  9337. var morphInfluences = new Float32Array( 8 );
  9338. function update( object, geometry, material, program ) {
  9339. var objectInfluences = object.morphTargetInfluences;
  9340. var length = objectInfluences.length;
  9341. var influences = influencesList[ geometry.id ];
  9342. if ( influences === undefined ) {
  9343. // initialise list
  9344. influences = [];
  9345. for ( var i = 0; i < length; i ++ ) {
  9346. influences[ i ] = [ i, 0 ];
  9347. }
  9348. influencesList[ geometry.id ] = influences;
  9349. }
  9350. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9351. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9352. // Remove current morphAttributes
  9353. for ( var i = 0; i < length; i ++ ) {
  9354. var influence = influences[ i ];
  9355. if ( influence[ 1 ] !== 0 ) {
  9356. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9357. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9358. }
  9359. }
  9360. // Collect influences
  9361. for ( var i = 0; i < length; i ++ ) {
  9362. var influence = influences[ i ];
  9363. influence[ 0 ] = i;
  9364. influence[ 1 ] = objectInfluences[ i ];
  9365. }
  9366. influences.sort( absNumericalSort );
  9367. // Add morphAttributes
  9368. for ( var i = 0; i < 8; i ++ ) {
  9369. var influence = influences[ i ];
  9370. if ( influence ) {
  9371. var index = influence[ 0 ];
  9372. var value = influence[ 1 ];
  9373. if ( value ) {
  9374. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9375. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9376. morphInfluences[ i ] = value;
  9377. continue;
  9378. }
  9379. }
  9380. morphInfluences[ i ] = 0;
  9381. }
  9382. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9383. }
  9384. return {
  9385. update: update
  9386. };
  9387. }
  9388. /**
  9389. * @author mrdoob / http://mrdoob.com/
  9390. */
  9391. function WebGLObjects( geometries, info ) {
  9392. var updateList = {};
  9393. function update( object ) {
  9394. var frame = info.render.frame;
  9395. var geometry = object.geometry;
  9396. var buffergeometry = geometries.get( object, geometry );
  9397. // Update once per frame
  9398. if ( updateList[ buffergeometry.id ] !== frame ) {
  9399. if ( geometry.isGeometry ) {
  9400. buffergeometry.updateFromObject( object );
  9401. }
  9402. geometries.update( buffergeometry );
  9403. updateList[ buffergeometry.id ] = frame;
  9404. }
  9405. return buffergeometry;
  9406. }
  9407. function dispose() {
  9408. updateList = {};
  9409. }
  9410. return {
  9411. update: update,
  9412. dispose: dispose
  9413. };
  9414. }
  9415. /**
  9416. * @author mrdoob / http://mrdoob.com/
  9417. */
  9418. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9419. images = images !== undefined ? images : [];
  9420. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9421. format = format !== undefined ? format : RGBFormat;
  9422. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9423. this.flipY = false;
  9424. }
  9425. CubeTexture.prototype = Object.create( Texture.prototype );
  9426. CubeTexture.prototype.constructor = CubeTexture;
  9427. CubeTexture.prototype.isCubeTexture = true;
  9428. Object.defineProperty( CubeTexture.prototype, 'images', {
  9429. get: function () {
  9430. return this.image;
  9431. },
  9432. set: function ( value ) {
  9433. this.image = value;
  9434. }
  9435. } );
  9436. /**
  9437. * @author Takahiro https://github.com/takahirox
  9438. */
  9439. function DataTexture2DArray( data, width, height, depth ) {
  9440. Texture.call( this, null );
  9441. this.image = { data: data, width: width, height: height, depth: depth };
  9442. this.magFilter = NearestFilter;
  9443. this.minFilter = NearestFilter;
  9444. this.wrapR = ClampToEdgeWrapping;
  9445. this.generateMipmaps = false;
  9446. this.flipY = false;
  9447. }
  9448. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9449. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9450. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9451. /**
  9452. * @author Artur Trzesiok
  9453. */
  9454. function DataTexture3D( data, width, height, depth ) {
  9455. // We're going to add .setXXX() methods for setting properties later.
  9456. // Users can still set in DataTexture3D directly.
  9457. //
  9458. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9459. // texture.anisotropy = 16;
  9460. //
  9461. // See #14839
  9462. Texture.call( this, null );
  9463. this.image = { data: data, width: width, height: height, depth: depth };
  9464. this.magFilter = NearestFilter;
  9465. this.minFilter = NearestFilter;
  9466. this.wrapR = ClampToEdgeWrapping;
  9467. this.generateMipmaps = false;
  9468. this.flipY = false;
  9469. }
  9470. DataTexture3D.prototype = Object.create( Texture.prototype );
  9471. DataTexture3D.prototype.constructor = DataTexture3D;
  9472. DataTexture3D.prototype.isDataTexture3D = true;
  9473. /**
  9474. * @author tschw
  9475. * @author Mugen87 / https://github.com/Mugen87
  9476. * @author mrdoob / http://mrdoob.com/
  9477. *
  9478. * Uniforms of a program.
  9479. * Those form a tree structure with a special top-level container for the root,
  9480. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9481. *
  9482. *
  9483. * Properties of inner nodes including the top-level container:
  9484. *
  9485. * .seq - array of nested uniforms
  9486. * .map - nested uniforms by name
  9487. *
  9488. *
  9489. * Methods of all nodes except the top-level container:
  9490. *
  9491. * .setValue( gl, value, [textures] )
  9492. *
  9493. * uploads a uniform value(s)
  9494. * the 'textures' parameter is needed for sampler uniforms
  9495. *
  9496. *
  9497. * Static methods of the top-level container (textures factorizations):
  9498. *
  9499. * .upload( gl, seq, values, textures )
  9500. *
  9501. * sets uniforms in 'seq' to 'values[id].value'
  9502. *
  9503. * .seqWithValue( seq, values ) : filteredSeq
  9504. *
  9505. * filters 'seq' entries with corresponding entry in values
  9506. *
  9507. *
  9508. * Methods of the top-level container (textures factorizations):
  9509. *
  9510. * .setValue( gl, name, value, textures )
  9511. *
  9512. * sets uniform with name 'name' to 'value'
  9513. *
  9514. * .setOptional( gl, obj, prop )
  9515. *
  9516. * like .set for an optional property of the object
  9517. *
  9518. */
  9519. var emptyTexture = new Texture();
  9520. var emptyTexture2dArray = new DataTexture2DArray();
  9521. var emptyTexture3d = new DataTexture3D();
  9522. var emptyCubeTexture = new CubeTexture();
  9523. // --- Utilities ---
  9524. // Array Caches (provide typed arrays for temporary by size)
  9525. var arrayCacheF32 = [];
  9526. var arrayCacheI32 = [];
  9527. // Float32Array caches used for uploading Matrix uniforms
  9528. var mat4array = new Float32Array( 16 );
  9529. var mat3array = new Float32Array( 9 );
  9530. var mat2array = new Float32Array( 4 );
  9531. // Flattening for arrays of vectors and matrices
  9532. function flatten( array, nBlocks, blockSize ) {
  9533. var firstElem = array[ 0 ];
  9534. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9535. // unoptimized: ! isNaN( firstElem )
  9536. // see http://jacksondunstan.com/articles/983
  9537. var n = nBlocks * blockSize,
  9538. r = arrayCacheF32[ n ];
  9539. if ( r === undefined ) {
  9540. r = new Float32Array( n );
  9541. arrayCacheF32[ n ] = r;
  9542. }
  9543. if ( nBlocks !== 0 ) {
  9544. firstElem.toArray( r, 0 );
  9545. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9546. offset += blockSize;
  9547. array[ i ].toArray( r, offset );
  9548. }
  9549. }
  9550. return r;
  9551. }
  9552. function arraysEqual( a, b ) {
  9553. if ( a.length !== b.length ) return false;
  9554. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9555. if ( a[ i ] !== b[ i ] ) return false;
  9556. }
  9557. return true;
  9558. }
  9559. function copyArray( a, b ) {
  9560. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9561. a[ i ] = b[ i ];
  9562. }
  9563. }
  9564. // Texture unit allocation
  9565. function allocTexUnits( textures, n ) {
  9566. var r = arrayCacheI32[ n ];
  9567. if ( r === undefined ) {
  9568. r = new Int32Array( n );
  9569. arrayCacheI32[ n ] = r;
  9570. }
  9571. for ( var i = 0; i !== n; ++ i )
  9572. r[ i ] = textures.allocateTextureUnit();
  9573. return r;
  9574. }
  9575. // --- Setters ---
  9576. // Note: Defining these methods externally, because they come in a bunch
  9577. // and this way their names minify.
  9578. // Single scalar
  9579. function setValue1f( gl, v ) {
  9580. var cache = this.cache;
  9581. if ( cache[ 0 ] === v ) return;
  9582. gl.uniform1f( this.addr, v );
  9583. cache[ 0 ] = v;
  9584. }
  9585. function setValue1i( gl, v ) {
  9586. var cache = this.cache;
  9587. if ( cache[ 0 ] === v ) return;
  9588. gl.uniform1i( this.addr, v );
  9589. cache[ 0 ] = v;
  9590. }
  9591. // Single float vector (from flat array or THREE.VectorN)
  9592. function setValue2fv( gl, v ) {
  9593. var cache = this.cache;
  9594. if ( v.x !== undefined ) {
  9595. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9596. gl.uniform2f( this.addr, v.x, v.y );
  9597. cache[ 0 ] = v.x;
  9598. cache[ 1 ] = v.y;
  9599. }
  9600. } else {
  9601. if ( arraysEqual( cache, v ) ) return;
  9602. gl.uniform2fv( this.addr, v );
  9603. copyArray( cache, v );
  9604. }
  9605. }
  9606. function setValue3fv( gl, v ) {
  9607. var cache = this.cache;
  9608. if ( v.x !== undefined ) {
  9609. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9610. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9611. cache[ 0 ] = v.x;
  9612. cache[ 1 ] = v.y;
  9613. cache[ 2 ] = v.z;
  9614. }
  9615. } else if ( v.r !== undefined ) {
  9616. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9617. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9618. cache[ 0 ] = v.r;
  9619. cache[ 1 ] = v.g;
  9620. cache[ 2 ] = v.b;
  9621. }
  9622. } else {
  9623. if ( arraysEqual( cache, v ) ) return;
  9624. gl.uniform3fv( this.addr, v );
  9625. copyArray( cache, v );
  9626. }
  9627. }
  9628. function setValue4fv( gl, v ) {
  9629. var cache = this.cache;
  9630. if ( v.x !== undefined ) {
  9631. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9632. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9633. cache[ 0 ] = v.x;
  9634. cache[ 1 ] = v.y;
  9635. cache[ 2 ] = v.z;
  9636. cache[ 3 ] = v.w;
  9637. }
  9638. } else {
  9639. if ( arraysEqual( cache, v ) ) return;
  9640. gl.uniform4fv( this.addr, v );
  9641. copyArray( cache, v );
  9642. }
  9643. }
  9644. // Single matrix (from flat array or MatrixN)
  9645. function setValue2fm( gl, v ) {
  9646. var cache = this.cache;
  9647. var elements = v.elements;
  9648. if ( elements === undefined ) {
  9649. if ( arraysEqual( cache, v ) ) return;
  9650. gl.uniformMatrix2fv( this.addr, false, v );
  9651. copyArray( cache, v );
  9652. } else {
  9653. if ( arraysEqual( cache, elements ) ) return;
  9654. mat2array.set( elements );
  9655. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9656. copyArray( cache, elements );
  9657. }
  9658. }
  9659. function setValue3fm( gl, v ) {
  9660. var cache = this.cache;
  9661. var elements = v.elements;
  9662. if ( elements === undefined ) {
  9663. if ( arraysEqual( cache, v ) ) return;
  9664. gl.uniformMatrix3fv( this.addr, false, v );
  9665. copyArray( cache, v );
  9666. } else {
  9667. if ( arraysEqual( cache, elements ) ) return;
  9668. mat3array.set( elements );
  9669. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9670. copyArray( cache, elements );
  9671. }
  9672. }
  9673. function setValue4fm( gl, v ) {
  9674. var cache = this.cache;
  9675. var elements = v.elements;
  9676. if ( elements === undefined ) {
  9677. if ( arraysEqual( cache, v ) ) return;
  9678. gl.uniformMatrix4fv( this.addr, false, v );
  9679. copyArray( cache, v );
  9680. } else {
  9681. if ( arraysEqual( cache, elements ) ) return;
  9682. mat4array.set( elements );
  9683. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9684. copyArray( cache, elements );
  9685. }
  9686. }
  9687. // Single texture (2D / Cube)
  9688. function setValueT1( gl, v, textures ) {
  9689. var cache = this.cache;
  9690. var unit = textures.allocateTextureUnit();
  9691. if ( cache[ 0 ] !== unit ) {
  9692. gl.uniform1i( this.addr, unit );
  9693. cache[ 0 ] = unit;
  9694. }
  9695. textures.safeSetTexture2D( v || emptyTexture, unit );
  9696. }
  9697. function setValueT2DArray1( gl, v, textures ) {
  9698. var cache = this.cache;
  9699. var unit = textures.allocateTextureUnit();
  9700. if ( cache[ 0 ] !== unit ) {
  9701. gl.uniform1i( this.addr, unit );
  9702. cache[ 0 ] = unit;
  9703. }
  9704. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  9705. }
  9706. function setValueT3D1( gl, v, textures ) {
  9707. var cache = this.cache;
  9708. var unit = textures.allocateTextureUnit();
  9709. if ( cache[ 0 ] !== unit ) {
  9710. gl.uniform1i( this.addr, unit );
  9711. cache[ 0 ] = unit;
  9712. }
  9713. textures.setTexture3D( v || emptyTexture3d, unit );
  9714. }
  9715. function setValueT6( gl, v, textures ) {
  9716. var cache = this.cache;
  9717. var unit = textures.allocateTextureUnit();
  9718. if ( cache[ 0 ] !== unit ) {
  9719. gl.uniform1i( this.addr, unit );
  9720. cache[ 0 ] = unit;
  9721. }
  9722. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  9723. }
  9724. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9725. function setValue2iv( gl, v ) {
  9726. var cache = this.cache;
  9727. if ( arraysEqual( cache, v ) ) return;
  9728. gl.uniform2iv( this.addr, v );
  9729. copyArray( cache, v );
  9730. }
  9731. function setValue3iv( gl, v ) {
  9732. var cache = this.cache;
  9733. if ( arraysEqual( cache, v ) ) return;
  9734. gl.uniform3iv( this.addr, v );
  9735. copyArray( cache, v );
  9736. }
  9737. function setValue4iv( gl, v ) {
  9738. var cache = this.cache;
  9739. if ( arraysEqual( cache, v ) ) return;
  9740. gl.uniform4iv( this.addr, v );
  9741. copyArray( cache, v );
  9742. }
  9743. // Helper to pick the right setter for the singular case
  9744. function getSingularSetter( type ) {
  9745. switch ( type ) {
  9746. case 0x1406: return setValue1f; // FLOAT
  9747. case 0x8b50: return setValue2fv; // _VEC2
  9748. case 0x8b51: return setValue3fv; // _VEC3
  9749. case 0x8b52: return setValue4fv; // _VEC4
  9750. case 0x8b5a: return setValue2fm; // _MAT2
  9751. case 0x8b5b: return setValue3fm; // _MAT3
  9752. case 0x8b5c: return setValue4fm; // _MAT4
  9753. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9754. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  9755. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9756. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  9757. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9758. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9759. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9760. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9761. }
  9762. }
  9763. // Array of scalars
  9764. function setValue1fv( gl, v ) {
  9765. var cache = this.cache;
  9766. if ( arraysEqual( cache, v ) ) return;
  9767. gl.uniform1fv( this.addr, v );
  9768. copyArray( cache, v );
  9769. }
  9770. function setValue1iv( gl, v ) {
  9771. var cache = this.cache;
  9772. if ( arraysEqual( cache, v ) ) return;
  9773. gl.uniform1iv( this.addr, v );
  9774. copyArray( cache, v );
  9775. }
  9776. // Array of vectors (flat or from THREE classes)
  9777. function setValueV2a( gl, v ) {
  9778. var cache = this.cache;
  9779. var data = flatten( v, this.size, 2 );
  9780. if ( arraysEqual( cache, data ) ) return;
  9781. gl.uniform2fv( this.addr, data );
  9782. this.updateCache( data );
  9783. }
  9784. function setValueV3a( gl, v ) {
  9785. var cache = this.cache;
  9786. var data = flatten( v, this.size, 3 );
  9787. if ( arraysEqual( cache, data ) ) return;
  9788. gl.uniform3fv( this.addr, data );
  9789. this.updateCache( data );
  9790. }
  9791. function setValueV4a( gl, v ) {
  9792. var cache = this.cache;
  9793. var data = flatten( v, this.size, 4 );
  9794. if ( arraysEqual( cache, data ) ) return;
  9795. gl.uniform4fv( this.addr, data );
  9796. this.updateCache( data );
  9797. }
  9798. // Array of matrices (flat or from THREE clases)
  9799. function setValueM2a( gl, v ) {
  9800. var cache = this.cache;
  9801. var data = flatten( v, this.size, 4 );
  9802. if ( arraysEqual( cache, data ) ) return;
  9803. gl.uniformMatrix2fv( this.addr, false, data );
  9804. this.updateCache( data );
  9805. }
  9806. function setValueM3a( gl, v ) {
  9807. var cache = this.cache;
  9808. var data = flatten( v, this.size, 9 );
  9809. if ( arraysEqual( cache, data ) ) return;
  9810. gl.uniformMatrix3fv( this.addr, false, data );
  9811. this.updateCache( data );
  9812. }
  9813. function setValueM4a( gl, v ) {
  9814. var cache = this.cache;
  9815. var data = flatten( v, this.size, 16 );
  9816. if ( arraysEqual( cache, data ) ) return;
  9817. gl.uniformMatrix4fv( this.addr, false, data );
  9818. this.updateCache( data );
  9819. }
  9820. // Array of textures (2D / Cube)
  9821. function setValueT1a( gl, v, textures ) {
  9822. var cache = this.cache;
  9823. var n = v.length;
  9824. var units = allocTexUnits( textures, n );
  9825. if ( arraysEqual( cache, units ) === false ) {
  9826. gl.uniform1iv( this.addr, units );
  9827. copyArray( cache, units );
  9828. }
  9829. for ( var i = 0; i !== n; ++ i ) {
  9830. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9831. }
  9832. }
  9833. function setValueT6a( gl, v, textures ) {
  9834. var cache = this.cache;
  9835. var n = v.length;
  9836. var units = allocTexUnits( textures, n );
  9837. if ( arraysEqual( cache, units ) === false ) {
  9838. gl.uniform1iv( this.addr, units );
  9839. copyArray( cache, units );
  9840. }
  9841. for ( var i = 0; i !== n; ++ i ) {
  9842. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9843. }
  9844. }
  9845. // Helper to pick the right setter for a pure (bottom-level) array
  9846. function getPureArraySetter( type ) {
  9847. switch ( type ) {
  9848. case 0x1406: return setValue1fv; // FLOAT
  9849. case 0x8b50: return setValueV2a; // _VEC2
  9850. case 0x8b51: return setValueV3a; // _VEC3
  9851. case 0x8b52: return setValueV4a; // _VEC4
  9852. case 0x8b5a: return setValueM2a; // _MAT2
  9853. case 0x8b5b: return setValueM3a; // _MAT3
  9854. case 0x8b5c: return setValueM4a; // _MAT4
  9855. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9856. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9857. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9858. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9859. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9860. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9861. }
  9862. }
  9863. // --- Uniform Classes ---
  9864. function SingleUniform( id, activeInfo, addr ) {
  9865. this.id = id;
  9866. this.addr = addr;
  9867. this.cache = [];
  9868. this.setValue = getSingularSetter( activeInfo.type );
  9869. // this.path = activeInfo.name; // DEBUG
  9870. }
  9871. function PureArrayUniform( id, activeInfo, addr ) {
  9872. this.id = id;
  9873. this.addr = addr;
  9874. this.cache = [];
  9875. this.size = activeInfo.size;
  9876. this.setValue = getPureArraySetter( activeInfo.type );
  9877. // this.path = activeInfo.name; // DEBUG
  9878. }
  9879. PureArrayUniform.prototype.updateCache = function ( data ) {
  9880. var cache = this.cache;
  9881. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9882. this.cache = new Float32Array( data.length );
  9883. }
  9884. copyArray( cache, data );
  9885. };
  9886. function StructuredUniform( id ) {
  9887. this.id = id;
  9888. this.seq = [];
  9889. this.map = {};
  9890. }
  9891. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  9892. var seq = this.seq;
  9893. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9894. var u = seq[ i ];
  9895. u.setValue( gl, value[ u.id ], textures );
  9896. }
  9897. };
  9898. // --- Top-level ---
  9899. // Parser - builds up the property tree from the path strings
  9900. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9901. // extracts
  9902. // - the identifier (member name or array index)
  9903. // - followed by an optional right bracket (found when array index)
  9904. // - followed by an optional left bracket or dot (type of subscript)
  9905. //
  9906. // Note: These portions can be read in a non-overlapping fashion and
  9907. // allow straightforward parsing of the hierarchy that WebGL encodes
  9908. // in the uniform names.
  9909. function addUniform( container, uniformObject ) {
  9910. container.seq.push( uniformObject );
  9911. container.map[ uniformObject.id ] = uniformObject;
  9912. }
  9913. function parseUniform( activeInfo, addr, container ) {
  9914. var path = activeInfo.name,
  9915. pathLength = path.length;
  9916. // reset RegExp object, because of the early exit of a previous run
  9917. RePathPart.lastIndex = 0;
  9918. while ( true ) {
  9919. var match = RePathPart.exec( path ),
  9920. matchEnd = RePathPart.lastIndex,
  9921. id = match[ 1 ],
  9922. idIsIndex = match[ 2 ] === ']',
  9923. subscript = match[ 3 ];
  9924. if ( idIsIndex ) id = id | 0; // convert to integer
  9925. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9926. // bare name or "pure" bottom-level array "[0]" suffix
  9927. addUniform( container, subscript === undefined ?
  9928. new SingleUniform( id, activeInfo, addr ) :
  9929. new PureArrayUniform( id, activeInfo, addr ) );
  9930. break;
  9931. } else {
  9932. // step into inner node / create it in case it doesn't exist
  9933. var map = container.map, next = map[ id ];
  9934. if ( next === undefined ) {
  9935. next = new StructuredUniform( id );
  9936. addUniform( container, next );
  9937. }
  9938. container = next;
  9939. }
  9940. }
  9941. }
  9942. // Root Container
  9943. function WebGLUniforms( gl, program ) {
  9944. this.seq = [];
  9945. this.map = {};
  9946. var n = gl.getProgramParameter( program, 35718 );
  9947. for ( var i = 0; i < n; ++ i ) {
  9948. var info = gl.getActiveUniform( program, i ),
  9949. addr = gl.getUniformLocation( program, info.name );
  9950. parseUniform( info, addr, this );
  9951. }
  9952. }
  9953. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  9954. var u = this.map[ name ];
  9955. if ( u !== undefined ) u.setValue( gl, value, textures );
  9956. };
  9957. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9958. var v = object[ name ];
  9959. if ( v !== undefined ) this.setValue( gl, name, v );
  9960. };
  9961. // Static interface
  9962. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  9963. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9964. var u = seq[ i ],
  9965. v = values[ u.id ];
  9966. if ( v.needsUpdate !== false ) {
  9967. // note: always updating when .needsUpdate is undefined
  9968. u.setValue( gl, v.value, textures );
  9969. }
  9970. }
  9971. };
  9972. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9973. var r = [];
  9974. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9975. var u = seq[ i ];
  9976. if ( u.id in values ) r.push( u );
  9977. }
  9978. return r;
  9979. };
  9980. /**
  9981. * @author mrdoob / http://mrdoob.com/
  9982. */
  9983. function addLineNumbers( string ) {
  9984. var lines = string.split( '\n' );
  9985. for ( var i = 0; i < lines.length; i ++ ) {
  9986. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9987. }
  9988. return lines.join( '\n' );
  9989. }
  9990. function WebGLShader( gl, type, string ) {
  9991. var shader = gl.createShader( type );
  9992. gl.shaderSource( shader, string );
  9993. gl.compileShader( shader );
  9994. if ( gl.getShaderParameter( shader, 35713 ) === false ) {
  9995. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9996. }
  9997. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9998. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === 35633 ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9999. }
  10000. // --enable-privileged-webgl-extension
  10001. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10002. return shader;
  10003. }
  10004. /**
  10005. * @author mrdoob / http://mrdoob.com/
  10006. */
  10007. var programIdCount = 0;
  10008. function getEncodingComponents( encoding ) {
  10009. switch ( encoding ) {
  10010. case LinearEncoding:
  10011. return [ 'Linear', '( value )' ];
  10012. case sRGBEncoding:
  10013. return [ 'sRGB', '( value )' ];
  10014. case RGBEEncoding:
  10015. return [ 'RGBE', '( value )' ];
  10016. case RGBM7Encoding:
  10017. return [ 'RGBM', '( value, 7.0 )' ];
  10018. case RGBM16Encoding:
  10019. return [ 'RGBM', '( value, 16.0 )' ];
  10020. case RGBDEncoding:
  10021. return [ 'RGBD', '( value, 256.0 )' ];
  10022. case GammaEncoding:
  10023. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10024. default:
  10025. throw new Error( 'unsupported encoding: ' + encoding );
  10026. }
  10027. }
  10028. function getTexelDecodingFunction( functionName, encoding ) {
  10029. var components = getEncodingComponents( encoding );
  10030. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10031. }
  10032. function getTexelEncodingFunction( functionName, encoding ) {
  10033. var components = getEncodingComponents( encoding );
  10034. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10035. }
  10036. function getToneMappingFunction( functionName, toneMapping ) {
  10037. var toneMappingName;
  10038. switch ( toneMapping ) {
  10039. case LinearToneMapping:
  10040. toneMappingName = 'Linear';
  10041. break;
  10042. case ReinhardToneMapping:
  10043. toneMappingName = 'Reinhard';
  10044. break;
  10045. case Uncharted2ToneMapping:
  10046. toneMappingName = 'Uncharted2';
  10047. break;
  10048. case CineonToneMapping:
  10049. toneMappingName = 'OptimizedCineon';
  10050. break;
  10051. case ACESFilmicToneMapping:
  10052. toneMappingName = 'ACESFilmic';
  10053. break;
  10054. default:
  10055. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10056. }
  10057. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10058. }
  10059. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10060. extensions = extensions || {};
  10061. var chunks = [
  10062. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10063. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10064. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10065. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10066. ];
  10067. return chunks.filter( filterEmptyLine ).join( '\n' );
  10068. }
  10069. function generateDefines( defines ) {
  10070. var chunks = [];
  10071. for ( var name in defines ) {
  10072. var value = defines[ name ];
  10073. if ( value === false ) continue;
  10074. chunks.push( '#define ' + name + ' ' + value );
  10075. }
  10076. return chunks.join( '\n' );
  10077. }
  10078. function fetchAttributeLocations( gl, program ) {
  10079. var attributes = {};
  10080. var n = gl.getProgramParameter( program, 35721 );
  10081. for ( var i = 0; i < n; i ++ ) {
  10082. var info = gl.getActiveAttrib( program, i );
  10083. var name = info.name;
  10084. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10085. attributes[ name ] = gl.getAttribLocation( program, name );
  10086. }
  10087. return attributes;
  10088. }
  10089. function filterEmptyLine( string ) {
  10090. return string !== '';
  10091. }
  10092. function replaceLightNums( string, parameters ) {
  10093. return string
  10094. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10095. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10096. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10097. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10098. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10099. }
  10100. function replaceClippingPlaneNums( string, parameters ) {
  10101. return string
  10102. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10103. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10104. }
  10105. function parseIncludes( string ) {
  10106. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10107. function replace( match, include ) {
  10108. var replace = ShaderChunk[ include ];
  10109. if ( replace === undefined ) {
  10110. throw new Error( 'Can not resolve #include <' + include + '>' );
  10111. }
  10112. return parseIncludes( replace );
  10113. }
  10114. return string.replace( pattern, replace );
  10115. }
  10116. function unrollLoops( string ) {
  10117. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10118. function replace( match, start, end, snippet ) {
  10119. var unroll = '';
  10120. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10121. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10122. }
  10123. return unroll;
  10124. }
  10125. return string.replace( pattern, replace );
  10126. }
  10127. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures ) {
  10128. var gl = renderer.context;
  10129. var defines = material.defines;
  10130. var vertexShader = shader.vertexShader;
  10131. var fragmentShader = shader.fragmentShader;
  10132. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10133. if ( parameters.shadowMapType === PCFShadowMap ) {
  10134. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10135. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10136. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10137. }
  10138. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10139. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10140. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10141. if ( parameters.envMap ) {
  10142. switch ( material.envMap.mapping ) {
  10143. case CubeReflectionMapping:
  10144. case CubeRefractionMapping:
  10145. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10146. break;
  10147. case CubeUVReflectionMapping:
  10148. case CubeUVRefractionMapping:
  10149. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10150. break;
  10151. case EquirectangularReflectionMapping:
  10152. case EquirectangularRefractionMapping:
  10153. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10154. break;
  10155. case SphericalReflectionMapping:
  10156. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10157. break;
  10158. }
  10159. switch ( material.envMap.mapping ) {
  10160. case CubeRefractionMapping:
  10161. case EquirectangularRefractionMapping:
  10162. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10163. break;
  10164. }
  10165. switch ( material.combine ) {
  10166. case MultiplyOperation:
  10167. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10168. break;
  10169. case MixOperation:
  10170. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10171. break;
  10172. case AddOperation:
  10173. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10174. break;
  10175. }
  10176. }
  10177. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10178. // console.log( 'building new program ' );
  10179. //
  10180. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10181. var customDefines = generateDefines( defines );
  10182. //
  10183. var program = gl.createProgram();
  10184. var prefixVertex, prefixFragment;
  10185. if ( material.isRawShaderMaterial ) {
  10186. prefixVertex = [
  10187. customDefines
  10188. ].filter( filterEmptyLine ).join( '\n' );
  10189. if ( prefixVertex.length > 0 ) {
  10190. prefixVertex += '\n';
  10191. }
  10192. prefixFragment = [
  10193. customExtensions,
  10194. customDefines
  10195. ].filter( filterEmptyLine ).join( '\n' );
  10196. if ( prefixFragment.length > 0 ) {
  10197. prefixFragment += '\n';
  10198. }
  10199. } else {
  10200. prefixVertex = [
  10201. 'precision ' + parameters.precision + ' float;',
  10202. 'precision ' + parameters.precision + ' int;',
  10203. '#define SHADER_NAME ' + shader.name,
  10204. customDefines,
  10205. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10206. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10207. '#define MAX_BONES ' + parameters.maxBones,
  10208. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10209. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10210. parameters.map ? '#define USE_MAP' : '',
  10211. parameters.envMap ? '#define USE_ENVMAP' : '',
  10212. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10213. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10214. parameters.aoMap ? '#define USE_AOMAP' : '',
  10215. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10216. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10217. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10218. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10219. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10220. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10221. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10222. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10223. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10224. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10225. parameters.vertexColors ? '#define USE_COLOR' : '',
  10226. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10227. parameters.skinning ? '#define USE_SKINNING' : '',
  10228. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10229. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10230. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10231. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10232. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10233. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10234. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10235. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10236. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10237. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10238. 'uniform mat4 modelMatrix;',
  10239. 'uniform mat4 modelViewMatrix;',
  10240. 'uniform mat4 projectionMatrix;',
  10241. 'uniform mat4 viewMatrix;',
  10242. 'uniform mat3 normalMatrix;',
  10243. 'uniform vec3 cameraPosition;',
  10244. 'attribute vec3 position;',
  10245. 'attribute vec3 normal;',
  10246. 'attribute vec2 uv;',
  10247. '#ifdef USE_TANGENT',
  10248. ' attribute vec4 tangent;',
  10249. '#endif',
  10250. '#ifdef USE_COLOR',
  10251. ' attribute vec3 color;',
  10252. '#endif',
  10253. '#ifdef USE_MORPHTARGETS',
  10254. ' attribute vec3 morphTarget0;',
  10255. ' attribute vec3 morphTarget1;',
  10256. ' attribute vec3 morphTarget2;',
  10257. ' attribute vec3 morphTarget3;',
  10258. ' #ifdef USE_MORPHNORMALS',
  10259. ' attribute vec3 morphNormal0;',
  10260. ' attribute vec3 morphNormal1;',
  10261. ' attribute vec3 morphNormal2;',
  10262. ' attribute vec3 morphNormal3;',
  10263. ' #else',
  10264. ' attribute vec3 morphTarget4;',
  10265. ' attribute vec3 morphTarget5;',
  10266. ' attribute vec3 morphTarget6;',
  10267. ' attribute vec3 morphTarget7;',
  10268. ' #endif',
  10269. '#endif',
  10270. '#ifdef USE_SKINNING',
  10271. ' attribute vec4 skinIndex;',
  10272. ' attribute vec4 skinWeight;',
  10273. '#endif',
  10274. '\n'
  10275. ].filter( filterEmptyLine ).join( '\n' );
  10276. prefixFragment = [
  10277. customExtensions,
  10278. 'precision ' + parameters.precision + ' float;',
  10279. 'precision ' + parameters.precision + ' int;',
  10280. '#define SHADER_NAME ' + shader.name,
  10281. customDefines,
  10282. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10283. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10284. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10285. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10286. parameters.map ? '#define USE_MAP' : '',
  10287. parameters.matcap ? '#define USE_MATCAP' : '',
  10288. parameters.envMap ? '#define USE_ENVMAP' : '',
  10289. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10290. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10291. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10292. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10293. parameters.aoMap ? '#define USE_AOMAP' : '',
  10294. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10295. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10296. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10297. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10298. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10299. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10300. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10301. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10302. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10303. parameters.vertexColors ? '#define USE_COLOR' : '',
  10304. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10305. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10306. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10307. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10308. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10309. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10310. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10311. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10312. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10313. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10314. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10315. 'uniform mat4 viewMatrix;',
  10316. 'uniform vec3 cameraPosition;',
  10317. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10318. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10319. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10320. parameters.dithering ? '#define DITHERING' : '',
  10321. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10322. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10323. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10324. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10325. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10326. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10327. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10328. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10329. '\n'
  10330. ].filter( filterEmptyLine ).join( '\n' );
  10331. }
  10332. vertexShader = parseIncludes( vertexShader );
  10333. vertexShader = replaceLightNums( vertexShader, parameters );
  10334. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10335. fragmentShader = parseIncludes( fragmentShader );
  10336. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10337. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10338. vertexShader = unrollLoops( vertexShader );
  10339. fragmentShader = unrollLoops( fragmentShader );
  10340. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10341. var isGLSL3ShaderMaterial = false;
  10342. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10343. if ( material.isShaderMaterial &&
  10344. vertexShader.match( versionRegex ) !== null &&
  10345. fragmentShader.match( versionRegex ) !== null ) {
  10346. isGLSL3ShaderMaterial = true;
  10347. vertexShader = vertexShader.replace( versionRegex, '' );
  10348. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10349. }
  10350. // GLSL 3.0 conversion
  10351. prefixVertex = [
  10352. '#version 300 es\n',
  10353. '#define attribute in',
  10354. '#define varying out',
  10355. '#define texture2D texture'
  10356. ].join( '\n' ) + '\n' + prefixVertex;
  10357. prefixFragment = [
  10358. '#version 300 es\n',
  10359. '#define varying in',
  10360. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10361. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10362. '#define gl_FragDepthEXT gl_FragDepth',
  10363. '#define texture2D texture',
  10364. '#define textureCube texture',
  10365. '#define texture2DProj textureProj',
  10366. '#define texture2DLodEXT textureLod',
  10367. '#define texture2DProjLodEXT textureProjLod',
  10368. '#define textureCubeLodEXT textureLod',
  10369. '#define texture2DGradEXT textureGrad',
  10370. '#define texture2DProjGradEXT textureProjGrad',
  10371. '#define textureCubeGradEXT textureGrad'
  10372. ].join( '\n' ) + '\n' + prefixFragment;
  10373. }
  10374. var vertexGlsl = prefixVertex + vertexShader;
  10375. var fragmentGlsl = prefixFragment + fragmentShader;
  10376. // console.log( '*VERTEX*', vertexGlsl );
  10377. // console.log( '*FRAGMENT*', fragmentGlsl );
  10378. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10379. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10380. gl.attachShader( program, glVertexShader );
  10381. gl.attachShader( program, glFragmentShader );
  10382. // Force a particular attribute to index 0.
  10383. if ( material.index0AttributeName !== undefined ) {
  10384. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10385. } else if ( parameters.morphTargets === true ) {
  10386. // programs with morphTargets displace position out of attribute 0
  10387. gl.bindAttribLocation( program, 0, 'position' );
  10388. }
  10389. gl.linkProgram( program );
  10390. var programLog = gl.getProgramInfoLog( program ).trim();
  10391. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10392. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10393. var runnable = true;
  10394. var haveDiagnostics = true;
  10395. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10396. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10397. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10398. runnable = false;
  10399. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10400. } else if ( programLog !== '' ) {
  10401. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10402. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10403. haveDiagnostics = false;
  10404. }
  10405. if ( haveDiagnostics ) {
  10406. this.diagnostics = {
  10407. runnable: runnable,
  10408. material: material,
  10409. programLog: programLog,
  10410. vertexShader: {
  10411. log: vertexLog,
  10412. prefix: prefixVertex
  10413. },
  10414. fragmentShader: {
  10415. log: fragmentLog,
  10416. prefix: prefixFragment
  10417. }
  10418. };
  10419. }
  10420. // clean up
  10421. gl.deleteShader( glVertexShader );
  10422. gl.deleteShader( glFragmentShader );
  10423. // set up caching for uniform locations
  10424. var cachedUniforms;
  10425. this.getUniforms = function () {
  10426. if ( cachedUniforms === undefined ) {
  10427. cachedUniforms = new WebGLUniforms( gl, program, textures );
  10428. }
  10429. return cachedUniforms;
  10430. };
  10431. // set up caching for attribute locations
  10432. var cachedAttributes;
  10433. this.getAttributes = function () {
  10434. if ( cachedAttributes === undefined ) {
  10435. cachedAttributes = fetchAttributeLocations( gl, program );
  10436. }
  10437. return cachedAttributes;
  10438. };
  10439. // free resource
  10440. this.destroy = function () {
  10441. gl.deleteProgram( program );
  10442. this.program = undefined;
  10443. };
  10444. // DEPRECATED
  10445. Object.defineProperties( this, {
  10446. uniforms: {
  10447. get: function () {
  10448. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10449. return this.getUniforms();
  10450. }
  10451. },
  10452. attributes: {
  10453. get: function () {
  10454. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10455. return this.getAttributes();
  10456. }
  10457. }
  10458. } );
  10459. //
  10460. this.name = shader.name;
  10461. this.id = programIdCount ++;
  10462. this.code = code;
  10463. this.usedTimes = 1;
  10464. this.program = program;
  10465. this.vertexShader = glVertexShader;
  10466. this.fragmentShader = glFragmentShader;
  10467. return this;
  10468. }
  10469. /**
  10470. * @author mrdoob / http://mrdoob.com/
  10471. */
  10472. function WebGLPrograms( renderer, extensions, capabilities, textures ) {
  10473. var programs = [];
  10474. var shaderIDs = {
  10475. MeshDepthMaterial: 'depth',
  10476. MeshDistanceMaterial: 'distanceRGBA',
  10477. MeshNormalMaterial: 'normal',
  10478. MeshBasicMaterial: 'basic',
  10479. MeshLambertMaterial: 'lambert',
  10480. MeshPhongMaterial: 'phong',
  10481. MeshToonMaterial: 'phong',
  10482. MeshStandardMaterial: 'physical',
  10483. MeshPhysicalMaterial: 'physical',
  10484. MeshMatcapMaterial: 'matcap',
  10485. LineBasicMaterial: 'basic',
  10486. LineDashedMaterial: 'dashed',
  10487. PointsMaterial: 'points',
  10488. ShadowMaterial: 'shadow',
  10489. SpriteMaterial: 'sprite'
  10490. };
  10491. var parameterNames = [
  10492. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10493. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10494. "roughnessMap", "metalnessMap", "gradientMap",
  10495. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10496. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10497. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10498. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10499. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10500. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10501. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10502. ];
  10503. function allocateBones( object ) {
  10504. var skeleton = object.skeleton;
  10505. var bones = skeleton.bones;
  10506. if ( capabilities.floatVertexTextures ) {
  10507. return 1024;
  10508. } else {
  10509. // default for when object is not specified
  10510. // ( for example when prebuilding shader to be used with multiple objects )
  10511. //
  10512. // - leave some extra space for other uniforms
  10513. // - limit here is ANGLE's 254 max uniform vectors
  10514. // (up to 54 should be safe)
  10515. var nVertexUniforms = capabilities.maxVertexUniforms;
  10516. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10517. var maxBones = Math.min( nVertexMatrices, bones.length );
  10518. if ( maxBones < bones.length ) {
  10519. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10520. return 0;
  10521. }
  10522. return maxBones;
  10523. }
  10524. }
  10525. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10526. var encoding;
  10527. if ( ! map ) {
  10528. encoding = LinearEncoding;
  10529. } else if ( map.isTexture ) {
  10530. encoding = map.encoding;
  10531. } else if ( map.isWebGLRenderTarget ) {
  10532. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10533. encoding = map.texture.encoding;
  10534. }
  10535. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10536. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10537. encoding = GammaEncoding;
  10538. }
  10539. return encoding;
  10540. }
  10541. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10542. var shaderID = shaderIDs[ material.type ];
  10543. // heuristics to create shader parameters according to lights in the scene
  10544. // (not to blow over maxLights budget)
  10545. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10546. var precision = capabilities.precision;
  10547. if ( material.precision !== null ) {
  10548. precision = capabilities.getMaxPrecision( material.precision );
  10549. if ( precision !== material.precision ) {
  10550. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10551. }
  10552. }
  10553. var currentRenderTarget = renderer.getRenderTarget();
  10554. var parameters = {
  10555. shaderID: shaderID,
  10556. precision: precision,
  10557. supportsVertexTextures: capabilities.vertexTextures,
  10558. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10559. map: !! material.map,
  10560. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10561. matcap: !! material.matcap,
  10562. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10563. envMap: !! material.envMap,
  10564. envMapMode: material.envMap && material.envMap.mapping,
  10565. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10566. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10567. lightMap: !! material.lightMap,
  10568. aoMap: !! material.aoMap,
  10569. emissiveMap: !! material.emissiveMap,
  10570. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10571. bumpMap: !! material.bumpMap,
  10572. normalMap: !! material.normalMap,
  10573. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10574. displacementMap: !! material.displacementMap,
  10575. roughnessMap: !! material.roughnessMap,
  10576. metalnessMap: !! material.metalnessMap,
  10577. specularMap: !! material.specularMap,
  10578. alphaMap: !! material.alphaMap,
  10579. gradientMap: !! material.gradientMap,
  10580. combine: material.combine,
  10581. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10582. vertexColors: material.vertexColors,
  10583. fog: !! fog,
  10584. useFog: material.fog,
  10585. fogExp: ( fog && fog.isFogExp2 ),
  10586. flatShading: material.flatShading,
  10587. sizeAttenuation: material.sizeAttenuation,
  10588. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10589. skinning: material.skinning && maxBones > 0,
  10590. maxBones: maxBones,
  10591. useVertexTexture: capabilities.floatVertexTextures,
  10592. morphTargets: material.morphTargets,
  10593. morphNormals: material.morphNormals,
  10594. maxMorphTargets: renderer.maxMorphTargets,
  10595. maxMorphNormals: renderer.maxMorphNormals,
  10596. numDirLights: lights.directional.length,
  10597. numPointLights: lights.point.length,
  10598. numSpotLights: lights.spot.length,
  10599. numRectAreaLights: lights.rectArea.length,
  10600. numHemiLights: lights.hemi.length,
  10601. numClippingPlanes: nClipPlanes,
  10602. numClipIntersection: nClipIntersection,
  10603. dithering: material.dithering,
  10604. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10605. shadowMapType: renderer.shadowMap.type,
  10606. toneMapping: renderer.toneMapping,
  10607. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10608. premultipliedAlpha: material.premultipliedAlpha,
  10609. alphaTest: material.alphaTest,
  10610. doubleSided: material.side === DoubleSide,
  10611. flipSided: material.side === BackSide,
  10612. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10613. };
  10614. return parameters;
  10615. };
  10616. this.getProgramCode = function ( material, parameters ) {
  10617. var array = [];
  10618. if ( parameters.shaderID ) {
  10619. array.push( parameters.shaderID );
  10620. } else {
  10621. array.push( material.fragmentShader );
  10622. array.push( material.vertexShader );
  10623. }
  10624. if ( material.defines !== undefined ) {
  10625. for ( var name in material.defines ) {
  10626. array.push( name );
  10627. array.push( material.defines[ name ] );
  10628. }
  10629. }
  10630. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10631. array.push( parameters[ parameterNames[ i ] ] );
  10632. }
  10633. array.push( material.onBeforeCompile.toString() );
  10634. array.push( renderer.gammaOutput );
  10635. array.push( renderer.gammaFactor );
  10636. return array.join();
  10637. };
  10638. this.acquireProgram = function ( material, shader, parameters, code ) {
  10639. var program;
  10640. // Check if code has been already compiled
  10641. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10642. var programInfo = programs[ p ];
  10643. if ( programInfo.code === code ) {
  10644. program = programInfo;
  10645. ++ program.usedTimes;
  10646. break;
  10647. }
  10648. }
  10649. if ( program === undefined ) {
  10650. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures );
  10651. programs.push( program );
  10652. }
  10653. return program;
  10654. };
  10655. this.releaseProgram = function ( program ) {
  10656. if ( -- program.usedTimes === 0 ) {
  10657. // Remove from unordered set
  10658. var i = programs.indexOf( program );
  10659. programs[ i ] = programs[ programs.length - 1 ];
  10660. programs.pop();
  10661. // Free WebGL resources
  10662. program.destroy();
  10663. }
  10664. };
  10665. // Exposed for resource monitoring & error feedback via renderer.info:
  10666. this.programs = programs;
  10667. }
  10668. /**
  10669. * @author fordacious / fordacious.github.io
  10670. */
  10671. function WebGLProperties() {
  10672. var properties = new WeakMap();
  10673. function get( object ) {
  10674. var map = properties.get( object );
  10675. if ( map === undefined ) {
  10676. map = {};
  10677. properties.set( object, map );
  10678. }
  10679. return map;
  10680. }
  10681. function remove( object ) {
  10682. properties.delete( object );
  10683. }
  10684. function update( object, key, value ) {
  10685. properties.get( object )[ key ] = value;
  10686. }
  10687. function dispose() {
  10688. properties = new WeakMap();
  10689. }
  10690. return {
  10691. get: get,
  10692. remove: remove,
  10693. update: update,
  10694. dispose: dispose
  10695. };
  10696. }
  10697. /**
  10698. * @author mrdoob / http://mrdoob.com/
  10699. */
  10700. function painterSortStable( a, b ) {
  10701. if ( a.groupOrder !== b.groupOrder ) {
  10702. return a.groupOrder - b.groupOrder;
  10703. } else if ( a.renderOrder !== b.renderOrder ) {
  10704. return a.renderOrder - b.renderOrder;
  10705. } else if ( a.program !== b.program ) {
  10706. return a.program.id - b.program.id;
  10707. } else if ( a.material.id !== b.material.id ) {
  10708. return a.material.id - b.material.id;
  10709. } else if ( a.z !== b.z ) {
  10710. return a.z - b.z;
  10711. } else {
  10712. return a.id - b.id;
  10713. }
  10714. }
  10715. function reversePainterSortStable( a, b ) {
  10716. if ( a.groupOrder !== b.groupOrder ) {
  10717. return a.groupOrder - b.groupOrder;
  10718. } else if ( a.renderOrder !== b.renderOrder ) {
  10719. return a.renderOrder - b.renderOrder;
  10720. } else if ( a.z !== b.z ) {
  10721. return b.z - a.z;
  10722. } else {
  10723. return a.id - b.id;
  10724. }
  10725. }
  10726. function WebGLRenderList() {
  10727. var renderItems = [];
  10728. var renderItemsIndex = 0;
  10729. var opaque = [];
  10730. var transparent = [];
  10731. var defaultProgram = { id: - 1 };
  10732. function init() {
  10733. renderItemsIndex = 0;
  10734. opaque.length = 0;
  10735. transparent.length = 0;
  10736. }
  10737. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10738. var renderItem = renderItems[ renderItemsIndex ];
  10739. if ( renderItem === undefined ) {
  10740. renderItem = {
  10741. id: object.id,
  10742. object: object,
  10743. geometry: geometry,
  10744. material: material,
  10745. program: material.program || defaultProgram,
  10746. groupOrder: groupOrder,
  10747. renderOrder: object.renderOrder,
  10748. z: z,
  10749. group: group
  10750. };
  10751. renderItems[ renderItemsIndex ] = renderItem;
  10752. } else {
  10753. renderItem.id = object.id;
  10754. renderItem.object = object;
  10755. renderItem.geometry = geometry;
  10756. renderItem.material = material;
  10757. renderItem.program = material.program || defaultProgram;
  10758. renderItem.groupOrder = groupOrder;
  10759. renderItem.renderOrder = object.renderOrder;
  10760. renderItem.z = z;
  10761. renderItem.group = group;
  10762. }
  10763. renderItemsIndex ++;
  10764. return renderItem;
  10765. }
  10766. function push( object, geometry, material, groupOrder, z, group ) {
  10767. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10768. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10769. }
  10770. function unshift( object, geometry, material, groupOrder, z, group ) {
  10771. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10772. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10773. }
  10774. function sort() {
  10775. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10776. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10777. }
  10778. return {
  10779. opaque: opaque,
  10780. transparent: transparent,
  10781. init: init,
  10782. push: push,
  10783. unshift: unshift,
  10784. sort: sort
  10785. };
  10786. }
  10787. function WebGLRenderLists() {
  10788. var lists = {};
  10789. function onSceneDispose( event ) {
  10790. var scene = event.target;
  10791. scene.removeEventListener( 'dispose', onSceneDispose );
  10792. delete lists[ scene.id ];
  10793. }
  10794. function get( scene, camera ) {
  10795. var cameras = lists[ scene.id ];
  10796. var list;
  10797. if ( cameras === undefined ) {
  10798. list = new WebGLRenderList();
  10799. lists[ scene.id ] = {};
  10800. lists[ scene.id ][ camera.id ] = list;
  10801. scene.addEventListener( 'dispose', onSceneDispose );
  10802. } else {
  10803. list = cameras[ camera.id ];
  10804. if ( list === undefined ) {
  10805. list = new WebGLRenderList();
  10806. cameras[ camera.id ] = list;
  10807. }
  10808. }
  10809. return list;
  10810. }
  10811. function dispose() {
  10812. lists = {};
  10813. }
  10814. return {
  10815. get: get,
  10816. dispose: dispose
  10817. };
  10818. }
  10819. /**
  10820. * @author mrdoob / http://mrdoob.com/
  10821. */
  10822. function UniformsCache() {
  10823. var lights = {};
  10824. return {
  10825. get: function ( light ) {
  10826. if ( lights[ light.id ] !== undefined ) {
  10827. return lights[ light.id ];
  10828. }
  10829. var uniforms;
  10830. switch ( light.type ) {
  10831. case 'DirectionalLight':
  10832. uniforms = {
  10833. direction: new Vector3(),
  10834. color: new Color(),
  10835. shadow: false,
  10836. shadowBias: 0,
  10837. shadowRadius: 1,
  10838. shadowMapSize: new Vector2()
  10839. };
  10840. break;
  10841. case 'SpotLight':
  10842. uniforms = {
  10843. position: new Vector3(),
  10844. direction: new Vector3(),
  10845. color: new Color(),
  10846. distance: 0,
  10847. coneCos: 0,
  10848. penumbraCos: 0,
  10849. decay: 0,
  10850. shadow: false,
  10851. shadowBias: 0,
  10852. shadowRadius: 1,
  10853. shadowMapSize: new Vector2()
  10854. };
  10855. break;
  10856. case 'PointLight':
  10857. uniforms = {
  10858. position: new Vector3(),
  10859. color: new Color(),
  10860. distance: 0,
  10861. decay: 0,
  10862. shadow: false,
  10863. shadowBias: 0,
  10864. shadowRadius: 1,
  10865. shadowMapSize: new Vector2(),
  10866. shadowCameraNear: 1,
  10867. shadowCameraFar: 1000
  10868. };
  10869. break;
  10870. case 'HemisphereLight':
  10871. uniforms = {
  10872. direction: new Vector3(),
  10873. skyColor: new Color(),
  10874. groundColor: new Color()
  10875. };
  10876. break;
  10877. case 'RectAreaLight':
  10878. uniforms = {
  10879. color: new Color(),
  10880. position: new Vector3(),
  10881. halfWidth: new Vector3(),
  10882. halfHeight: new Vector3()
  10883. // TODO (abelnation): set RectAreaLight shadow uniforms
  10884. };
  10885. break;
  10886. }
  10887. lights[ light.id ] = uniforms;
  10888. return uniforms;
  10889. }
  10890. };
  10891. }
  10892. var count = 0;
  10893. function WebGLLights() {
  10894. var cache = new UniformsCache();
  10895. var state = {
  10896. id: count ++,
  10897. hash: {
  10898. stateID: - 1,
  10899. directionalLength: - 1,
  10900. pointLength: - 1,
  10901. spotLength: - 1,
  10902. rectAreaLength: - 1,
  10903. hemiLength: - 1,
  10904. shadowsLength: - 1
  10905. },
  10906. ambient: [ 0, 0, 0 ],
  10907. probe: [],
  10908. directional: [],
  10909. directionalShadowMap: [],
  10910. directionalShadowMatrix: [],
  10911. spot: [],
  10912. spotShadowMap: [],
  10913. spotShadowMatrix: [],
  10914. rectArea: [],
  10915. point: [],
  10916. pointShadowMap: [],
  10917. pointShadowMatrix: [],
  10918. hemi: []
  10919. };
  10920. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  10921. var vector3 = new Vector3();
  10922. var matrix4 = new Matrix4();
  10923. var matrix42 = new Matrix4();
  10924. function setup( lights, shadows, camera ) {
  10925. var r = 0, g = 0, b = 0;
  10926. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  10927. var directionalLength = 0;
  10928. var pointLength = 0;
  10929. var spotLength = 0;
  10930. var rectAreaLength = 0;
  10931. var hemiLength = 0;
  10932. var viewMatrix = camera.matrixWorldInverse;
  10933. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10934. var light = lights[ i ];
  10935. var color = light.color;
  10936. var intensity = light.intensity;
  10937. var distance = light.distance;
  10938. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10939. if ( light.isAmbientLight ) {
  10940. r += color.r * intensity;
  10941. g += color.g * intensity;
  10942. b += color.b * intensity;
  10943. } else if ( light.isLightProbe ) {
  10944. for ( var j = 0; j < 9; j ++ ) {
  10945. var probe = state.probe[ j ];
  10946. var coeff = light.sh.coefficients[ j ];
  10947. probe.x += coeff.x * color.r * intensity;
  10948. probe.y += coeff.y * color.g * intensity;
  10949. probe.z += coeff.z * color.b * intensity;
  10950. }
  10951. } else if ( light.isDirectionalLight ) {
  10952. var uniforms = cache.get( light );
  10953. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10954. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10955. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10956. uniforms.direction.sub( vector3 );
  10957. uniforms.direction.transformDirection( viewMatrix );
  10958. uniforms.shadow = light.castShadow;
  10959. if ( light.castShadow ) {
  10960. var shadow = light.shadow;
  10961. uniforms.shadowBias = shadow.bias;
  10962. uniforms.shadowRadius = shadow.radius;
  10963. uniforms.shadowMapSize = shadow.mapSize;
  10964. }
  10965. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10966. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10967. state.directional[ directionalLength ] = uniforms;
  10968. directionalLength ++;
  10969. } else if ( light.isSpotLight ) {
  10970. var uniforms = cache.get( light );
  10971. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10972. uniforms.position.applyMatrix4( viewMatrix );
  10973. uniforms.color.copy( color ).multiplyScalar( intensity );
  10974. uniforms.distance = distance;
  10975. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10976. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10977. uniforms.direction.sub( vector3 );
  10978. uniforms.direction.transformDirection( viewMatrix );
  10979. uniforms.coneCos = Math.cos( light.angle );
  10980. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10981. uniforms.decay = light.decay;
  10982. uniforms.shadow = light.castShadow;
  10983. if ( light.castShadow ) {
  10984. var shadow = light.shadow;
  10985. uniforms.shadowBias = shadow.bias;
  10986. uniforms.shadowRadius = shadow.radius;
  10987. uniforms.shadowMapSize = shadow.mapSize;
  10988. }
  10989. state.spotShadowMap[ spotLength ] = shadowMap;
  10990. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10991. state.spot[ spotLength ] = uniforms;
  10992. spotLength ++;
  10993. } else if ( light.isRectAreaLight ) {
  10994. var uniforms = cache.get( light );
  10995. // (a) intensity is the total visible light emitted
  10996. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10997. // (b) intensity is the brightness of the light
  10998. uniforms.color.copy( color ).multiplyScalar( intensity );
  10999. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11000. uniforms.position.applyMatrix4( viewMatrix );
  11001. // extract local rotation of light to derive width/height half vectors
  11002. matrix42.identity();
  11003. matrix4.copy( light.matrixWorld );
  11004. matrix4.premultiply( viewMatrix );
  11005. matrix42.extractRotation( matrix4 );
  11006. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11007. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11008. uniforms.halfWidth.applyMatrix4( matrix42 );
  11009. uniforms.halfHeight.applyMatrix4( matrix42 );
  11010. // TODO (abelnation): RectAreaLight distance?
  11011. // uniforms.distance = distance;
  11012. state.rectArea[ rectAreaLength ] = uniforms;
  11013. rectAreaLength ++;
  11014. } else if ( light.isPointLight ) {
  11015. var uniforms = cache.get( light );
  11016. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11017. uniforms.position.applyMatrix4( viewMatrix );
  11018. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11019. uniforms.distance = light.distance;
  11020. uniforms.decay = light.decay;
  11021. uniforms.shadow = light.castShadow;
  11022. if ( light.castShadow ) {
  11023. var shadow = light.shadow;
  11024. uniforms.shadowBias = shadow.bias;
  11025. uniforms.shadowRadius = shadow.radius;
  11026. uniforms.shadowMapSize = shadow.mapSize;
  11027. uniforms.shadowCameraNear = shadow.camera.near;
  11028. uniforms.shadowCameraFar = shadow.camera.far;
  11029. }
  11030. state.pointShadowMap[ pointLength ] = shadowMap;
  11031. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11032. state.point[ pointLength ] = uniforms;
  11033. pointLength ++;
  11034. } else if ( light.isHemisphereLight ) {
  11035. var uniforms = cache.get( light );
  11036. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11037. uniforms.direction.transformDirection( viewMatrix );
  11038. uniforms.direction.normalize();
  11039. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11040. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11041. state.hemi[ hemiLength ] = uniforms;
  11042. hemiLength ++;
  11043. }
  11044. }
  11045. state.ambient[ 0 ] = r;
  11046. state.ambient[ 1 ] = g;
  11047. state.ambient[ 2 ] = b;
  11048. state.directional.length = directionalLength;
  11049. state.spot.length = spotLength;
  11050. state.rectArea.length = rectAreaLength;
  11051. state.point.length = pointLength;
  11052. state.hemi.length = hemiLength;
  11053. state.hash.stateID = state.id;
  11054. state.hash.directionalLength = directionalLength;
  11055. state.hash.pointLength = pointLength;
  11056. state.hash.spotLength = spotLength;
  11057. state.hash.rectAreaLength = rectAreaLength;
  11058. state.hash.hemiLength = hemiLength;
  11059. state.hash.shadowsLength = shadows.length;
  11060. }
  11061. return {
  11062. setup: setup,
  11063. state: state
  11064. };
  11065. }
  11066. /**
  11067. * @author Mugen87 / https://github.com/Mugen87
  11068. */
  11069. function WebGLRenderState() {
  11070. var lights = new WebGLLights();
  11071. var lightsArray = [];
  11072. var shadowsArray = [];
  11073. function init() {
  11074. lightsArray.length = 0;
  11075. shadowsArray.length = 0;
  11076. }
  11077. function pushLight( light ) {
  11078. lightsArray.push( light );
  11079. }
  11080. function pushShadow( shadowLight ) {
  11081. shadowsArray.push( shadowLight );
  11082. }
  11083. function setupLights( camera ) {
  11084. lights.setup( lightsArray, shadowsArray, camera );
  11085. }
  11086. var state = {
  11087. lightsArray: lightsArray,
  11088. shadowsArray: shadowsArray,
  11089. lights: lights
  11090. };
  11091. return {
  11092. init: init,
  11093. state: state,
  11094. setupLights: setupLights,
  11095. pushLight: pushLight,
  11096. pushShadow: pushShadow
  11097. };
  11098. }
  11099. function WebGLRenderStates() {
  11100. var renderStates = {};
  11101. function onSceneDispose( event ) {
  11102. var scene = event.target;
  11103. scene.removeEventListener( 'dispose', onSceneDispose );
  11104. delete renderStates[ scene.id ];
  11105. }
  11106. function get( scene, camera ) {
  11107. var renderState;
  11108. if ( renderStates[ scene.id ] === undefined ) {
  11109. renderState = new WebGLRenderState();
  11110. renderStates[ scene.id ] = {};
  11111. renderStates[ scene.id ][ camera.id ] = renderState;
  11112. scene.addEventListener( 'dispose', onSceneDispose );
  11113. } else {
  11114. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11115. renderState = new WebGLRenderState();
  11116. renderStates[ scene.id ][ camera.id ] = renderState;
  11117. } else {
  11118. renderState = renderStates[ scene.id ][ camera.id ];
  11119. }
  11120. }
  11121. return renderState;
  11122. }
  11123. function dispose() {
  11124. renderStates = {};
  11125. }
  11126. return {
  11127. get: get,
  11128. dispose: dispose
  11129. };
  11130. }
  11131. /**
  11132. * @author mrdoob / http://mrdoob.com/
  11133. * @author alteredq / http://alteredqualia.com/
  11134. * @author bhouston / https://clara.io
  11135. * @author WestLangley / http://github.com/WestLangley
  11136. *
  11137. * parameters = {
  11138. *
  11139. * opacity: <float>,
  11140. *
  11141. * map: new THREE.Texture( <Image> ),
  11142. *
  11143. * alphaMap: new THREE.Texture( <Image> ),
  11144. *
  11145. * displacementMap: new THREE.Texture( <Image> ),
  11146. * displacementScale: <float>,
  11147. * displacementBias: <float>,
  11148. *
  11149. * wireframe: <boolean>,
  11150. * wireframeLinewidth: <float>
  11151. * }
  11152. */
  11153. function MeshDepthMaterial( parameters ) {
  11154. Material.call( this );
  11155. this.type = 'MeshDepthMaterial';
  11156. this.depthPacking = BasicDepthPacking;
  11157. this.skinning = false;
  11158. this.morphTargets = false;
  11159. this.map = null;
  11160. this.alphaMap = null;
  11161. this.displacementMap = null;
  11162. this.displacementScale = 1;
  11163. this.displacementBias = 0;
  11164. this.wireframe = false;
  11165. this.wireframeLinewidth = 1;
  11166. this.fog = false;
  11167. this.lights = false;
  11168. this.setValues( parameters );
  11169. }
  11170. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11171. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11172. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11173. MeshDepthMaterial.prototype.copy = function ( source ) {
  11174. Material.prototype.copy.call( this, source );
  11175. this.depthPacking = source.depthPacking;
  11176. this.skinning = source.skinning;
  11177. this.morphTargets = source.morphTargets;
  11178. this.map = source.map;
  11179. this.alphaMap = source.alphaMap;
  11180. this.displacementMap = source.displacementMap;
  11181. this.displacementScale = source.displacementScale;
  11182. this.displacementBias = source.displacementBias;
  11183. this.wireframe = source.wireframe;
  11184. this.wireframeLinewidth = source.wireframeLinewidth;
  11185. return this;
  11186. };
  11187. /**
  11188. * @author WestLangley / http://github.com/WestLangley
  11189. *
  11190. * parameters = {
  11191. *
  11192. * referencePosition: <float>,
  11193. * nearDistance: <float>,
  11194. * farDistance: <float>,
  11195. *
  11196. * skinning: <bool>,
  11197. * morphTargets: <bool>,
  11198. *
  11199. * map: new THREE.Texture( <Image> ),
  11200. *
  11201. * alphaMap: new THREE.Texture( <Image> ),
  11202. *
  11203. * displacementMap: new THREE.Texture( <Image> ),
  11204. * displacementScale: <float>,
  11205. * displacementBias: <float>
  11206. *
  11207. * }
  11208. */
  11209. function MeshDistanceMaterial( parameters ) {
  11210. Material.call( this );
  11211. this.type = 'MeshDistanceMaterial';
  11212. this.referencePosition = new Vector3();
  11213. this.nearDistance = 1;
  11214. this.farDistance = 1000;
  11215. this.skinning = false;
  11216. this.morphTargets = false;
  11217. this.map = null;
  11218. this.alphaMap = null;
  11219. this.displacementMap = null;
  11220. this.displacementScale = 1;
  11221. this.displacementBias = 0;
  11222. this.fog = false;
  11223. this.lights = false;
  11224. this.setValues( parameters );
  11225. }
  11226. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11227. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11228. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11229. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11230. Material.prototype.copy.call( this, source );
  11231. this.referencePosition.copy( source.referencePosition );
  11232. this.nearDistance = source.nearDistance;
  11233. this.farDistance = source.farDistance;
  11234. this.skinning = source.skinning;
  11235. this.morphTargets = source.morphTargets;
  11236. this.map = source.map;
  11237. this.alphaMap = source.alphaMap;
  11238. this.displacementMap = source.displacementMap;
  11239. this.displacementScale = source.displacementScale;
  11240. this.displacementBias = source.displacementBias;
  11241. return this;
  11242. };
  11243. /**
  11244. * @author alteredq / http://alteredqualia.com/
  11245. * @author mrdoob / http://mrdoob.com/
  11246. */
  11247. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11248. var _frustum = new Frustum(),
  11249. _projScreenMatrix = new Matrix4(),
  11250. _shadowMapSize = new Vector2(),
  11251. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11252. _lookTarget = new Vector3(),
  11253. _lightPositionWorld = new Vector3(),
  11254. _MorphingFlag = 1,
  11255. _SkinningFlag = 2,
  11256. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11257. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11258. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11259. _materialCache = {};
  11260. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11261. var cubeDirections = [
  11262. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11263. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11264. ];
  11265. var cubeUps = [
  11266. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11267. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11268. ];
  11269. var cube2DViewPorts = [
  11270. new Vector4(), new Vector4(), new Vector4(),
  11271. new Vector4(), new Vector4(), new Vector4()
  11272. ];
  11273. // init
  11274. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11275. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11276. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11277. var depthMaterial = new MeshDepthMaterial( {
  11278. depthPacking: RGBADepthPacking,
  11279. morphTargets: useMorphing,
  11280. skinning: useSkinning
  11281. } );
  11282. _depthMaterials[ i ] = depthMaterial;
  11283. //
  11284. var distanceMaterial = new MeshDistanceMaterial( {
  11285. morphTargets: useMorphing,
  11286. skinning: useSkinning
  11287. } );
  11288. _distanceMaterials[ i ] = distanceMaterial;
  11289. }
  11290. //
  11291. var scope = this;
  11292. this.enabled = false;
  11293. this.autoUpdate = true;
  11294. this.needsUpdate = false;
  11295. this.type = PCFShadowMap;
  11296. this.render = function ( lights, scene, camera ) {
  11297. if ( scope.enabled === false ) return;
  11298. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11299. if ( lights.length === 0 ) return;
  11300. var currentRenderTarget = _renderer.getRenderTarget();
  11301. var _state = _renderer.state;
  11302. // Set GL state for depth map.
  11303. _state.setBlending( NoBlending );
  11304. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11305. _state.buffers.depth.setTest( true );
  11306. _state.setScissorTest( false );
  11307. // render depth map
  11308. var faceCount;
  11309. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11310. var light = lights[ i ];
  11311. var shadow = light.shadow;
  11312. var isPointLight = light && light.isPointLight;
  11313. if ( shadow === undefined ) {
  11314. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11315. continue;
  11316. }
  11317. var shadowCamera = shadow.camera;
  11318. _shadowMapSize.copy( shadow.mapSize );
  11319. _shadowMapSize.min( _maxShadowMapSize );
  11320. if ( isPointLight ) {
  11321. var vpWidth = _shadowMapSize.x;
  11322. var vpHeight = _shadowMapSize.y;
  11323. // These viewports map a cube-map onto a 2D texture with the
  11324. // following orientation:
  11325. //
  11326. // xzXZ
  11327. // y Y
  11328. //
  11329. // X - Positive x direction
  11330. // x - Negative x direction
  11331. // Y - Positive y direction
  11332. // y - Negative y direction
  11333. // Z - Positive z direction
  11334. // z - Negative z direction
  11335. // positive X
  11336. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11337. // negative X
  11338. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11339. // positive Z
  11340. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11341. // negative Z
  11342. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11343. // positive Y
  11344. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11345. // negative Y
  11346. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11347. _shadowMapSize.x *= 4.0;
  11348. _shadowMapSize.y *= 2.0;
  11349. }
  11350. if ( shadow.map === null ) {
  11351. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11352. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11353. shadow.map.texture.name = light.name + ".shadowMap";
  11354. shadowCamera.updateProjectionMatrix();
  11355. }
  11356. if ( shadow.isSpotLightShadow ) {
  11357. shadow.update( light );
  11358. }
  11359. var shadowMap = shadow.map;
  11360. var shadowMatrix = shadow.matrix;
  11361. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11362. shadowCamera.position.copy( _lightPositionWorld );
  11363. if ( isPointLight ) {
  11364. faceCount = 6;
  11365. // for point lights we set the shadow matrix to be a translation-only matrix
  11366. // equal to inverse of the light's position
  11367. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11368. } else {
  11369. faceCount = 1;
  11370. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11371. shadowCamera.lookAt( _lookTarget );
  11372. shadowCamera.updateMatrixWorld();
  11373. // compute shadow matrix
  11374. shadowMatrix.set(
  11375. 0.5, 0.0, 0.0, 0.5,
  11376. 0.0, 0.5, 0.0, 0.5,
  11377. 0.0, 0.0, 0.5, 0.5,
  11378. 0.0, 0.0, 0.0, 1.0
  11379. );
  11380. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11381. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11382. }
  11383. _renderer.setRenderTarget( shadowMap );
  11384. _renderer.clear();
  11385. // render shadow map for each cube face (if omni-directional) or
  11386. // run a single pass if not
  11387. for ( var face = 0; face < faceCount; face ++ ) {
  11388. if ( isPointLight ) {
  11389. _lookTarget.copy( shadowCamera.position );
  11390. _lookTarget.add( cubeDirections[ face ] );
  11391. shadowCamera.up.copy( cubeUps[ face ] );
  11392. shadowCamera.lookAt( _lookTarget );
  11393. shadowCamera.updateMatrixWorld();
  11394. var vpDimensions = cube2DViewPorts[ face ];
  11395. _state.viewport( vpDimensions );
  11396. }
  11397. // update camera matrices and frustum
  11398. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11399. _frustum.setFromMatrix( _projScreenMatrix );
  11400. // set object matrices & frustum culling
  11401. renderObject( scene, camera, shadowCamera, isPointLight );
  11402. }
  11403. }
  11404. scope.needsUpdate = false;
  11405. _renderer.setRenderTarget( currentRenderTarget );
  11406. };
  11407. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11408. var geometry = object.geometry;
  11409. var result = null;
  11410. var materialVariants = _depthMaterials;
  11411. var customMaterial = object.customDepthMaterial;
  11412. if ( isPointLight ) {
  11413. materialVariants = _distanceMaterials;
  11414. customMaterial = object.customDistanceMaterial;
  11415. }
  11416. if ( ! customMaterial ) {
  11417. var useMorphing = false;
  11418. if ( material.morphTargets ) {
  11419. if ( geometry && geometry.isBufferGeometry ) {
  11420. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11421. } else if ( geometry && geometry.isGeometry ) {
  11422. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11423. }
  11424. }
  11425. if ( object.isSkinnedMesh && material.skinning === false ) {
  11426. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11427. }
  11428. var useSkinning = object.isSkinnedMesh && material.skinning;
  11429. var variantIndex = 0;
  11430. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11431. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11432. result = materialVariants[ variantIndex ];
  11433. } else {
  11434. result = customMaterial;
  11435. }
  11436. if ( _renderer.localClippingEnabled &&
  11437. material.clipShadows === true &&
  11438. material.clippingPlanes.length !== 0 ) {
  11439. // in this case we need a unique material instance reflecting the
  11440. // appropriate state
  11441. var keyA = result.uuid, keyB = material.uuid;
  11442. var materialsForVariant = _materialCache[ keyA ];
  11443. if ( materialsForVariant === undefined ) {
  11444. materialsForVariant = {};
  11445. _materialCache[ keyA ] = materialsForVariant;
  11446. }
  11447. var cachedMaterial = materialsForVariant[ keyB ];
  11448. if ( cachedMaterial === undefined ) {
  11449. cachedMaterial = result.clone();
  11450. materialsForVariant[ keyB ] = cachedMaterial;
  11451. }
  11452. result = cachedMaterial;
  11453. }
  11454. result.visible = material.visible;
  11455. result.wireframe = material.wireframe;
  11456. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11457. result.clipShadows = material.clipShadows;
  11458. result.clippingPlanes = material.clippingPlanes;
  11459. result.clipIntersection = material.clipIntersection;
  11460. result.wireframeLinewidth = material.wireframeLinewidth;
  11461. result.linewidth = material.linewidth;
  11462. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11463. result.referencePosition.copy( lightPositionWorld );
  11464. result.nearDistance = shadowCameraNear;
  11465. result.farDistance = shadowCameraFar;
  11466. }
  11467. return result;
  11468. }
  11469. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11470. if ( object.visible === false ) return;
  11471. var visible = object.layers.test( camera.layers );
  11472. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11473. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11474. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11475. var geometry = _objects.update( object );
  11476. var material = object.material;
  11477. if ( Array.isArray( material ) ) {
  11478. var groups = geometry.groups;
  11479. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11480. var group = groups[ k ];
  11481. var groupMaterial = material[ group.materialIndex ];
  11482. if ( groupMaterial && groupMaterial.visible ) {
  11483. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11484. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11485. }
  11486. }
  11487. } else if ( material.visible ) {
  11488. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11489. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11490. }
  11491. }
  11492. }
  11493. var children = object.children;
  11494. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11495. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11496. }
  11497. }
  11498. }
  11499. /**
  11500. * @author mrdoob / http://mrdoob.com/
  11501. */
  11502. function WebGLState( gl, extensions, utils, capabilities ) {
  11503. function ColorBuffer() {
  11504. var locked = false;
  11505. var color = new Vector4();
  11506. var currentColorMask = null;
  11507. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11508. return {
  11509. setMask: function ( colorMask ) {
  11510. if ( currentColorMask !== colorMask && ! locked ) {
  11511. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11512. currentColorMask = colorMask;
  11513. }
  11514. },
  11515. setLocked: function ( lock ) {
  11516. locked = lock;
  11517. },
  11518. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11519. if ( premultipliedAlpha === true ) {
  11520. r *= a; g *= a; b *= a;
  11521. }
  11522. color.set( r, g, b, a );
  11523. if ( currentColorClear.equals( color ) === false ) {
  11524. gl.clearColor( r, g, b, a );
  11525. currentColorClear.copy( color );
  11526. }
  11527. },
  11528. reset: function () {
  11529. locked = false;
  11530. currentColorMask = null;
  11531. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11532. }
  11533. };
  11534. }
  11535. function DepthBuffer() {
  11536. var locked = false;
  11537. var currentDepthMask = null;
  11538. var currentDepthFunc = null;
  11539. var currentDepthClear = null;
  11540. return {
  11541. setTest: function ( depthTest ) {
  11542. if ( depthTest ) {
  11543. enable( 2929 );
  11544. } else {
  11545. disable( 2929 );
  11546. }
  11547. },
  11548. setMask: function ( depthMask ) {
  11549. if ( currentDepthMask !== depthMask && ! locked ) {
  11550. gl.depthMask( depthMask );
  11551. currentDepthMask = depthMask;
  11552. }
  11553. },
  11554. setFunc: function ( depthFunc ) {
  11555. if ( currentDepthFunc !== depthFunc ) {
  11556. if ( depthFunc ) {
  11557. switch ( depthFunc ) {
  11558. case NeverDepth:
  11559. gl.depthFunc( 512 );
  11560. break;
  11561. case AlwaysDepth:
  11562. gl.depthFunc( 519 );
  11563. break;
  11564. case LessDepth:
  11565. gl.depthFunc( 513 );
  11566. break;
  11567. case LessEqualDepth:
  11568. gl.depthFunc( 515 );
  11569. break;
  11570. case EqualDepth:
  11571. gl.depthFunc( 514 );
  11572. break;
  11573. case GreaterEqualDepth:
  11574. gl.depthFunc( 518 );
  11575. break;
  11576. case GreaterDepth:
  11577. gl.depthFunc( 516 );
  11578. break;
  11579. case NotEqualDepth:
  11580. gl.depthFunc( 517 );
  11581. break;
  11582. default:
  11583. gl.depthFunc( 515 );
  11584. }
  11585. } else {
  11586. gl.depthFunc( 515 );
  11587. }
  11588. currentDepthFunc = depthFunc;
  11589. }
  11590. },
  11591. setLocked: function ( lock ) {
  11592. locked = lock;
  11593. },
  11594. setClear: function ( depth ) {
  11595. if ( currentDepthClear !== depth ) {
  11596. gl.clearDepth( depth );
  11597. currentDepthClear = depth;
  11598. }
  11599. },
  11600. reset: function () {
  11601. locked = false;
  11602. currentDepthMask = null;
  11603. currentDepthFunc = null;
  11604. currentDepthClear = null;
  11605. }
  11606. };
  11607. }
  11608. function StencilBuffer() {
  11609. var locked = false;
  11610. var currentStencilMask = null;
  11611. var currentStencilFunc = null;
  11612. var currentStencilRef = null;
  11613. var currentStencilFuncMask = null;
  11614. var currentStencilFail = null;
  11615. var currentStencilZFail = null;
  11616. var currentStencilZPass = null;
  11617. var currentStencilClear = null;
  11618. return {
  11619. setTest: function ( stencilTest ) {
  11620. if ( stencilTest ) {
  11621. enable( 2960 );
  11622. } else {
  11623. disable( 2960 );
  11624. }
  11625. },
  11626. setMask: function ( stencilMask ) {
  11627. if ( currentStencilMask !== stencilMask && ! locked ) {
  11628. gl.stencilMask( stencilMask );
  11629. currentStencilMask = stencilMask;
  11630. }
  11631. },
  11632. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11633. if ( currentStencilFunc !== stencilFunc ||
  11634. currentStencilRef !== stencilRef ||
  11635. currentStencilFuncMask !== stencilMask ) {
  11636. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11637. currentStencilFunc = stencilFunc;
  11638. currentStencilRef = stencilRef;
  11639. currentStencilFuncMask = stencilMask;
  11640. }
  11641. },
  11642. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11643. if ( currentStencilFail !== stencilFail ||
  11644. currentStencilZFail !== stencilZFail ||
  11645. currentStencilZPass !== stencilZPass ) {
  11646. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11647. currentStencilFail = stencilFail;
  11648. currentStencilZFail = stencilZFail;
  11649. currentStencilZPass = stencilZPass;
  11650. }
  11651. },
  11652. setLocked: function ( lock ) {
  11653. locked = lock;
  11654. },
  11655. setClear: function ( stencil ) {
  11656. if ( currentStencilClear !== stencil ) {
  11657. gl.clearStencil( stencil );
  11658. currentStencilClear = stencil;
  11659. }
  11660. },
  11661. reset: function () {
  11662. locked = false;
  11663. currentStencilMask = null;
  11664. currentStencilFunc = null;
  11665. currentStencilRef = null;
  11666. currentStencilFuncMask = null;
  11667. currentStencilFail = null;
  11668. currentStencilZFail = null;
  11669. currentStencilZPass = null;
  11670. currentStencilClear = null;
  11671. }
  11672. };
  11673. }
  11674. //
  11675. var colorBuffer = new ColorBuffer();
  11676. var depthBuffer = new DepthBuffer();
  11677. var stencilBuffer = new StencilBuffer();
  11678. var maxVertexAttributes = gl.getParameter( 34921 );
  11679. var newAttributes = new Uint8Array( maxVertexAttributes );
  11680. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11681. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11682. var enabledCapabilities = {};
  11683. var compressedTextureFormats = null;
  11684. var currentProgram = null;
  11685. var currentBlendingEnabled = null;
  11686. var currentBlending = null;
  11687. var currentBlendEquation = null;
  11688. var currentBlendSrc = null;
  11689. var currentBlendDst = null;
  11690. var currentBlendEquationAlpha = null;
  11691. var currentBlendSrcAlpha = null;
  11692. var currentBlendDstAlpha = null;
  11693. var currentPremultipledAlpha = false;
  11694. var currentFlipSided = null;
  11695. var currentCullFace = null;
  11696. var currentLineWidth = null;
  11697. var currentPolygonOffsetFactor = null;
  11698. var currentPolygonOffsetUnits = null;
  11699. var maxTextures = gl.getParameter( 35661 );
  11700. var lineWidthAvailable = false;
  11701. var version = 0;
  11702. var glVersion = gl.getParameter( 7938 );
  11703. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11704. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11705. lineWidthAvailable = ( version >= 1.0 );
  11706. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11707. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11708. lineWidthAvailable = ( version >= 2.0 );
  11709. }
  11710. var currentTextureSlot = null;
  11711. var currentBoundTextures = {};
  11712. var currentScissor = new Vector4();
  11713. var currentViewport = new Vector4();
  11714. function createTexture( type, target, count ) {
  11715. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11716. var texture = gl.createTexture();
  11717. gl.bindTexture( type, texture );
  11718. gl.texParameteri( type, 10241, 9728 );
  11719. gl.texParameteri( type, 10240, 9728 );
  11720. for ( var i = 0; i < count; i ++ ) {
  11721. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11722. }
  11723. return texture;
  11724. }
  11725. var emptyTextures = {};
  11726. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11727. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11728. // init
  11729. colorBuffer.setClear( 0, 0, 0, 1 );
  11730. depthBuffer.setClear( 1 );
  11731. stencilBuffer.setClear( 0 );
  11732. enable( 2929 );
  11733. depthBuffer.setFunc( LessEqualDepth );
  11734. setFlipSided( false );
  11735. setCullFace( CullFaceBack );
  11736. enable( 2884 );
  11737. setBlending( NoBlending );
  11738. //
  11739. function initAttributes() {
  11740. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11741. newAttributes[ i ] = 0;
  11742. }
  11743. }
  11744. function enableAttribute( attribute ) {
  11745. enableAttributeAndDivisor( attribute, 0 );
  11746. }
  11747. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11748. newAttributes[ attribute ] = 1;
  11749. if ( enabledAttributes[ attribute ] === 0 ) {
  11750. gl.enableVertexAttribArray( attribute );
  11751. enabledAttributes[ attribute ] = 1;
  11752. }
  11753. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11754. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  11755. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  11756. attributeDivisors[ attribute ] = meshPerAttribute;
  11757. }
  11758. }
  11759. function disableUnusedAttributes() {
  11760. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11761. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11762. gl.disableVertexAttribArray( i );
  11763. enabledAttributes[ i ] = 0;
  11764. }
  11765. }
  11766. }
  11767. function enable( id ) {
  11768. if ( enabledCapabilities[ id ] !== true ) {
  11769. gl.enable( id );
  11770. enabledCapabilities[ id ] = true;
  11771. }
  11772. }
  11773. function disable( id ) {
  11774. if ( enabledCapabilities[ id ] !== false ) {
  11775. gl.disable( id );
  11776. enabledCapabilities[ id ] = false;
  11777. }
  11778. }
  11779. function getCompressedTextureFormats() {
  11780. if ( compressedTextureFormats === null ) {
  11781. compressedTextureFormats = [];
  11782. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11783. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11784. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11785. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11786. var formats = gl.getParameter( 34467 );
  11787. for ( var i = 0; i < formats.length; i ++ ) {
  11788. compressedTextureFormats.push( formats[ i ] );
  11789. }
  11790. }
  11791. }
  11792. return compressedTextureFormats;
  11793. }
  11794. function useProgram( program ) {
  11795. if ( currentProgram !== program ) {
  11796. gl.useProgram( program );
  11797. currentProgram = program;
  11798. return true;
  11799. }
  11800. return false;
  11801. }
  11802. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11803. if ( blending === NoBlending ) {
  11804. if ( currentBlendingEnabled ) {
  11805. disable( 3042 );
  11806. currentBlendingEnabled = false;
  11807. }
  11808. return;
  11809. }
  11810. if ( ! currentBlendingEnabled ) {
  11811. enable( 3042 );
  11812. currentBlendingEnabled = true;
  11813. }
  11814. if ( blending !== CustomBlending ) {
  11815. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11816. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11817. gl.blendEquation( 32774 );
  11818. currentBlendEquation = AddEquation;
  11819. currentBlendEquationAlpha = AddEquation;
  11820. }
  11821. if ( premultipliedAlpha ) {
  11822. switch ( blending ) {
  11823. case NormalBlending:
  11824. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11825. break;
  11826. case AdditiveBlending:
  11827. gl.blendFunc( 1, 1 );
  11828. break;
  11829. case SubtractiveBlending:
  11830. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11831. break;
  11832. case MultiplyBlending:
  11833. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11834. break;
  11835. default:
  11836. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11837. break;
  11838. }
  11839. } else {
  11840. switch ( blending ) {
  11841. case NormalBlending:
  11842. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11843. break;
  11844. case AdditiveBlending:
  11845. gl.blendFunc( 770, 1 );
  11846. break;
  11847. case SubtractiveBlending:
  11848. gl.blendFunc( 0, 769 );
  11849. break;
  11850. case MultiplyBlending:
  11851. gl.blendFunc( 0, 768 );
  11852. break;
  11853. default:
  11854. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11855. break;
  11856. }
  11857. }
  11858. currentBlendSrc = null;
  11859. currentBlendDst = null;
  11860. currentBlendSrcAlpha = null;
  11861. currentBlendDstAlpha = null;
  11862. currentBlending = blending;
  11863. currentPremultipledAlpha = premultipliedAlpha;
  11864. }
  11865. return;
  11866. }
  11867. // custom blending
  11868. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11869. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11870. blendDstAlpha = blendDstAlpha || blendDst;
  11871. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11872. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11873. currentBlendEquation = blendEquation;
  11874. currentBlendEquationAlpha = blendEquationAlpha;
  11875. }
  11876. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11877. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11878. currentBlendSrc = blendSrc;
  11879. currentBlendDst = blendDst;
  11880. currentBlendSrcAlpha = blendSrcAlpha;
  11881. currentBlendDstAlpha = blendDstAlpha;
  11882. }
  11883. currentBlending = blending;
  11884. currentPremultipledAlpha = null;
  11885. }
  11886. function setMaterial( material, frontFaceCW ) {
  11887. material.side === DoubleSide
  11888. ? disable( 2884 )
  11889. : enable( 2884 );
  11890. var flipSided = ( material.side === BackSide );
  11891. if ( frontFaceCW ) flipSided = ! flipSided;
  11892. setFlipSided( flipSided );
  11893. ( material.blending === NormalBlending && material.transparent === false )
  11894. ? setBlending( NoBlending )
  11895. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11896. depthBuffer.setFunc( material.depthFunc );
  11897. depthBuffer.setTest( material.depthTest );
  11898. depthBuffer.setMask( material.depthWrite );
  11899. colorBuffer.setMask( material.colorWrite );
  11900. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11901. }
  11902. //
  11903. function setFlipSided( flipSided ) {
  11904. if ( currentFlipSided !== flipSided ) {
  11905. if ( flipSided ) {
  11906. gl.frontFace( 2304 );
  11907. } else {
  11908. gl.frontFace( 2305 );
  11909. }
  11910. currentFlipSided = flipSided;
  11911. }
  11912. }
  11913. function setCullFace( cullFace ) {
  11914. if ( cullFace !== CullFaceNone ) {
  11915. enable( 2884 );
  11916. if ( cullFace !== currentCullFace ) {
  11917. if ( cullFace === CullFaceBack ) {
  11918. gl.cullFace( 1029 );
  11919. } else if ( cullFace === CullFaceFront ) {
  11920. gl.cullFace( 1028 );
  11921. } else {
  11922. gl.cullFace( 1032 );
  11923. }
  11924. }
  11925. } else {
  11926. disable( 2884 );
  11927. }
  11928. currentCullFace = cullFace;
  11929. }
  11930. function setLineWidth( width ) {
  11931. if ( width !== currentLineWidth ) {
  11932. if ( lineWidthAvailable ) gl.lineWidth( width );
  11933. currentLineWidth = width;
  11934. }
  11935. }
  11936. function setPolygonOffset( polygonOffset, factor, units ) {
  11937. if ( polygonOffset ) {
  11938. enable( 32823 );
  11939. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11940. gl.polygonOffset( factor, units );
  11941. currentPolygonOffsetFactor = factor;
  11942. currentPolygonOffsetUnits = units;
  11943. }
  11944. } else {
  11945. disable( 32823 );
  11946. }
  11947. }
  11948. function setScissorTest( scissorTest ) {
  11949. if ( scissorTest ) {
  11950. enable( 3089 );
  11951. } else {
  11952. disable( 3089 );
  11953. }
  11954. }
  11955. // texture
  11956. function activeTexture( webglSlot ) {
  11957. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11958. if ( currentTextureSlot !== webglSlot ) {
  11959. gl.activeTexture( webglSlot );
  11960. currentTextureSlot = webglSlot;
  11961. }
  11962. }
  11963. function bindTexture( webglType, webglTexture ) {
  11964. if ( currentTextureSlot === null ) {
  11965. activeTexture();
  11966. }
  11967. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11968. if ( boundTexture === undefined ) {
  11969. boundTexture = { type: undefined, texture: undefined };
  11970. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11971. }
  11972. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11973. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11974. boundTexture.type = webglType;
  11975. boundTexture.texture = webglTexture;
  11976. }
  11977. }
  11978. function compressedTexImage2D() {
  11979. try {
  11980. gl.compressedTexImage2D.apply( gl, arguments );
  11981. } catch ( error ) {
  11982. console.error( 'THREE.WebGLState:', error );
  11983. }
  11984. }
  11985. function texImage2D() {
  11986. try {
  11987. gl.texImage2D.apply( gl, arguments );
  11988. } catch ( error ) {
  11989. console.error( 'THREE.WebGLState:', error );
  11990. }
  11991. }
  11992. function texImage3D() {
  11993. try {
  11994. gl.texImage3D.apply( gl, arguments );
  11995. } catch ( error ) {
  11996. console.error( 'THREE.WebGLState:', error );
  11997. }
  11998. }
  11999. //
  12000. function scissor( scissor ) {
  12001. if ( currentScissor.equals( scissor ) === false ) {
  12002. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12003. currentScissor.copy( scissor );
  12004. }
  12005. }
  12006. function viewport( viewport ) {
  12007. if ( currentViewport.equals( viewport ) === false ) {
  12008. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12009. currentViewport.copy( viewport );
  12010. }
  12011. }
  12012. //
  12013. function reset() {
  12014. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12015. if ( enabledAttributes[ i ] === 1 ) {
  12016. gl.disableVertexAttribArray( i );
  12017. enabledAttributes[ i ] = 0;
  12018. }
  12019. }
  12020. enabledCapabilities = {};
  12021. compressedTextureFormats = null;
  12022. currentTextureSlot = null;
  12023. currentBoundTextures = {};
  12024. currentProgram = null;
  12025. currentBlending = null;
  12026. currentFlipSided = null;
  12027. currentCullFace = null;
  12028. colorBuffer.reset();
  12029. depthBuffer.reset();
  12030. stencilBuffer.reset();
  12031. }
  12032. return {
  12033. buffers: {
  12034. color: colorBuffer,
  12035. depth: depthBuffer,
  12036. stencil: stencilBuffer
  12037. },
  12038. initAttributes: initAttributes,
  12039. enableAttribute: enableAttribute,
  12040. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12041. disableUnusedAttributes: disableUnusedAttributes,
  12042. enable: enable,
  12043. disable: disable,
  12044. getCompressedTextureFormats: getCompressedTextureFormats,
  12045. useProgram: useProgram,
  12046. setBlending: setBlending,
  12047. setMaterial: setMaterial,
  12048. setFlipSided: setFlipSided,
  12049. setCullFace: setCullFace,
  12050. setLineWidth: setLineWidth,
  12051. setPolygonOffset: setPolygonOffset,
  12052. setScissorTest: setScissorTest,
  12053. activeTexture: activeTexture,
  12054. bindTexture: bindTexture,
  12055. compressedTexImage2D: compressedTexImage2D,
  12056. texImage2D: texImage2D,
  12057. texImage3D: texImage3D,
  12058. scissor: scissor,
  12059. viewport: viewport,
  12060. reset: reset
  12061. };
  12062. }
  12063. /**
  12064. * @author mrdoob / http://mrdoob.com/
  12065. */
  12066. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12067. var _videoTextures = {};
  12068. var _canvas;
  12069. //
  12070. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12071. function createCanvas( width, height ) {
  12072. // Use OffscreenCanvas when available. Specially needed in web workers
  12073. return useOffscreenCanvas ?
  12074. new OffscreenCanvas( width, height ) :
  12075. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12076. }
  12077. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12078. var scale = 1;
  12079. // handle case if texture exceeds max size
  12080. if ( image.width > maxSize || image.height > maxSize ) {
  12081. scale = maxSize / Math.max( image.width, image.height );
  12082. }
  12083. // only perform resize if necessary
  12084. if ( scale < 1 || needsPowerOfTwo === true ) {
  12085. // only perform resize for certain image types
  12086. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12087. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12088. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12089. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12090. var width = floor( scale * image.width );
  12091. var height = floor( scale * image.height );
  12092. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12093. // cube textures can't reuse the same canvas
  12094. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12095. canvas.width = width;
  12096. canvas.height = height;
  12097. var context = canvas.getContext( '2d' );
  12098. context.drawImage( image, 0, 0, width, height );
  12099. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12100. return canvas;
  12101. } else {
  12102. if ( 'data' in image ) {
  12103. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12104. }
  12105. return image;
  12106. }
  12107. }
  12108. return image;
  12109. }
  12110. function isPowerOfTwo( image ) {
  12111. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12112. }
  12113. function textureNeedsPowerOfTwo( texture ) {
  12114. if ( capabilities.isWebGL2 ) return false;
  12115. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12116. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12117. }
  12118. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12119. return texture.generateMipmaps && supportsMips &&
  12120. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12121. }
  12122. function generateMipmap( target, texture, width, height ) {
  12123. _gl.generateMipmap( target );
  12124. var textureProperties = properties.get( texture );
  12125. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12126. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12127. }
  12128. function getInternalFormat( glFormat, glType ) {
  12129. if ( ! capabilities.isWebGL2 ) return glFormat;
  12130. var internalFormat = glFormat;
  12131. if ( glFormat === 6403 ) {
  12132. if ( glType === 5126 ) internalFormat = 33326;
  12133. if ( glType === 5131 ) internalFormat = 33325;
  12134. if ( glType === 5121 ) internalFormat = 33321;
  12135. }
  12136. if ( glFormat === 6407 ) {
  12137. if ( glType === 5126 ) internalFormat = 34837;
  12138. if ( glType === 5131 ) internalFormat = 34843;
  12139. if ( glType === 5121 ) internalFormat = 32849;
  12140. }
  12141. if ( glFormat === 6408 ) {
  12142. if ( glType === 5126 ) internalFormat = 34836;
  12143. if ( glType === 5131 ) internalFormat = 34842;
  12144. if ( glType === 5121 ) internalFormat = 32856;
  12145. }
  12146. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12147. internalFormat === 34842 || internalFormat === 34836 ) {
  12148. extensions.get( 'EXT_color_buffer_float' );
  12149. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12150. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12151. }
  12152. return internalFormat;
  12153. }
  12154. // Fallback filters for non-power-of-2 textures
  12155. function filterFallback( f ) {
  12156. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  12157. return 9728;
  12158. }
  12159. return 9729;
  12160. }
  12161. //
  12162. function onTextureDispose( event ) {
  12163. var texture = event.target;
  12164. texture.removeEventListener( 'dispose', onTextureDispose );
  12165. deallocateTexture( texture );
  12166. if ( texture.isVideoTexture ) {
  12167. delete _videoTextures[ texture.id ];
  12168. }
  12169. info.memory.textures --;
  12170. }
  12171. function onRenderTargetDispose( event ) {
  12172. var renderTarget = event.target;
  12173. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12174. deallocateRenderTarget( renderTarget );
  12175. info.memory.textures --;
  12176. }
  12177. //
  12178. function deallocateTexture( texture ) {
  12179. var textureProperties = properties.get( texture );
  12180. if ( textureProperties.__webglInit === undefined ) return;
  12181. _gl.deleteTexture( textureProperties.__webglTexture );
  12182. properties.remove( texture );
  12183. }
  12184. function deallocateRenderTarget( renderTarget ) {
  12185. var renderTargetProperties = properties.get( renderTarget );
  12186. var textureProperties = properties.get( renderTarget.texture );
  12187. if ( ! renderTarget ) return;
  12188. if ( textureProperties.__webglTexture !== undefined ) {
  12189. _gl.deleteTexture( textureProperties.__webglTexture );
  12190. }
  12191. if ( renderTarget.depthTexture ) {
  12192. renderTarget.depthTexture.dispose();
  12193. }
  12194. if ( renderTarget.isWebGLRenderTargetCube ) {
  12195. for ( var i = 0; i < 6; i ++ ) {
  12196. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12197. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12198. }
  12199. } else {
  12200. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12201. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12202. }
  12203. properties.remove( renderTarget.texture );
  12204. properties.remove( renderTarget );
  12205. }
  12206. //
  12207. var textureUnits = 0;
  12208. function resetTextureUnits() {
  12209. textureUnits = 0;
  12210. }
  12211. function allocateTextureUnit() {
  12212. var textureUnit = textureUnits;
  12213. if ( textureUnit >= capabilities.maxTextures ) {
  12214. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12215. }
  12216. textureUnits += 1;
  12217. return textureUnit;
  12218. }
  12219. //
  12220. function setTexture2D( texture, slot ) {
  12221. var textureProperties = properties.get( texture );
  12222. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12223. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12224. var image = texture.image;
  12225. if ( image === undefined ) {
  12226. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12227. } else if ( image.complete === false ) {
  12228. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12229. } else {
  12230. uploadTexture( textureProperties, texture, slot );
  12231. return;
  12232. }
  12233. }
  12234. state.activeTexture( 33984 + slot );
  12235. state.bindTexture( 3553, textureProperties.__webglTexture );
  12236. }
  12237. function setTexture2DArray( texture, slot ) {
  12238. var textureProperties = properties.get( texture );
  12239. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12240. uploadTexture( textureProperties, texture, slot );
  12241. return;
  12242. }
  12243. state.activeTexture( 33984 + slot );
  12244. state.bindTexture( 35866, textureProperties.__webglTexture );
  12245. }
  12246. function setTexture3D( texture, slot ) {
  12247. var textureProperties = properties.get( texture );
  12248. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12249. uploadTexture( textureProperties, texture, slot );
  12250. return;
  12251. }
  12252. state.activeTexture( 33984 + slot );
  12253. state.bindTexture( 32879, textureProperties.__webglTexture );
  12254. }
  12255. function setTextureCube( texture, slot ) {
  12256. var textureProperties = properties.get( texture );
  12257. if ( texture.image.length === 6 ) {
  12258. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12259. initTexture( textureProperties, texture );
  12260. state.activeTexture( 33984 + slot );
  12261. state.bindTexture( 34067, textureProperties.__webglTexture );
  12262. _gl.pixelStorei( 37440, texture.flipY );
  12263. var isCompressed = ( texture && texture.isCompressedTexture );
  12264. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12265. var cubeImage = [];
  12266. for ( var i = 0; i < 6; i ++ ) {
  12267. if ( ! isCompressed && ! isDataTexture ) {
  12268. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12269. } else {
  12270. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12271. }
  12272. }
  12273. var image = cubeImage[ 0 ],
  12274. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12275. glFormat = utils.convert( texture.format ),
  12276. glType = utils.convert( texture.type ),
  12277. glInternalFormat = getInternalFormat( glFormat, glType );
  12278. setTextureParameters( 34067, texture, supportsMips );
  12279. for ( var i = 0; i < 6; i ++ ) {
  12280. if ( ! isCompressed ) {
  12281. if ( isDataTexture ) {
  12282. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12283. } else {
  12284. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12285. }
  12286. } else {
  12287. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12288. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12289. mipmap = mipmaps[ j ];
  12290. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12291. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12292. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12293. } else {
  12294. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12295. }
  12296. } else {
  12297. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12298. }
  12299. }
  12300. }
  12301. }
  12302. if ( ! isCompressed ) {
  12303. textureProperties.__maxMipLevel = 0;
  12304. } else {
  12305. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12306. }
  12307. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12308. // We assume images for cube map have the same size.
  12309. generateMipmap( 34067, texture, image.width, image.height );
  12310. }
  12311. textureProperties.__version = texture.version;
  12312. if ( texture.onUpdate ) texture.onUpdate( texture );
  12313. } else {
  12314. state.activeTexture( 33984 + slot );
  12315. state.bindTexture( 34067, textureProperties.__webglTexture );
  12316. }
  12317. }
  12318. }
  12319. function setTextureCubeDynamic( texture, slot ) {
  12320. state.activeTexture( 33984 + slot );
  12321. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12322. }
  12323. function setTextureParameters( textureType, texture, supportsMips ) {
  12324. var extension;
  12325. if ( supportsMips ) {
  12326. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12327. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12328. if ( textureType === 32879 || textureType === 35866 ) {
  12329. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12330. }
  12331. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12332. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12333. } else {
  12334. _gl.texParameteri( textureType, 10242, 33071 );
  12335. _gl.texParameteri( textureType, 10243, 33071 );
  12336. if ( textureType === 32879 || textureType === 35866 ) {
  12337. _gl.texParameteri( textureType, 32882, 33071 );
  12338. }
  12339. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12340. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12341. }
  12342. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12343. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12344. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12345. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12346. }
  12347. }
  12348. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12349. if ( extension ) {
  12350. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12351. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12352. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12353. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12354. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12355. }
  12356. }
  12357. }
  12358. function initTexture( textureProperties, texture ) {
  12359. if ( textureProperties.__webglInit === undefined ) {
  12360. textureProperties.__webglInit = true;
  12361. texture.addEventListener( 'dispose', onTextureDispose );
  12362. textureProperties.__webglTexture = _gl.createTexture();
  12363. info.memory.textures ++;
  12364. }
  12365. }
  12366. function uploadTexture( textureProperties, texture, slot ) {
  12367. var textureType = 3553;
  12368. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12369. if ( texture.isDataTexture3D ) textureType = 32879;
  12370. initTexture( textureProperties, texture );
  12371. state.activeTexture( 33984 + slot );
  12372. state.bindTexture( textureType, textureProperties.__webglTexture );
  12373. _gl.pixelStorei( 37440, texture.flipY );
  12374. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12375. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12376. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12377. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12378. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12379. glFormat = utils.convert( texture.format ),
  12380. glType = utils.convert( texture.type ),
  12381. glInternalFormat = getInternalFormat( glFormat, glType );
  12382. setTextureParameters( textureType, texture, supportsMips );
  12383. var mipmap, mipmaps = texture.mipmaps;
  12384. if ( texture.isDepthTexture ) {
  12385. // populate depth texture with dummy data
  12386. glInternalFormat = 6402;
  12387. if ( texture.type === FloatType ) {
  12388. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12389. glInternalFormat = 36012;
  12390. } else if ( capabilities.isWebGL2 ) {
  12391. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12392. glInternalFormat = 33189;
  12393. }
  12394. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12395. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12396. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12397. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12398. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12399. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12400. texture.type = UnsignedShortType;
  12401. glType = utils.convert( texture.type );
  12402. }
  12403. }
  12404. // Depth stencil textures need the DEPTH_STENCIL internal format
  12405. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12406. if ( texture.format === DepthStencilFormat ) {
  12407. glInternalFormat = 34041;
  12408. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12409. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12410. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12411. if ( texture.type !== UnsignedInt248Type ) {
  12412. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12413. texture.type = UnsignedInt248Type;
  12414. glType = utils.convert( texture.type );
  12415. }
  12416. }
  12417. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12418. } else if ( texture.isDataTexture ) {
  12419. // use manually created mipmaps if available
  12420. // if there are no manual mipmaps
  12421. // set 0 level mipmap and then use GL to generate other mipmap levels
  12422. if ( mipmaps.length > 0 && supportsMips ) {
  12423. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12424. mipmap = mipmaps[ i ];
  12425. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12426. }
  12427. texture.generateMipmaps = false;
  12428. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12429. } else {
  12430. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12431. textureProperties.__maxMipLevel = 0;
  12432. }
  12433. } else if ( texture.isCompressedTexture ) {
  12434. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12435. mipmap = mipmaps[ i ];
  12436. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12437. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12438. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12439. } else {
  12440. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12441. }
  12442. } else {
  12443. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12444. }
  12445. }
  12446. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12447. } else if ( texture.isDataTexture2DArray ) {
  12448. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12449. textureProperties.__maxMipLevel = 0;
  12450. } else if ( texture.isDataTexture3D ) {
  12451. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12452. textureProperties.__maxMipLevel = 0;
  12453. } else {
  12454. // regular Texture (image, video, canvas)
  12455. // use manually created mipmaps if available
  12456. // if there are no manual mipmaps
  12457. // set 0 level mipmap and then use GL to generate other mipmap levels
  12458. if ( mipmaps.length > 0 && supportsMips ) {
  12459. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12460. mipmap = mipmaps[ i ];
  12461. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12462. }
  12463. texture.generateMipmaps = false;
  12464. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12465. } else {
  12466. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12467. textureProperties.__maxMipLevel = 0;
  12468. }
  12469. }
  12470. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12471. generateMipmap( 3553, texture, image.width, image.height );
  12472. }
  12473. textureProperties.__version = texture.version;
  12474. if ( texture.onUpdate ) texture.onUpdate( texture );
  12475. }
  12476. // Render targets
  12477. // Setup storage for target texture and bind it to correct framebuffer
  12478. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12479. var glFormat = utils.convert( renderTarget.texture.format );
  12480. var glType = utils.convert( renderTarget.texture.type );
  12481. var glInternalFormat = getInternalFormat( glFormat, glType );
  12482. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12483. _gl.bindFramebuffer( 36160, framebuffer );
  12484. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12485. _gl.bindFramebuffer( 36160, null );
  12486. }
  12487. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12488. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12489. _gl.bindRenderbuffer( 36161, renderbuffer );
  12490. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12491. if ( isMultisample ) {
  12492. var samples = getRenderTargetSamples( renderTarget );
  12493. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12494. } else {
  12495. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12496. }
  12497. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12498. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12499. if ( isMultisample ) {
  12500. var samples = getRenderTargetSamples( renderTarget );
  12501. _gl.renderbufferStorageMultisample( 36161, samples, 34041, renderTarget.width, renderTarget.height );
  12502. } else {
  12503. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12504. }
  12505. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12506. } else {
  12507. var glFormat = utils.convert( renderTarget.texture.format );
  12508. var glType = utils.convert( renderTarget.texture.type );
  12509. var glInternalFormat = getInternalFormat( glFormat, glType );
  12510. if ( isMultisample ) {
  12511. var samples = getRenderTargetSamples( renderTarget );
  12512. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12513. } else {
  12514. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12515. }
  12516. }
  12517. _gl.bindRenderbuffer( 36161, null );
  12518. }
  12519. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12520. function setupDepthTexture( framebuffer, renderTarget ) {
  12521. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12522. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12523. _gl.bindFramebuffer( 36160, framebuffer );
  12524. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12525. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12526. }
  12527. // upload an empty depth texture with framebuffer size
  12528. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12529. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12530. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12531. renderTarget.depthTexture.image.width = renderTarget.width;
  12532. renderTarget.depthTexture.image.height = renderTarget.height;
  12533. renderTarget.depthTexture.needsUpdate = true;
  12534. }
  12535. setTexture2D( renderTarget.depthTexture, 0 );
  12536. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12537. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12538. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12539. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12540. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12541. } else {
  12542. throw new Error( 'Unknown depthTexture format' );
  12543. }
  12544. }
  12545. // Setup GL resources for a non-texture depth buffer
  12546. function setupDepthRenderbuffer( renderTarget ) {
  12547. var renderTargetProperties = properties.get( renderTarget );
  12548. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12549. if ( renderTarget.depthTexture ) {
  12550. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12551. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12552. } else {
  12553. if ( isCube ) {
  12554. renderTargetProperties.__webglDepthbuffer = [];
  12555. for ( var i = 0; i < 6; i ++ ) {
  12556. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12557. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12558. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12559. }
  12560. } else {
  12561. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12562. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12563. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12564. }
  12565. }
  12566. _gl.bindFramebuffer( 36160, null );
  12567. }
  12568. // Set up GL resources for the render target
  12569. function setupRenderTarget( renderTarget ) {
  12570. var renderTargetProperties = properties.get( renderTarget );
  12571. var textureProperties = properties.get( renderTarget.texture );
  12572. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12573. textureProperties.__webglTexture = _gl.createTexture();
  12574. info.memory.textures ++;
  12575. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12576. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12577. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12578. // Setup framebuffer
  12579. if ( isCube ) {
  12580. renderTargetProperties.__webglFramebuffer = [];
  12581. for ( var i = 0; i < 6; i ++ ) {
  12582. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12583. }
  12584. } else {
  12585. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12586. if ( isMultisample ) {
  12587. if ( capabilities.isWebGL2 ) {
  12588. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12589. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12590. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12591. var glFormat = utils.convert( renderTarget.texture.format );
  12592. var glType = utils.convert( renderTarget.texture.type );
  12593. var glInternalFormat = getInternalFormat( glFormat, glType );
  12594. var samples = getRenderTargetSamples( renderTarget );
  12595. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12596. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12597. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12598. _gl.bindRenderbuffer( 36161, null );
  12599. if ( renderTarget.depthBuffer ) {
  12600. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12601. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12602. }
  12603. _gl.bindFramebuffer( 36160, null );
  12604. } else {
  12605. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12606. }
  12607. }
  12608. }
  12609. // Setup color buffer
  12610. if ( isCube ) {
  12611. state.bindTexture( 34067, textureProperties.__webglTexture );
  12612. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12613. for ( var i = 0; i < 6; i ++ ) {
  12614. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12615. }
  12616. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12617. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12618. }
  12619. state.bindTexture( 34067, null );
  12620. } else {
  12621. state.bindTexture( 3553, textureProperties.__webglTexture );
  12622. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12623. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12624. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12625. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12626. }
  12627. state.bindTexture( 3553, null );
  12628. }
  12629. // Setup depth and stencil buffers
  12630. if ( renderTarget.depthBuffer ) {
  12631. setupDepthRenderbuffer( renderTarget );
  12632. }
  12633. }
  12634. function updateRenderTargetMipmap( renderTarget ) {
  12635. var texture = renderTarget.texture;
  12636. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12637. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12638. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  12639. var webglTexture = properties.get( texture ).__webglTexture;
  12640. state.bindTexture( target, webglTexture );
  12641. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12642. state.bindTexture( target, null );
  12643. }
  12644. }
  12645. function updateMultisampleRenderTarget( renderTarget ) {
  12646. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12647. if ( capabilities.isWebGL2 ) {
  12648. var renderTargetProperties = properties.get( renderTarget );
  12649. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12650. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12651. var width = renderTarget.width;
  12652. var height = renderTarget.height;
  12653. var mask = 16384;
  12654. if ( renderTarget.depthBuffer ) mask |= 256;
  12655. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12656. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12657. } else {
  12658. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12659. }
  12660. }
  12661. }
  12662. function getRenderTargetSamples( renderTarget ) {
  12663. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12664. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  12665. }
  12666. function updateVideoTexture( texture ) {
  12667. var id = texture.id;
  12668. var frame = info.render.frame;
  12669. // Check the last frame we updated the VideoTexture
  12670. if ( _videoTextures[ id ] !== frame ) {
  12671. _videoTextures[ id ] = frame;
  12672. texture.update();
  12673. }
  12674. }
  12675. // backwards compatibility
  12676. var warnedTexture2D = false;
  12677. var warnedTextureCube = false;
  12678. function safeSetTexture2D( texture, slot ) {
  12679. if ( texture && texture.isWebGLRenderTarget ) {
  12680. if ( warnedTexture2D === false ) {
  12681. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  12682. warnedTexture2D = true;
  12683. }
  12684. texture = texture.texture;
  12685. }
  12686. setTexture2D( texture, slot );
  12687. }
  12688. function safeSetTextureCube( texture, slot ) {
  12689. if ( texture && texture.isWebGLRenderTargetCube ) {
  12690. if ( warnedTextureCube === false ) {
  12691. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  12692. warnedTextureCube = true;
  12693. }
  12694. texture = texture.texture;
  12695. }
  12696. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  12697. // TODO: unify these code paths
  12698. if ( ( texture && texture.isCubeTexture ) ||
  12699. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  12700. // CompressedTexture can have Array in image :/
  12701. // this function alone should take care of cube textures
  12702. setTextureCube( texture, slot );
  12703. } else {
  12704. // assumed: texture property of THREE.WebGLRenderTargetCube
  12705. setTextureCubeDynamic( texture, slot );
  12706. }
  12707. }
  12708. //
  12709. this.allocateTextureUnit = allocateTextureUnit;
  12710. this.resetTextureUnits = resetTextureUnits;
  12711. this.setTexture2D = setTexture2D;
  12712. this.setTexture2DArray = setTexture2DArray;
  12713. this.setTexture3D = setTexture3D;
  12714. this.setTextureCube = setTextureCube;
  12715. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12716. this.setupRenderTarget = setupRenderTarget;
  12717. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12718. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12719. this.safeSetTexture2D = safeSetTexture2D;
  12720. this.safeSetTextureCube = safeSetTextureCube;
  12721. }
  12722. /**
  12723. * @author thespite / http://www.twitter.com/thespite
  12724. */
  12725. function WebGLUtils( gl, extensions, capabilities ) {
  12726. function convert( p ) {
  12727. var extension;
  12728. if ( p === RepeatWrapping ) return 10497;
  12729. if ( p === ClampToEdgeWrapping ) return 33071;
  12730. if ( p === MirroredRepeatWrapping ) return 33648;
  12731. if ( p === NearestFilter ) return 9728;
  12732. if ( p === NearestMipMapNearestFilter ) return 9984;
  12733. if ( p === NearestMipMapLinearFilter ) return 9986;
  12734. if ( p === LinearFilter ) return 9729;
  12735. if ( p === LinearMipMapNearestFilter ) return 9985;
  12736. if ( p === LinearMipMapLinearFilter ) return 9987;
  12737. if ( p === UnsignedByteType ) return 5121;
  12738. if ( p === UnsignedShort4444Type ) return 32819;
  12739. if ( p === UnsignedShort5551Type ) return 32820;
  12740. if ( p === UnsignedShort565Type ) return 33635;
  12741. if ( p === ByteType ) return 5120;
  12742. if ( p === ShortType ) return 5122;
  12743. if ( p === UnsignedShortType ) return 5123;
  12744. if ( p === IntType ) return 5124;
  12745. if ( p === UnsignedIntType ) return 5125;
  12746. if ( p === FloatType ) return 5126;
  12747. if ( p === HalfFloatType ) {
  12748. if ( capabilities.isWebGL2 ) return 5131;
  12749. extension = extensions.get( 'OES_texture_half_float' );
  12750. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12751. }
  12752. if ( p === AlphaFormat ) return 6406;
  12753. if ( p === RGBFormat ) return 6407;
  12754. if ( p === RGBAFormat ) return 6408;
  12755. if ( p === LuminanceFormat ) return 6409;
  12756. if ( p === LuminanceAlphaFormat ) return 6410;
  12757. if ( p === DepthFormat ) return 6402;
  12758. if ( p === DepthStencilFormat ) return 34041;
  12759. if ( p === RedFormat ) return 6403;
  12760. if ( p === AddEquation ) return 32774;
  12761. if ( p === SubtractEquation ) return 32778;
  12762. if ( p === ReverseSubtractEquation ) return 32779;
  12763. if ( p === ZeroFactor ) return 0;
  12764. if ( p === OneFactor ) return 1;
  12765. if ( p === SrcColorFactor ) return 768;
  12766. if ( p === OneMinusSrcColorFactor ) return 769;
  12767. if ( p === SrcAlphaFactor ) return 770;
  12768. if ( p === OneMinusSrcAlphaFactor ) return 771;
  12769. if ( p === DstAlphaFactor ) return 772;
  12770. if ( p === OneMinusDstAlphaFactor ) return 773;
  12771. if ( p === DstColorFactor ) return 774;
  12772. if ( p === OneMinusDstColorFactor ) return 775;
  12773. if ( p === SrcAlphaSaturateFactor ) return 776;
  12774. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12775. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12776. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12777. if ( extension !== null ) {
  12778. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12779. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12780. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12781. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12782. }
  12783. }
  12784. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12785. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12786. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12787. if ( extension !== null ) {
  12788. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12789. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12790. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12791. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12792. }
  12793. }
  12794. if ( p === RGB_ETC1_Format ) {
  12795. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12796. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12797. }
  12798. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12799. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12800. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12801. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12802. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12803. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12804. if ( extension !== null ) {
  12805. return p;
  12806. }
  12807. }
  12808. if ( p === MinEquation || p === MaxEquation ) {
  12809. if ( capabilities.isWebGL2 ) {
  12810. if ( p === MinEquation ) return 32775;
  12811. if ( p === MaxEquation ) return 32776;
  12812. }
  12813. extension = extensions.get( 'EXT_blend_minmax' );
  12814. if ( extension !== null ) {
  12815. if ( p === MinEquation ) return extension.MIN_EXT;
  12816. if ( p === MaxEquation ) return extension.MAX_EXT;
  12817. }
  12818. }
  12819. if ( p === UnsignedInt248Type ) {
  12820. if ( capabilities.isWebGL2 ) return 34042;
  12821. extension = extensions.get( 'WEBGL_depth_texture' );
  12822. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12823. }
  12824. return 0;
  12825. }
  12826. return { convert: convert };
  12827. }
  12828. /**
  12829. * @author mrdoob / http://mrdoob.com/
  12830. */
  12831. function Group() {
  12832. Object3D.call( this );
  12833. this.type = 'Group';
  12834. }
  12835. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12836. constructor: Group,
  12837. isGroup: true
  12838. } );
  12839. /**
  12840. * @author mrdoob / http://mrdoob.com/
  12841. * @author mikael emtinger / http://gomo.se/
  12842. * @author WestLangley / http://github.com/WestLangley
  12843. */
  12844. function Camera() {
  12845. Object3D.call( this );
  12846. this.type = 'Camera';
  12847. this.matrixWorldInverse = new Matrix4();
  12848. this.projectionMatrix = new Matrix4();
  12849. this.projectionMatrixInverse = new Matrix4();
  12850. }
  12851. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12852. constructor: Camera,
  12853. isCamera: true,
  12854. copy: function ( source, recursive ) {
  12855. Object3D.prototype.copy.call( this, source, recursive );
  12856. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  12857. this.projectionMatrix.copy( source.projectionMatrix );
  12858. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  12859. return this;
  12860. },
  12861. getWorldDirection: function ( target ) {
  12862. if ( target === undefined ) {
  12863. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  12864. target = new Vector3();
  12865. }
  12866. this.updateMatrixWorld( true );
  12867. var e = this.matrixWorld.elements;
  12868. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  12869. },
  12870. updateMatrixWorld: function ( force ) {
  12871. Object3D.prototype.updateMatrixWorld.call( this, force );
  12872. this.matrixWorldInverse.getInverse( this.matrixWorld );
  12873. },
  12874. clone: function () {
  12875. return new this.constructor().copy( this );
  12876. }
  12877. } );
  12878. /**
  12879. * @author mrdoob / http://mrdoob.com/
  12880. * @author greggman / http://games.greggman.com/
  12881. * @author zz85 / http://www.lab4games.net/zz85/blog
  12882. * @author tschw
  12883. */
  12884. function PerspectiveCamera( fov, aspect, near, far ) {
  12885. Camera.call( this );
  12886. this.type = 'PerspectiveCamera';
  12887. this.fov = fov !== undefined ? fov : 50;
  12888. this.zoom = 1;
  12889. this.near = near !== undefined ? near : 0.1;
  12890. this.far = far !== undefined ? far : 2000;
  12891. this.focus = 10;
  12892. this.aspect = aspect !== undefined ? aspect : 1;
  12893. this.view = null;
  12894. this.filmGauge = 35; // width of the film (default in millimeters)
  12895. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12896. this.updateProjectionMatrix();
  12897. }
  12898. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12899. constructor: PerspectiveCamera,
  12900. isPerspectiveCamera: true,
  12901. copy: function ( source, recursive ) {
  12902. Camera.prototype.copy.call( this, source, recursive );
  12903. this.fov = source.fov;
  12904. this.zoom = source.zoom;
  12905. this.near = source.near;
  12906. this.far = source.far;
  12907. this.focus = source.focus;
  12908. this.aspect = source.aspect;
  12909. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12910. this.filmGauge = source.filmGauge;
  12911. this.filmOffset = source.filmOffset;
  12912. return this;
  12913. },
  12914. /**
  12915. * Sets the FOV by focal length in respect to the current .filmGauge.
  12916. *
  12917. * The default film gauge is 35, so that the focal length can be specified for
  12918. * a 35mm (full frame) camera.
  12919. *
  12920. * Values for focal length and film gauge must have the same unit.
  12921. */
  12922. setFocalLength: function ( focalLength ) {
  12923. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12924. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12925. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12926. this.updateProjectionMatrix();
  12927. },
  12928. /**
  12929. * Calculates the focal length from the current .fov and .filmGauge.
  12930. */
  12931. getFocalLength: function () {
  12932. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12933. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12934. },
  12935. getEffectiveFOV: function () {
  12936. return _Math.RAD2DEG * 2 * Math.atan(
  12937. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12938. },
  12939. getFilmWidth: function () {
  12940. // film not completely covered in portrait format (aspect < 1)
  12941. return this.filmGauge * Math.min( this.aspect, 1 );
  12942. },
  12943. getFilmHeight: function () {
  12944. // film not completely covered in landscape format (aspect > 1)
  12945. return this.filmGauge / Math.max( this.aspect, 1 );
  12946. },
  12947. /**
  12948. * Sets an offset in a larger frustum. This is useful for multi-window or
  12949. * multi-monitor/multi-machine setups.
  12950. *
  12951. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12952. * the monitors are in grid like this
  12953. *
  12954. * +---+---+---+
  12955. * | A | B | C |
  12956. * +---+---+---+
  12957. * | D | E | F |
  12958. * +---+---+---+
  12959. *
  12960. * then for each monitor you would call it like this
  12961. *
  12962. * var w = 1920;
  12963. * var h = 1080;
  12964. * var fullWidth = w * 3;
  12965. * var fullHeight = h * 2;
  12966. *
  12967. * --A--
  12968. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12969. * --B--
  12970. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12971. * --C--
  12972. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12973. * --D--
  12974. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12975. * --E--
  12976. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12977. * --F--
  12978. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12979. *
  12980. * Note there is no reason monitors have to be the same size or in a grid.
  12981. */
  12982. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12983. this.aspect = fullWidth / fullHeight;
  12984. if ( this.view === null ) {
  12985. this.view = {
  12986. enabled: true,
  12987. fullWidth: 1,
  12988. fullHeight: 1,
  12989. offsetX: 0,
  12990. offsetY: 0,
  12991. width: 1,
  12992. height: 1
  12993. };
  12994. }
  12995. this.view.enabled = true;
  12996. this.view.fullWidth = fullWidth;
  12997. this.view.fullHeight = fullHeight;
  12998. this.view.offsetX = x;
  12999. this.view.offsetY = y;
  13000. this.view.width = width;
  13001. this.view.height = height;
  13002. this.updateProjectionMatrix();
  13003. },
  13004. clearViewOffset: function () {
  13005. if ( this.view !== null ) {
  13006. this.view.enabled = false;
  13007. }
  13008. this.updateProjectionMatrix();
  13009. },
  13010. updateProjectionMatrix: function () {
  13011. var near = this.near,
  13012. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  13013. height = 2 * top,
  13014. width = this.aspect * height,
  13015. left = - 0.5 * width,
  13016. view = this.view;
  13017. if ( this.view !== null && this.view.enabled ) {
  13018. var fullWidth = view.fullWidth,
  13019. fullHeight = view.fullHeight;
  13020. left += view.offsetX * width / fullWidth;
  13021. top -= view.offsetY * height / fullHeight;
  13022. width *= view.width / fullWidth;
  13023. height *= view.height / fullHeight;
  13024. }
  13025. var skew = this.filmOffset;
  13026. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  13027. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  13028. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  13029. },
  13030. toJSON: function ( meta ) {
  13031. var data = Object3D.prototype.toJSON.call( this, meta );
  13032. data.object.fov = this.fov;
  13033. data.object.zoom = this.zoom;
  13034. data.object.near = this.near;
  13035. data.object.far = this.far;
  13036. data.object.focus = this.focus;
  13037. data.object.aspect = this.aspect;
  13038. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  13039. data.object.filmGauge = this.filmGauge;
  13040. data.object.filmOffset = this.filmOffset;
  13041. return data;
  13042. }
  13043. } );
  13044. /**
  13045. * @author mrdoob / http://mrdoob.com/
  13046. */
  13047. function ArrayCamera( array ) {
  13048. PerspectiveCamera.call( this );
  13049. this.cameras = array || [];
  13050. }
  13051. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13052. constructor: ArrayCamera,
  13053. isArrayCamera: true
  13054. } );
  13055. /**
  13056. * @author jsantell / https://www.jsantell.com/
  13057. * @author mrdoob / http://mrdoob.com/
  13058. */
  13059. var cameraLPos = new Vector3();
  13060. var cameraRPos = new Vector3();
  13061. /**
  13062. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13063. * the cameras' projection and world matrices have already been set.
  13064. * And that near and far planes are identical for both cameras.
  13065. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13066. */
  13067. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13068. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13069. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13070. var ipd = cameraLPos.distanceTo( cameraRPos );
  13071. var projL = cameraL.projectionMatrix.elements;
  13072. var projR = cameraR.projectionMatrix.elements;
  13073. // VR systems will have identical far and near planes, and
  13074. // most likely identical top and bottom frustum extents.
  13075. // Use the left camera for these values.
  13076. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13077. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13078. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13079. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13080. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13081. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13082. var left = near * leftFov;
  13083. var right = near * rightFov;
  13084. // Calculate the new camera's position offset from the
  13085. // left camera. xOffset should be roughly half `ipd`.
  13086. var zOffset = ipd / ( - leftFov + rightFov );
  13087. var xOffset = zOffset * - leftFov;
  13088. // TODO: Better way to apply this offset?
  13089. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13090. camera.translateX( xOffset );
  13091. camera.translateZ( zOffset );
  13092. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13093. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13094. // Find the union of the frustum values of the cameras and scale
  13095. // the values so that the near plane's position does not change in world space,
  13096. // although must now be relative to the new union camera.
  13097. var near2 = near + zOffset;
  13098. var far2 = far + zOffset;
  13099. var left2 = left - xOffset;
  13100. var right2 = right + ( ipd - xOffset );
  13101. var top2 = topFov * far / far2 * near2;
  13102. var bottom2 = bottomFov * far / far2 * near2;
  13103. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13104. }
  13105. /**
  13106. * @author mrdoob / http://mrdoob.com/
  13107. */
  13108. function WebVRManager( renderer ) {
  13109. var scope = this;
  13110. var device = null;
  13111. var frameData = null;
  13112. var poseTarget = null;
  13113. var controllers = [];
  13114. var standingMatrix = new Matrix4();
  13115. var standingMatrixInverse = new Matrix4();
  13116. var framebufferScaleFactor = 1.0;
  13117. var frameOfReferenceType = 'stage';
  13118. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13119. frameData = new window.VRFrameData();
  13120. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13121. }
  13122. var matrixWorldInverse = new Matrix4();
  13123. var tempQuaternion = new Quaternion();
  13124. var tempPosition = new Vector3();
  13125. var cameraL = new PerspectiveCamera();
  13126. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  13127. cameraL.layers.enable( 1 );
  13128. var cameraR = new PerspectiveCamera();
  13129. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  13130. cameraR.layers.enable( 2 );
  13131. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13132. cameraVR.layers.enable( 1 );
  13133. cameraVR.layers.enable( 2 );
  13134. //
  13135. function isPresenting() {
  13136. return device !== null && device.isPresenting === true;
  13137. }
  13138. var currentSize = new Vector2(), currentPixelRatio;
  13139. function onVRDisplayPresentChange() {
  13140. if ( isPresenting() ) {
  13141. var eyeParameters = device.getEyeParameters( 'left' );
  13142. var renderWidth = eyeParameters.renderWidth * framebufferScaleFactor;
  13143. var renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13144. currentPixelRatio = renderer.getPixelRatio();
  13145. renderer.getSize( currentSize );
  13146. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  13147. animation.start();
  13148. } else {
  13149. if ( scope.enabled ) {
  13150. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13151. }
  13152. animation.stop();
  13153. }
  13154. }
  13155. //
  13156. var triggers = [];
  13157. function findGamepad( id ) {
  13158. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13159. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13160. var gamepad = gamepads[ i ];
  13161. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13162. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13163. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13164. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13165. if ( j === id ) return gamepad;
  13166. j ++;
  13167. }
  13168. }
  13169. }
  13170. function updateControllers() {
  13171. for ( var i = 0; i < controllers.length; i ++ ) {
  13172. var controller = controllers[ i ];
  13173. var gamepad = findGamepad( i );
  13174. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13175. if ( gamepad.pose === null ) return;
  13176. // Pose
  13177. var pose = gamepad.pose;
  13178. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13179. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13180. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13181. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13182. controller.matrix.premultiply( standingMatrix );
  13183. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13184. controller.matrixWorldNeedsUpdate = true;
  13185. controller.visible = true;
  13186. // Trigger
  13187. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13188. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13189. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13190. if ( triggers[ i ] === true ) {
  13191. controller.dispatchEvent( { type: 'selectstart' } );
  13192. } else {
  13193. controller.dispatchEvent( { type: 'selectend' } );
  13194. controller.dispatchEvent( { type: 'select' } );
  13195. }
  13196. }
  13197. } else {
  13198. controller.visible = false;
  13199. }
  13200. }
  13201. }
  13202. //
  13203. this.enabled = false;
  13204. this.getController = function ( id ) {
  13205. var controller = controllers[ id ];
  13206. if ( controller === undefined ) {
  13207. controller = new Group();
  13208. controller.matrixAutoUpdate = false;
  13209. controller.visible = false;
  13210. controllers[ id ] = controller;
  13211. }
  13212. return controller;
  13213. };
  13214. this.getDevice = function () {
  13215. return device;
  13216. };
  13217. this.setDevice = function ( value ) {
  13218. if ( value !== undefined ) device = value;
  13219. animation.setContext( value );
  13220. };
  13221. this.setFramebufferScaleFactor = function ( value ) {
  13222. framebufferScaleFactor = value;
  13223. };
  13224. this.setFrameOfReferenceType = function ( value ) {
  13225. frameOfReferenceType = value;
  13226. };
  13227. this.setPoseTarget = function ( object ) {
  13228. if ( object !== undefined ) poseTarget = object;
  13229. };
  13230. this.getCamera = function ( camera ) {
  13231. var userHeight = frameOfReferenceType === 'stage' ? 1.6 : 0;
  13232. if ( isPresenting() === false ) {
  13233. camera.position.set( 0, userHeight, 0 );
  13234. camera.rotation.set( 0, 0, 0 );
  13235. return camera;
  13236. }
  13237. device.depthNear = camera.near;
  13238. device.depthFar = camera.far;
  13239. device.getFrameData( frameData );
  13240. //
  13241. if ( frameOfReferenceType === 'stage' ) {
  13242. var stageParameters = device.stageParameters;
  13243. if ( stageParameters ) {
  13244. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13245. } else {
  13246. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13247. }
  13248. }
  13249. var pose = frameData.pose;
  13250. var poseObject = poseTarget !== null ? poseTarget : camera;
  13251. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13252. poseObject.matrix.copy( standingMatrix );
  13253. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13254. if ( pose.orientation !== null ) {
  13255. tempQuaternion.fromArray( pose.orientation );
  13256. poseObject.quaternion.multiply( tempQuaternion );
  13257. }
  13258. if ( pose.position !== null ) {
  13259. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13260. tempPosition.fromArray( pose.position );
  13261. tempPosition.applyQuaternion( tempQuaternion );
  13262. poseObject.position.add( tempPosition );
  13263. }
  13264. poseObject.updateMatrixWorld();
  13265. //
  13266. cameraL.near = camera.near;
  13267. cameraR.near = camera.near;
  13268. cameraL.far = camera.far;
  13269. cameraR.far = camera.far;
  13270. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13271. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13272. // TODO (mrdoob) Double check this code
  13273. standingMatrixInverse.getInverse( standingMatrix );
  13274. if ( frameOfReferenceType === 'stage' ) {
  13275. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13276. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13277. }
  13278. var parent = poseObject.parent;
  13279. if ( parent !== null ) {
  13280. matrixWorldInverse.getInverse( parent.matrixWorld );
  13281. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13282. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13283. }
  13284. // envMap and Mirror needs camera.matrixWorld
  13285. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13286. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13287. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13288. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13289. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13290. //
  13291. var layers = device.getLayers();
  13292. if ( layers.length ) {
  13293. var layer = layers[ 0 ];
  13294. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  13295. cameraL.bounds.fromArray( layer.leftBounds );
  13296. }
  13297. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  13298. cameraR.bounds.fromArray( layer.rightBounds );
  13299. }
  13300. }
  13301. updateControllers();
  13302. return cameraVR;
  13303. };
  13304. this.getStandingMatrix = function () {
  13305. return standingMatrix;
  13306. };
  13307. this.isPresenting = isPresenting;
  13308. // Animation Loop
  13309. var animation = new WebGLAnimation();
  13310. this.setAnimationLoop = function ( callback ) {
  13311. animation.setAnimationLoop( callback );
  13312. if ( isPresenting() ) animation.start();
  13313. };
  13314. this.submitFrame = function () {
  13315. if ( isPresenting() ) device.submitFrame();
  13316. };
  13317. this.dispose = function () {
  13318. if ( typeof window !== 'undefined' ) {
  13319. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13320. }
  13321. };
  13322. }
  13323. /**
  13324. * @author mrdoob / http://mrdoob.com/
  13325. */
  13326. function WebXRManager( renderer ) {
  13327. var gl = renderer.context;
  13328. var device = null;
  13329. var session = null;
  13330. var framebufferScaleFactor = 1.0;
  13331. var frameOfReference = null;
  13332. var frameOfReferenceType = 'stage';
  13333. var pose = null;
  13334. var controllers = [];
  13335. var inputSources = [];
  13336. function isPresenting() {
  13337. return session !== null && frameOfReference !== null;
  13338. }
  13339. //
  13340. var cameraL = new PerspectiveCamera();
  13341. cameraL.layers.enable( 1 );
  13342. cameraL.viewport = new Vector4();
  13343. var cameraR = new PerspectiveCamera();
  13344. cameraR.layers.enable( 2 );
  13345. cameraR.viewport = new Vector4();
  13346. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13347. cameraVR.layers.enable( 1 );
  13348. cameraVR.layers.enable( 2 );
  13349. //
  13350. this.enabled = false;
  13351. this.getController = function ( id ) {
  13352. var controller = controllers[ id ];
  13353. if ( controller === undefined ) {
  13354. controller = new Group();
  13355. controller.matrixAutoUpdate = false;
  13356. controller.visible = false;
  13357. controllers[ id ] = controller;
  13358. }
  13359. return controller;
  13360. };
  13361. this.getDevice = function () {
  13362. return device;
  13363. };
  13364. this.setDevice = function ( value ) {
  13365. if ( value !== undefined ) device = value;
  13366. if ( value instanceof XRDevice ) gl.setCompatibleXRDevice( value );
  13367. };
  13368. //
  13369. function onSessionEvent( event ) {
  13370. var controller = controllers[ inputSources.indexOf( event.inputSource ) ];
  13371. if ( controller ) controller.dispatchEvent( { type: event.type } );
  13372. }
  13373. function onSessionEnd() {
  13374. renderer.setFramebuffer( null );
  13375. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13376. animation.stop();
  13377. }
  13378. this.setFramebufferScaleFactor = function ( value ) {
  13379. framebufferScaleFactor = value;
  13380. };
  13381. this.setFrameOfReferenceType = function ( value ) {
  13382. frameOfReferenceType = value;
  13383. };
  13384. this.setSession = function ( value ) {
  13385. session = value;
  13386. if ( session !== null ) {
  13387. session.addEventListener( 'select', onSessionEvent );
  13388. session.addEventListener( 'selectstart', onSessionEvent );
  13389. session.addEventListener( 'selectend', onSessionEvent );
  13390. session.addEventListener( 'end', onSessionEnd );
  13391. session.baseLayer = new XRWebGLLayer( session, gl, { framebufferScaleFactor: framebufferScaleFactor } );
  13392. session.requestFrameOfReference( frameOfReferenceType ).then( function ( value ) {
  13393. frameOfReference = value;
  13394. renderer.setFramebuffer( session.baseLayer.framebuffer );
  13395. animation.setContext( session );
  13396. animation.start();
  13397. } );
  13398. //
  13399. inputSources = session.getInputSources();
  13400. session.addEventListener( 'inputsourceschange', function () {
  13401. inputSources = session.getInputSources();
  13402. console.log( inputSources );
  13403. for ( var i = 0; i < controllers.length; i ++ ) {
  13404. var controller = controllers[ i ];
  13405. controller.userData.inputSource = inputSources[ i ];
  13406. }
  13407. } );
  13408. }
  13409. };
  13410. function updateCamera( camera, parent ) {
  13411. if ( parent === null ) {
  13412. camera.matrixWorld.copy( camera.matrix );
  13413. } else {
  13414. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13415. }
  13416. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13417. }
  13418. this.getCamera = function ( camera ) {
  13419. if ( isPresenting() ) {
  13420. var parent = camera.parent;
  13421. var cameras = cameraVR.cameras;
  13422. updateCamera( cameraVR, parent );
  13423. for ( var i = 0; i < cameras.length; i ++ ) {
  13424. updateCamera( cameras[ i ], parent );
  13425. }
  13426. // update camera and its children
  13427. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13428. var children = camera.children;
  13429. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13430. children[ i ].updateMatrixWorld( true );
  13431. }
  13432. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13433. return cameraVR;
  13434. }
  13435. return camera;
  13436. };
  13437. this.isPresenting = isPresenting;
  13438. // Animation Loop
  13439. var onAnimationFrameCallback = null;
  13440. function onAnimationFrame( time, frame ) {
  13441. pose = frame.getDevicePose( frameOfReference );
  13442. if ( pose !== null ) {
  13443. var layer = session.baseLayer;
  13444. var views = frame.views;
  13445. for ( var i = 0; i < views.length; i ++ ) {
  13446. var view = views[ i ];
  13447. var viewport = layer.getViewport( view );
  13448. var viewMatrix = pose.getViewMatrix( view );
  13449. var camera = cameraVR.cameras[ i ];
  13450. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13451. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13452. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13453. if ( i === 0 ) {
  13454. cameraVR.matrix.copy( camera.matrix );
  13455. }
  13456. }
  13457. }
  13458. //
  13459. for ( var i = 0; i < controllers.length; i ++ ) {
  13460. var controller = controllers[ i ];
  13461. var inputSource = inputSources[ i ];
  13462. if ( inputSource ) {
  13463. var inputPose = frame.getInputPose( inputSource, frameOfReference );
  13464. if ( inputPose !== null ) {
  13465. if ( 'targetRay' in inputPose ) {
  13466. controller.matrix.elements = inputPose.targetRay.transformMatrix;
  13467. } else if ( 'pointerMatrix' in inputPose ) {
  13468. // DEPRECATED
  13469. controller.matrix.elements = inputPose.pointerMatrix;
  13470. }
  13471. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13472. controller.visible = true;
  13473. continue;
  13474. }
  13475. }
  13476. controller.visible = false;
  13477. }
  13478. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13479. }
  13480. var animation = new WebGLAnimation();
  13481. animation.setAnimationLoop( onAnimationFrame );
  13482. this.setAnimationLoop = function ( callback ) {
  13483. onAnimationFrameCallback = callback;
  13484. };
  13485. this.dispose = function () {};
  13486. // DEPRECATED
  13487. this.getStandingMatrix = function () {
  13488. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13489. return new Matrix4();
  13490. };
  13491. this.submitFrame = function () {};
  13492. }
  13493. /**
  13494. * @author supereggbert / http://www.paulbrunt.co.uk/
  13495. * @author mrdoob / http://mrdoob.com/
  13496. * @author alteredq / http://alteredqualia.com/
  13497. * @author szimek / https://github.com/szimek/
  13498. * @author tschw
  13499. */
  13500. function WebGLRenderer( parameters ) {
  13501. console.log( 'THREE.WebGLRenderer', REVISION );
  13502. parameters = parameters || {};
  13503. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13504. _context = parameters.context !== undefined ? parameters.context : null,
  13505. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13506. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13507. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13508. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13509. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13510. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13511. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  13512. var currentRenderList = null;
  13513. var currentRenderState = null;
  13514. // public properties
  13515. this.domElement = _canvas;
  13516. this.context = null;
  13517. // clearing
  13518. this.autoClear = true;
  13519. this.autoClearColor = true;
  13520. this.autoClearDepth = true;
  13521. this.autoClearStencil = true;
  13522. // scene graph
  13523. this.sortObjects = true;
  13524. // user-defined clipping
  13525. this.clippingPlanes = [];
  13526. this.localClippingEnabled = false;
  13527. // physically based shading
  13528. this.gammaFactor = 2.0; // for backwards compatibility
  13529. this.gammaInput = false;
  13530. this.gammaOutput = false;
  13531. // physical lights
  13532. this.physicallyCorrectLights = false;
  13533. // tone mapping
  13534. this.toneMapping = LinearToneMapping;
  13535. this.toneMappingExposure = 1.0;
  13536. this.toneMappingWhitePoint = 1.0;
  13537. // morphs
  13538. this.maxMorphTargets = 8;
  13539. this.maxMorphNormals = 4;
  13540. // internal properties
  13541. var _this = this,
  13542. _isContextLost = false,
  13543. // internal state cache
  13544. _framebuffer = null,
  13545. _currentRenderTarget = null,
  13546. _currentFramebuffer = null,
  13547. _currentMaterialId = - 1,
  13548. // geometry and program caching
  13549. _currentGeometryProgram = {
  13550. geometry: null,
  13551. program: null,
  13552. wireframe: false
  13553. },
  13554. _currentCamera = null,
  13555. _currentArrayCamera = null,
  13556. _currentViewport = new Vector4(),
  13557. _currentScissor = new Vector4(),
  13558. _currentScissorTest = null,
  13559. //
  13560. _width = _canvas.width,
  13561. _height = _canvas.height,
  13562. _pixelRatio = 1,
  13563. _viewport = new Vector4( 0, 0, _width, _height ),
  13564. _scissor = new Vector4( 0, 0, _width, _height ),
  13565. _scissorTest = false,
  13566. // frustum
  13567. _frustum = new Frustum(),
  13568. // clipping
  13569. _clipping = new WebGLClipping(),
  13570. _clippingEnabled = false,
  13571. _localClippingEnabled = false,
  13572. // camera matrices cache
  13573. _projScreenMatrix = new Matrix4(),
  13574. _vector3 = new Vector3();
  13575. function getTargetPixelRatio() {
  13576. return _currentRenderTarget === null ? _pixelRatio : 1;
  13577. }
  13578. // initialize
  13579. var _gl;
  13580. try {
  13581. var contextAttributes = {
  13582. alpha: _alpha,
  13583. depth: _depth,
  13584. stencil: _stencil,
  13585. antialias: _antialias,
  13586. premultipliedAlpha: _premultipliedAlpha,
  13587. preserveDrawingBuffer: _preserveDrawingBuffer,
  13588. powerPreference: _powerPreference
  13589. };
  13590. // event listeners must be registered before WebGL context is created, see #12753
  13591. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13592. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13593. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13594. if ( _gl === null ) {
  13595. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13596. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13597. } else {
  13598. throw new Error( 'Error creating WebGL context.' );
  13599. }
  13600. }
  13601. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13602. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13603. _gl.getShaderPrecisionFormat = function () {
  13604. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13605. };
  13606. }
  13607. } catch ( error ) {
  13608. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13609. throw error;
  13610. }
  13611. var extensions, capabilities, state, info;
  13612. var properties, textures, attributes, geometries, objects;
  13613. var programCache, renderLists, renderStates;
  13614. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13615. var utils;
  13616. function initGLContext() {
  13617. extensions = new WebGLExtensions( _gl );
  13618. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13619. if ( ! capabilities.isWebGL2 ) {
  13620. extensions.get( 'WEBGL_depth_texture' );
  13621. extensions.get( 'OES_texture_float' );
  13622. extensions.get( 'OES_texture_half_float' );
  13623. extensions.get( 'OES_texture_half_float_linear' );
  13624. extensions.get( 'OES_standard_derivatives' );
  13625. extensions.get( 'OES_element_index_uint' );
  13626. extensions.get( 'ANGLE_instanced_arrays' );
  13627. }
  13628. extensions.get( 'OES_texture_float_linear' );
  13629. utils = new WebGLUtils( _gl, extensions, capabilities );
  13630. state = new WebGLState( _gl, extensions, utils, capabilities );
  13631. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13632. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13633. info = new WebGLInfo( _gl );
  13634. properties = new WebGLProperties();
  13635. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13636. attributes = new WebGLAttributes( _gl );
  13637. geometries = new WebGLGeometries( _gl, attributes, info );
  13638. objects = new WebGLObjects( geometries, info );
  13639. morphtargets = new WebGLMorphtargets( _gl );
  13640. programCache = new WebGLPrograms( _this, extensions, capabilities, textures );
  13641. renderLists = new WebGLRenderLists();
  13642. renderStates = new WebGLRenderStates();
  13643. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13644. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13645. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13646. info.programs = programCache.programs;
  13647. _this.context = _gl;
  13648. _this.capabilities = capabilities;
  13649. _this.extensions = extensions;
  13650. _this.properties = properties;
  13651. _this.renderLists = renderLists;
  13652. _this.state = state;
  13653. _this.info = info;
  13654. }
  13655. initGLContext();
  13656. // vr
  13657. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13658. this.vr = vr;
  13659. // shadow map
  13660. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13661. this.shadowMap = shadowMap;
  13662. // API
  13663. this.getContext = function () {
  13664. return _gl;
  13665. };
  13666. this.getContextAttributes = function () {
  13667. return _gl.getContextAttributes();
  13668. };
  13669. this.forceContextLoss = function () {
  13670. var extension = extensions.get( 'WEBGL_lose_context' );
  13671. if ( extension ) extension.loseContext();
  13672. };
  13673. this.forceContextRestore = function () {
  13674. var extension = extensions.get( 'WEBGL_lose_context' );
  13675. if ( extension ) extension.restoreContext();
  13676. };
  13677. this.getPixelRatio = function () {
  13678. return _pixelRatio;
  13679. };
  13680. this.setPixelRatio = function ( value ) {
  13681. if ( value === undefined ) return;
  13682. _pixelRatio = value;
  13683. this.setSize( _width, _height, false );
  13684. };
  13685. this.getSize = function ( target ) {
  13686. if ( target === undefined ) {
  13687. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13688. target = new Vector2();
  13689. }
  13690. return target.set( _width, _height );
  13691. };
  13692. this.setSize = function ( width, height, updateStyle ) {
  13693. if ( vr.isPresenting() ) {
  13694. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13695. return;
  13696. }
  13697. _width = width;
  13698. _height = height;
  13699. _canvas.width = width * _pixelRatio;
  13700. _canvas.height = height * _pixelRatio;
  13701. if ( updateStyle !== false ) {
  13702. _canvas.style.width = width + 'px';
  13703. _canvas.style.height = height + 'px';
  13704. }
  13705. this.setViewport( 0, 0, width, height );
  13706. };
  13707. this.getDrawingBufferSize = function ( target ) {
  13708. if ( target === undefined ) {
  13709. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13710. target = new Vector2();
  13711. }
  13712. return target.set( _width * _pixelRatio, _height * _pixelRatio );
  13713. };
  13714. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13715. _width = width;
  13716. _height = height;
  13717. _pixelRatio = pixelRatio;
  13718. _canvas.width = width * pixelRatio;
  13719. _canvas.height = height * pixelRatio;
  13720. this.setViewport( 0, 0, width, height );
  13721. };
  13722. this.getCurrentViewport = function ( target ) {
  13723. if ( target === undefined ) {
  13724. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13725. target = new Vector4();
  13726. }
  13727. return target.copy( _currentViewport );
  13728. };
  13729. this.getViewport = function ( target ) {
  13730. return target.copy( _viewport );
  13731. };
  13732. this.setViewport = function ( x, y, width, height ) {
  13733. if ( x.isVector4 ) {
  13734. _viewport.set( x.x, x.y, x.z, x.w );
  13735. } else {
  13736. _viewport.set( x, y, width, height );
  13737. }
  13738. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13739. };
  13740. this.getScissor = function ( target ) {
  13741. return target.copy( _scissor );
  13742. };
  13743. this.setScissor = function ( x, y, width, height ) {
  13744. if ( x.isVector4 ) {
  13745. _scissor.set( x.x, x.y, x.z, x.w );
  13746. } else {
  13747. _scissor.set( x, y, width, height );
  13748. }
  13749. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13750. };
  13751. this.getScissorTest = function () {
  13752. return _scissorTest;
  13753. };
  13754. this.setScissorTest = function ( boolean ) {
  13755. state.setScissorTest( _scissorTest = boolean );
  13756. };
  13757. // Clearing
  13758. this.getClearColor = function () {
  13759. return background.getClearColor();
  13760. };
  13761. this.setClearColor = function () {
  13762. background.setClearColor.apply( background, arguments );
  13763. };
  13764. this.getClearAlpha = function () {
  13765. return background.getClearAlpha();
  13766. };
  13767. this.setClearAlpha = function () {
  13768. background.setClearAlpha.apply( background, arguments );
  13769. };
  13770. this.clear = function ( color, depth, stencil ) {
  13771. var bits = 0;
  13772. if ( color === undefined || color ) bits |= 16384;
  13773. if ( depth === undefined || depth ) bits |= 256;
  13774. if ( stencil === undefined || stencil ) bits |= 1024;
  13775. _gl.clear( bits );
  13776. };
  13777. this.clearColor = function () {
  13778. this.clear( true, false, false );
  13779. };
  13780. this.clearDepth = function () {
  13781. this.clear( false, true, false );
  13782. };
  13783. this.clearStencil = function () {
  13784. this.clear( false, false, true );
  13785. };
  13786. //
  13787. this.dispose = function () {
  13788. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13789. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13790. renderLists.dispose();
  13791. renderStates.dispose();
  13792. properties.dispose();
  13793. objects.dispose();
  13794. vr.dispose();
  13795. animation.stop();
  13796. };
  13797. // Events
  13798. function onContextLost( event ) {
  13799. event.preventDefault();
  13800. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13801. _isContextLost = true;
  13802. }
  13803. function onContextRestore( /* event */ ) {
  13804. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13805. _isContextLost = false;
  13806. initGLContext();
  13807. }
  13808. function onMaterialDispose( event ) {
  13809. var material = event.target;
  13810. material.removeEventListener( 'dispose', onMaterialDispose );
  13811. deallocateMaterial( material );
  13812. }
  13813. // Buffer deallocation
  13814. function deallocateMaterial( material ) {
  13815. releaseMaterialProgramReference( material );
  13816. properties.remove( material );
  13817. }
  13818. function releaseMaterialProgramReference( material ) {
  13819. var programInfo = properties.get( material ).program;
  13820. material.program = undefined;
  13821. if ( programInfo !== undefined ) {
  13822. programCache.releaseProgram( programInfo );
  13823. }
  13824. }
  13825. // Buffer rendering
  13826. function renderObjectImmediate( object, program ) {
  13827. object.render( function ( object ) {
  13828. _this.renderBufferImmediate( object, program );
  13829. } );
  13830. }
  13831. this.renderBufferImmediate = function ( object, program ) {
  13832. state.initAttributes();
  13833. var buffers = properties.get( object );
  13834. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13835. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13836. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13837. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13838. var programAttributes = program.getAttributes();
  13839. if ( object.hasPositions ) {
  13840. _gl.bindBuffer( 34962, buffers.position );
  13841. _gl.bufferData( 34962, object.positionArray, 35048 );
  13842. state.enableAttribute( programAttributes.position );
  13843. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  13844. }
  13845. if ( object.hasNormals ) {
  13846. _gl.bindBuffer( 34962, buffers.normal );
  13847. _gl.bufferData( 34962, object.normalArray, 35048 );
  13848. state.enableAttribute( programAttributes.normal );
  13849. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  13850. }
  13851. if ( object.hasUvs ) {
  13852. _gl.bindBuffer( 34962, buffers.uv );
  13853. _gl.bufferData( 34962, object.uvArray, 35048 );
  13854. state.enableAttribute( programAttributes.uv );
  13855. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  13856. }
  13857. if ( object.hasColors ) {
  13858. _gl.bindBuffer( 34962, buffers.color );
  13859. _gl.bufferData( 34962, object.colorArray, 35048 );
  13860. state.enableAttribute( programAttributes.color );
  13861. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  13862. }
  13863. state.disableUnusedAttributes();
  13864. _gl.drawArrays( 4, 0, object.count );
  13865. object.count = 0;
  13866. };
  13867. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13868. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13869. state.setMaterial( material, frontFaceCW );
  13870. var program = setProgram( camera, fog, material, object );
  13871. var updateBuffers = false;
  13872. if ( _currentGeometryProgram.geometry !== geometry.id ||
  13873. _currentGeometryProgram.program !== program.id ||
  13874. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  13875. _currentGeometryProgram.geometry = geometry.id;
  13876. _currentGeometryProgram.program = program.id;
  13877. _currentGeometryProgram.wireframe = material.wireframe === true;
  13878. updateBuffers = true;
  13879. }
  13880. if ( object.morphTargetInfluences ) {
  13881. morphtargets.update( object, geometry, material, program );
  13882. updateBuffers = true;
  13883. }
  13884. //
  13885. var index = geometry.index;
  13886. var position = geometry.attributes.position;
  13887. var rangeFactor = 1;
  13888. if ( material.wireframe === true ) {
  13889. index = geometries.getWireframeAttribute( geometry );
  13890. rangeFactor = 2;
  13891. }
  13892. var attribute;
  13893. var renderer = bufferRenderer;
  13894. if ( index !== null ) {
  13895. attribute = attributes.get( index );
  13896. renderer = indexedBufferRenderer;
  13897. renderer.setIndex( attribute );
  13898. }
  13899. if ( updateBuffers ) {
  13900. setupVertexAttributes( material, program, geometry );
  13901. if ( index !== null ) {
  13902. _gl.bindBuffer( 34963, attribute.buffer );
  13903. }
  13904. }
  13905. //
  13906. var dataCount = Infinity;
  13907. if ( index !== null ) {
  13908. dataCount = index.count;
  13909. } else if ( position !== undefined ) {
  13910. dataCount = position.count;
  13911. }
  13912. var rangeStart = geometry.drawRange.start * rangeFactor;
  13913. var rangeCount = geometry.drawRange.count * rangeFactor;
  13914. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13915. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13916. var drawStart = Math.max( rangeStart, groupStart );
  13917. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13918. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13919. if ( drawCount === 0 ) return;
  13920. //
  13921. if ( object.isMesh ) {
  13922. if ( material.wireframe === true ) {
  13923. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13924. renderer.setMode( 1 );
  13925. } else {
  13926. switch ( object.drawMode ) {
  13927. case TrianglesDrawMode:
  13928. renderer.setMode( 4 );
  13929. break;
  13930. case TriangleStripDrawMode:
  13931. renderer.setMode( 5 );
  13932. break;
  13933. case TriangleFanDrawMode:
  13934. renderer.setMode( 6 );
  13935. break;
  13936. }
  13937. }
  13938. } else if ( object.isLine ) {
  13939. var lineWidth = material.linewidth;
  13940. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13941. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13942. if ( object.isLineSegments ) {
  13943. renderer.setMode( 1 );
  13944. } else if ( object.isLineLoop ) {
  13945. renderer.setMode( 2 );
  13946. } else {
  13947. renderer.setMode( 3 );
  13948. }
  13949. } else if ( object.isPoints ) {
  13950. renderer.setMode( 0 );
  13951. } else if ( object.isSprite ) {
  13952. renderer.setMode( 4 );
  13953. }
  13954. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13955. if ( geometry.maxInstancedCount > 0 ) {
  13956. renderer.renderInstances( geometry, drawStart, drawCount );
  13957. }
  13958. } else {
  13959. renderer.render( drawStart, drawCount );
  13960. }
  13961. };
  13962. function setupVertexAttributes( material, program, geometry ) {
  13963. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  13964. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13965. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13966. return;
  13967. }
  13968. }
  13969. state.initAttributes();
  13970. var geometryAttributes = geometry.attributes;
  13971. var programAttributes = program.getAttributes();
  13972. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13973. for ( var name in programAttributes ) {
  13974. var programAttribute = programAttributes[ name ];
  13975. if ( programAttribute >= 0 ) {
  13976. var geometryAttribute = geometryAttributes[ name ];
  13977. if ( geometryAttribute !== undefined ) {
  13978. var normalized = geometryAttribute.normalized;
  13979. var size = geometryAttribute.itemSize;
  13980. var attribute = attributes.get( geometryAttribute );
  13981. // TODO Attribute may not be available on context restore
  13982. if ( attribute === undefined ) continue;
  13983. var buffer = attribute.buffer;
  13984. var type = attribute.type;
  13985. var bytesPerElement = attribute.bytesPerElement;
  13986. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13987. var data = geometryAttribute.data;
  13988. var stride = data.stride;
  13989. var offset = geometryAttribute.offset;
  13990. if ( data && data.isInstancedInterleavedBuffer ) {
  13991. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13992. if ( geometry.maxInstancedCount === undefined ) {
  13993. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13994. }
  13995. } else {
  13996. state.enableAttribute( programAttribute );
  13997. }
  13998. _gl.bindBuffer( 34962, buffer );
  13999. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14000. } else {
  14001. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14002. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14003. if ( geometry.maxInstancedCount === undefined ) {
  14004. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14005. }
  14006. } else {
  14007. state.enableAttribute( programAttribute );
  14008. }
  14009. _gl.bindBuffer( 34962, buffer );
  14010. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14011. }
  14012. } else if ( materialDefaultAttributeValues !== undefined ) {
  14013. var value = materialDefaultAttributeValues[ name ];
  14014. if ( value !== undefined ) {
  14015. switch ( value.length ) {
  14016. case 2:
  14017. _gl.vertexAttrib2fv( programAttribute, value );
  14018. break;
  14019. case 3:
  14020. _gl.vertexAttrib3fv( programAttribute, value );
  14021. break;
  14022. case 4:
  14023. _gl.vertexAttrib4fv( programAttribute, value );
  14024. break;
  14025. default:
  14026. _gl.vertexAttrib1fv( programAttribute, value );
  14027. }
  14028. }
  14029. }
  14030. }
  14031. }
  14032. state.disableUnusedAttributes();
  14033. }
  14034. // Compile
  14035. this.compile = function ( scene, camera ) {
  14036. currentRenderState = renderStates.get( scene, camera );
  14037. currentRenderState.init();
  14038. scene.traverse( function ( object ) {
  14039. if ( object.isLight ) {
  14040. currentRenderState.pushLight( object );
  14041. if ( object.castShadow ) {
  14042. currentRenderState.pushShadow( object );
  14043. }
  14044. }
  14045. } );
  14046. currentRenderState.setupLights( camera );
  14047. scene.traverse( function ( object ) {
  14048. if ( object.material ) {
  14049. if ( Array.isArray( object.material ) ) {
  14050. for ( var i = 0; i < object.material.length; i ++ ) {
  14051. initMaterial( object.material[ i ], scene.fog, object );
  14052. }
  14053. } else {
  14054. initMaterial( object.material, scene.fog, object );
  14055. }
  14056. }
  14057. } );
  14058. };
  14059. // Animation Loop
  14060. var onAnimationFrameCallback = null;
  14061. function onAnimationFrame( time ) {
  14062. if ( vr.isPresenting() ) return;
  14063. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14064. }
  14065. var animation = new WebGLAnimation();
  14066. animation.setAnimationLoop( onAnimationFrame );
  14067. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14068. this.setAnimationLoop = function ( callback ) {
  14069. onAnimationFrameCallback = callback;
  14070. vr.setAnimationLoop( callback );
  14071. animation.start();
  14072. };
  14073. // Rendering
  14074. this.render = function ( scene, camera ) {
  14075. var renderTarget, forceClear;
  14076. if ( arguments[ 2 ] !== undefined ) {
  14077. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14078. renderTarget = arguments[ 2 ];
  14079. }
  14080. if ( arguments[ 3 ] !== undefined ) {
  14081. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14082. forceClear = arguments[ 3 ];
  14083. }
  14084. if ( ! ( camera && camera.isCamera ) ) {
  14085. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14086. return;
  14087. }
  14088. if ( _isContextLost ) return;
  14089. // reset caching for this frame
  14090. _currentGeometryProgram.geometry = null;
  14091. _currentGeometryProgram.program = null;
  14092. _currentGeometryProgram.wireframe = false;
  14093. _currentMaterialId = - 1;
  14094. _currentCamera = null;
  14095. // update scene graph
  14096. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14097. // update camera matrices and frustum
  14098. if ( camera.parent === null ) camera.updateMatrixWorld();
  14099. if ( vr.enabled ) {
  14100. camera = vr.getCamera( camera );
  14101. }
  14102. //
  14103. currentRenderState = renderStates.get( scene, camera );
  14104. currentRenderState.init();
  14105. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14106. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14107. _frustum.setFromMatrix( _projScreenMatrix );
  14108. _localClippingEnabled = this.localClippingEnabled;
  14109. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14110. currentRenderList = renderLists.get( scene, camera );
  14111. currentRenderList.init();
  14112. projectObject( scene, camera, 0, _this.sortObjects );
  14113. if ( _this.sortObjects === true ) {
  14114. currentRenderList.sort();
  14115. }
  14116. //
  14117. if ( _clippingEnabled ) _clipping.beginShadows();
  14118. var shadowsArray = currentRenderState.state.shadowsArray;
  14119. shadowMap.render( shadowsArray, scene, camera );
  14120. currentRenderState.setupLights( camera );
  14121. if ( _clippingEnabled ) _clipping.endShadows();
  14122. //
  14123. if ( this.info.autoReset ) this.info.reset();
  14124. if ( renderTarget !== undefined ) {
  14125. this.setRenderTarget( renderTarget );
  14126. }
  14127. //
  14128. background.render( currentRenderList, scene, camera, forceClear );
  14129. // render scene
  14130. var opaqueObjects = currentRenderList.opaque;
  14131. var transparentObjects = currentRenderList.transparent;
  14132. if ( scene.overrideMaterial ) {
  14133. var overrideMaterial = scene.overrideMaterial;
  14134. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14135. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14136. } else {
  14137. // opaque pass (front-to-back order)
  14138. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14139. // transparent pass (back-to-front order)
  14140. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14141. }
  14142. //
  14143. scene.onAfterRender( _this, scene, camera );
  14144. //
  14145. if ( _currentRenderTarget !== null ) {
  14146. // Generate mipmap if we're using any kind of mipmap filtering
  14147. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14148. // resolve multisample renderbuffers to a single-sample texture if necessary
  14149. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14150. }
  14151. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14152. state.buffers.depth.setTest( true );
  14153. state.buffers.depth.setMask( true );
  14154. state.buffers.color.setMask( true );
  14155. state.setPolygonOffset( false );
  14156. if ( vr.enabled ) {
  14157. vr.submitFrame();
  14158. }
  14159. // _gl.finish();
  14160. currentRenderList = null;
  14161. currentRenderState = null;
  14162. };
  14163. function projectObject( object, camera, groupOrder, sortObjects ) {
  14164. if ( object.visible === false ) return;
  14165. var visible = object.layers.test( camera.layers );
  14166. if ( visible ) {
  14167. if ( object.isGroup ) {
  14168. groupOrder = object.renderOrder;
  14169. } else if ( object.isLight ) {
  14170. currentRenderState.pushLight( object );
  14171. if ( object.castShadow ) {
  14172. currentRenderState.pushShadow( object );
  14173. }
  14174. } else if ( object.isSprite ) {
  14175. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14176. if ( sortObjects ) {
  14177. _vector3.setFromMatrixPosition( object.matrixWorld )
  14178. .applyMatrix4( _projScreenMatrix );
  14179. }
  14180. var geometry = objects.update( object );
  14181. var material = object.material;
  14182. if ( material.visible ) {
  14183. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14184. }
  14185. }
  14186. } else if ( object.isImmediateRenderObject ) {
  14187. if ( sortObjects ) {
  14188. _vector3.setFromMatrixPosition( object.matrixWorld )
  14189. .applyMatrix4( _projScreenMatrix );
  14190. }
  14191. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14192. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14193. if ( object.isSkinnedMesh ) {
  14194. object.skeleton.update();
  14195. }
  14196. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14197. if ( sortObjects ) {
  14198. _vector3.setFromMatrixPosition( object.matrixWorld )
  14199. .applyMatrix4( _projScreenMatrix );
  14200. }
  14201. var geometry = objects.update( object );
  14202. var material = object.material;
  14203. if ( Array.isArray( material ) ) {
  14204. var groups = geometry.groups;
  14205. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14206. var group = groups[ i ];
  14207. var groupMaterial = material[ group.materialIndex ];
  14208. if ( groupMaterial && groupMaterial.visible ) {
  14209. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14210. }
  14211. }
  14212. } else if ( material.visible ) {
  14213. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14214. }
  14215. }
  14216. }
  14217. }
  14218. var children = object.children;
  14219. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14220. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14221. }
  14222. }
  14223. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14224. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14225. var renderItem = renderList[ i ];
  14226. var object = renderItem.object;
  14227. var geometry = renderItem.geometry;
  14228. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14229. var group = renderItem.group;
  14230. if ( camera.isArrayCamera ) {
  14231. _currentArrayCamera = camera;
  14232. var cameras = camera.cameras;
  14233. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14234. var camera2 = cameras[ j ];
  14235. if ( object.layers.test( camera2.layers ) ) {
  14236. if ( 'viewport' in camera2 ) { // XR
  14237. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14238. } else {
  14239. var bounds = camera2.bounds;
  14240. var x = bounds.x * _width;
  14241. var y = bounds.y * _height;
  14242. var width = bounds.z * _width;
  14243. var height = bounds.w * _height;
  14244. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  14245. }
  14246. currentRenderState.setupLights( camera2 );
  14247. renderObject( object, scene, camera2, geometry, material, group );
  14248. }
  14249. }
  14250. } else {
  14251. _currentArrayCamera = null;
  14252. renderObject( object, scene, camera, geometry, material, group );
  14253. }
  14254. }
  14255. }
  14256. function renderObject( object, scene, camera, geometry, material, group ) {
  14257. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14258. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14259. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14260. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14261. if ( object.isImmediateRenderObject ) {
  14262. state.setMaterial( material );
  14263. var program = setProgram( camera, scene.fog, material, object );
  14264. _currentGeometryProgram.geometry = null;
  14265. _currentGeometryProgram.program = null;
  14266. _currentGeometryProgram.wireframe = false;
  14267. renderObjectImmediate( object, program );
  14268. } else {
  14269. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14270. }
  14271. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14272. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14273. }
  14274. function initMaterial( material, fog, object ) {
  14275. var materialProperties = properties.get( material );
  14276. var lights = currentRenderState.state.lights;
  14277. var shadowsArray = currentRenderState.state.shadowsArray;
  14278. var lightsHash = materialProperties.lightsHash;
  14279. var lightsStateHash = lights.state.hash;
  14280. var parameters = programCache.getParameters(
  14281. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14282. var code = programCache.getProgramCode( material, parameters );
  14283. var program = materialProperties.program;
  14284. var programChange = true;
  14285. if ( program === undefined ) {
  14286. // new material
  14287. material.addEventListener( 'dispose', onMaterialDispose );
  14288. } else if ( program.code !== code ) {
  14289. // changed glsl or parameters
  14290. releaseMaterialProgramReference( material );
  14291. } else if ( lightsHash.stateID !== lightsStateHash.stateID ||
  14292. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14293. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14294. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14295. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14296. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14297. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) {
  14298. lightsHash.stateID = lightsStateHash.stateID;
  14299. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14300. lightsHash.pointLength = lightsStateHash.pointLength;
  14301. lightsHash.spotLength = lightsStateHash.spotLength;
  14302. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14303. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14304. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14305. programChange = false;
  14306. } else if ( parameters.shaderID !== undefined ) {
  14307. // same glsl and uniform list
  14308. return;
  14309. } else {
  14310. // only rebuild uniform list
  14311. programChange = false;
  14312. }
  14313. if ( programChange ) {
  14314. if ( parameters.shaderID ) {
  14315. var shader = ShaderLib[ parameters.shaderID ];
  14316. materialProperties.shader = {
  14317. name: material.type,
  14318. uniforms: cloneUniforms( shader.uniforms ),
  14319. vertexShader: shader.vertexShader,
  14320. fragmentShader: shader.fragmentShader
  14321. };
  14322. } else {
  14323. materialProperties.shader = {
  14324. name: material.type,
  14325. uniforms: material.uniforms,
  14326. vertexShader: material.vertexShader,
  14327. fragmentShader: material.fragmentShader
  14328. };
  14329. }
  14330. material.onBeforeCompile( materialProperties.shader, _this );
  14331. // Computing code again as onBeforeCompile may have changed the shaders
  14332. code = programCache.getProgramCode( material, parameters );
  14333. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14334. materialProperties.program = program;
  14335. material.program = program;
  14336. }
  14337. var programAttributes = program.getAttributes();
  14338. if ( material.morphTargets ) {
  14339. material.numSupportedMorphTargets = 0;
  14340. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14341. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14342. material.numSupportedMorphTargets ++;
  14343. }
  14344. }
  14345. }
  14346. if ( material.morphNormals ) {
  14347. material.numSupportedMorphNormals = 0;
  14348. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14349. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14350. material.numSupportedMorphNormals ++;
  14351. }
  14352. }
  14353. }
  14354. var uniforms = materialProperties.shader.uniforms;
  14355. if ( ! material.isShaderMaterial &&
  14356. ! material.isRawShaderMaterial ||
  14357. material.clipping === true ) {
  14358. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14359. materialProperties.numIntersection = _clipping.numIntersection;
  14360. uniforms.clippingPlanes = _clipping.uniform;
  14361. }
  14362. materialProperties.fog = fog;
  14363. // store the light setup it was created for
  14364. if ( lightsHash === undefined ) {
  14365. materialProperties.lightsHash = lightsHash = {};
  14366. }
  14367. lightsHash.stateID = lightsStateHash.stateID;
  14368. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14369. lightsHash.pointLength = lightsStateHash.pointLength;
  14370. lightsHash.spotLength = lightsStateHash.spotLength;
  14371. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14372. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14373. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14374. if ( material.lights ) {
  14375. // wire up the material to this renderer's lighting state
  14376. uniforms.ambientLightColor.value = lights.state.ambient;
  14377. uniforms.lightProbe.value = lights.state.probe;
  14378. uniforms.directionalLights.value = lights.state.directional;
  14379. uniforms.spotLights.value = lights.state.spot;
  14380. uniforms.rectAreaLights.value = lights.state.rectArea;
  14381. uniforms.pointLights.value = lights.state.point;
  14382. uniforms.hemisphereLights.value = lights.state.hemi;
  14383. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14384. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14385. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14386. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14387. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14388. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14389. // TODO (abelnation): add area lights shadow info to uniforms
  14390. }
  14391. var progUniforms = materialProperties.program.getUniforms(),
  14392. uniformsList =
  14393. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14394. materialProperties.uniformsList = uniformsList;
  14395. }
  14396. function setProgram( camera, fog, material, object ) {
  14397. textures.resetTextureUnits();
  14398. var materialProperties = properties.get( material );
  14399. var lights = currentRenderState.state.lights;
  14400. var lightsHash = materialProperties.lightsHash;
  14401. var lightsStateHash = lights.state.hash;
  14402. if ( _clippingEnabled ) {
  14403. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14404. var useCache =
  14405. camera === _currentCamera &&
  14406. material.id === _currentMaterialId;
  14407. // we might want to call this function with some ClippingGroup
  14408. // object instead of the material, once it becomes feasible
  14409. // (#8465, #8379)
  14410. _clipping.setState(
  14411. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14412. camera, materialProperties, useCache );
  14413. }
  14414. }
  14415. if ( material.needsUpdate === false ) {
  14416. if ( materialProperties.program === undefined ) {
  14417. material.needsUpdate = true;
  14418. } else if ( material.fog && materialProperties.fog !== fog ) {
  14419. material.needsUpdate = true;
  14420. } else if ( material.lights && ( lightsHash.stateID !== lightsStateHash.stateID ||
  14421. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14422. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14423. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14424. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14425. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14426. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) ) {
  14427. material.needsUpdate = true;
  14428. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14429. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14430. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14431. material.needsUpdate = true;
  14432. }
  14433. }
  14434. if ( material.needsUpdate ) {
  14435. initMaterial( material, fog, object );
  14436. material.needsUpdate = false;
  14437. }
  14438. var refreshProgram = false;
  14439. var refreshMaterial = false;
  14440. var refreshLights = false;
  14441. var program = materialProperties.program,
  14442. p_uniforms = program.getUniforms(),
  14443. m_uniforms = materialProperties.shader.uniforms;
  14444. if ( state.useProgram( program.program ) ) {
  14445. refreshProgram = true;
  14446. refreshMaterial = true;
  14447. refreshLights = true;
  14448. }
  14449. if ( material.id !== _currentMaterialId ) {
  14450. _currentMaterialId = material.id;
  14451. refreshMaterial = true;
  14452. }
  14453. if ( refreshProgram || _currentCamera !== camera ) {
  14454. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14455. if ( capabilities.logarithmicDepthBuffer ) {
  14456. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14457. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14458. }
  14459. if ( _currentCamera !== camera ) {
  14460. _currentCamera = camera;
  14461. // lighting uniforms depend on the camera so enforce an update
  14462. // now, in case this material supports lights - or later, when
  14463. // the next material that does gets activated:
  14464. refreshMaterial = true; // set to true on material change
  14465. refreshLights = true; // remains set until update done
  14466. }
  14467. // load material specific uniforms
  14468. // (shader material also gets them for the sake of genericity)
  14469. if ( material.isShaderMaterial ||
  14470. material.isMeshPhongMaterial ||
  14471. material.isMeshStandardMaterial ||
  14472. material.envMap ) {
  14473. var uCamPos = p_uniforms.map.cameraPosition;
  14474. if ( uCamPos !== undefined ) {
  14475. uCamPos.setValue( _gl,
  14476. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14477. }
  14478. }
  14479. if ( material.isMeshPhongMaterial ||
  14480. material.isMeshLambertMaterial ||
  14481. material.isMeshBasicMaterial ||
  14482. material.isMeshStandardMaterial ||
  14483. material.isShaderMaterial ||
  14484. material.skinning ) {
  14485. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14486. }
  14487. }
  14488. // skinning uniforms must be set even if material didn't change
  14489. // auto-setting of texture unit for bone texture must go before other textures
  14490. // not sure why, but otherwise weird things happen
  14491. if ( material.skinning ) {
  14492. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14493. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14494. var skeleton = object.skeleton;
  14495. if ( skeleton ) {
  14496. var bones = skeleton.bones;
  14497. if ( capabilities.floatVertexTextures ) {
  14498. if ( skeleton.boneTexture === undefined ) {
  14499. // layout (1 matrix = 4 pixels)
  14500. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14501. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14502. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14503. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14504. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14505. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14506. size = _Math.ceilPowerOfTwo( size );
  14507. size = Math.max( size, 4 );
  14508. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14509. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14510. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14511. boneTexture.needsUpdate = true;
  14512. skeleton.boneMatrices = boneMatrices;
  14513. skeleton.boneTexture = boneTexture;
  14514. skeleton.boneTextureSize = size;
  14515. }
  14516. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14517. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14518. } else {
  14519. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14520. }
  14521. }
  14522. }
  14523. if ( refreshMaterial ) {
  14524. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14525. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14526. if ( material.lights ) {
  14527. // the current material requires lighting info
  14528. // note: all lighting uniforms are always set correctly
  14529. // they simply reference the renderer's state for their
  14530. // values
  14531. //
  14532. // use the current material's .needsUpdate flags to set
  14533. // the GL state when required
  14534. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14535. }
  14536. // refresh uniforms common to several materials
  14537. if ( fog && material.fog ) {
  14538. refreshUniformsFog( m_uniforms, fog );
  14539. }
  14540. if ( material.isMeshBasicMaterial ) {
  14541. refreshUniformsCommon( m_uniforms, material );
  14542. } else if ( material.isMeshLambertMaterial ) {
  14543. refreshUniformsCommon( m_uniforms, material );
  14544. refreshUniformsLambert( m_uniforms, material );
  14545. } else if ( material.isMeshPhongMaterial ) {
  14546. refreshUniformsCommon( m_uniforms, material );
  14547. if ( material.isMeshToonMaterial ) {
  14548. refreshUniformsToon( m_uniforms, material );
  14549. } else {
  14550. refreshUniformsPhong( m_uniforms, material );
  14551. }
  14552. } else if ( material.isMeshStandardMaterial ) {
  14553. refreshUniformsCommon( m_uniforms, material );
  14554. if ( material.isMeshPhysicalMaterial ) {
  14555. refreshUniformsPhysical( m_uniforms, material );
  14556. } else {
  14557. refreshUniformsStandard( m_uniforms, material );
  14558. }
  14559. } else if ( material.isMeshMatcapMaterial ) {
  14560. refreshUniformsCommon( m_uniforms, material );
  14561. refreshUniformsMatcap( m_uniforms, material );
  14562. } else if ( material.isMeshDepthMaterial ) {
  14563. refreshUniformsCommon( m_uniforms, material );
  14564. refreshUniformsDepth( m_uniforms, material );
  14565. } else if ( material.isMeshDistanceMaterial ) {
  14566. refreshUniformsCommon( m_uniforms, material );
  14567. refreshUniformsDistance( m_uniforms, material );
  14568. } else if ( material.isMeshNormalMaterial ) {
  14569. refreshUniformsCommon( m_uniforms, material );
  14570. refreshUniformsNormal( m_uniforms, material );
  14571. } else if ( material.isLineBasicMaterial ) {
  14572. refreshUniformsLine( m_uniforms, material );
  14573. if ( material.isLineDashedMaterial ) {
  14574. refreshUniformsDash( m_uniforms, material );
  14575. }
  14576. } else if ( material.isPointsMaterial ) {
  14577. refreshUniformsPoints( m_uniforms, material );
  14578. } else if ( material.isSpriteMaterial ) {
  14579. refreshUniformsSprites( m_uniforms, material );
  14580. } else if ( material.isShadowMaterial ) {
  14581. m_uniforms.color.value = material.color;
  14582. m_uniforms.opacity.value = material.opacity;
  14583. }
  14584. // RectAreaLight Texture
  14585. // TODO (mrdoob): Find a nicer implementation
  14586. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14587. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14588. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14589. }
  14590. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14591. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14592. material.uniformsNeedUpdate = false;
  14593. }
  14594. if ( material.isSpriteMaterial ) {
  14595. p_uniforms.setValue( _gl, 'center', object.center );
  14596. }
  14597. // common matrices
  14598. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14599. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14600. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14601. return program;
  14602. }
  14603. // Uniforms (refresh uniforms objects)
  14604. function refreshUniformsCommon( uniforms, material ) {
  14605. uniforms.opacity.value = material.opacity;
  14606. if ( material.color ) {
  14607. uniforms.diffuse.value = material.color;
  14608. }
  14609. if ( material.emissive ) {
  14610. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14611. }
  14612. if ( material.map ) {
  14613. uniforms.map.value = material.map;
  14614. }
  14615. if ( material.alphaMap ) {
  14616. uniforms.alphaMap.value = material.alphaMap;
  14617. }
  14618. if ( material.specularMap ) {
  14619. uniforms.specularMap.value = material.specularMap;
  14620. }
  14621. if ( material.envMap ) {
  14622. uniforms.envMap.value = material.envMap;
  14623. // don't flip CubeTexture envMaps, flip everything else:
  14624. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14625. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14626. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14627. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14628. uniforms.reflectivity.value = material.reflectivity;
  14629. uniforms.refractionRatio.value = material.refractionRatio;
  14630. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14631. }
  14632. if ( material.lightMap ) {
  14633. uniforms.lightMap.value = material.lightMap;
  14634. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14635. }
  14636. if ( material.aoMap ) {
  14637. uniforms.aoMap.value = material.aoMap;
  14638. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14639. }
  14640. // uv repeat and offset setting priorities
  14641. // 1. color map
  14642. // 2. specular map
  14643. // 3. normal map
  14644. // 4. bump map
  14645. // 5. alpha map
  14646. // 6. emissive map
  14647. var uvScaleMap;
  14648. if ( material.map ) {
  14649. uvScaleMap = material.map;
  14650. } else if ( material.specularMap ) {
  14651. uvScaleMap = material.specularMap;
  14652. } else if ( material.displacementMap ) {
  14653. uvScaleMap = material.displacementMap;
  14654. } else if ( material.normalMap ) {
  14655. uvScaleMap = material.normalMap;
  14656. } else if ( material.bumpMap ) {
  14657. uvScaleMap = material.bumpMap;
  14658. } else if ( material.roughnessMap ) {
  14659. uvScaleMap = material.roughnessMap;
  14660. } else if ( material.metalnessMap ) {
  14661. uvScaleMap = material.metalnessMap;
  14662. } else if ( material.alphaMap ) {
  14663. uvScaleMap = material.alphaMap;
  14664. } else if ( material.emissiveMap ) {
  14665. uvScaleMap = material.emissiveMap;
  14666. }
  14667. if ( uvScaleMap !== undefined ) {
  14668. // backwards compatibility
  14669. if ( uvScaleMap.isWebGLRenderTarget ) {
  14670. uvScaleMap = uvScaleMap.texture;
  14671. }
  14672. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14673. uvScaleMap.updateMatrix();
  14674. }
  14675. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14676. }
  14677. }
  14678. function refreshUniformsLine( uniforms, material ) {
  14679. uniforms.diffuse.value = material.color;
  14680. uniforms.opacity.value = material.opacity;
  14681. }
  14682. function refreshUniformsDash( uniforms, material ) {
  14683. uniforms.dashSize.value = material.dashSize;
  14684. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14685. uniforms.scale.value = material.scale;
  14686. }
  14687. function refreshUniformsPoints( uniforms, material ) {
  14688. uniforms.diffuse.value = material.color;
  14689. uniforms.opacity.value = material.opacity;
  14690. uniforms.size.value = material.size * _pixelRatio;
  14691. uniforms.scale.value = _height * 0.5;
  14692. uniforms.map.value = material.map;
  14693. if ( material.map !== null ) {
  14694. if ( material.map.matrixAutoUpdate === true ) {
  14695. material.map.updateMatrix();
  14696. }
  14697. uniforms.uvTransform.value.copy( material.map.matrix );
  14698. }
  14699. }
  14700. function refreshUniformsSprites( uniforms, material ) {
  14701. uniforms.diffuse.value = material.color;
  14702. uniforms.opacity.value = material.opacity;
  14703. uniforms.rotation.value = material.rotation;
  14704. uniforms.map.value = material.map;
  14705. if ( material.map !== null ) {
  14706. if ( material.map.matrixAutoUpdate === true ) {
  14707. material.map.updateMatrix();
  14708. }
  14709. uniforms.uvTransform.value.copy( material.map.matrix );
  14710. }
  14711. }
  14712. function refreshUniformsFog( uniforms, fog ) {
  14713. uniforms.fogColor.value = fog.color;
  14714. if ( fog.isFog ) {
  14715. uniforms.fogNear.value = fog.near;
  14716. uniforms.fogFar.value = fog.far;
  14717. } else if ( fog.isFogExp2 ) {
  14718. uniforms.fogDensity.value = fog.density;
  14719. }
  14720. }
  14721. function refreshUniformsLambert( uniforms, material ) {
  14722. if ( material.emissiveMap ) {
  14723. uniforms.emissiveMap.value = material.emissiveMap;
  14724. }
  14725. }
  14726. function refreshUniformsPhong( uniforms, material ) {
  14727. uniforms.specular.value = material.specular;
  14728. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14729. if ( material.emissiveMap ) {
  14730. uniforms.emissiveMap.value = material.emissiveMap;
  14731. }
  14732. if ( material.bumpMap ) {
  14733. uniforms.bumpMap.value = material.bumpMap;
  14734. uniforms.bumpScale.value = material.bumpScale;
  14735. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14736. }
  14737. if ( material.normalMap ) {
  14738. uniforms.normalMap.value = material.normalMap;
  14739. uniforms.normalScale.value.copy( material.normalScale );
  14740. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14741. }
  14742. if ( material.displacementMap ) {
  14743. uniforms.displacementMap.value = material.displacementMap;
  14744. uniforms.displacementScale.value = material.displacementScale;
  14745. uniforms.displacementBias.value = material.displacementBias;
  14746. }
  14747. }
  14748. function refreshUniformsToon( uniforms, material ) {
  14749. refreshUniformsPhong( uniforms, material );
  14750. if ( material.gradientMap ) {
  14751. uniforms.gradientMap.value = material.gradientMap;
  14752. }
  14753. }
  14754. function refreshUniformsStandard( uniforms, material ) {
  14755. uniforms.roughness.value = material.roughness;
  14756. uniforms.metalness.value = material.metalness;
  14757. if ( material.roughnessMap ) {
  14758. uniforms.roughnessMap.value = material.roughnessMap;
  14759. }
  14760. if ( material.metalnessMap ) {
  14761. uniforms.metalnessMap.value = material.metalnessMap;
  14762. }
  14763. if ( material.emissiveMap ) {
  14764. uniforms.emissiveMap.value = material.emissiveMap;
  14765. }
  14766. if ( material.bumpMap ) {
  14767. uniforms.bumpMap.value = material.bumpMap;
  14768. uniforms.bumpScale.value = material.bumpScale;
  14769. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14770. }
  14771. if ( material.normalMap ) {
  14772. uniforms.normalMap.value = material.normalMap;
  14773. uniforms.normalScale.value.copy( material.normalScale );
  14774. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14775. }
  14776. if ( material.displacementMap ) {
  14777. uniforms.displacementMap.value = material.displacementMap;
  14778. uniforms.displacementScale.value = material.displacementScale;
  14779. uniforms.displacementBias.value = material.displacementBias;
  14780. }
  14781. if ( material.envMap ) {
  14782. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14783. uniforms.envMapIntensity.value = material.envMapIntensity;
  14784. }
  14785. }
  14786. function refreshUniformsPhysical( uniforms, material ) {
  14787. refreshUniformsStandard( uniforms, material );
  14788. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14789. uniforms.clearCoat.value = material.clearCoat;
  14790. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14791. }
  14792. function refreshUniformsMatcap( uniforms, material ) {
  14793. if ( material.matcap ) {
  14794. uniforms.matcap.value = material.matcap;
  14795. }
  14796. if ( material.bumpMap ) {
  14797. uniforms.bumpMap.value = material.bumpMap;
  14798. uniforms.bumpScale.value = material.bumpScale;
  14799. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14800. }
  14801. if ( material.normalMap ) {
  14802. uniforms.normalMap.value = material.normalMap;
  14803. uniforms.normalScale.value.copy( material.normalScale );
  14804. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14805. }
  14806. if ( material.displacementMap ) {
  14807. uniforms.displacementMap.value = material.displacementMap;
  14808. uniforms.displacementScale.value = material.displacementScale;
  14809. uniforms.displacementBias.value = material.displacementBias;
  14810. }
  14811. }
  14812. function refreshUniformsDepth( uniforms, material ) {
  14813. if ( material.displacementMap ) {
  14814. uniforms.displacementMap.value = material.displacementMap;
  14815. uniforms.displacementScale.value = material.displacementScale;
  14816. uniforms.displacementBias.value = material.displacementBias;
  14817. }
  14818. }
  14819. function refreshUniformsDistance( uniforms, material ) {
  14820. if ( material.displacementMap ) {
  14821. uniforms.displacementMap.value = material.displacementMap;
  14822. uniforms.displacementScale.value = material.displacementScale;
  14823. uniforms.displacementBias.value = material.displacementBias;
  14824. }
  14825. uniforms.referencePosition.value.copy( material.referencePosition );
  14826. uniforms.nearDistance.value = material.nearDistance;
  14827. uniforms.farDistance.value = material.farDistance;
  14828. }
  14829. function refreshUniformsNormal( uniforms, material ) {
  14830. if ( material.bumpMap ) {
  14831. uniforms.bumpMap.value = material.bumpMap;
  14832. uniforms.bumpScale.value = material.bumpScale;
  14833. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14834. }
  14835. if ( material.normalMap ) {
  14836. uniforms.normalMap.value = material.normalMap;
  14837. uniforms.normalScale.value.copy( material.normalScale );
  14838. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14839. }
  14840. if ( material.displacementMap ) {
  14841. uniforms.displacementMap.value = material.displacementMap;
  14842. uniforms.displacementScale.value = material.displacementScale;
  14843. uniforms.displacementBias.value = material.displacementBias;
  14844. }
  14845. }
  14846. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14847. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14848. uniforms.ambientLightColor.needsUpdate = value;
  14849. uniforms.lightProbe.needsUpdate = value;
  14850. uniforms.directionalLights.needsUpdate = value;
  14851. uniforms.pointLights.needsUpdate = value;
  14852. uniforms.spotLights.needsUpdate = value;
  14853. uniforms.rectAreaLights.needsUpdate = value;
  14854. uniforms.hemisphereLights.needsUpdate = value;
  14855. }
  14856. //
  14857. this.setFramebuffer = function ( value ) {
  14858. _framebuffer = value;
  14859. };
  14860. this.getRenderTarget = function () {
  14861. return _currentRenderTarget;
  14862. };
  14863. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipMapLevel ) {
  14864. _currentRenderTarget = renderTarget;
  14865. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14866. textures.setupRenderTarget( renderTarget );
  14867. }
  14868. var framebuffer = _framebuffer;
  14869. var isCube = false;
  14870. if ( renderTarget ) {
  14871. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14872. if ( renderTarget.isWebGLRenderTargetCube ) {
  14873. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  14874. isCube = true;
  14875. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14876. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14877. } else {
  14878. framebuffer = __webglFramebuffer;
  14879. }
  14880. _currentViewport.copy( renderTarget.viewport );
  14881. _currentScissor.copy( renderTarget.scissor );
  14882. _currentScissorTest = renderTarget.scissorTest;
  14883. } else {
  14884. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14885. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14886. _currentScissorTest = _scissorTest;
  14887. }
  14888. if ( _currentFramebuffer !== framebuffer ) {
  14889. _gl.bindFramebuffer( 36160, framebuffer );
  14890. _currentFramebuffer = framebuffer;
  14891. }
  14892. state.viewport( _currentViewport );
  14893. state.scissor( _currentScissor );
  14894. state.setScissorTest( _currentScissorTest );
  14895. if ( isCube ) {
  14896. var textureProperties = properties.get( renderTarget.texture );
  14897. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipMapLevel || 0 );
  14898. }
  14899. };
  14900. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14901. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14902. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14903. return;
  14904. }
  14905. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14906. if ( framebuffer ) {
  14907. var restore = false;
  14908. if ( framebuffer !== _currentFramebuffer ) {
  14909. _gl.bindFramebuffer( 36160, framebuffer );
  14910. restore = true;
  14911. }
  14912. try {
  14913. var texture = renderTarget.texture;
  14914. var textureFormat = texture.format;
  14915. var textureType = texture.type;
  14916. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14917. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14918. return;
  14919. }
  14920. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14921. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14922. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14923. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14924. return;
  14925. }
  14926. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14927. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14928. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14929. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14930. }
  14931. } else {
  14932. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14933. }
  14934. } finally {
  14935. if ( restore ) {
  14936. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14937. }
  14938. }
  14939. }
  14940. };
  14941. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14942. var width = texture.image.width;
  14943. var height = texture.image.height;
  14944. var glFormat = utils.convert( texture.format );
  14945. textures.setTexture2D( texture, 0 );
  14946. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14947. };
  14948. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14949. var width = srcTexture.image.width;
  14950. var height = srcTexture.image.height;
  14951. var glFormat = utils.convert( dstTexture.format );
  14952. var glType = utils.convert( dstTexture.type );
  14953. textures.setTexture2D( dstTexture, 0 );
  14954. if ( srcTexture.isDataTexture ) {
  14955. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14956. } else {
  14957. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14958. }
  14959. };
  14960. }
  14961. /**
  14962. * @author mrdoob / http://mrdoob.com/
  14963. * @author alteredq / http://alteredqualia.com/
  14964. */
  14965. function FogExp2( color, density ) {
  14966. this.name = '';
  14967. this.color = new Color( color );
  14968. this.density = ( density !== undefined ) ? density : 0.00025;
  14969. }
  14970. Object.assign( FogExp2.prototype, {
  14971. isFogExp2: true,
  14972. clone: function () {
  14973. return new FogExp2( this.color, this.density );
  14974. },
  14975. toJSON: function ( /* meta */ ) {
  14976. return {
  14977. type: 'FogExp2',
  14978. color: this.color.getHex(),
  14979. density: this.density
  14980. };
  14981. }
  14982. } );
  14983. /**
  14984. * @author mrdoob / http://mrdoob.com/
  14985. * @author alteredq / http://alteredqualia.com/
  14986. */
  14987. function Fog( color, near, far ) {
  14988. this.name = '';
  14989. this.color = new Color( color );
  14990. this.near = ( near !== undefined ) ? near : 1;
  14991. this.far = ( far !== undefined ) ? far : 1000;
  14992. }
  14993. Object.assign( Fog.prototype, {
  14994. isFog: true,
  14995. clone: function () {
  14996. return new Fog( this.color, this.near, this.far );
  14997. },
  14998. toJSON: function ( /* meta */ ) {
  14999. return {
  15000. type: 'Fog',
  15001. color: this.color.getHex(),
  15002. near: this.near,
  15003. far: this.far
  15004. };
  15005. }
  15006. } );
  15007. /**
  15008. * @author mrdoob / http://mrdoob.com/
  15009. */
  15010. function Scene() {
  15011. Object3D.call( this );
  15012. this.type = 'Scene';
  15013. this.background = null;
  15014. this.fog = null;
  15015. this.overrideMaterial = null;
  15016. this.autoUpdate = true; // checked by the renderer
  15017. }
  15018. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15019. constructor: Scene,
  15020. isScene: true,
  15021. copy: function ( source, recursive ) {
  15022. Object3D.prototype.copy.call( this, source, recursive );
  15023. if ( source.background !== null ) this.background = source.background.clone();
  15024. if ( source.fog !== null ) this.fog = source.fog.clone();
  15025. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  15026. this.autoUpdate = source.autoUpdate;
  15027. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15028. return this;
  15029. },
  15030. toJSON: function ( meta ) {
  15031. var data = Object3D.prototype.toJSON.call( this, meta );
  15032. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  15033. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  15034. return data;
  15035. },
  15036. dispose: function () {
  15037. this.dispatchEvent( { type: 'dispose' } );
  15038. }
  15039. } );
  15040. /**
  15041. * @author benaadams / https://twitter.com/ben_a_adams
  15042. */
  15043. function InterleavedBuffer( array, stride ) {
  15044. this.array = array;
  15045. this.stride = stride;
  15046. this.count = array !== undefined ? array.length / stride : 0;
  15047. this.dynamic = false;
  15048. this.updateRange = { offset: 0, count: - 1 };
  15049. this.version = 0;
  15050. }
  15051. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15052. set: function ( value ) {
  15053. if ( value === true ) this.version ++;
  15054. }
  15055. } );
  15056. Object.assign( InterleavedBuffer.prototype, {
  15057. isInterleavedBuffer: true,
  15058. onUploadCallback: function () {},
  15059. setArray: function ( array ) {
  15060. if ( Array.isArray( array ) ) {
  15061. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15062. }
  15063. this.count = array !== undefined ? array.length / this.stride : 0;
  15064. this.array = array;
  15065. return this;
  15066. },
  15067. setDynamic: function ( value ) {
  15068. this.dynamic = value;
  15069. return this;
  15070. },
  15071. copy: function ( source ) {
  15072. this.array = new source.array.constructor( source.array );
  15073. this.count = source.count;
  15074. this.stride = source.stride;
  15075. this.dynamic = source.dynamic;
  15076. return this;
  15077. },
  15078. copyAt: function ( index1, attribute, index2 ) {
  15079. index1 *= this.stride;
  15080. index2 *= attribute.stride;
  15081. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15082. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15083. }
  15084. return this;
  15085. },
  15086. set: function ( value, offset ) {
  15087. if ( offset === undefined ) offset = 0;
  15088. this.array.set( value, offset );
  15089. return this;
  15090. },
  15091. clone: function () {
  15092. return new this.constructor().copy( this );
  15093. },
  15094. onUpload: function ( callback ) {
  15095. this.onUploadCallback = callback;
  15096. return this;
  15097. }
  15098. } );
  15099. /**
  15100. * @author benaadams / https://twitter.com/ben_a_adams
  15101. */
  15102. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15103. this.data = interleavedBuffer;
  15104. this.itemSize = itemSize;
  15105. this.offset = offset;
  15106. this.normalized = normalized === true;
  15107. }
  15108. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15109. count: {
  15110. get: function () {
  15111. return this.data.count;
  15112. }
  15113. },
  15114. array: {
  15115. get: function () {
  15116. return this.data.array;
  15117. }
  15118. }
  15119. } );
  15120. Object.assign( InterleavedBufferAttribute.prototype, {
  15121. isInterleavedBufferAttribute: true,
  15122. setX: function ( index, x ) {
  15123. this.data.array[ index * this.data.stride + this.offset ] = x;
  15124. return this;
  15125. },
  15126. setY: function ( index, y ) {
  15127. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15128. return this;
  15129. },
  15130. setZ: function ( index, z ) {
  15131. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15132. return this;
  15133. },
  15134. setW: function ( index, w ) {
  15135. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15136. return this;
  15137. },
  15138. getX: function ( index ) {
  15139. return this.data.array[ index * this.data.stride + this.offset ];
  15140. },
  15141. getY: function ( index ) {
  15142. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15143. },
  15144. getZ: function ( index ) {
  15145. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15146. },
  15147. getW: function ( index ) {
  15148. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15149. },
  15150. setXY: function ( index, x, y ) {
  15151. index = index * this.data.stride + this.offset;
  15152. this.data.array[ index + 0 ] = x;
  15153. this.data.array[ index + 1 ] = y;
  15154. return this;
  15155. },
  15156. setXYZ: function ( index, x, y, z ) {
  15157. index = index * this.data.stride + this.offset;
  15158. this.data.array[ index + 0 ] = x;
  15159. this.data.array[ index + 1 ] = y;
  15160. this.data.array[ index + 2 ] = z;
  15161. return this;
  15162. },
  15163. setXYZW: function ( index, x, y, z, w ) {
  15164. index = index * this.data.stride + this.offset;
  15165. this.data.array[ index + 0 ] = x;
  15166. this.data.array[ index + 1 ] = y;
  15167. this.data.array[ index + 2 ] = z;
  15168. this.data.array[ index + 3 ] = w;
  15169. return this;
  15170. }
  15171. } );
  15172. /**
  15173. * @author alteredq / http://alteredqualia.com/
  15174. *
  15175. * parameters = {
  15176. * color: <hex>,
  15177. * map: new THREE.Texture( <Image> ),
  15178. * rotation: <float>,
  15179. * sizeAttenuation: <bool>
  15180. * }
  15181. */
  15182. function SpriteMaterial( parameters ) {
  15183. Material.call( this );
  15184. this.type = 'SpriteMaterial';
  15185. this.color = new Color( 0xffffff );
  15186. this.map = null;
  15187. this.rotation = 0;
  15188. this.sizeAttenuation = true;
  15189. this.lights = false;
  15190. this.transparent = true;
  15191. this.setValues( parameters );
  15192. }
  15193. SpriteMaterial.prototype = Object.create( Material.prototype );
  15194. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15195. SpriteMaterial.prototype.isSpriteMaterial = true;
  15196. SpriteMaterial.prototype.copy = function ( source ) {
  15197. Material.prototype.copy.call( this, source );
  15198. this.color.copy( source.color );
  15199. this.map = source.map;
  15200. this.rotation = source.rotation;
  15201. this.sizeAttenuation = source.sizeAttenuation;
  15202. return this;
  15203. };
  15204. /**
  15205. * @author mikael emtinger / http://gomo.se/
  15206. * @author alteredq / http://alteredqualia.com/
  15207. */
  15208. var geometry;
  15209. function Sprite( material ) {
  15210. Object3D.call( this );
  15211. this.type = 'Sprite';
  15212. if ( geometry === undefined ) {
  15213. geometry = new BufferGeometry();
  15214. var float32Array = new Float32Array( [
  15215. - 0.5, - 0.5, 0, 0, 0,
  15216. 0.5, - 0.5, 0, 1, 0,
  15217. 0.5, 0.5, 0, 1, 1,
  15218. - 0.5, 0.5, 0, 0, 1
  15219. ] );
  15220. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15221. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15222. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15223. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15224. }
  15225. this.geometry = geometry;
  15226. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15227. this.center = new Vector2( 0.5, 0.5 );
  15228. }
  15229. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15230. constructor: Sprite,
  15231. isSprite: true,
  15232. raycast: ( function () {
  15233. var intersectPoint = new Vector3();
  15234. var worldScale = new Vector3();
  15235. var mvPosition = new Vector3();
  15236. var alignedPosition = new Vector2();
  15237. var rotatedPosition = new Vector2();
  15238. var viewWorldMatrix = new Matrix4();
  15239. var vA = new Vector3();
  15240. var vB = new Vector3();
  15241. var vC = new Vector3();
  15242. var uvA = new Vector2();
  15243. var uvB = new Vector2();
  15244. var uvC = new Vector2();
  15245. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15246. // compute position in camera space
  15247. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15248. // to check if rotation is not zero
  15249. if ( sin !== undefined ) {
  15250. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15251. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15252. } else {
  15253. rotatedPosition.copy( alignedPosition );
  15254. }
  15255. vertexPosition.copy( mvPosition );
  15256. vertexPosition.x += rotatedPosition.x;
  15257. vertexPosition.y += rotatedPosition.y;
  15258. // transform to world space
  15259. vertexPosition.applyMatrix4( viewWorldMatrix );
  15260. }
  15261. return function raycast( raycaster, intersects ) {
  15262. worldScale.setFromMatrixScale( this.matrixWorld );
  15263. viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
  15264. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15265. var rotation = this.material.rotation;
  15266. var sin, cos;
  15267. if ( rotation !== 0 ) {
  15268. cos = Math.cos( rotation );
  15269. sin = Math.sin( rotation );
  15270. }
  15271. var center = this.center;
  15272. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15273. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15274. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15275. uvA.set( 0, 0 );
  15276. uvB.set( 1, 0 );
  15277. uvC.set( 1, 1 );
  15278. // check first triangle
  15279. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15280. if ( intersect === null ) {
  15281. // check second triangle
  15282. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15283. uvB.set( 0, 1 );
  15284. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15285. if ( intersect === null ) {
  15286. return;
  15287. }
  15288. }
  15289. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15290. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15291. intersects.push( {
  15292. distance: distance,
  15293. point: intersectPoint.clone(),
  15294. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15295. face: null,
  15296. object: this
  15297. } );
  15298. };
  15299. }() ),
  15300. clone: function () {
  15301. return new this.constructor( this.material ).copy( this );
  15302. },
  15303. copy: function ( source ) {
  15304. Object3D.prototype.copy.call( this, source );
  15305. if ( source.center !== undefined ) this.center.copy( source.center );
  15306. return this;
  15307. }
  15308. } );
  15309. /**
  15310. * @author mikael emtinger / http://gomo.se/
  15311. * @author alteredq / http://alteredqualia.com/
  15312. * @author mrdoob / http://mrdoob.com/
  15313. */
  15314. function LOD() {
  15315. Object3D.call( this );
  15316. this.type = 'LOD';
  15317. Object.defineProperties( this, {
  15318. levels: {
  15319. enumerable: true,
  15320. value: []
  15321. }
  15322. } );
  15323. }
  15324. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15325. constructor: LOD,
  15326. isLOD: true,
  15327. copy: function ( source ) {
  15328. Object3D.prototype.copy.call( this, source, false );
  15329. var levels = source.levels;
  15330. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15331. var level = levels[ i ];
  15332. this.addLevel( level.object.clone(), level.distance );
  15333. }
  15334. return this;
  15335. },
  15336. addLevel: function ( object, distance ) {
  15337. if ( distance === undefined ) distance = 0;
  15338. distance = Math.abs( distance );
  15339. var levels = this.levels;
  15340. for ( var l = 0; l < levels.length; l ++ ) {
  15341. if ( distance < levels[ l ].distance ) {
  15342. break;
  15343. }
  15344. }
  15345. levels.splice( l, 0, { distance: distance, object: object } );
  15346. this.add( object );
  15347. return this;
  15348. },
  15349. getObjectForDistance: function ( distance ) {
  15350. var levels = this.levels;
  15351. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15352. if ( distance < levels[ i ].distance ) {
  15353. break;
  15354. }
  15355. }
  15356. return levels[ i - 1 ].object;
  15357. },
  15358. raycast: ( function () {
  15359. var matrixPosition = new Vector3();
  15360. return function raycast( raycaster, intersects ) {
  15361. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15362. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15363. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15364. };
  15365. }() ),
  15366. update: function () {
  15367. var v1 = new Vector3();
  15368. var v2 = new Vector3();
  15369. return function update( camera ) {
  15370. var levels = this.levels;
  15371. if ( levels.length > 1 ) {
  15372. v1.setFromMatrixPosition( camera.matrixWorld );
  15373. v2.setFromMatrixPosition( this.matrixWorld );
  15374. var distance = v1.distanceTo( v2 );
  15375. levels[ 0 ].object.visible = true;
  15376. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15377. if ( distance >= levels[ i ].distance ) {
  15378. levels[ i - 1 ].object.visible = false;
  15379. levels[ i ].object.visible = true;
  15380. } else {
  15381. break;
  15382. }
  15383. }
  15384. for ( ; i < l; i ++ ) {
  15385. levels[ i ].object.visible = false;
  15386. }
  15387. }
  15388. };
  15389. }(),
  15390. toJSON: function ( meta ) {
  15391. var data = Object3D.prototype.toJSON.call( this, meta );
  15392. data.object.levels = [];
  15393. var levels = this.levels;
  15394. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15395. var level = levels[ i ];
  15396. data.object.levels.push( {
  15397. object: level.object.uuid,
  15398. distance: level.distance
  15399. } );
  15400. }
  15401. return data;
  15402. }
  15403. } );
  15404. /**
  15405. * @author mikael emtinger / http://gomo.se/
  15406. * @author alteredq / http://alteredqualia.com/
  15407. * @author ikerr / http://verold.com
  15408. */
  15409. function SkinnedMesh( geometry, material ) {
  15410. if ( geometry && geometry.isGeometry ) {
  15411. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15412. }
  15413. Mesh.call( this, geometry, material );
  15414. this.type = 'SkinnedMesh';
  15415. this.bindMode = 'attached';
  15416. this.bindMatrix = new Matrix4();
  15417. this.bindMatrixInverse = new Matrix4();
  15418. }
  15419. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15420. constructor: SkinnedMesh,
  15421. isSkinnedMesh: true,
  15422. bind: function ( skeleton, bindMatrix ) {
  15423. this.skeleton = skeleton;
  15424. if ( bindMatrix === undefined ) {
  15425. this.updateMatrixWorld( true );
  15426. this.skeleton.calculateInverses();
  15427. bindMatrix = this.matrixWorld;
  15428. }
  15429. this.bindMatrix.copy( bindMatrix );
  15430. this.bindMatrixInverse.getInverse( bindMatrix );
  15431. },
  15432. pose: function () {
  15433. this.skeleton.pose();
  15434. },
  15435. normalizeSkinWeights: function () {
  15436. var vector = new Vector4();
  15437. var skinWeight = this.geometry.attributes.skinWeight;
  15438. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15439. vector.x = skinWeight.getX( i );
  15440. vector.y = skinWeight.getY( i );
  15441. vector.z = skinWeight.getZ( i );
  15442. vector.w = skinWeight.getW( i );
  15443. var scale = 1.0 / vector.manhattanLength();
  15444. if ( scale !== Infinity ) {
  15445. vector.multiplyScalar( scale );
  15446. } else {
  15447. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15448. }
  15449. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15450. }
  15451. },
  15452. updateMatrixWorld: function ( force ) {
  15453. Mesh.prototype.updateMatrixWorld.call( this, force );
  15454. if ( this.bindMode === 'attached' ) {
  15455. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15456. } else if ( this.bindMode === 'detached' ) {
  15457. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15458. } else {
  15459. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15460. }
  15461. },
  15462. clone: function () {
  15463. return new this.constructor( this.geometry, this.material ).copy( this );
  15464. }
  15465. } );
  15466. /**
  15467. * @author mikael emtinger / http://gomo.se/
  15468. * @author alteredq / http://alteredqualia.com/
  15469. * @author michael guerrero / http://realitymeltdown.com
  15470. * @author ikerr / http://verold.com
  15471. */
  15472. function Skeleton( bones, boneInverses ) {
  15473. // copy the bone array
  15474. bones = bones || [];
  15475. this.bones = bones.slice( 0 );
  15476. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15477. // use the supplied bone inverses or calculate the inverses
  15478. if ( boneInverses === undefined ) {
  15479. this.calculateInverses();
  15480. } else {
  15481. if ( this.bones.length === boneInverses.length ) {
  15482. this.boneInverses = boneInverses.slice( 0 );
  15483. } else {
  15484. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15485. this.boneInverses = [];
  15486. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15487. this.boneInverses.push( new Matrix4() );
  15488. }
  15489. }
  15490. }
  15491. }
  15492. Object.assign( Skeleton.prototype, {
  15493. calculateInverses: function () {
  15494. this.boneInverses = [];
  15495. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15496. var inverse = new Matrix4();
  15497. if ( this.bones[ i ] ) {
  15498. inverse.getInverse( this.bones[ i ].matrixWorld );
  15499. }
  15500. this.boneInverses.push( inverse );
  15501. }
  15502. },
  15503. pose: function () {
  15504. var bone, i, il;
  15505. // recover the bind-time world matrices
  15506. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15507. bone = this.bones[ i ];
  15508. if ( bone ) {
  15509. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15510. }
  15511. }
  15512. // compute the local matrices, positions, rotations and scales
  15513. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15514. bone = this.bones[ i ];
  15515. if ( bone ) {
  15516. if ( bone.parent && bone.parent.isBone ) {
  15517. bone.matrix.getInverse( bone.parent.matrixWorld );
  15518. bone.matrix.multiply( bone.matrixWorld );
  15519. } else {
  15520. bone.matrix.copy( bone.matrixWorld );
  15521. }
  15522. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15523. }
  15524. }
  15525. },
  15526. update: ( function () {
  15527. var offsetMatrix = new Matrix4();
  15528. var identityMatrix = new Matrix4();
  15529. return function update() {
  15530. var bones = this.bones;
  15531. var boneInverses = this.boneInverses;
  15532. var boneMatrices = this.boneMatrices;
  15533. var boneTexture = this.boneTexture;
  15534. // flatten bone matrices to array
  15535. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15536. // compute the offset between the current and the original transform
  15537. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15538. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15539. offsetMatrix.toArray( boneMatrices, i * 16 );
  15540. }
  15541. if ( boneTexture !== undefined ) {
  15542. boneTexture.needsUpdate = true;
  15543. }
  15544. };
  15545. } )(),
  15546. clone: function () {
  15547. return new Skeleton( this.bones, this.boneInverses );
  15548. },
  15549. getBoneByName: function ( name ) {
  15550. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15551. var bone = this.bones[ i ];
  15552. if ( bone.name === name ) {
  15553. return bone;
  15554. }
  15555. }
  15556. return undefined;
  15557. }
  15558. } );
  15559. /**
  15560. * @author mikael emtinger / http://gomo.se/
  15561. * @author alteredq / http://alteredqualia.com/
  15562. * @author ikerr / http://verold.com
  15563. */
  15564. function Bone() {
  15565. Object3D.call( this );
  15566. this.type = 'Bone';
  15567. }
  15568. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15569. constructor: Bone,
  15570. isBone: true
  15571. } );
  15572. /**
  15573. * @author mrdoob / http://mrdoob.com/
  15574. * @author alteredq / http://alteredqualia.com/
  15575. *
  15576. * parameters = {
  15577. * color: <hex>,
  15578. * opacity: <float>,
  15579. *
  15580. * linewidth: <float>,
  15581. * linecap: "round",
  15582. * linejoin: "round"
  15583. * }
  15584. */
  15585. function LineBasicMaterial( parameters ) {
  15586. Material.call( this );
  15587. this.type = 'LineBasicMaterial';
  15588. this.color = new Color( 0xffffff );
  15589. this.linewidth = 1;
  15590. this.linecap = 'round';
  15591. this.linejoin = 'round';
  15592. this.lights = false;
  15593. this.setValues( parameters );
  15594. }
  15595. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15596. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15597. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15598. LineBasicMaterial.prototype.copy = function ( source ) {
  15599. Material.prototype.copy.call( this, source );
  15600. this.color.copy( source.color );
  15601. this.linewidth = source.linewidth;
  15602. this.linecap = source.linecap;
  15603. this.linejoin = source.linejoin;
  15604. return this;
  15605. };
  15606. /**
  15607. * @author mrdoob / http://mrdoob.com/
  15608. */
  15609. function Line( geometry, material, mode ) {
  15610. if ( mode === 1 ) {
  15611. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15612. }
  15613. Object3D.call( this );
  15614. this.type = 'Line';
  15615. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15616. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15617. }
  15618. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15619. constructor: Line,
  15620. isLine: true,
  15621. computeLineDistances: ( function () {
  15622. var start = new Vector3();
  15623. var end = new Vector3();
  15624. return function computeLineDistances() {
  15625. var geometry = this.geometry;
  15626. if ( geometry.isBufferGeometry ) {
  15627. // we assume non-indexed geometry
  15628. if ( geometry.index === null ) {
  15629. var positionAttribute = geometry.attributes.position;
  15630. var lineDistances = [ 0 ];
  15631. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15632. start.fromBufferAttribute( positionAttribute, i - 1 );
  15633. end.fromBufferAttribute( positionAttribute, i );
  15634. lineDistances[ i ] = lineDistances[ i - 1 ];
  15635. lineDistances[ i ] += start.distanceTo( end );
  15636. }
  15637. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15638. } else {
  15639. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15640. }
  15641. } else if ( geometry.isGeometry ) {
  15642. var vertices = geometry.vertices;
  15643. var lineDistances = geometry.lineDistances;
  15644. lineDistances[ 0 ] = 0;
  15645. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15646. lineDistances[ i ] = lineDistances[ i - 1 ];
  15647. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15648. }
  15649. }
  15650. return this;
  15651. };
  15652. }() ),
  15653. raycast: ( function () {
  15654. var inverseMatrix = new Matrix4();
  15655. var ray = new Ray();
  15656. var sphere = new Sphere();
  15657. return function raycast( raycaster, intersects ) {
  15658. var precision = raycaster.linePrecision;
  15659. var geometry = this.geometry;
  15660. var matrixWorld = this.matrixWorld;
  15661. // Checking boundingSphere distance to ray
  15662. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15663. sphere.copy( geometry.boundingSphere );
  15664. sphere.applyMatrix4( matrixWorld );
  15665. sphere.radius += precision;
  15666. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15667. //
  15668. inverseMatrix.getInverse( matrixWorld );
  15669. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15670. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15671. var localPrecisionSq = localPrecision * localPrecision;
  15672. var vStart = new Vector3();
  15673. var vEnd = new Vector3();
  15674. var interSegment = new Vector3();
  15675. var interRay = new Vector3();
  15676. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15677. if ( geometry.isBufferGeometry ) {
  15678. var index = geometry.index;
  15679. var attributes = geometry.attributes;
  15680. var positions = attributes.position.array;
  15681. if ( index !== null ) {
  15682. var indices = index.array;
  15683. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15684. var a = indices[ i ];
  15685. var b = indices[ i + 1 ];
  15686. vStart.fromArray( positions, a * 3 );
  15687. vEnd.fromArray( positions, b * 3 );
  15688. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15689. if ( distSq > localPrecisionSq ) continue;
  15690. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15691. var distance = raycaster.ray.origin.distanceTo( interRay );
  15692. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15693. intersects.push( {
  15694. distance: distance,
  15695. // What do we want? intersection point on the ray or on the segment??
  15696. // point: raycaster.ray.at( distance ),
  15697. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15698. index: i,
  15699. face: null,
  15700. faceIndex: null,
  15701. object: this
  15702. } );
  15703. }
  15704. } else {
  15705. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15706. vStart.fromArray( positions, 3 * i );
  15707. vEnd.fromArray( positions, 3 * i + 3 );
  15708. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15709. if ( distSq > localPrecisionSq ) continue;
  15710. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15711. var distance = raycaster.ray.origin.distanceTo( interRay );
  15712. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15713. intersects.push( {
  15714. distance: distance,
  15715. // What do we want? intersection point on the ray or on the segment??
  15716. // point: raycaster.ray.at( distance ),
  15717. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15718. index: i,
  15719. face: null,
  15720. faceIndex: null,
  15721. object: this
  15722. } );
  15723. }
  15724. }
  15725. } else if ( geometry.isGeometry ) {
  15726. var vertices = geometry.vertices;
  15727. var nbVertices = vertices.length;
  15728. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15729. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15730. if ( distSq > localPrecisionSq ) continue;
  15731. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15732. var distance = raycaster.ray.origin.distanceTo( interRay );
  15733. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15734. intersects.push( {
  15735. distance: distance,
  15736. // What do we want? intersection point on the ray or on the segment??
  15737. // point: raycaster.ray.at( distance ),
  15738. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15739. index: i,
  15740. face: null,
  15741. faceIndex: null,
  15742. object: this
  15743. } );
  15744. }
  15745. }
  15746. };
  15747. }() ),
  15748. clone: function () {
  15749. return new this.constructor( this.geometry, this.material ).copy( this );
  15750. }
  15751. } );
  15752. /**
  15753. * @author mrdoob / http://mrdoob.com/
  15754. */
  15755. function LineSegments( geometry, material ) {
  15756. Line.call( this, geometry, material );
  15757. this.type = 'LineSegments';
  15758. }
  15759. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15760. constructor: LineSegments,
  15761. isLineSegments: true,
  15762. computeLineDistances: ( function () {
  15763. var start = new Vector3();
  15764. var end = new Vector3();
  15765. return function computeLineDistances() {
  15766. var geometry = this.geometry;
  15767. if ( geometry.isBufferGeometry ) {
  15768. // we assume non-indexed geometry
  15769. if ( geometry.index === null ) {
  15770. var positionAttribute = geometry.attributes.position;
  15771. var lineDistances = [];
  15772. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15773. start.fromBufferAttribute( positionAttribute, i );
  15774. end.fromBufferAttribute( positionAttribute, i + 1 );
  15775. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15776. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15777. }
  15778. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15779. } else {
  15780. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15781. }
  15782. } else if ( geometry.isGeometry ) {
  15783. var vertices = geometry.vertices;
  15784. var lineDistances = geometry.lineDistances;
  15785. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  15786. start.copy( vertices[ i ] );
  15787. end.copy( vertices[ i + 1 ] );
  15788. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15789. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15790. }
  15791. }
  15792. return this;
  15793. };
  15794. }() )
  15795. } );
  15796. /**
  15797. * @author mgreter / http://github.com/mgreter
  15798. */
  15799. function LineLoop( geometry, material ) {
  15800. Line.call( this, geometry, material );
  15801. this.type = 'LineLoop';
  15802. }
  15803. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15804. constructor: LineLoop,
  15805. isLineLoop: true,
  15806. } );
  15807. /**
  15808. * @author mrdoob / http://mrdoob.com/
  15809. * @author alteredq / http://alteredqualia.com/
  15810. *
  15811. * parameters = {
  15812. * color: <hex>,
  15813. * opacity: <float>,
  15814. * map: new THREE.Texture( <Image> ),
  15815. *
  15816. * size: <float>,
  15817. * sizeAttenuation: <bool>
  15818. *
  15819. * morphTargets: <bool>
  15820. * }
  15821. */
  15822. function PointsMaterial( parameters ) {
  15823. Material.call( this );
  15824. this.type = 'PointsMaterial';
  15825. this.color = new Color( 0xffffff );
  15826. this.map = null;
  15827. this.size = 1;
  15828. this.sizeAttenuation = true;
  15829. this.morphTargets = false;
  15830. this.lights = false;
  15831. this.setValues( parameters );
  15832. }
  15833. PointsMaterial.prototype = Object.create( Material.prototype );
  15834. PointsMaterial.prototype.constructor = PointsMaterial;
  15835. PointsMaterial.prototype.isPointsMaterial = true;
  15836. PointsMaterial.prototype.copy = function ( source ) {
  15837. Material.prototype.copy.call( this, source );
  15838. this.color.copy( source.color );
  15839. this.map = source.map;
  15840. this.size = source.size;
  15841. this.sizeAttenuation = source.sizeAttenuation;
  15842. this.morphTargets = source.morphTargets;
  15843. return this;
  15844. };
  15845. /**
  15846. * @author alteredq / http://alteredqualia.com/
  15847. */
  15848. function Points( geometry, material ) {
  15849. Object3D.call( this );
  15850. this.type = 'Points';
  15851. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15852. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15853. }
  15854. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15855. constructor: Points,
  15856. isPoints: true,
  15857. raycast: ( function () {
  15858. var inverseMatrix = new Matrix4();
  15859. var ray = new Ray();
  15860. var sphere = new Sphere();
  15861. return function raycast( raycaster, intersects ) {
  15862. var object = this;
  15863. var geometry = this.geometry;
  15864. var matrixWorld = this.matrixWorld;
  15865. var threshold = raycaster.params.Points.threshold;
  15866. // Checking boundingSphere distance to ray
  15867. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15868. sphere.copy( geometry.boundingSphere );
  15869. sphere.applyMatrix4( matrixWorld );
  15870. sphere.radius += threshold;
  15871. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15872. //
  15873. inverseMatrix.getInverse( matrixWorld );
  15874. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15875. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15876. var localThresholdSq = localThreshold * localThreshold;
  15877. var position = new Vector3();
  15878. var intersectPoint = new Vector3();
  15879. function testPoint( point, index ) {
  15880. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15881. if ( rayPointDistanceSq < localThresholdSq ) {
  15882. ray.closestPointToPoint( point, intersectPoint );
  15883. intersectPoint.applyMatrix4( matrixWorld );
  15884. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15885. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15886. intersects.push( {
  15887. distance: distance,
  15888. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15889. point: intersectPoint.clone(),
  15890. index: index,
  15891. face: null,
  15892. object: object
  15893. } );
  15894. }
  15895. }
  15896. if ( geometry.isBufferGeometry ) {
  15897. var index = geometry.index;
  15898. var attributes = geometry.attributes;
  15899. var positions = attributes.position.array;
  15900. if ( index !== null ) {
  15901. var indices = index.array;
  15902. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15903. var a = indices[ i ];
  15904. position.fromArray( positions, a * 3 );
  15905. testPoint( position, a );
  15906. }
  15907. } else {
  15908. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15909. position.fromArray( positions, i * 3 );
  15910. testPoint( position, i );
  15911. }
  15912. }
  15913. } else {
  15914. var vertices = geometry.vertices;
  15915. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15916. testPoint( vertices[ i ], i );
  15917. }
  15918. }
  15919. };
  15920. }() ),
  15921. clone: function () {
  15922. return new this.constructor( this.geometry, this.material ).copy( this );
  15923. }
  15924. } );
  15925. /**
  15926. * @author mrdoob / http://mrdoob.com/
  15927. */
  15928. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15929. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15930. this.format = format !== undefined ? format : RGBFormat;
  15931. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  15932. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  15933. this.generateMipmaps = false;
  15934. }
  15935. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15936. constructor: VideoTexture,
  15937. isVideoTexture: true,
  15938. update: function () {
  15939. var video = this.image;
  15940. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15941. this.needsUpdate = true;
  15942. }
  15943. }
  15944. } );
  15945. /**
  15946. * @author alteredq / http://alteredqualia.com/
  15947. */
  15948. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15949. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15950. this.image = { width: width, height: height };
  15951. this.mipmaps = mipmaps;
  15952. // no flipping for cube textures
  15953. // (also flipping doesn't work for compressed textures )
  15954. this.flipY = false;
  15955. // can't generate mipmaps for compressed textures
  15956. // mips must be embedded in DDS files
  15957. this.generateMipmaps = false;
  15958. }
  15959. CompressedTexture.prototype = Object.create( Texture.prototype );
  15960. CompressedTexture.prototype.constructor = CompressedTexture;
  15961. CompressedTexture.prototype.isCompressedTexture = true;
  15962. /**
  15963. * @author mrdoob / http://mrdoob.com/
  15964. */
  15965. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15966. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15967. this.needsUpdate = true;
  15968. }
  15969. CanvasTexture.prototype = Object.create( Texture.prototype );
  15970. CanvasTexture.prototype.constructor = CanvasTexture;
  15971. CanvasTexture.prototype.isCanvasTexture = true;
  15972. /**
  15973. * @author Matt DesLauriers / @mattdesl
  15974. * @author atix / arthursilber.de
  15975. */
  15976. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15977. format = format !== undefined ? format : DepthFormat;
  15978. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15979. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15980. }
  15981. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15982. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15983. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15984. this.image = { width: width, height: height };
  15985. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  15986. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  15987. this.flipY = false;
  15988. this.generateMipmaps = false;
  15989. }
  15990. DepthTexture.prototype = Object.create( Texture.prototype );
  15991. DepthTexture.prototype.constructor = DepthTexture;
  15992. DepthTexture.prototype.isDepthTexture = true;
  15993. /**
  15994. * @author mrdoob / http://mrdoob.com/
  15995. * @author Mugen87 / https://github.com/Mugen87
  15996. */
  15997. function WireframeGeometry( geometry ) {
  15998. BufferGeometry.call( this );
  15999. this.type = 'WireframeGeometry';
  16000. // buffer
  16001. var vertices = [];
  16002. // helper variables
  16003. var i, j, l, o, ol;
  16004. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16005. var key, keys = [ 'a', 'b', 'c' ];
  16006. var vertex;
  16007. // different logic for Geometry and BufferGeometry
  16008. if ( geometry && geometry.isGeometry ) {
  16009. // create a data structure that contains all edges without duplicates
  16010. var faces = geometry.faces;
  16011. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16012. var face = faces[ i ];
  16013. for ( j = 0; j < 3; j ++ ) {
  16014. edge1 = face[ keys[ j ] ];
  16015. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16016. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16017. edge[ 1 ] = Math.max( edge1, edge2 );
  16018. key = edge[ 0 ] + ',' + edge[ 1 ];
  16019. if ( edges[ key ] === undefined ) {
  16020. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16021. }
  16022. }
  16023. }
  16024. // generate vertices
  16025. for ( key in edges ) {
  16026. e = edges[ key ];
  16027. vertex = geometry.vertices[ e.index1 ];
  16028. vertices.push( vertex.x, vertex.y, vertex.z );
  16029. vertex = geometry.vertices[ e.index2 ];
  16030. vertices.push( vertex.x, vertex.y, vertex.z );
  16031. }
  16032. } else if ( geometry && geometry.isBufferGeometry ) {
  16033. var position, indices, groups;
  16034. var group, start, count;
  16035. var index1, index2;
  16036. vertex = new Vector3();
  16037. if ( geometry.index !== null ) {
  16038. // indexed BufferGeometry
  16039. position = geometry.attributes.position;
  16040. indices = geometry.index;
  16041. groups = geometry.groups;
  16042. if ( groups.length === 0 ) {
  16043. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16044. }
  16045. // create a data structure that contains all eges without duplicates
  16046. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16047. group = groups[ o ];
  16048. start = group.start;
  16049. count = group.count;
  16050. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16051. for ( j = 0; j < 3; j ++ ) {
  16052. edge1 = indices.getX( i + j );
  16053. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16054. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16055. edge[ 1 ] = Math.max( edge1, edge2 );
  16056. key = edge[ 0 ] + ',' + edge[ 1 ];
  16057. if ( edges[ key ] === undefined ) {
  16058. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16059. }
  16060. }
  16061. }
  16062. }
  16063. // generate vertices
  16064. for ( key in edges ) {
  16065. e = edges[ key ];
  16066. vertex.fromBufferAttribute( position, e.index1 );
  16067. vertices.push( vertex.x, vertex.y, vertex.z );
  16068. vertex.fromBufferAttribute( position, e.index2 );
  16069. vertices.push( vertex.x, vertex.y, vertex.z );
  16070. }
  16071. } else {
  16072. // non-indexed BufferGeometry
  16073. position = geometry.attributes.position;
  16074. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16075. for ( j = 0; j < 3; j ++ ) {
  16076. // three edges per triangle, an edge is represented as (index1, index2)
  16077. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16078. index1 = 3 * i + j;
  16079. vertex.fromBufferAttribute( position, index1 );
  16080. vertices.push( vertex.x, vertex.y, vertex.z );
  16081. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16082. vertex.fromBufferAttribute( position, index2 );
  16083. vertices.push( vertex.x, vertex.y, vertex.z );
  16084. }
  16085. }
  16086. }
  16087. }
  16088. // build geometry
  16089. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16090. }
  16091. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16092. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16093. /**
  16094. * @author zz85 / https://github.com/zz85
  16095. * @author Mugen87 / https://github.com/Mugen87
  16096. *
  16097. * Parametric Surfaces Geometry
  16098. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16099. */
  16100. // ParametricGeometry
  16101. function ParametricGeometry( func, slices, stacks ) {
  16102. Geometry.call( this );
  16103. this.type = 'ParametricGeometry';
  16104. this.parameters = {
  16105. func: func,
  16106. slices: slices,
  16107. stacks: stacks
  16108. };
  16109. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16110. this.mergeVertices();
  16111. }
  16112. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16113. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16114. // ParametricBufferGeometry
  16115. function ParametricBufferGeometry( func, slices, stacks ) {
  16116. BufferGeometry.call( this );
  16117. this.type = 'ParametricBufferGeometry';
  16118. this.parameters = {
  16119. func: func,
  16120. slices: slices,
  16121. stacks: stacks
  16122. };
  16123. // buffers
  16124. var indices = [];
  16125. var vertices = [];
  16126. var normals = [];
  16127. var uvs = [];
  16128. var EPS = 0.00001;
  16129. var normal = new Vector3();
  16130. var p0 = new Vector3(), p1 = new Vector3();
  16131. var pu = new Vector3(), pv = new Vector3();
  16132. var i, j;
  16133. if ( func.length < 3 ) {
  16134. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16135. }
  16136. // generate vertices, normals and uvs
  16137. var sliceCount = slices + 1;
  16138. for ( i = 0; i <= stacks; i ++ ) {
  16139. var v = i / stacks;
  16140. for ( j = 0; j <= slices; j ++ ) {
  16141. var u = j / slices;
  16142. // vertex
  16143. func( u, v, p0 );
  16144. vertices.push( p0.x, p0.y, p0.z );
  16145. // normal
  16146. // approximate tangent vectors via finite differences
  16147. if ( u - EPS >= 0 ) {
  16148. func( u - EPS, v, p1 );
  16149. pu.subVectors( p0, p1 );
  16150. } else {
  16151. func( u + EPS, v, p1 );
  16152. pu.subVectors( p1, p0 );
  16153. }
  16154. if ( v - EPS >= 0 ) {
  16155. func( u, v - EPS, p1 );
  16156. pv.subVectors( p0, p1 );
  16157. } else {
  16158. func( u, v + EPS, p1 );
  16159. pv.subVectors( p1, p0 );
  16160. }
  16161. // cross product of tangent vectors returns surface normal
  16162. normal.crossVectors( pu, pv ).normalize();
  16163. normals.push( normal.x, normal.y, normal.z );
  16164. // uv
  16165. uvs.push( u, v );
  16166. }
  16167. }
  16168. // generate indices
  16169. for ( i = 0; i < stacks; i ++ ) {
  16170. for ( j = 0; j < slices; j ++ ) {
  16171. var a = i * sliceCount + j;
  16172. var b = i * sliceCount + j + 1;
  16173. var c = ( i + 1 ) * sliceCount + j + 1;
  16174. var d = ( i + 1 ) * sliceCount + j;
  16175. // faces one and two
  16176. indices.push( a, b, d );
  16177. indices.push( b, c, d );
  16178. }
  16179. }
  16180. // build geometry
  16181. this.setIndex( indices );
  16182. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16183. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16184. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16185. }
  16186. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16187. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16188. /**
  16189. * @author clockworkgeek / https://github.com/clockworkgeek
  16190. * @author timothypratley / https://github.com/timothypratley
  16191. * @author WestLangley / http://github.com/WestLangley
  16192. * @author Mugen87 / https://github.com/Mugen87
  16193. */
  16194. // PolyhedronGeometry
  16195. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16196. Geometry.call( this );
  16197. this.type = 'PolyhedronGeometry';
  16198. this.parameters = {
  16199. vertices: vertices,
  16200. indices: indices,
  16201. radius: radius,
  16202. detail: detail
  16203. };
  16204. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16205. this.mergeVertices();
  16206. }
  16207. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16208. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16209. // PolyhedronBufferGeometry
  16210. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16211. BufferGeometry.call( this );
  16212. this.type = 'PolyhedronBufferGeometry';
  16213. this.parameters = {
  16214. vertices: vertices,
  16215. indices: indices,
  16216. radius: radius,
  16217. detail: detail
  16218. };
  16219. radius = radius || 1;
  16220. detail = detail || 0;
  16221. // default buffer data
  16222. var vertexBuffer = [];
  16223. var uvBuffer = [];
  16224. // the subdivision creates the vertex buffer data
  16225. subdivide( detail );
  16226. // all vertices should lie on a conceptual sphere with a given radius
  16227. appplyRadius( radius );
  16228. // finally, create the uv data
  16229. generateUVs();
  16230. // build non-indexed geometry
  16231. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16232. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16233. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16234. if ( detail === 0 ) {
  16235. this.computeVertexNormals(); // flat normals
  16236. } else {
  16237. this.normalizeNormals(); // smooth normals
  16238. }
  16239. // helper functions
  16240. function subdivide( detail ) {
  16241. var a = new Vector3();
  16242. var b = new Vector3();
  16243. var c = new Vector3();
  16244. // iterate over all faces and apply a subdivison with the given detail value
  16245. for ( var i = 0; i < indices.length; i += 3 ) {
  16246. // get the vertices of the face
  16247. getVertexByIndex( indices[ i + 0 ], a );
  16248. getVertexByIndex( indices[ i + 1 ], b );
  16249. getVertexByIndex( indices[ i + 2 ], c );
  16250. // perform subdivision
  16251. subdivideFace( a, b, c, detail );
  16252. }
  16253. }
  16254. function subdivideFace( a, b, c, detail ) {
  16255. var cols = Math.pow( 2, detail );
  16256. // we use this multidimensional array as a data structure for creating the subdivision
  16257. var v = [];
  16258. var i, j;
  16259. // construct all of the vertices for this subdivision
  16260. for ( i = 0; i <= cols; i ++ ) {
  16261. v[ i ] = [];
  16262. var aj = a.clone().lerp( c, i / cols );
  16263. var bj = b.clone().lerp( c, i / cols );
  16264. var rows = cols - i;
  16265. for ( j = 0; j <= rows; j ++ ) {
  16266. if ( j === 0 && i === cols ) {
  16267. v[ i ][ j ] = aj;
  16268. } else {
  16269. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16270. }
  16271. }
  16272. }
  16273. // construct all of the faces
  16274. for ( i = 0; i < cols; i ++ ) {
  16275. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16276. var k = Math.floor( j / 2 );
  16277. if ( j % 2 === 0 ) {
  16278. pushVertex( v[ i ][ k + 1 ] );
  16279. pushVertex( v[ i + 1 ][ k ] );
  16280. pushVertex( v[ i ][ k ] );
  16281. } else {
  16282. pushVertex( v[ i ][ k + 1 ] );
  16283. pushVertex( v[ i + 1 ][ k + 1 ] );
  16284. pushVertex( v[ i + 1 ][ k ] );
  16285. }
  16286. }
  16287. }
  16288. }
  16289. function appplyRadius( radius ) {
  16290. var vertex = new Vector3();
  16291. // iterate over the entire buffer and apply the radius to each vertex
  16292. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16293. vertex.x = vertexBuffer[ i + 0 ];
  16294. vertex.y = vertexBuffer[ i + 1 ];
  16295. vertex.z = vertexBuffer[ i + 2 ];
  16296. vertex.normalize().multiplyScalar( radius );
  16297. vertexBuffer[ i + 0 ] = vertex.x;
  16298. vertexBuffer[ i + 1 ] = vertex.y;
  16299. vertexBuffer[ i + 2 ] = vertex.z;
  16300. }
  16301. }
  16302. function generateUVs() {
  16303. var vertex = new Vector3();
  16304. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16305. vertex.x = vertexBuffer[ i + 0 ];
  16306. vertex.y = vertexBuffer[ i + 1 ];
  16307. vertex.z = vertexBuffer[ i + 2 ];
  16308. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16309. var v = inclination( vertex ) / Math.PI + 0.5;
  16310. uvBuffer.push( u, 1 - v );
  16311. }
  16312. correctUVs();
  16313. correctSeam();
  16314. }
  16315. function correctSeam() {
  16316. // handle case when face straddles the seam, see #3269
  16317. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16318. // uv data of a single face
  16319. var x0 = uvBuffer[ i + 0 ];
  16320. var x1 = uvBuffer[ i + 2 ];
  16321. var x2 = uvBuffer[ i + 4 ];
  16322. var max = Math.max( x0, x1, x2 );
  16323. var min = Math.min( x0, x1, x2 );
  16324. // 0.9 is somewhat arbitrary
  16325. if ( max > 0.9 && min < 0.1 ) {
  16326. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16327. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16328. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16329. }
  16330. }
  16331. }
  16332. function pushVertex( vertex ) {
  16333. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16334. }
  16335. function getVertexByIndex( index, vertex ) {
  16336. var stride = index * 3;
  16337. vertex.x = vertices[ stride + 0 ];
  16338. vertex.y = vertices[ stride + 1 ];
  16339. vertex.z = vertices[ stride + 2 ];
  16340. }
  16341. function correctUVs() {
  16342. var a = new Vector3();
  16343. var b = new Vector3();
  16344. var c = new Vector3();
  16345. var centroid = new Vector3();
  16346. var uvA = new Vector2();
  16347. var uvB = new Vector2();
  16348. var uvC = new Vector2();
  16349. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16350. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16351. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16352. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16353. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16354. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16355. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16356. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16357. var azi = azimuth( centroid );
  16358. correctUV( uvA, j + 0, a, azi );
  16359. correctUV( uvB, j + 2, b, azi );
  16360. correctUV( uvC, j + 4, c, azi );
  16361. }
  16362. }
  16363. function correctUV( uv, stride, vector, azimuth ) {
  16364. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16365. uvBuffer[ stride ] = uv.x - 1;
  16366. }
  16367. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16368. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16369. }
  16370. }
  16371. // Angle around the Y axis, counter-clockwise when looking from above.
  16372. function azimuth( vector ) {
  16373. return Math.atan2( vector.z, - vector.x );
  16374. }
  16375. // Angle above the XZ plane.
  16376. function inclination( vector ) {
  16377. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16378. }
  16379. }
  16380. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16381. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16382. /**
  16383. * @author timothypratley / https://github.com/timothypratley
  16384. * @author Mugen87 / https://github.com/Mugen87
  16385. */
  16386. // TetrahedronGeometry
  16387. function TetrahedronGeometry( radius, detail ) {
  16388. Geometry.call( this );
  16389. this.type = 'TetrahedronGeometry';
  16390. this.parameters = {
  16391. radius: radius,
  16392. detail: detail
  16393. };
  16394. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16395. this.mergeVertices();
  16396. }
  16397. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16398. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16399. // TetrahedronBufferGeometry
  16400. function TetrahedronBufferGeometry( radius, detail ) {
  16401. var vertices = [
  16402. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16403. ];
  16404. var indices = [
  16405. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16406. ];
  16407. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16408. this.type = 'TetrahedronBufferGeometry';
  16409. this.parameters = {
  16410. radius: radius,
  16411. detail: detail
  16412. };
  16413. }
  16414. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16415. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16416. /**
  16417. * @author timothypratley / https://github.com/timothypratley
  16418. * @author Mugen87 / https://github.com/Mugen87
  16419. */
  16420. // OctahedronGeometry
  16421. function OctahedronGeometry( radius, detail ) {
  16422. Geometry.call( this );
  16423. this.type = 'OctahedronGeometry';
  16424. this.parameters = {
  16425. radius: radius,
  16426. detail: detail
  16427. };
  16428. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16429. this.mergeVertices();
  16430. }
  16431. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16432. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16433. // OctahedronBufferGeometry
  16434. function OctahedronBufferGeometry( radius, detail ) {
  16435. var vertices = [
  16436. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16437. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16438. ];
  16439. var indices = [
  16440. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16441. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16442. 1, 3, 4, 1, 4, 2
  16443. ];
  16444. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16445. this.type = 'OctahedronBufferGeometry';
  16446. this.parameters = {
  16447. radius: radius,
  16448. detail: detail
  16449. };
  16450. }
  16451. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16452. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16453. /**
  16454. * @author timothypratley / https://github.com/timothypratley
  16455. * @author Mugen87 / https://github.com/Mugen87
  16456. */
  16457. // IcosahedronGeometry
  16458. function IcosahedronGeometry( radius, detail ) {
  16459. Geometry.call( this );
  16460. this.type = 'IcosahedronGeometry';
  16461. this.parameters = {
  16462. radius: radius,
  16463. detail: detail
  16464. };
  16465. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16466. this.mergeVertices();
  16467. }
  16468. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16469. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16470. // IcosahedronBufferGeometry
  16471. function IcosahedronBufferGeometry( radius, detail ) {
  16472. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16473. var vertices = [
  16474. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16475. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16476. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16477. ];
  16478. var indices = [
  16479. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16480. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16481. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16482. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16483. ];
  16484. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16485. this.type = 'IcosahedronBufferGeometry';
  16486. this.parameters = {
  16487. radius: radius,
  16488. detail: detail
  16489. };
  16490. }
  16491. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16492. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16493. /**
  16494. * @author Abe Pazos / https://hamoid.com
  16495. * @author Mugen87 / https://github.com/Mugen87
  16496. */
  16497. // DodecahedronGeometry
  16498. function DodecahedronGeometry( radius, detail ) {
  16499. Geometry.call( this );
  16500. this.type = 'DodecahedronGeometry';
  16501. this.parameters = {
  16502. radius: radius,
  16503. detail: detail
  16504. };
  16505. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16506. this.mergeVertices();
  16507. }
  16508. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16509. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16510. // DodecahedronBufferGeometry
  16511. function DodecahedronBufferGeometry( radius, detail ) {
  16512. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16513. var r = 1 / t;
  16514. var vertices = [
  16515. // (±1, ±1, ±1)
  16516. - 1, - 1, - 1, - 1, - 1, 1,
  16517. - 1, 1, - 1, - 1, 1, 1,
  16518. 1, - 1, - 1, 1, - 1, 1,
  16519. 1, 1, - 1, 1, 1, 1,
  16520. // (0, ±1/φ, ±φ)
  16521. 0, - r, - t, 0, - r, t,
  16522. 0, r, - t, 0, r, t,
  16523. // (±1/φ, ±φ, 0)
  16524. - r, - t, 0, - r, t, 0,
  16525. r, - t, 0, r, t, 0,
  16526. // (±φ, 0, ±1/φ)
  16527. - t, 0, - r, t, 0, - r,
  16528. - t, 0, r, t, 0, r
  16529. ];
  16530. var indices = [
  16531. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16532. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16533. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16534. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16535. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16536. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16537. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16538. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16539. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16540. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16541. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16542. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16543. ];
  16544. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16545. this.type = 'DodecahedronBufferGeometry';
  16546. this.parameters = {
  16547. radius: radius,
  16548. detail: detail
  16549. };
  16550. }
  16551. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16552. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16553. /**
  16554. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16555. * @author WestLangley / https://github.com/WestLangley
  16556. * @author zz85 / https://github.com/zz85
  16557. * @author miningold / https://github.com/miningold
  16558. * @author jonobr1 / https://github.com/jonobr1
  16559. * @author Mugen87 / https://github.com/Mugen87
  16560. *
  16561. */
  16562. // TubeGeometry
  16563. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16564. Geometry.call( this );
  16565. this.type = 'TubeGeometry';
  16566. this.parameters = {
  16567. path: path,
  16568. tubularSegments: tubularSegments,
  16569. radius: radius,
  16570. radialSegments: radialSegments,
  16571. closed: closed
  16572. };
  16573. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16574. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16575. // expose internals
  16576. this.tangents = bufferGeometry.tangents;
  16577. this.normals = bufferGeometry.normals;
  16578. this.binormals = bufferGeometry.binormals;
  16579. // create geometry
  16580. this.fromBufferGeometry( bufferGeometry );
  16581. this.mergeVertices();
  16582. }
  16583. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16584. TubeGeometry.prototype.constructor = TubeGeometry;
  16585. // TubeBufferGeometry
  16586. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16587. BufferGeometry.call( this );
  16588. this.type = 'TubeBufferGeometry';
  16589. this.parameters = {
  16590. path: path,
  16591. tubularSegments: tubularSegments,
  16592. radius: radius,
  16593. radialSegments: radialSegments,
  16594. closed: closed
  16595. };
  16596. tubularSegments = tubularSegments || 64;
  16597. radius = radius || 1;
  16598. radialSegments = radialSegments || 8;
  16599. closed = closed || false;
  16600. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16601. // expose internals
  16602. this.tangents = frames.tangents;
  16603. this.normals = frames.normals;
  16604. this.binormals = frames.binormals;
  16605. // helper variables
  16606. var vertex = new Vector3();
  16607. var normal = new Vector3();
  16608. var uv = new Vector2();
  16609. var P = new Vector3();
  16610. var i, j;
  16611. // buffer
  16612. var vertices = [];
  16613. var normals = [];
  16614. var uvs = [];
  16615. var indices = [];
  16616. // create buffer data
  16617. generateBufferData();
  16618. // build geometry
  16619. this.setIndex( indices );
  16620. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16621. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16622. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16623. // functions
  16624. function generateBufferData() {
  16625. for ( i = 0; i < tubularSegments; i ++ ) {
  16626. generateSegment( i );
  16627. }
  16628. // if the geometry is not closed, generate the last row of vertices and normals
  16629. // at the regular position on the given path
  16630. //
  16631. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16632. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16633. // uvs are generated in a separate function.
  16634. // this makes it easy compute correct values for closed geometries
  16635. generateUVs();
  16636. // finally create faces
  16637. generateIndices();
  16638. }
  16639. function generateSegment( i ) {
  16640. // we use getPointAt to sample evenly distributed points from the given path
  16641. P = path.getPointAt( i / tubularSegments, P );
  16642. // retrieve corresponding normal and binormal
  16643. var N = frames.normals[ i ];
  16644. var B = frames.binormals[ i ];
  16645. // generate normals and vertices for the current segment
  16646. for ( j = 0; j <= radialSegments; j ++ ) {
  16647. var v = j / radialSegments * Math.PI * 2;
  16648. var sin = Math.sin( v );
  16649. var cos = - Math.cos( v );
  16650. // normal
  16651. normal.x = ( cos * N.x + sin * B.x );
  16652. normal.y = ( cos * N.y + sin * B.y );
  16653. normal.z = ( cos * N.z + sin * B.z );
  16654. normal.normalize();
  16655. normals.push( normal.x, normal.y, normal.z );
  16656. // vertex
  16657. vertex.x = P.x + radius * normal.x;
  16658. vertex.y = P.y + radius * normal.y;
  16659. vertex.z = P.z + radius * normal.z;
  16660. vertices.push( vertex.x, vertex.y, vertex.z );
  16661. }
  16662. }
  16663. function generateIndices() {
  16664. for ( j = 1; j <= tubularSegments; j ++ ) {
  16665. for ( i = 1; i <= radialSegments; i ++ ) {
  16666. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16667. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16668. var c = ( radialSegments + 1 ) * j + i;
  16669. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16670. // faces
  16671. indices.push( a, b, d );
  16672. indices.push( b, c, d );
  16673. }
  16674. }
  16675. }
  16676. function generateUVs() {
  16677. for ( i = 0; i <= tubularSegments; i ++ ) {
  16678. for ( j = 0; j <= radialSegments; j ++ ) {
  16679. uv.x = i / tubularSegments;
  16680. uv.y = j / radialSegments;
  16681. uvs.push( uv.x, uv.y );
  16682. }
  16683. }
  16684. }
  16685. }
  16686. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16687. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16688. TubeBufferGeometry.prototype.toJSON = function () {
  16689. var data = BufferGeometry.prototype.toJSON.call( this );
  16690. data.path = this.parameters.path.toJSON();
  16691. return data;
  16692. };
  16693. /**
  16694. * @author oosmoxiecode
  16695. * @author Mugen87 / https://github.com/Mugen87
  16696. *
  16697. * based on http://www.blackpawn.com/texts/pqtorus/
  16698. */
  16699. // TorusKnotGeometry
  16700. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16701. Geometry.call( this );
  16702. this.type = 'TorusKnotGeometry';
  16703. this.parameters = {
  16704. radius: radius,
  16705. tube: tube,
  16706. tubularSegments: tubularSegments,
  16707. radialSegments: radialSegments,
  16708. p: p,
  16709. q: q
  16710. };
  16711. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16712. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16713. this.mergeVertices();
  16714. }
  16715. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16716. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16717. // TorusKnotBufferGeometry
  16718. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16719. BufferGeometry.call( this );
  16720. this.type = 'TorusKnotBufferGeometry';
  16721. this.parameters = {
  16722. radius: radius,
  16723. tube: tube,
  16724. tubularSegments: tubularSegments,
  16725. radialSegments: radialSegments,
  16726. p: p,
  16727. q: q
  16728. };
  16729. radius = radius || 1;
  16730. tube = tube || 0.4;
  16731. tubularSegments = Math.floor( tubularSegments ) || 64;
  16732. radialSegments = Math.floor( radialSegments ) || 8;
  16733. p = p || 2;
  16734. q = q || 3;
  16735. // buffers
  16736. var indices = [];
  16737. var vertices = [];
  16738. var normals = [];
  16739. var uvs = [];
  16740. // helper variables
  16741. var i, j;
  16742. var vertex = new Vector3();
  16743. var normal = new Vector3();
  16744. var P1 = new Vector3();
  16745. var P2 = new Vector3();
  16746. var B = new Vector3();
  16747. var T = new Vector3();
  16748. var N = new Vector3();
  16749. // generate vertices, normals and uvs
  16750. for ( i = 0; i <= tubularSegments; ++ i ) {
  16751. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  16752. var u = i / tubularSegments * p * Math.PI * 2;
  16753. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  16754. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  16755. calculatePositionOnCurve( u, p, q, radius, P1 );
  16756. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  16757. // calculate orthonormal basis
  16758. T.subVectors( P2, P1 );
  16759. N.addVectors( P2, P1 );
  16760. B.crossVectors( T, N );
  16761. N.crossVectors( B, T );
  16762. // normalize B, N. T can be ignored, we don't use it
  16763. B.normalize();
  16764. N.normalize();
  16765. for ( j = 0; j <= radialSegments; ++ j ) {
  16766. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  16767. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  16768. var v = j / radialSegments * Math.PI * 2;
  16769. var cx = - tube * Math.cos( v );
  16770. var cy = tube * Math.sin( v );
  16771. // now calculate the final vertex position.
  16772. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  16773. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  16774. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  16775. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  16776. vertices.push( vertex.x, vertex.y, vertex.z );
  16777. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  16778. normal.subVectors( vertex, P1 ).normalize();
  16779. normals.push( normal.x, normal.y, normal.z );
  16780. // uv
  16781. uvs.push( i / tubularSegments );
  16782. uvs.push( j / radialSegments );
  16783. }
  16784. }
  16785. // generate indices
  16786. for ( j = 1; j <= tubularSegments; j ++ ) {
  16787. for ( i = 1; i <= radialSegments; i ++ ) {
  16788. // indices
  16789. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16790. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16791. var c = ( radialSegments + 1 ) * j + i;
  16792. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16793. // faces
  16794. indices.push( a, b, d );
  16795. indices.push( b, c, d );
  16796. }
  16797. }
  16798. // build geometry
  16799. this.setIndex( indices );
  16800. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16801. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16802. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16803. // this function calculates the current position on the torus curve
  16804. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16805. var cu = Math.cos( u );
  16806. var su = Math.sin( u );
  16807. var quOverP = q / p * u;
  16808. var cs = Math.cos( quOverP );
  16809. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16810. position.y = radius * ( 2 + cs ) * su * 0.5;
  16811. position.z = radius * Math.sin( quOverP ) * 0.5;
  16812. }
  16813. }
  16814. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16815. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16816. /**
  16817. * @author oosmoxiecode
  16818. * @author mrdoob / http://mrdoob.com/
  16819. * @author Mugen87 / https://github.com/Mugen87
  16820. */
  16821. // TorusGeometry
  16822. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16823. Geometry.call( this );
  16824. this.type = 'TorusGeometry';
  16825. this.parameters = {
  16826. radius: radius,
  16827. tube: tube,
  16828. radialSegments: radialSegments,
  16829. tubularSegments: tubularSegments,
  16830. arc: arc
  16831. };
  16832. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16833. this.mergeVertices();
  16834. }
  16835. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16836. TorusGeometry.prototype.constructor = TorusGeometry;
  16837. // TorusBufferGeometry
  16838. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16839. BufferGeometry.call( this );
  16840. this.type = 'TorusBufferGeometry';
  16841. this.parameters = {
  16842. radius: radius,
  16843. tube: tube,
  16844. radialSegments: radialSegments,
  16845. tubularSegments: tubularSegments,
  16846. arc: arc
  16847. };
  16848. radius = radius || 1;
  16849. tube = tube || 0.4;
  16850. radialSegments = Math.floor( radialSegments ) || 8;
  16851. tubularSegments = Math.floor( tubularSegments ) || 6;
  16852. arc = arc || Math.PI * 2;
  16853. // buffers
  16854. var indices = [];
  16855. var vertices = [];
  16856. var normals = [];
  16857. var uvs = [];
  16858. // helper variables
  16859. var center = new Vector3();
  16860. var vertex = new Vector3();
  16861. var normal = new Vector3();
  16862. var j, i;
  16863. // generate vertices, normals and uvs
  16864. for ( j = 0; j <= radialSegments; j ++ ) {
  16865. for ( i = 0; i <= tubularSegments; i ++ ) {
  16866. var u = i / tubularSegments * arc;
  16867. var v = j / radialSegments * Math.PI * 2;
  16868. // vertex
  16869. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16870. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16871. vertex.z = tube * Math.sin( v );
  16872. vertices.push( vertex.x, vertex.y, vertex.z );
  16873. // normal
  16874. center.x = radius * Math.cos( u );
  16875. center.y = radius * Math.sin( u );
  16876. normal.subVectors( vertex, center ).normalize();
  16877. normals.push( normal.x, normal.y, normal.z );
  16878. // uv
  16879. uvs.push( i / tubularSegments );
  16880. uvs.push( j / radialSegments );
  16881. }
  16882. }
  16883. // generate indices
  16884. for ( j = 1; j <= radialSegments; j ++ ) {
  16885. for ( i = 1; i <= tubularSegments; i ++ ) {
  16886. // indices
  16887. var a = ( tubularSegments + 1 ) * j + i - 1;
  16888. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16889. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16890. var d = ( tubularSegments + 1 ) * j + i;
  16891. // faces
  16892. indices.push( a, b, d );
  16893. indices.push( b, c, d );
  16894. }
  16895. }
  16896. // build geometry
  16897. this.setIndex( indices );
  16898. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16899. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16900. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16901. }
  16902. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16903. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16904. /**
  16905. * @author Mugen87 / https://github.com/Mugen87
  16906. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16907. */
  16908. var Earcut = {
  16909. triangulate: function ( data, holeIndices, dim ) {
  16910. dim = dim || 2;
  16911. var hasHoles = holeIndices && holeIndices.length,
  16912. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16913. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16914. triangles = [];
  16915. if ( ! outerNode ) return triangles;
  16916. var minX, minY, maxX, maxY, x, y, invSize;
  16917. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16918. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16919. if ( data.length > 80 * dim ) {
  16920. minX = maxX = data[ 0 ];
  16921. minY = maxY = data[ 1 ];
  16922. for ( var i = dim; i < outerLen; i += dim ) {
  16923. x = data[ i ];
  16924. y = data[ i + 1 ];
  16925. if ( x < minX ) minX = x;
  16926. if ( y < minY ) minY = y;
  16927. if ( x > maxX ) maxX = x;
  16928. if ( y > maxY ) maxY = y;
  16929. }
  16930. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16931. invSize = Math.max( maxX - minX, maxY - minY );
  16932. invSize = invSize !== 0 ? 1 / invSize : 0;
  16933. }
  16934. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16935. return triangles;
  16936. }
  16937. };
  16938. // create a circular doubly linked list from polygon points in the specified winding order
  16939. function linkedList( data, start, end, dim, clockwise ) {
  16940. var i, last;
  16941. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16942. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16943. } else {
  16944. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16945. }
  16946. if ( last && equals( last, last.next ) ) {
  16947. removeNode( last );
  16948. last = last.next;
  16949. }
  16950. return last;
  16951. }
  16952. // eliminate colinear or duplicate points
  16953. function filterPoints( start, end ) {
  16954. if ( ! start ) return start;
  16955. if ( ! end ) end = start;
  16956. var p = start, again;
  16957. do {
  16958. again = false;
  16959. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16960. removeNode( p );
  16961. p = end = p.prev;
  16962. if ( p === p.next ) break;
  16963. again = true;
  16964. } else {
  16965. p = p.next;
  16966. }
  16967. } while ( again || p !== end );
  16968. return end;
  16969. }
  16970. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16971. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16972. if ( ! ear ) return;
  16973. // interlink polygon nodes in z-order
  16974. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16975. var stop = ear, prev, next;
  16976. // iterate through ears, slicing them one by one
  16977. while ( ear.prev !== ear.next ) {
  16978. prev = ear.prev;
  16979. next = ear.next;
  16980. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16981. // cut off the triangle
  16982. triangles.push( prev.i / dim );
  16983. triangles.push( ear.i / dim );
  16984. triangles.push( next.i / dim );
  16985. removeNode( ear );
  16986. // skipping the next vertice leads to less sliver triangles
  16987. ear = next.next;
  16988. stop = next.next;
  16989. continue;
  16990. }
  16991. ear = next;
  16992. // if we looped through the whole remaining polygon and can't find any more ears
  16993. if ( ear === stop ) {
  16994. // try filtering points and slicing again
  16995. if ( ! pass ) {
  16996. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16997. // if this didn't work, try curing all small self-intersections locally
  16998. } else if ( pass === 1 ) {
  16999. ear = cureLocalIntersections( ear, triangles, dim );
  17000. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17001. // as a last resort, try splitting the remaining polygon into two
  17002. } else if ( pass === 2 ) {
  17003. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17004. }
  17005. break;
  17006. }
  17007. }
  17008. }
  17009. // check whether a polygon node forms a valid ear with adjacent nodes
  17010. function isEar( ear ) {
  17011. var a = ear.prev,
  17012. b = ear,
  17013. c = ear.next;
  17014. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17015. // now make sure we don't have other points inside the potential ear
  17016. var p = ear.next.next;
  17017. while ( p !== ear.prev ) {
  17018. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) {
  17019. return false;
  17020. }
  17021. p = p.next;
  17022. }
  17023. return true;
  17024. }
  17025. function isEarHashed( ear, minX, minY, invSize ) {
  17026. var a = ear.prev,
  17027. b = ear,
  17028. c = ear.next;
  17029. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17030. // triangle bbox; min & max are calculated like this for speed
  17031. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17032. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17033. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17034. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17035. // z-order range for the current triangle bbox;
  17036. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17037. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17038. // first look for points inside the triangle in increasing z-order
  17039. var p = ear.nextZ;
  17040. while ( p && p.z <= maxZ ) {
  17041. if ( p !== ear.prev && p !== ear.next &&
  17042. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17043. area( p.prev, p, p.next ) >= 0 ) return false;
  17044. p = p.nextZ;
  17045. }
  17046. // then look for points in decreasing z-order
  17047. p = ear.prevZ;
  17048. while ( p && p.z >= minZ ) {
  17049. if ( p !== ear.prev && p !== ear.next &&
  17050. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17051. area( p.prev, p, p.next ) >= 0 ) return false;
  17052. p = p.prevZ;
  17053. }
  17054. return true;
  17055. }
  17056. // go through all polygon nodes and cure small local self-intersections
  17057. function cureLocalIntersections( start, triangles, dim ) {
  17058. var p = start;
  17059. do {
  17060. var a = p.prev, b = p.next.next;
  17061. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17062. triangles.push( a.i / dim );
  17063. triangles.push( p.i / dim );
  17064. triangles.push( b.i / dim );
  17065. // remove two nodes involved
  17066. removeNode( p );
  17067. removeNode( p.next );
  17068. p = start = b;
  17069. }
  17070. p = p.next;
  17071. } while ( p !== start );
  17072. return p;
  17073. }
  17074. // try splitting polygon into two and triangulate them independently
  17075. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17076. // look for a valid diagonal that divides the polygon into two
  17077. var a = start;
  17078. do {
  17079. var b = a.next.next;
  17080. while ( b !== a.prev ) {
  17081. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17082. // split the polygon in two by the diagonal
  17083. var c = splitPolygon( a, b );
  17084. // filter colinear points around the cuts
  17085. a = filterPoints( a, a.next );
  17086. c = filterPoints( c, c.next );
  17087. // run earcut on each half
  17088. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17089. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17090. return;
  17091. }
  17092. b = b.next;
  17093. }
  17094. a = a.next;
  17095. } while ( a !== start );
  17096. }
  17097. // link every hole into the outer loop, producing a single-ring polygon without holes
  17098. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17099. var queue = [], i, len, start, end, list;
  17100. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17101. start = holeIndices[ i ] * dim;
  17102. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17103. list = linkedList( data, start, end, dim, false );
  17104. if ( list === list.next ) list.steiner = true;
  17105. queue.push( getLeftmost( list ) );
  17106. }
  17107. queue.sort( compareX );
  17108. // process holes from left to right
  17109. for ( i = 0; i < queue.length; i ++ ) {
  17110. eliminateHole( queue[ i ], outerNode );
  17111. outerNode = filterPoints( outerNode, outerNode.next );
  17112. }
  17113. return outerNode;
  17114. }
  17115. function compareX( a, b ) {
  17116. return a.x - b.x;
  17117. }
  17118. // find a bridge between vertices that connects hole with an outer ring and and link it
  17119. function eliminateHole( hole, outerNode ) {
  17120. outerNode = findHoleBridge( hole, outerNode );
  17121. if ( outerNode ) {
  17122. var b = splitPolygon( outerNode, hole );
  17123. filterPoints( b, b.next );
  17124. }
  17125. }
  17126. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17127. function findHoleBridge( hole, outerNode ) {
  17128. var p = outerNode,
  17129. hx = hole.x,
  17130. hy = hole.y,
  17131. qx = - Infinity,
  17132. m;
  17133. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17134. // segment's endpoint with lesser x will be potential connection point
  17135. do {
  17136. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17137. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17138. if ( x <= hx && x > qx ) {
  17139. qx = x;
  17140. if ( x === hx ) {
  17141. if ( hy === p.y ) return p;
  17142. if ( hy === p.next.y ) return p.next;
  17143. }
  17144. m = p.x < p.next.x ? p : p.next;
  17145. }
  17146. }
  17147. p = p.next;
  17148. } while ( p !== outerNode );
  17149. if ( ! m ) return null;
  17150. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17151. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17152. // if there are no points found, we have a valid connection;
  17153. // otherwise choose the point of the minimum angle with the ray as connection point
  17154. var stop = m,
  17155. mx = m.x,
  17156. my = m.y,
  17157. tanMin = Infinity,
  17158. tan;
  17159. p = m.next;
  17160. while ( p !== stop ) {
  17161. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17162. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17163. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17164. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17165. m = p;
  17166. tanMin = tan;
  17167. }
  17168. }
  17169. p = p.next;
  17170. }
  17171. return m;
  17172. }
  17173. // interlink polygon nodes in z-order
  17174. function indexCurve( start, minX, minY, invSize ) {
  17175. var p = start;
  17176. do {
  17177. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17178. p.prevZ = p.prev;
  17179. p.nextZ = p.next;
  17180. p = p.next;
  17181. } while ( p !== start );
  17182. p.prevZ.nextZ = null;
  17183. p.prevZ = null;
  17184. sortLinked( p );
  17185. }
  17186. // Simon Tatham's linked list merge sort algorithm
  17187. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17188. function sortLinked( list ) {
  17189. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  17190. do {
  17191. p = list;
  17192. list = null;
  17193. tail = null;
  17194. numMerges = 0;
  17195. while ( p ) {
  17196. numMerges ++;
  17197. q = p;
  17198. pSize = 0;
  17199. for ( i = 0; i < inSize; i ++ ) {
  17200. pSize ++;
  17201. q = q.nextZ;
  17202. if ( ! q ) break;
  17203. }
  17204. qSize = inSize;
  17205. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17206. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17207. e = p;
  17208. p = p.nextZ;
  17209. pSize --;
  17210. } else {
  17211. e = q;
  17212. q = q.nextZ;
  17213. qSize --;
  17214. }
  17215. if ( tail ) tail.nextZ = e;
  17216. else list = e;
  17217. e.prevZ = tail;
  17218. tail = e;
  17219. }
  17220. p = q;
  17221. }
  17222. tail.nextZ = null;
  17223. inSize *= 2;
  17224. } while ( numMerges > 1 );
  17225. return list;
  17226. }
  17227. // z-order of a point given coords and inverse of the longer side of data bbox
  17228. function zOrder( x, y, minX, minY, invSize ) {
  17229. // coords are transformed into non-negative 15-bit integer range
  17230. x = 32767 * ( x - minX ) * invSize;
  17231. y = 32767 * ( y - minY ) * invSize;
  17232. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17233. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17234. x = ( x | ( x << 2 ) ) & 0x33333333;
  17235. x = ( x | ( x << 1 ) ) & 0x55555555;
  17236. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17237. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17238. y = ( y | ( y << 2 ) ) & 0x33333333;
  17239. y = ( y | ( y << 1 ) ) & 0x55555555;
  17240. return x | ( y << 1 );
  17241. }
  17242. // find the leftmost node of a polygon ring
  17243. function getLeftmost( start ) {
  17244. var p = start, leftmost = start;
  17245. do {
  17246. if ( p.x < leftmost.x ) leftmost = p;
  17247. p = p.next;
  17248. } while ( p !== start );
  17249. return leftmost;
  17250. }
  17251. // check if a point lies within a convex triangle
  17252. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17253. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17254. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17255. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17256. }
  17257. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17258. function isValidDiagonal( a, b ) {
  17259. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17260. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17261. }
  17262. // signed area of a triangle
  17263. function area( p, q, r ) {
  17264. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17265. }
  17266. // check if two points are equal
  17267. function equals( p1, p2 ) {
  17268. return p1.x === p2.x && p1.y === p2.y;
  17269. }
  17270. // check if two segments intersect
  17271. function intersects( p1, q1, p2, q2 ) {
  17272. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  17273. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17274. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17275. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17276. }
  17277. // check if a polygon diagonal intersects any polygon segments
  17278. function intersectsPolygon( a, b ) {
  17279. var p = a;
  17280. do {
  17281. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17282. intersects( p, p.next, a, b ) ) {
  17283. return true;
  17284. }
  17285. p = p.next;
  17286. } while ( p !== a );
  17287. return false;
  17288. }
  17289. // check if a polygon diagonal is locally inside the polygon
  17290. function locallyInside( a, b ) {
  17291. return area( a.prev, a, a.next ) < 0 ?
  17292. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17293. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17294. }
  17295. // check if the middle point of a polygon diagonal is inside the polygon
  17296. function middleInside( a, b ) {
  17297. var p = a,
  17298. inside = false,
  17299. px = ( a.x + b.x ) / 2,
  17300. py = ( a.y + b.y ) / 2;
  17301. do {
  17302. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17303. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  17304. inside = ! inside;
  17305. }
  17306. p = p.next;
  17307. } while ( p !== a );
  17308. return inside;
  17309. }
  17310. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17311. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17312. function splitPolygon( a, b ) {
  17313. var a2 = new Node( a.i, a.x, a.y ),
  17314. b2 = new Node( b.i, b.x, b.y ),
  17315. an = a.next,
  17316. bp = b.prev;
  17317. a.next = b;
  17318. b.prev = a;
  17319. a2.next = an;
  17320. an.prev = a2;
  17321. b2.next = a2;
  17322. a2.prev = b2;
  17323. bp.next = b2;
  17324. b2.prev = bp;
  17325. return b2;
  17326. }
  17327. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17328. function insertNode( i, x, y, last ) {
  17329. var p = new Node( i, x, y );
  17330. if ( ! last ) {
  17331. p.prev = p;
  17332. p.next = p;
  17333. } else {
  17334. p.next = last.next;
  17335. p.prev = last;
  17336. last.next.prev = p;
  17337. last.next = p;
  17338. }
  17339. return p;
  17340. }
  17341. function removeNode( p ) {
  17342. p.next.prev = p.prev;
  17343. p.prev.next = p.next;
  17344. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17345. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17346. }
  17347. function Node( i, x, y ) {
  17348. // vertice index in coordinates array
  17349. this.i = i;
  17350. // vertex coordinates
  17351. this.x = x;
  17352. this.y = y;
  17353. // previous and next vertice nodes in a polygon ring
  17354. this.prev = null;
  17355. this.next = null;
  17356. // z-order curve value
  17357. this.z = null;
  17358. // previous and next nodes in z-order
  17359. this.prevZ = null;
  17360. this.nextZ = null;
  17361. // indicates whether this is a steiner point
  17362. this.steiner = false;
  17363. }
  17364. function signedArea( data, start, end, dim ) {
  17365. var sum = 0;
  17366. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17367. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17368. j = i;
  17369. }
  17370. return sum;
  17371. }
  17372. /**
  17373. * @author zz85 / http://www.lab4games.net/zz85/blog
  17374. */
  17375. var ShapeUtils = {
  17376. // calculate area of the contour polygon
  17377. area: function ( contour ) {
  17378. var n = contour.length;
  17379. var a = 0.0;
  17380. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17381. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17382. }
  17383. return a * 0.5;
  17384. },
  17385. isClockWise: function ( pts ) {
  17386. return ShapeUtils.area( pts ) < 0;
  17387. },
  17388. triangulateShape: function ( contour, holes ) {
  17389. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17390. var holeIndices = []; // array of hole indices
  17391. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17392. removeDupEndPts( contour );
  17393. addContour( vertices, contour );
  17394. //
  17395. var holeIndex = contour.length;
  17396. holes.forEach( removeDupEndPts );
  17397. for ( var i = 0; i < holes.length; i ++ ) {
  17398. holeIndices.push( holeIndex );
  17399. holeIndex += holes[ i ].length;
  17400. addContour( vertices, holes[ i ] );
  17401. }
  17402. //
  17403. var triangles = Earcut.triangulate( vertices, holeIndices );
  17404. //
  17405. for ( var i = 0; i < triangles.length; i += 3 ) {
  17406. faces.push( triangles.slice( i, i + 3 ) );
  17407. }
  17408. return faces;
  17409. }
  17410. };
  17411. function removeDupEndPts( points ) {
  17412. var l = points.length;
  17413. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17414. points.pop();
  17415. }
  17416. }
  17417. function addContour( vertices, contour ) {
  17418. for ( var i = 0; i < contour.length; i ++ ) {
  17419. vertices.push( contour[ i ].x );
  17420. vertices.push( contour[ i ].y );
  17421. }
  17422. }
  17423. /**
  17424. * @author zz85 / http://www.lab4games.net/zz85/blog
  17425. *
  17426. * Creates extruded geometry from a path shape.
  17427. *
  17428. * parameters = {
  17429. *
  17430. * curveSegments: <int>, // number of points on the curves
  17431. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17432. * depth: <float>, // Depth to extrude the shape
  17433. *
  17434. * bevelEnabled: <bool>, // turn on bevel
  17435. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17436. * bevelSize: <float>, // how far from shape outline is bevel
  17437. * bevelSegments: <int>, // number of bevel layers
  17438. *
  17439. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17440. *
  17441. * UVGenerator: <Object> // object that provides UV generator functions
  17442. *
  17443. * }
  17444. */
  17445. // ExtrudeGeometry
  17446. function ExtrudeGeometry( shapes, options ) {
  17447. Geometry.call( this );
  17448. this.type = 'ExtrudeGeometry';
  17449. this.parameters = {
  17450. shapes: shapes,
  17451. options: options
  17452. };
  17453. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17454. this.mergeVertices();
  17455. }
  17456. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17457. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17458. ExtrudeGeometry.prototype.toJSON = function () {
  17459. var data = Geometry.prototype.toJSON.call( this );
  17460. var shapes = this.parameters.shapes;
  17461. var options = this.parameters.options;
  17462. return toJSON( shapes, options, data );
  17463. };
  17464. // ExtrudeBufferGeometry
  17465. function ExtrudeBufferGeometry( shapes, options ) {
  17466. BufferGeometry.call( this );
  17467. this.type = 'ExtrudeBufferGeometry';
  17468. this.parameters = {
  17469. shapes: shapes,
  17470. options: options
  17471. };
  17472. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17473. var scope = this;
  17474. var verticesArray = [];
  17475. var uvArray = [];
  17476. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17477. var shape = shapes[ i ];
  17478. addShape( shape );
  17479. }
  17480. // build geometry
  17481. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17482. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17483. this.computeVertexNormals();
  17484. // functions
  17485. function addShape( shape ) {
  17486. var placeholder = [];
  17487. // options
  17488. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17489. var steps = options.steps !== undefined ? options.steps : 1;
  17490. var depth = options.depth !== undefined ? options.depth : 100;
  17491. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17492. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17493. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17494. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17495. var extrudePath = options.extrudePath;
  17496. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17497. // deprecated options
  17498. if ( options.amount !== undefined ) {
  17499. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17500. depth = options.amount;
  17501. }
  17502. //
  17503. var extrudePts, extrudeByPath = false;
  17504. var splineTube, binormal, normal, position2;
  17505. if ( extrudePath ) {
  17506. extrudePts = extrudePath.getSpacedPoints( steps );
  17507. extrudeByPath = true;
  17508. bevelEnabled = false; // bevels not supported for path extrusion
  17509. // SETUP TNB variables
  17510. // TODO1 - have a .isClosed in spline?
  17511. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17512. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17513. binormal = new Vector3();
  17514. normal = new Vector3();
  17515. position2 = new Vector3();
  17516. }
  17517. // Safeguards if bevels are not enabled
  17518. if ( ! bevelEnabled ) {
  17519. bevelSegments = 0;
  17520. bevelThickness = 0;
  17521. bevelSize = 0;
  17522. }
  17523. // Variables initialization
  17524. var ahole, h, hl; // looping of holes
  17525. var shapePoints = shape.extractPoints( curveSegments );
  17526. var vertices = shapePoints.shape;
  17527. var holes = shapePoints.holes;
  17528. var reverse = ! ShapeUtils.isClockWise( vertices );
  17529. if ( reverse ) {
  17530. vertices = vertices.reverse();
  17531. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17532. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17533. ahole = holes[ h ];
  17534. if ( ShapeUtils.isClockWise( ahole ) ) {
  17535. holes[ h ] = ahole.reverse();
  17536. }
  17537. }
  17538. }
  17539. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17540. /* Vertices */
  17541. var contour = vertices; // vertices has all points but contour has only points of circumference
  17542. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17543. ahole = holes[ h ];
  17544. vertices = vertices.concat( ahole );
  17545. }
  17546. function scalePt2( pt, vec, size ) {
  17547. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17548. return vec.clone().multiplyScalar( size ).add( pt );
  17549. }
  17550. var b, bs, t, z,
  17551. vert, vlen = vertices.length,
  17552. face, flen = faces.length;
  17553. // Find directions for point movement
  17554. function getBevelVec( inPt, inPrev, inNext ) {
  17555. // computes for inPt the corresponding point inPt' on a new contour
  17556. // shifted by 1 unit (length of normalized vector) to the left
  17557. // if we walk along contour clockwise, this new contour is outside the old one
  17558. //
  17559. // inPt' is the intersection of the two lines parallel to the two
  17560. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17561. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17562. // good reading for geometry algorithms (here: line-line intersection)
  17563. // http://geomalgorithms.com/a05-_intersect-1.html
  17564. var v_prev_x = inPt.x - inPrev.x,
  17565. v_prev_y = inPt.y - inPrev.y;
  17566. var v_next_x = inNext.x - inPt.x,
  17567. v_next_y = inNext.y - inPt.y;
  17568. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17569. // check for collinear edges
  17570. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17571. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17572. // not collinear
  17573. // length of vectors for normalizing
  17574. var v_prev_len = Math.sqrt( v_prev_lensq );
  17575. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17576. // shift adjacent points by unit vectors to the left
  17577. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17578. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17579. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17580. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17581. // scaling factor for v_prev to intersection point
  17582. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17583. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17584. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17585. // vector from inPt to intersection point
  17586. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17587. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17588. // Don't normalize!, otherwise sharp corners become ugly
  17589. // but prevent crazy spikes
  17590. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17591. if ( v_trans_lensq <= 2 ) {
  17592. return new Vector2( v_trans_x, v_trans_y );
  17593. } else {
  17594. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17595. }
  17596. } else {
  17597. // handle special case of collinear edges
  17598. var direction_eq = false; // assumes: opposite
  17599. if ( v_prev_x > Number.EPSILON ) {
  17600. if ( v_next_x > Number.EPSILON ) {
  17601. direction_eq = true;
  17602. }
  17603. } else {
  17604. if ( v_prev_x < - Number.EPSILON ) {
  17605. if ( v_next_x < - Number.EPSILON ) {
  17606. direction_eq = true;
  17607. }
  17608. } else {
  17609. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17610. direction_eq = true;
  17611. }
  17612. }
  17613. }
  17614. if ( direction_eq ) {
  17615. // console.log("Warning: lines are a straight sequence");
  17616. v_trans_x = - v_prev_y;
  17617. v_trans_y = v_prev_x;
  17618. shrink_by = Math.sqrt( v_prev_lensq );
  17619. } else {
  17620. // console.log("Warning: lines are a straight spike");
  17621. v_trans_x = v_prev_x;
  17622. v_trans_y = v_prev_y;
  17623. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17624. }
  17625. }
  17626. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17627. }
  17628. var contourMovements = [];
  17629. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17630. if ( j === il ) j = 0;
  17631. if ( k === il ) k = 0;
  17632. // (j)---(i)---(k)
  17633. // console.log('i,j,k', i, j , k)
  17634. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17635. }
  17636. var holesMovements = [],
  17637. oneHoleMovements, verticesMovements = contourMovements.concat();
  17638. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17639. ahole = holes[ h ];
  17640. oneHoleMovements = [];
  17641. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17642. if ( j === il ) j = 0;
  17643. if ( k === il ) k = 0;
  17644. // (j)---(i)---(k)
  17645. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17646. }
  17647. holesMovements.push( oneHoleMovements );
  17648. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17649. }
  17650. // Loop bevelSegments, 1 for the front, 1 for the back
  17651. for ( b = 0; b < bevelSegments; b ++ ) {
  17652. //for ( b = bevelSegments; b > 0; b -- ) {
  17653. t = b / bevelSegments;
  17654. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17655. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17656. // contract shape
  17657. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17658. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17659. v( vert.x, vert.y, - z );
  17660. }
  17661. // expand holes
  17662. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17663. ahole = holes[ h ];
  17664. oneHoleMovements = holesMovements[ h ];
  17665. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17666. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17667. v( vert.x, vert.y, - z );
  17668. }
  17669. }
  17670. }
  17671. bs = bevelSize;
  17672. // Back facing vertices
  17673. for ( i = 0; i < vlen; i ++ ) {
  17674. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17675. if ( ! extrudeByPath ) {
  17676. v( vert.x, vert.y, 0 );
  17677. } else {
  17678. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17679. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17680. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17681. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17682. v( position2.x, position2.y, position2.z );
  17683. }
  17684. }
  17685. // Add stepped vertices...
  17686. // Including front facing vertices
  17687. var s;
  17688. for ( s = 1; s <= steps; s ++ ) {
  17689. for ( i = 0; i < vlen; i ++ ) {
  17690. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17691. if ( ! extrudeByPath ) {
  17692. v( vert.x, vert.y, depth / steps * s );
  17693. } else {
  17694. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17695. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17696. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17697. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17698. v( position2.x, position2.y, position2.z );
  17699. }
  17700. }
  17701. }
  17702. // Add bevel segments planes
  17703. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17704. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17705. t = b / bevelSegments;
  17706. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17707. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17708. // contract shape
  17709. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17710. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17711. v( vert.x, vert.y, depth + z );
  17712. }
  17713. // expand holes
  17714. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17715. ahole = holes[ h ];
  17716. oneHoleMovements = holesMovements[ h ];
  17717. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17718. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17719. if ( ! extrudeByPath ) {
  17720. v( vert.x, vert.y, depth + z );
  17721. } else {
  17722. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17723. }
  17724. }
  17725. }
  17726. }
  17727. /* Faces */
  17728. // Top and bottom faces
  17729. buildLidFaces();
  17730. // Sides faces
  17731. buildSideFaces();
  17732. ///// Internal functions
  17733. function buildLidFaces() {
  17734. var start = verticesArray.length / 3;
  17735. if ( bevelEnabled ) {
  17736. var layer = 0; // steps + 1
  17737. var offset = vlen * layer;
  17738. // Bottom faces
  17739. for ( i = 0; i < flen; i ++ ) {
  17740. face = faces[ i ];
  17741. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17742. }
  17743. layer = steps + bevelSegments * 2;
  17744. offset = vlen * layer;
  17745. // Top faces
  17746. for ( i = 0; i < flen; i ++ ) {
  17747. face = faces[ i ];
  17748. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17749. }
  17750. } else {
  17751. // Bottom faces
  17752. for ( i = 0; i < flen; i ++ ) {
  17753. face = faces[ i ];
  17754. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17755. }
  17756. // Top faces
  17757. for ( i = 0; i < flen; i ++ ) {
  17758. face = faces[ i ];
  17759. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17760. }
  17761. }
  17762. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17763. }
  17764. // Create faces for the z-sides of the shape
  17765. function buildSideFaces() {
  17766. var start = verticesArray.length / 3;
  17767. var layeroffset = 0;
  17768. sidewalls( contour, layeroffset );
  17769. layeroffset += contour.length;
  17770. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17771. ahole = holes[ h ];
  17772. sidewalls( ahole, layeroffset );
  17773. //, true
  17774. layeroffset += ahole.length;
  17775. }
  17776. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17777. }
  17778. function sidewalls( contour, layeroffset ) {
  17779. var j, k;
  17780. i = contour.length;
  17781. while ( -- i >= 0 ) {
  17782. j = i;
  17783. k = i - 1;
  17784. if ( k < 0 ) k = contour.length - 1;
  17785. //console.log('b', i,j, i-1, k,vertices.length);
  17786. var s = 0,
  17787. sl = steps + bevelSegments * 2;
  17788. for ( s = 0; s < sl; s ++ ) {
  17789. var slen1 = vlen * s;
  17790. var slen2 = vlen * ( s + 1 );
  17791. var a = layeroffset + j + slen1,
  17792. b = layeroffset + k + slen1,
  17793. c = layeroffset + k + slen2,
  17794. d = layeroffset + j + slen2;
  17795. f4( a, b, c, d );
  17796. }
  17797. }
  17798. }
  17799. function v( x, y, z ) {
  17800. placeholder.push( x );
  17801. placeholder.push( y );
  17802. placeholder.push( z );
  17803. }
  17804. function f3( a, b, c ) {
  17805. addVertex( a );
  17806. addVertex( b );
  17807. addVertex( c );
  17808. var nextIndex = verticesArray.length / 3;
  17809. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17810. addUV( uvs[ 0 ] );
  17811. addUV( uvs[ 1 ] );
  17812. addUV( uvs[ 2 ] );
  17813. }
  17814. function f4( a, b, c, d ) {
  17815. addVertex( a );
  17816. addVertex( b );
  17817. addVertex( d );
  17818. addVertex( b );
  17819. addVertex( c );
  17820. addVertex( d );
  17821. var nextIndex = verticesArray.length / 3;
  17822. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17823. addUV( uvs[ 0 ] );
  17824. addUV( uvs[ 1 ] );
  17825. addUV( uvs[ 3 ] );
  17826. addUV( uvs[ 1 ] );
  17827. addUV( uvs[ 2 ] );
  17828. addUV( uvs[ 3 ] );
  17829. }
  17830. function addVertex( index ) {
  17831. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17832. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17833. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17834. }
  17835. function addUV( vector2 ) {
  17836. uvArray.push( vector2.x );
  17837. uvArray.push( vector2.y );
  17838. }
  17839. }
  17840. }
  17841. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17842. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17843. ExtrudeBufferGeometry.prototype.toJSON = function () {
  17844. var data = BufferGeometry.prototype.toJSON.call( this );
  17845. var shapes = this.parameters.shapes;
  17846. var options = this.parameters.options;
  17847. return toJSON( shapes, options, data );
  17848. };
  17849. //
  17850. var WorldUVGenerator = {
  17851. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17852. var a_x = vertices[ indexA * 3 ];
  17853. var a_y = vertices[ indexA * 3 + 1 ];
  17854. var b_x = vertices[ indexB * 3 ];
  17855. var b_y = vertices[ indexB * 3 + 1 ];
  17856. var c_x = vertices[ indexC * 3 ];
  17857. var c_y = vertices[ indexC * 3 + 1 ];
  17858. return [
  17859. new Vector2( a_x, a_y ),
  17860. new Vector2( b_x, b_y ),
  17861. new Vector2( c_x, c_y )
  17862. ];
  17863. },
  17864. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17865. var a_x = vertices[ indexA * 3 ];
  17866. var a_y = vertices[ indexA * 3 + 1 ];
  17867. var a_z = vertices[ indexA * 3 + 2 ];
  17868. var b_x = vertices[ indexB * 3 ];
  17869. var b_y = vertices[ indexB * 3 + 1 ];
  17870. var b_z = vertices[ indexB * 3 + 2 ];
  17871. var c_x = vertices[ indexC * 3 ];
  17872. var c_y = vertices[ indexC * 3 + 1 ];
  17873. var c_z = vertices[ indexC * 3 + 2 ];
  17874. var d_x = vertices[ indexD * 3 ];
  17875. var d_y = vertices[ indexD * 3 + 1 ];
  17876. var d_z = vertices[ indexD * 3 + 2 ];
  17877. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17878. return [
  17879. new Vector2( a_x, 1 - a_z ),
  17880. new Vector2( b_x, 1 - b_z ),
  17881. new Vector2( c_x, 1 - c_z ),
  17882. new Vector2( d_x, 1 - d_z )
  17883. ];
  17884. } else {
  17885. return [
  17886. new Vector2( a_y, 1 - a_z ),
  17887. new Vector2( b_y, 1 - b_z ),
  17888. new Vector2( c_y, 1 - c_z ),
  17889. new Vector2( d_y, 1 - d_z )
  17890. ];
  17891. }
  17892. }
  17893. };
  17894. function toJSON( shapes, options, data ) {
  17895. //
  17896. data.shapes = [];
  17897. if ( Array.isArray( shapes ) ) {
  17898. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17899. var shape = shapes[ i ];
  17900. data.shapes.push( shape.uuid );
  17901. }
  17902. } else {
  17903. data.shapes.push( shapes.uuid );
  17904. }
  17905. //
  17906. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17907. return data;
  17908. }
  17909. /**
  17910. * @author zz85 / http://www.lab4games.net/zz85/blog
  17911. * @author alteredq / http://alteredqualia.com/
  17912. *
  17913. * Text = 3D Text
  17914. *
  17915. * parameters = {
  17916. * font: <THREE.Font>, // font
  17917. *
  17918. * size: <float>, // size of the text
  17919. * height: <float>, // thickness to extrude text
  17920. * curveSegments: <int>, // number of points on the curves
  17921. *
  17922. * bevelEnabled: <bool>, // turn on bevel
  17923. * bevelThickness: <float>, // how deep into text bevel goes
  17924. * bevelSize: <float> // how far from text outline is bevel
  17925. * }
  17926. */
  17927. // TextGeometry
  17928. function TextGeometry( text, parameters ) {
  17929. Geometry.call( this );
  17930. this.type = 'TextGeometry';
  17931. this.parameters = {
  17932. text: text,
  17933. parameters: parameters
  17934. };
  17935. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17936. this.mergeVertices();
  17937. }
  17938. TextGeometry.prototype = Object.create( Geometry.prototype );
  17939. TextGeometry.prototype.constructor = TextGeometry;
  17940. // TextBufferGeometry
  17941. function TextBufferGeometry( text, parameters ) {
  17942. parameters = parameters || {};
  17943. var font = parameters.font;
  17944. if ( ! ( font && font.isFont ) ) {
  17945. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17946. return new Geometry();
  17947. }
  17948. var shapes = font.generateShapes( text, parameters.size );
  17949. // translate parameters to ExtrudeGeometry API
  17950. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17951. // defaults
  17952. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17953. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17954. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17955. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17956. this.type = 'TextBufferGeometry';
  17957. }
  17958. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17959. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17960. /**
  17961. * @author mrdoob / http://mrdoob.com/
  17962. * @author benaadams / https://twitter.com/ben_a_adams
  17963. * @author Mugen87 / https://github.com/Mugen87
  17964. */
  17965. // SphereGeometry
  17966. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17967. Geometry.call( this );
  17968. this.type = 'SphereGeometry';
  17969. this.parameters = {
  17970. radius: radius,
  17971. widthSegments: widthSegments,
  17972. heightSegments: heightSegments,
  17973. phiStart: phiStart,
  17974. phiLength: phiLength,
  17975. thetaStart: thetaStart,
  17976. thetaLength: thetaLength
  17977. };
  17978. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17979. this.mergeVertices();
  17980. }
  17981. SphereGeometry.prototype = Object.create( Geometry.prototype );
  17982. SphereGeometry.prototype.constructor = SphereGeometry;
  17983. // SphereBufferGeometry
  17984. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17985. BufferGeometry.call( this );
  17986. this.type = 'SphereBufferGeometry';
  17987. this.parameters = {
  17988. radius: radius,
  17989. widthSegments: widthSegments,
  17990. heightSegments: heightSegments,
  17991. phiStart: phiStart,
  17992. phiLength: phiLength,
  17993. thetaStart: thetaStart,
  17994. thetaLength: thetaLength
  17995. };
  17996. radius = radius || 1;
  17997. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17998. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17999. phiStart = phiStart !== undefined ? phiStart : 0;
  18000. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18001. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18002. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18003. var thetaEnd = thetaStart + thetaLength;
  18004. var ix, iy;
  18005. var index = 0;
  18006. var grid = [];
  18007. var vertex = new Vector3();
  18008. var normal = new Vector3();
  18009. // buffers
  18010. var indices = [];
  18011. var vertices = [];
  18012. var normals = [];
  18013. var uvs = [];
  18014. // generate vertices, normals and uvs
  18015. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18016. var verticesRow = [];
  18017. var v = iy / heightSegments;
  18018. // special case for the poles
  18019. var uOffset = ( iy == 0 ) ? 0.5 / widthSegments : ( ( iy == heightSegments ) ? - 0.5 / widthSegments : 0 );
  18020. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18021. var u = ix / widthSegments;
  18022. // vertex
  18023. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18024. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18025. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18026. vertices.push( vertex.x, vertex.y, vertex.z );
  18027. // normal
  18028. normal.copy( vertex ).normalize();
  18029. normals.push( normal.x, normal.y, normal.z );
  18030. // uv
  18031. uvs.push( u + uOffset, 1 - v );
  18032. verticesRow.push( index ++ );
  18033. }
  18034. grid.push( verticesRow );
  18035. }
  18036. // indices
  18037. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18038. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18039. var a = grid[ iy ][ ix + 1 ];
  18040. var b = grid[ iy ][ ix ];
  18041. var c = grid[ iy + 1 ][ ix ];
  18042. var d = grid[ iy + 1 ][ ix + 1 ];
  18043. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18044. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18045. }
  18046. }
  18047. // build geometry
  18048. this.setIndex( indices );
  18049. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18050. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18051. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18052. }
  18053. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18054. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18055. /**
  18056. * @author Kaleb Murphy
  18057. * @author Mugen87 / https://github.com/Mugen87
  18058. */
  18059. // RingGeometry
  18060. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18061. Geometry.call( this );
  18062. this.type = 'RingGeometry';
  18063. this.parameters = {
  18064. innerRadius: innerRadius,
  18065. outerRadius: outerRadius,
  18066. thetaSegments: thetaSegments,
  18067. phiSegments: phiSegments,
  18068. thetaStart: thetaStart,
  18069. thetaLength: thetaLength
  18070. };
  18071. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18072. this.mergeVertices();
  18073. }
  18074. RingGeometry.prototype = Object.create( Geometry.prototype );
  18075. RingGeometry.prototype.constructor = RingGeometry;
  18076. // RingBufferGeometry
  18077. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18078. BufferGeometry.call( this );
  18079. this.type = 'RingBufferGeometry';
  18080. this.parameters = {
  18081. innerRadius: innerRadius,
  18082. outerRadius: outerRadius,
  18083. thetaSegments: thetaSegments,
  18084. phiSegments: phiSegments,
  18085. thetaStart: thetaStart,
  18086. thetaLength: thetaLength
  18087. };
  18088. innerRadius = innerRadius || 0.5;
  18089. outerRadius = outerRadius || 1;
  18090. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18091. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18092. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18093. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18094. // buffers
  18095. var indices = [];
  18096. var vertices = [];
  18097. var normals = [];
  18098. var uvs = [];
  18099. // some helper variables
  18100. var segment;
  18101. var radius = innerRadius;
  18102. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18103. var vertex = new Vector3();
  18104. var uv = new Vector2();
  18105. var j, i;
  18106. // generate vertices, normals and uvs
  18107. for ( j = 0; j <= phiSegments; j ++ ) {
  18108. for ( i = 0; i <= thetaSegments; i ++ ) {
  18109. // values are generate from the inside of the ring to the outside
  18110. segment = thetaStart + i / thetaSegments * thetaLength;
  18111. // vertex
  18112. vertex.x = radius * Math.cos( segment );
  18113. vertex.y = radius * Math.sin( segment );
  18114. vertices.push( vertex.x, vertex.y, vertex.z );
  18115. // normal
  18116. normals.push( 0, 0, 1 );
  18117. // uv
  18118. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18119. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18120. uvs.push( uv.x, uv.y );
  18121. }
  18122. // increase the radius for next row of vertices
  18123. radius += radiusStep;
  18124. }
  18125. // indices
  18126. for ( j = 0; j < phiSegments; j ++ ) {
  18127. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18128. for ( i = 0; i < thetaSegments; i ++ ) {
  18129. segment = i + thetaSegmentLevel;
  18130. var a = segment;
  18131. var b = segment + thetaSegments + 1;
  18132. var c = segment + thetaSegments + 2;
  18133. var d = segment + 1;
  18134. // faces
  18135. indices.push( a, b, d );
  18136. indices.push( b, c, d );
  18137. }
  18138. }
  18139. // build geometry
  18140. this.setIndex( indices );
  18141. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18142. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18143. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18144. }
  18145. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18146. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18147. /**
  18148. * @author zz85 / https://github.com/zz85
  18149. * @author bhouston / http://clara.io
  18150. * @author Mugen87 / https://github.com/Mugen87
  18151. */
  18152. // LatheGeometry
  18153. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18154. Geometry.call( this );
  18155. this.type = 'LatheGeometry';
  18156. this.parameters = {
  18157. points: points,
  18158. segments: segments,
  18159. phiStart: phiStart,
  18160. phiLength: phiLength
  18161. };
  18162. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18163. this.mergeVertices();
  18164. }
  18165. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18166. LatheGeometry.prototype.constructor = LatheGeometry;
  18167. // LatheBufferGeometry
  18168. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18169. BufferGeometry.call( this );
  18170. this.type = 'LatheBufferGeometry';
  18171. this.parameters = {
  18172. points: points,
  18173. segments: segments,
  18174. phiStart: phiStart,
  18175. phiLength: phiLength
  18176. };
  18177. segments = Math.floor( segments ) || 12;
  18178. phiStart = phiStart || 0;
  18179. phiLength = phiLength || Math.PI * 2;
  18180. // clamp phiLength so it's in range of [ 0, 2PI ]
  18181. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18182. // buffers
  18183. var indices = [];
  18184. var vertices = [];
  18185. var uvs = [];
  18186. // helper variables
  18187. var base;
  18188. var inverseSegments = 1.0 / segments;
  18189. var vertex = new Vector3();
  18190. var uv = new Vector2();
  18191. var i, j;
  18192. // generate vertices and uvs
  18193. for ( i = 0; i <= segments; i ++ ) {
  18194. var phi = phiStart + i * inverseSegments * phiLength;
  18195. var sin = Math.sin( phi );
  18196. var cos = Math.cos( phi );
  18197. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18198. // vertex
  18199. vertex.x = points[ j ].x * sin;
  18200. vertex.y = points[ j ].y;
  18201. vertex.z = points[ j ].x * cos;
  18202. vertices.push( vertex.x, vertex.y, vertex.z );
  18203. // uv
  18204. uv.x = i / segments;
  18205. uv.y = j / ( points.length - 1 );
  18206. uvs.push( uv.x, uv.y );
  18207. }
  18208. }
  18209. // indices
  18210. for ( i = 0; i < segments; i ++ ) {
  18211. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18212. base = j + i * points.length;
  18213. var a = base;
  18214. var b = base + points.length;
  18215. var c = base + points.length + 1;
  18216. var d = base + 1;
  18217. // faces
  18218. indices.push( a, b, d );
  18219. indices.push( b, c, d );
  18220. }
  18221. }
  18222. // build geometry
  18223. this.setIndex( indices );
  18224. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18225. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18226. // generate normals
  18227. this.computeVertexNormals();
  18228. // if the geometry is closed, we need to average the normals along the seam.
  18229. // because the corresponding vertices are identical (but still have different UVs).
  18230. if ( phiLength === Math.PI * 2 ) {
  18231. var normals = this.attributes.normal.array;
  18232. var n1 = new Vector3();
  18233. var n2 = new Vector3();
  18234. var n = new Vector3();
  18235. // this is the buffer offset for the last line of vertices
  18236. base = segments * points.length * 3;
  18237. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18238. // select the normal of the vertex in the first line
  18239. n1.x = normals[ j + 0 ];
  18240. n1.y = normals[ j + 1 ];
  18241. n1.z = normals[ j + 2 ];
  18242. // select the normal of the vertex in the last line
  18243. n2.x = normals[ base + j + 0 ];
  18244. n2.y = normals[ base + j + 1 ];
  18245. n2.z = normals[ base + j + 2 ];
  18246. // average normals
  18247. n.addVectors( n1, n2 ).normalize();
  18248. // assign the new values to both normals
  18249. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18250. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18251. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18252. }
  18253. }
  18254. }
  18255. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18256. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18257. /**
  18258. * @author jonobr1 / http://jonobr1.com
  18259. * @author Mugen87 / https://github.com/Mugen87
  18260. */
  18261. // ShapeGeometry
  18262. function ShapeGeometry( shapes, curveSegments ) {
  18263. Geometry.call( this );
  18264. this.type = 'ShapeGeometry';
  18265. if ( typeof curveSegments === 'object' ) {
  18266. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18267. curveSegments = curveSegments.curveSegments;
  18268. }
  18269. this.parameters = {
  18270. shapes: shapes,
  18271. curveSegments: curveSegments
  18272. };
  18273. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18274. this.mergeVertices();
  18275. }
  18276. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18277. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18278. ShapeGeometry.prototype.toJSON = function () {
  18279. var data = Geometry.prototype.toJSON.call( this );
  18280. var shapes = this.parameters.shapes;
  18281. return toJSON$1( shapes, data );
  18282. };
  18283. // ShapeBufferGeometry
  18284. function ShapeBufferGeometry( shapes, curveSegments ) {
  18285. BufferGeometry.call( this );
  18286. this.type = 'ShapeBufferGeometry';
  18287. this.parameters = {
  18288. shapes: shapes,
  18289. curveSegments: curveSegments
  18290. };
  18291. curveSegments = curveSegments || 12;
  18292. // buffers
  18293. var indices = [];
  18294. var vertices = [];
  18295. var normals = [];
  18296. var uvs = [];
  18297. // helper variables
  18298. var groupStart = 0;
  18299. var groupCount = 0;
  18300. // allow single and array values for "shapes" parameter
  18301. if ( Array.isArray( shapes ) === false ) {
  18302. addShape( shapes );
  18303. } else {
  18304. for ( var i = 0; i < shapes.length; i ++ ) {
  18305. addShape( shapes[ i ] );
  18306. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18307. groupStart += groupCount;
  18308. groupCount = 0;
  18309. }
  18310. }
  18311. // build geometry
  18312. this.setIndex( indices );
  18313. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18314. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18315. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18316. // helper functions
  18317. function addShape( shape ) {
  18318. var i, l, shapeHole;
  18319. var indexOffset = vertices.length / 3;
  18320. var points = shape.extractPoints( curveSegments );
  18321. var shapeVertices = points.shape;
  18322. var shapeHoles = points.holes;
  18323. // check direction of vertices
  18324. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18325. shapeVertices = shapeVertices.reverse();
  18326. }
  18327. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18328. shapeHole = shapeHoles[ i ];
  18329. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18330. shapeHoles[ i ] = shapeHole.reverse();
  18331. }
  18332. }
  18333. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18334. // join vertices of inner and outer paths to a single array
  18335. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18336. shapeHole = shapeHoles[ i ];
  18337. shapeVertices = shapeVertices.concat( shapeHole );
  18338. }
  18339. // vertices, normals, uvs
  18340. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18341. var vertex = shapeVertices[ i ];
  18342. vertices.push( vertex.x, vertex.y, 0 );
  18343. normals.push( 0, 0, 1 );
  18344. uvs.push( vertex.x, vertex.y ); // world uvs
  18345. }
  18346. // incides
  18347. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18348. var face = faces[ i ];
  18349. var a = face[ 0 ] + indexOffset;
  18350. var b = face[ 1 ] + indexOffset;
  18351. var c = face[ 2 ] + indexOffset;
  18352. indices.push( a, b, c );
  18353. groupCount += 3;
  18354. }
  18355. }
  18356. }
  18357. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18358. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18359. ShapeBufferGeometry.prototype.toJSON = function () {
  18360. var data = BufferGeometry.prototype.toJSON.call( this );
  18361. var shapes = this.parameters.shapes;
  18362. return toJSON$1( shapes, data );
  18363. };
  18364. //
  18365. function toJSON$1( shapes, data ) {
  18366. data.shapes = [];
  18367. if ( Array.isArray( shapes ) ) {
  18368. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18369. var shape = shapes[ i ];
  18370. data.shapes.push( shape.uuid );
  18371. }
  18372. } else {
  18373. data.shapes.push( shapes.uuid );
  18374. }
  18375. return data;
  18376. }
  18377. /**
  18378. * @author WestLangley / http://github.com/WestLangley
  18379. * @author Mugen87 / https://github.com/Mugen87
  18380. */
  18381. function EdgesGeometry( geometry, thresholdAngle ) {
  18382. BufferGeometry.call( this );
  18383. this.type = 'EdgesGeometry';
  18384. this.parameters = {
  18385. thresholdAngle: thresholdAngle
  18386. };
  18387. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18388. // buffer
  18389. var vertices = [];
  18390. // helper variables
  18391. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18392. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18393. var key, keys = [ 'a', 'b', 'c' ];
  18394. // prepare source geometry
  18395. var geometry2;
  18396. if ( geometry.isBufferGeometry ) {
  18397. geometry2 = new Geometry();
  18398. geometry2.fromBufferGeometry( geometry );
  18399. } else {
  18400. geometry2 = geometry.clone();
  18401. }
  18402. geometry2.mergeVertices();
  18403. geometry2.computeFaceNormals();
  18404. var sourceVertices = geometry2.vertices;
  18405. var faces = geometry2.faces;
  18406. // now create a data structure where each entry represents an edge with its adjoining faces
  18407. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18408. var face = faces[ i ];
  18409. for ( var j = 0; j < 3; j ++ ) {
  18410. edge1 = face[ keys[ j ] ];
  18411. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18412. edge[ 0 ] = Math.min( edge1, edge2 );
  18413. edge[ 1 ] = Math.max( edge1, edge2 );
  18414. key = edge[ 0 ] + ',' + edge[ 1 ];
  18415. if ( edges[ key ] === undefined ) {
  18416. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18417. } else {
  18418. edges[ key ].face2 = i;
  18419. }
  18420. }
  18421. }
  18422. // generate vertices
  18423. for ( key in edges ) {
  18424. var e = edges[ key ];
  18425. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18426. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18427. var vertex = sourceVertices[ e.index1 ];
  18428. vertices.push( vertex.x, vertex.y, vertex.z );
  18429. vertex = sourceVertices[ e.index2 ];
  18430. vertices.push( vertex.x, vertex.y, vertex.z );
  18431. }
  18432. }
  18433. // build geometry
  18434. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18435. }
  18436. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18437. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18438. /**
  18439. * @author mrdoob / http://mrdoob.com/
  18440. * @author Mugen87 / https://github.com/Mugen87
  18441. */
  18442. // CylinderGeometry
  18443. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18444. Geometry.call( this );
  18445. this.type = 'CylinderGeometry';
  18446. this.parameters = {
  18447. radiusTop: radiusTop,
  18448. radiusBottom: radiusBottom,
  18449. height: height,
  18450. radialSegments: radialSegments,
  18451. heightSegments: heightSegments,
  18452. openEnded: openEnded,
  18453. thetaStart: thetaStart,
  18454. thetaLength: thetaLength
  18455. };
  18456. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18457. this.mergeVertices();
  18458. }
  18459. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18460. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18461. // CylinderBufferGeometry
  18462. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18463. BufferGeometry.call( this );
  18464. this.type = 'CylinderBufferGeometry';
  18465. this.parameters = {
  18466. radiusTop: radiusTop,
  18467. radiusBottom: radiusBottom,
  18468. height: height,
  18469. radialSegments: radialSegments,
  18470. heightSegments: heightSegments,
  18471. openEnded: openEnded,
  18472. thetaStart: thetaStart,
  18473. thetaLength: thetaLength
  18474. };
  18475. var scope = this;
  18476. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18477. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18478. height = height || 1;
  18479. radialSegments = Math.floor( radialSegments ) || 8;
  18480. heightSegments = Math.floor( heightSegments ) || 1;
  18481. openEnded = openEnded !== undefined ? openEnded : false;
  18482. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18483. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18484. // buffers
  18485. var indices = [];
  18486. var vertices = [];
  18487. var normals = [];
  18488. var uvs = [];
  18489. // helper variables
  18490. var index = 0;
  18491. var indexArray = [];
  18492. var halfHeight = height / 2;
  18493. var groupStart = 0;
  18494. // generate geometry
  18495. generateTorso();
  18496. if ( openEnded === false ) {
  18497. if ( radiusTop > 0 ) generateCap( true );
  18498. if ( radiusBottom > 0 ) generateCap( false );
  18499. }
  18500. // build geometry
  18501. this.setIndex( indices );
  18502. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18503. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18504. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18505. function generateTorso() {
  18506. var x, y;
  18507. var normal = new Vector3();
  18508. var vertex = new Vector3();
  18509. var groupCount = 0;
  18510. // this will be used to calculate the normal
  18511. var slope = ( radiusBottom - radiusTop ) / height;
  18512. // generate vertices, normals and uvs
  18513. for ( y = 0; y <= heightSegments; y ++ ) {
  18514. var indexRow = [];
  18515. var v = y / heightSegments;
  18516. // calculate the radius of the current row
  18517. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18518. for ( x = 0; x <= radialSegments; x ++ ) {
  18519. var u = x / radialSegments;
  18520. var theta = u * thetaLength + thetaStart;
  18521. var sinTheta = Math.sin( theta );
  18522. var cosTheta = Math.cos( theta );
  18523. // vertex
  18524. vertex.x = radius * sinTheta;
  18525. vertex.y = - v * height + halfHeight;
  18526. vertex.z = radius * cosTheta;
  18527. vertices.push( vertex.x, vertex.y, vertex.z );
  18528. // normal
  18529. normal.set( sinTheta, slope, cosTheta ).normalize();
  18530. normals.push( normal.x, normal.y, normal.z );
  18531. // uv
  18532. uvs.push( u, 1 - v );
  18533. // save index of vertex in respective row
  18534. indexRow.push( index ++ );
  18535. }
  18536. // now save vertices of the row in our index array
  18537. indexArray.push( indexRow );
  18538. }
  18539. // generate indices
  18540. for ( x = 0; x < radialSegments; x ++ ) {
  18541. for ( y = 0; y < heightSegments; y ++ ) {
  18542. // we use the index array to access the correct indices
  18543. var a = indexArray[ y ][ x ];
  18544. var b = indexArray[ y + 1 ][ x ];
  18545. var c = indexArray[ y + 1 ][ x + 1 ];
  18546. var d = indexArray[ y ][ x + 1 ];
  18547. // faces
  18548. indices.push( a, b, d );
  18549. indices.push( b, c, d );
  18550. // update group counter
  18551. groupCount += 6;
  18552. }
  18553. }
  18554. // add a group to the geometry. this will ensure multi material support
  18555. scope.addGroup( groupStart, groupCount, 0 );
  18556. // calculate new start value for groups
  18557. groupStart += groupCount;
  18558. }
  18559. function generateCap( top ) {
  18560. var x, centerIndexStart, centerIndexEnd;
  18561. var uv = new Vector2();
  18562. var vertex = new Vector3();
  18563. var groupCount = 0;
  18564. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18565. var sign = ( top === true ) ? 1 : - 1;
  18566. // save the index of the first center vertex
  18567. centerIndexStart = index;
  18568. // first we generate the center vertex data of the cap.
  18569. // because the geometry needs one set of uvs per face,
  18570. // we must generate a center vertex per face/segment
  18571. for ( x = 1; x <= radialSegments; x ++ ) {
  18572. // vertex
  18573. vertices.push( 0, halfHeight * sign, 0 );
  18574. // normal
  18575. normals.push( 0, sign, 0 );
  18576. // uv
  18577. uvs.push( 0.5, 0.5 );
  18578. // increase index
  18579. index ++;
  18580. }
  18581. // save the index of the last center vertex
  18582. centerIndexEnd = index;
  18583. // now we generate the surrounding vertices, normals and uvs
  18584. for ( x = 0; x <= radialSegments; x ++ ) {
  18585. var u = x / radialSegments;
  18586. var theta = u * thetaLength + thetaStart;
  18587. var cosTheta = Math.cos( theta );
  18588. var sinTheta = Math.sin( theta );
  18589. // vertex
  18590. vertex.x = radius * sinTheta;
  18591. vertex.y = halfHeight * sign;
  18592. vertex.z = radius * cosTheta;
  18593. vertices.push( vertex.x, vertex.y, vertex.z );
  18594. // normal
  18595. normals.push( 0, sign, 0 );
  18596. // uv
  18597. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18598. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18599. uvs.push( uv.x, uv.y );
  18600. // increase index
  18601. index ++;
  18602. }
  18603. // generate indices
  18604. for ( x = 0; x < radialSegments; x ++ ) {
  18605. var c = centerIndexStart + x;
  18606. var i = centerIndexEnd + x;
  18607. if ( top === true ) {
  18608. // face top
  18609. indices.push( i, i + 1, c );
  18610. } else {
  18611. // face bottom
  18612. indices.push( i + 1, i, c );
  18613. }
  18614. groupCount += 3;
  18615. }
  18616. // add a group to the geometry. this will ensure multi material support
  18617. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18618. // calculate new start value for groups
  18619. groupStart += groupCount;
  18620. }
  18621. }
  18622. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18623. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18624. /**
  18625. * @author abelnation / http://github.com/abelnation
  18626. */
  18627. // ConeGeometry
  18628. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18629. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18630. this.type = 'ConeGeometry';
  18631. this.parameters = {
  18632. radius: radius,
  18633. height: height,
  18634. radialSegments: radialSegments,
  18635. heightSegments: heightSegments,
  18636. openEnded: openEnded,
  18637. thetaStart: thetaStart,
  18638. thetaLength: thetaLength
  18639. };
  18640. }
  18641. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18642. ConeGeometry.prototype.constructor = ConeGeometry;
  18643. // ConeBufferGeometry
  18644. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18645. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18646. this.type = 'ConeBufferGeometry';
  18647. this.parameters = {
  18648. radius: radius,
  18649. height: height,
  18650. radialSegments: radialSegments,
  18651. heightSegments: heightSegments,
  18652. openEnded: openEnded,
  18653. thetaStart: thetaStart,
  18654. thetaLength: thetaLength
  18655. };
  18656. }
  18657. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18658. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18659. /**
  18660. * @author benaadams / https://twitter.com/ben_a_adams
  18661. * @author Mugen87 / https://github.com/Mugen87
  18662. * @author hughes
  18663. */
  18664. // CircleGeometry
  18665. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18666. Geometry.call( this );
  18667. this.type = 'CircleGeometry';
  18668. this.parameters = {
  18669. radius: radius,
  18670. segments: segments,
  18671. thetaStart: thetaStart,
  18672. thetaLength: thetaLength
  18673. };
  18674. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18675. this.mergeVertices();
  18676. }
  18677. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18678. CircleGeometry.prototype.constructor = CircleGeometry;
  18679. // CircleBufferGeometry
  18680. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18681. BufferGeometry.call( this );
  18682. this.type = 'CircleBufferGeometry';
  18683. this.parameters = {
  18684. radius: radius,
  18685. segments: segments,
  18686. thetaStart: thetaStart,
  18687. thetaLength: thetaLength
  18688. };
  18689. radius = radius || 1;
  18690. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18691. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18692. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18693. // buffers
  18694. var indices = [];
  18695. var vertices = [];
  18696. var normals = [];
  18697. var uvs = [];
  18698. // helper variables
  18699. var i, s;
  18700. var vertex = new Vector3();
  18701. var uv = new Vector2();
  18702. // center point
  18703. vertices.push( 0, 0, 0 );
  18704. normals.push( 0, 0, 1 );
  18705. uvs.push( 0.5, 0.5 );
  18706. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18707. var segment = thetaStart + s / segments * thetaLength;
  18708. // vertex
  18709. vertex.x = radius * Math.cos( segment );
  18710. vertex.y = radius * Math.sin( segment );
  18711. vertices.push( vertex.x, vertex.y, vertex.z );
  18712. // normal
  18713. normals.push( 0, 0, 1 );
  18714. // uvs
  18715. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  18716. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  18717. uvs.push( uv.x, uv.y );
  18718. }
  18719. // indices
  18720. for ( i = 1; i <= segments; i ++ ) {
  18721. indices.push( i, i + 1, 0 );
  18722. }
  18723. // build geometry
  18724. this.setIndex( indices );
  18725. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18726. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18727. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18728. }
  18729. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18730. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  18731. var Geometries = /*#__PURE__*/Object.freeze({
  18732. WireframeGeometry: WireframeGeometry,
  18733. ParametricGeometry: ParametricGeometry,
  18734. ParametricBufferGeometry: ParametricBufferGeometry,
  18735. TetrahedronGeometry: TetrahedronGeometry,
  18736. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  18737. OctahedronGeometry: OctahedronGeometry,
  18738. OctahedronBufferGeometry: OctahedronBufferGeometry,
  18739. IcosahedronGeometry: IcosahedronGeometry,
  18740. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  18741. DodecahedronGeometry: DodecahedronGeometry,
  18742. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  18743. PolyhedronGeometry: PolyhedronGeometry,
  18744. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  18745. TubeGeometry: TubeGeometry,
  18746. TubeBufferGeometry: TubeBufferGeometry,
  18747. TorusKnotGeometry: TorusKnotGeometry,
  18748. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  18749. TorusGeometry: TorusGeometry,
  18750. TorusBufferGeometry: TorusBufferGeometry,
  18751. TextGeometry: TextGeometry,
  18752. TextBufferGeometry: TextBufferGeometry,
  18753. SphereGeometry: SphereGeometry,
  18754. SphereBufferGeometry: SphereBufferGeometry,
  18755. RingGeometry: RingGeometry,
  18756. RingBufferGeometry: RingBufferGeometry,
  18757. PlaneGeometry: PlaneGeometry,
  18758. PlaneBufferGeometry: PlaneBufferGeometry,
  18759. LatheGeometry: LatheGeometry,
  18760. LatheBufferGeometry: LatheBufferGeometry,
  18761. ShapeGeometry: ShapeGeometry,
  18762. ShapeBufferGeometry: ShapeBufferGeometry,
  18763. ExtrudeGeometry: ExtrudeGeometry,
  18764. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  18765. EdgesGeometry: EdgesGeometry,
  18766. ConeGeometry: ConeGeometry,
  18767. ConeBufferGeometry: ConeBufferGeometry,
  18768. CylinderGeometry: CylinderGeometry,
  18769. CylinderBufferGeometry: CylinderBufferGeometry,
  18770. CircleGeometry: CircleGeometry,
  18771. CircleBufferGeometry: CircleBufferGeometry,
  18772. BoxGeometry: BoxGeometry,
  18773. BoxBufferGeometry: BoxBufferGeometry
  18774. });
  18775. /**
  18776. * @author mrdoob / http://mrdoob.com/
  18777. *
  18778. * parameters = {
  18779. * color: <THREE.Color>
  18780. * }
  18781. */
  18782. function ShadowMaterial( parameters ) {
  18783. Material.call( this );
  18784. this.type = 'ShadowMaterial';
  18785. this.color = new Color( 0x000000 );
  18786. this.transparent = true;
  18787. this.setValues( parameters );
  18788. }
  18789. ShadowMaterial.prototype = Object.create( Material.prototype );
  18790. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18791. ShadowMaterial.prototype.isShadowMaterial = true;
  18792. ShadowMaterial.prototype.copy = function ( source ) {
  18793. Material.prototype.copy.call( this, source );
  18794. this.color.copy( source.color );
  18795. return this;
  18796. };
  18797. /**
  18798. * @author mrdoob / http://mrdoob.com/
  18799. */
  18800. function RawShaderMaterial( parameters ) {
  18801. ShaderMaterial.call( this, parameters );
  18802. this.type = 'RawShaderMaterial';
  18803. }
  18804. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18805. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18806. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18807. /**
  18808. * @author WestLangley / http://github.com/WestLangley
  18809. *
  18810. * parameters = {
  18811. * color: <hex>,
  18812. * roughness: <float>,
  18813. * metalness: <float>,
  18814. * opacity: <float>,
  18815. *
  18816. * map: new THREE.Texture( <Image> ),
  18817. *
  18818. * lightMap: new THREE.Texture( <Image> ),
  18819. * lightMapIntensity: <float>
  18820. *
  18821. * aoMap: new THREE.Texture( <Image> ),
  18822. * aoMapIntensity: <float>
  18823. *
  18824. * emissive: <hex>,
  18825. * emissiveIntensity: <float>
  18826. * emissiveMap: new THREE.Texture( <Image> ),
  18827. *
  18828. * bumpMap: new THREE.Texture( <Image> ),
  18829. * bumpScale: <float>,
  18830. *
  18831. * normalMap: new THREE.Texture( <Image> ),
  18832. * normalMapType: THREE.TangentSpaceNormalMap,
  18833. * normalScale: <Vector2>,
  18834. *
  18835. * displacementMap: new THREE.Texture( <Image> ),
  18836. * displacementScale: <float>,
  18837. * displacementBias: <float>,
  18838. *
  18839. * roughnessMap: new THREE.Texture( <Image> ),
  18840. *
  18841. * metalnessMap: new THREE.Texture( <Image> ),
  18842. *
  18843. * alphaMap: new THREE.Texture( <Image> ),
  18844. *
  18845. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18846. * envMapIntensity: <float>
  18847. *
  18848. * refractionRatio: <float>,
  18849. *
  18850. * wireframe: <boolean>,
  18851. * wireframeLinewidth: <float>,
  18852. *
  18853. * skinning: <bool>,
  18854. * morphTargets: <bool>,
  18855. * morphNormals: <bool>
  18856. * }
  18857. */
  18858. function MeshStandardMaterial( parameters ) {
  18859. Material.call( this );
  18860. this.defines = { 'STANDARD': '' };
  18861. this.type = 'MeshStandardMaterial';
  18862. this.color = new Color( 0xffffff ); // diffuse
  18863. this.roughness = 0.5;
  18864. this.metalness = 0.5;
  18865. this.map = null;
  18866. this.lightMap = null;
  18867. this.lightMapIntensity = 1.0;
  18868. this.aoMap = null;
  18869. this.aoMapIntensity = 1.0;
  18870. this.emissive = new Color( 0x000000 );
  18871. this.emissiveIntensity = 1.0;
  18872. this.emissiveMap = null;
  18873. this.bumpMap = null;
  18874. this.bumpScale = 1;
  18875. this.normalMap = null;
  18876. this.normalMapType = TangentSpaceNormalMap;
  18877. this.normalScale = new Vector2( 1, 1 );
  18878. this.displacementMap = null;
  18879. this.displacementScale = 1;
  18880. this.displacementBias = 0;
  18881. this.roughnessMap = null;
  18882. this.metalnessMap = null;
  18883. this.alphaMap = null;
  18884. this.envMap = null;
  18885. this.envMapIntensity = 1.0;
  18886. this.refractionRatio = 0.98;
  18887. this.wireframe = false;
  18888. this.wireframeLinewidth = 1;
  18889. this.wireframeLinecap = 'round';
  18890. this.wireframeLinejoin = 'round';
  18891. this.skinning = false;
  18892. this.morphTargets = false;
  18893. this.morphNormals = false;
  18894. this.setValues( parameters );
  18895. }
  18896. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18897. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18898. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18899. MeshStandardMaterial.prototype.copy = function ( source ) {
  18900. Material.prototype.copy.call( this, source );
  18901. this.defines = { 'STANDARD': '' };
  18902. this.color.copy( source.color );
  18903. this.roughness = source.roughness;
  18904. this.metalness = source.metalness;
  18905. this.map = source.map;
  18906. this.lightMap = source.lightMap;
  18907. this.lightMapIntensity = source.lightMapIntensity;
  18908. this.aoMap = source.aoMap;
  18909. this.aoMapIntensity = source.aoMapIntensity;
  18910. this.emissive.copy( source.emissive );
  18911. this.emissiveMap = source.emissiveMap;
  18912. this.emissiveIntensity = source.emissiveIntensity;
  18913. this.bumpMap = source.bumpMap;
  18914. this.bumpScale = source.bumpScale;
  18915. this.normalMap = source.normalMap;
  18916. this.normalMapType = source.normalMapType;
  18917. this.normalScale.copy( source.normalScale );
  18918. this.displacementMap = source.displacementMap;
  18919. this.displacementScale = source.displacementScale;
  18920. this.displacementBias = source.displacementBias;
  18921. this.roughnessMap = source.roughnessMap;
  18922. this.metalnessMap = source.metalnessMap;
  18923. this.alphaMap = source.alphaMap;
  18924. this.envMap = source.envMap;
  18925. this.envMapIntensity = source.envMapIntensity;
  18926. this.refractionRatio = source.refractionRatio;
  18927. this.wireframe = source.wireframe;
  18928. this.wireframeLinewidth = source.wireframeLinewidth;
  18929. this.wireframeLinecap = source.wireframeLinecap;
  18930. this.wireframeLinejoin = source.wireframeLinejoin;
  18931. this.skinning = source.skinning;
  18932. this.morphTargets = source.morphTargets;
  18933. this.morphNormals = source.morphNormals;
  18934. return this;
  18935. };
  18936. /**
  18937. * @author WestLangley / http://github.com/WestLangley
  18938. *
  18939. * parameters = {
  18940. * reflectivity: <float>
  18941. * clearCoat: <float>
  18942. * clearCoatRoughness: <float>
  18943. * }
  18944. */
  18945. function MeshPhysicalMaterial( parameters ) {
  18946. MeshStandardMaterial.call( this );
  18947. this.defines = { 'PHYSICAL': '' };
  18948. this.type = 'MeshPhysicalMaterial';
  18949. this.reflectivity = 0.5; // maps to F0 = 0.04
  18950. this.clearCoat = 0.0;
  18951. this.clearCoatRoughness = 0.0;
  18952. this.setValues( parameters );
  18953. }
  18954. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18955. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18956. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18957. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18958. MeshStandardMaterial.prototype.copy.call( this, source );
  18959. this.defines = { 'PHYSICAL': '' };
  18960. this.reflectivity = source.reflectivity;
  18961. this.clearCoat = source.clearCoat;
  18962. this.clearCoatRoughness = source.clearCoatRoughness;
  18963. return this;
  18964. };
  18965. /**
  18966. * @author mrdoob / http://mrdoob.com/
  18967. * @author alteredq / http://alteredqualia.com/
  18968. *
  18969. * parameters = {
  18970. * color: <hex>,
  18971. * specular: <hex>,
  18972. * shininess: <float>,
  18973. * opacity: <float>,
  18974. *
  18975. * map: new THREE.Texture( <Image> ),
  18976. *
  18977. * lightMap: new THREE.Texture( <Image> ),
  18978. * lightMapIntensity: <float>
  18979. *
  18980. * aoMap: new THREE.Texture( <Image> ),
  18981. * aoMapIntensity: <float>
  18982. *
  18983. * emissive: <hex>,
  18984. * emissiveIntensity: <float>
  18985. * emissiveMap: new THREE.Texture( <Image> ),
  18986. *
  18987. * bumpMap: new THREE.Texture( <Image> ),
  18988. * bumpScale: <float>,
  18989. *
  18990. * normalMap: new THREE.Texture( <Image> ),
  18991. * normalMapType: THREE.TangentSpaceNormalMap,
  18992. * normalScale: <Vector2>,
  18993. *
  18994. * displacementMap: new THREE.Texture( <Image> ),
  18995. * displacementScale: <float>,
  18996. * displacementBias: <float>,
  18997. *
  18998. * specularMap: new THREE.Texture( <Image> ),
  18999. *
  19000. * alphaMap: new THREE.Texture( <Image> ),
  19001. *
  19002. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19003. * combine: THREE.Multiply,
  19004. * reflectivity: <float>,
  19005. * refractionRatio: <float>,
  19006. *
  19007. * wireframe: <boolean>,
  19008. * wireframeLinewidth: <float>,
  19009. *
  19010. * skinning: <bool>,
  19011. * morphTargets: <bool>,
  19012. * morphNormals: <bool>
  19013. * }
  19014. */
  19015. function MeshPhongMaterial( parameters ) {
  19016. Material.call( this );
  19017. this.type = 'MeshPhongMaterial';
  19018. this.color = new Color( 0xffffff ); // diffuse
  19019. this.specular = new Color( 0x111111 );
  19020. this.shininess = 30;
  19021. this.map = null;
  19022. this.lightMap = null;
  19023. this.lightMapIntensity = 1.0;
  19024. this.aoMap = null;
  19025. this.aoMapIntensity = 1.0;
  19026. this.emissive = new Color( 0x000000 );
  19027. this.emissiveIntensity = 1.0;
  19028. this.emissiveMap = null;
  19029. this.bumpMap = null;
  19030. this.bumpScale = 1;
  19031. this.normalMap = null;
  19032. this.normalMapType = TangentSpaceNormalMap;
  19033. this.normalScale = new Vector2( 1, 1 );
  19034. this.displacementMap = null;
  19035. this.displacementScale = 1;
  19036. this.displacementBias = 0;
  19037. this.specularMap = null;
  19038. this.alphaMap = null;
  19039. this.envMap = null;
  19040. this.combine = MultiplyOperation;
  19041. this.reflectivity = 1;
  19042. this.refractionRatio = 0.98;
  19043. this.wireframe = false;
  19044. this.wireframeLinewidth = 1;
  19045. this.wireframeLinecap = 'round';
  19046. this.wireframeLinejoin = 'round';
  19047. this.skinning = false;
  19048. this.morphTargets = false;
  19049. this.morphNormals = false;
  19050. this.setValues( parameters );
  19051. }
  19052. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19053. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19054. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19055. MeshPhongMaterial.prototype.copy = function ( source ) {
  19056. Material.prototype.copy.call( this, source );
  19057. this.color.copy( source.color );
  19058. this.specular.copy( source.specular );
  19059. this.shininess = source.shininess;
  19060. this.map = source.map;
  19061. this.lightMap = source.lightMap;
  19062. this.lightMapIntensity = source.lightMapIntensity;
  19063. this.aoMap = source.aoMap;
  19064. this.aoMapIntensity = source.aoMapIntensity;
  19065. this.emissive.copy( source.emissive );
  19066. this.emissiveMap = source.emissiveMap;
  19067. this.emissiveIntensity = source.emissiveIntensity;
  19068. this.bumpMap = source.bumpMap;
  19069. this.bumpScale = source.bumpScale;
  19070. this.normalMap = source.normalMap;
  19071. this.normalMapType = source.normalMapType;
  19072. this.normalScale.copy( source.normalScale );
  19073. this.displacementMap = source.displacementMap;
  19074. this.displacementScale = source.displacementScale;
  19075. this.displacementBias = source.displacementBias;
  19076. this.specularMap = source.specularMap;
  19077. this.alphaMap = source.alphaMap;
  19078. this.envMap = source.envMap;
  19079. this.combine = source.combine;
  19080. this.reflectivity = source.reflectivity;
  19081. this.refractionRatio = source.refractionRatio;
  19082. this.wireframe = source.wireframe;
  19083. this.wireframeLinewidth = source.wireframeLinewidth;
  19084. this.wireframeLinecap = source.wireframeLinecap;
  19085. this.wireframeLinejoin = source.wireframeLinejoin;
  19086. this.skinning = source.skinning;
  19087. this.morphTargets = source.morphTargets;
  19088. this.morphNormals = source.morphNormals;
  19089. return this;
  19090. };
  19091. /**
  19092. * @author takahirox / http://github.com/takahirox
  19093. *
  19094. * parameters = {
  19095. * gradientMap: new THREE.Texture( <Image> )
  19096. * }
  19097. */
  19098. function MeshToonMaterial( parameters ) {
  19099. MeshPhongMaterial.call( this );
  19100. this.defines = { 'TOON': '' };
  19101. this.type = 'MeshToonMaterial';
  19102. this.gradientMap = null;
  19103. this.setValues( parameters );
  19104. }
  19105. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19106. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19107. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19108. MeshToonMaterial.prototype.copy = function ( source ) {
  19109. MeshPhongMaterial.prototype.copy.call( this, source );
  19110. this.gradientMap = source.gradientMap;
  19111. return this;
  19112. };
  19113. /**
  19114. * @author mrdoob / http://mrdoob.com/
  19115. * @author WestLangley / http://github.com/WestLangley
  19116. *
  19117. * parameters = {
  19118. * opacity: <float>,
  19119. *
  19120. * bumpMap: new THREE.Texture( <Image> ),
  19121. * bumpScale: <float>,
  19122. *
  19123. * normalMap: new THREE.Texture( <Image> ),
  19124. * normalMapType: THREE.TangentSpaceNormalMap,
  19125. * normalScale: <Vector2>,
  19126. *
  19127. * displacementMap: new THREE.Texture( <Image> ),
  19128. * displacementScale: <float>,
  19129. * displacementBias: <float>,
  19130. *
  19131. * wireframe: <boolean>,
  19132. * wireframeLinewidth: <float>
  19133. *
  19134. * skinning: <bool>,
  19135. * morphTargets: <bool>,
  19136. * morphNormals: <bool>
  19137. * }
  19138. */
  19139. function MeshNormalMaterial( parameters ) {
  19140. Material.call( this );
  19141. this.type = 'MeshNormalMaterial';
  19142. this.bumpMap = null;
  19143. this.bumpScale = 1;
  19144. this.normalMap = null;
  19145. this.normalMapType = TangentSpaceNormalMap;
  19146. this.normalScale = new Vector2( 1, 1 );
  19147. this.displacementMap = null;
  19148. this.displacementScale = 1;
  19149. this.displacementBias = 0;
  19150. this.wireframe = false;
  19151. this.wireframeLinewidth = 1;
  19152. this.fog = false;
  19153. this.lights = false;
  19154. this.skinning = false;
  19155. this.morphTargets = false;
  19156. this.morphNormals = false;
  19157. this.setValues( parameters );
  19158. }
  19159. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19160. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19161. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19162. MeshNormalMaterial.prototype.copy = function ( source ) {
  19163. Material.prototype.copy.call( this, source );
  19164. this.bumpMap = source.bumpMap;
  19165. this.bumpScale = source.bumpScale;
  19166. this.normalMap = source.normalMap;
  19167. this.normalMapType = source.normalMapType;
  19168. this.normalScale.copy( source.normalScale );
  19169. this.displacementMap = source.displacementMap;
  19170. this.displacementScale = source.displacementScale;
  19171. this.displacementBias = source.displacementBias;
  19172. this.wireframe = source.wireframe;
  19173. this.wireframeLinewidth = source.wireframeLinewidth;
  19174. this.skinning = source.skinning;
  19175. this.morphTargets = source.morphTargets;
  19176. this.morphNormals = source.morphNormals;
  19177. return this;
  19178. };
  19179. /**
  19180. * @author mrdoob / http://mrdoob.com/
  19181. * @author alteredq / http://alteredqualia.com/
  19182. *
  19183. * parameters = {
  19184. * color: <hex>,
  19185. * opacity: <float>,
  19186. *
  19187. * map: new THREE.Texture( <Image> ),
  19188. *
  19189. * lightMap: new THREE.Texture( <Image> ),
  19190. * lightMapIntensity: <float>
  19191. *
  19192. * aoMap: new THREE.Texture( <Image> ),
  19193. * aoMapIntensity: <float>
  19194. *
  19195. * emissive: <hex>,
  19196. * emissiveIntensity: <float>
  19197. * emissiveMap: new THREE.Texture( <Image> ),
  19198. *
  19199. * specularMap: new THREE.Texture( <Image> ),
  19200. *
  19201. * alphaMap: new THREE.Texture( <Image> ),
  19202. *
  19203. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19204. * combine: THREE.Multiply,
  19205. * reflectivity: <float>,
  19206. * refractionRatio: <float>,
  19207. *
  19208. * wireframe: <boolean>,
  19209. * wireframeLinewidth: <float>,
  19210. *
  19211. * skinning: <bool>,
  19212. * morphTargets: <bool>,
  19213. * morphNormals: <bool>
  19214. * }
  19215. */
  19216. function MeshLambertMaterial( parameters ) {
  19217. Material.call( this );
  19218. this.type = 'MeshLambertMaterial';
  19219. this.color = new Color( 0xffffff ); // diffuse
  19220. this.map = null;
  19221. this.lightMap = null;
  19222. this.lightMapIntensity = 1.0;
  19223. this.aoMap = null;
  19224. this.aoMapIntensity = 1.0;
  19225. this.emissive = new Color( 0x000000 );
  19226. this.emissiveIntensity = 1.0;
  19227. this.emissiveMap = null;
  19228. this.specularMap = null;
  19229. this.alphaMap = null;
  19230. this.envMap = null;
  19231. this.combine = MultiplyOperation;
  19232. this.reflectivity = 1;
  19233. this.refractionRatio = 0.98;
  19234. this.wireframe = false;
  19235. this.wireframeLinewidth = 1;
  19236. this.wireframeLinecap = 'round';
  19237. this.wireframeLinejoin = 'round';
  19238. this.skinning = false;
  19239. this.morphTargets = false;
  19240. this.morphNormals = false;
  19241. this.setValues( parameters );
  19242. }
  19243. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19244. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19245. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19246. MeshLambertMaterial.prototype.copy = function ( source ) {
  19247. Material.prototype.copy.call( this, source );
  19248. this.color.copy( source.color );
  19249. this.map = source.map;
  19250. this.lightMap = source.lightMap;
  19251. this.lightMapIntensity = source.lightMapIntensity;
  19252. this.aoMap = source.aoMap;
  19253. this.aoMapIntensity = source.aoMapIntensity;
  19254. this.emissive.copy( source.emissive );
  19255. this.emissiveMap = source.emissiveMap;
  19256. this.emissiveIntensity = source.emissiveIntensity;
  19257. this.specularMap = source.specularMap;
  19258. this.alphaMap = source.alphaMap;
  19259. this.envMap = source.envMap;
  19260. this.combine = source.combine;
  19261. this.reflectivity = source.reflectivity;
  19262. this.refractionRatio = source.refractionRatio;
  19263. this.wireframe = source.wireframe;
  19264. this.wireframeLinewidth = source.wireframeLinewidth;
  19265. this.wireframeLinecap = source.wireframeLinecap;
  19266. this.wireframeLinejoin = source.wireframeLinejoin;
  19267. this.skinning = source.skinning;
  19268. this.morphTargets = source.morphTargets;
  19269. this.morphNormals = source.morphNormals;
  19270. return this;
  19271. };
  19272. /**
  19273. * @author WestLangley / http://github.com/WestLangley
  19274. *
  19275. * parameters = {
  19276. * color: <hex>,
  19277. * opacity: <float>,
  19278. *
  19279. * matcap: new THREE.Texture( <Image> ),
  19280. *
  19281. * map: new THREE.Texture( <Image> ),
  19282. *
  19283. * bumpMap: new THREE.Texture( <Image> ),
  19284. * bumpScale: <float>,
  19285. *
  19286. * normalMap: new THREE.Texture( <Image> ),
  19287. * normalMapType: THREE.TangentSpaceNormalMap,
  19288. * normalScale: <Vector2>,
  19289. *
  19290. * displacementMap: new THREE.Texture( <Image> ),
  19291. * displacementScale: <float>,
  19292. * displacementBias: <float>,
  19293. *
  19294. * alphaMap: new THREE.Texture( <Image> ),
  19295. *
  19296. * skinning: <bool>,
  19297. * morphTargets: <bool>,
  19298. * morphNormals: <bool>
  19299. * }
  19300. */
  19301. function MeshMatcapMaterial( parameters ) {
  19302. Material.call( this );
  19303. this.defines = { 'MATCAP': '' };
  19304. this.type = 'MeshMatcapMaterial';
  19305. this.color = new Color( 0xffffff ); // diffuse
  19306. this.matcap = null;
  19307. this.map = null;
  19308. this.bumpMap = null;
  19309. this.bumpScale = 1;
  19310. this.normalMap = null;
  19311. this.normalMapType = TangentSpaceNormalMap;
  19312. this.normalScale = new Vector2( 1, 1 );
  19313. this.displacementMap = null;
  19314. this.displacementScale = 1;
  19315. this.displacementBias = 0;
  19316. this.alphaMap = null;
  19317. this.skinning = false;
  19318. this.morphTargets = false;
  19319. this.morphNormals = false;
  19320. this.lights = false;
  19321. this.setValues( parameters );
  19322. }
  19323. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19324. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19325. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19326. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19327. Material.prototype.copy.call( this, source );
  19328. this.defines = { 'MATCAP': '' };
  19329. this.color.copy( source.color );
  19330. this.matcap = source.matcap;
  19331. this.map = source.map;
  19332. this.bumpMap = source.bumpMap;
  19333. this.bumpScale = source.bumpScale;
  19334. this.normalMap = source.normalMap;
  19335. this.normalMapType = source.normalMapType;
  19336. this.normalScale.copy( source.normalScale );
  19337. this.displacementMap = source.displacementMap;
  19338. this.displacementScale = source.displacementScale;
  19339. this.displacementBias = source.displacementBias;
  19340. this.alphaMap = source.alphaMap;
  19341. this.skinning = source.skinning;
  19342. this.morphTargets = source.morphTargets;
  19343. this.morphNormals = source.morphNormals;
  19344. return this;
  19345. };
  19346. /**
  19347. * @author alteredq / http://alteredqualia.com/
  19348. *
  19349. * parameters = {
  19350. * color: <hex>,
  19351. * opacity: <float>,
  19352. *
  19353. * linewidth: <float>,
  19354. *
  19355. * scale: <float>,
  19356. * dashSize: <float>,
  19357. * gapSize: <float>
  19358. * }
  19359. */
  19360. function LineDashedMaterial( parameters ) {
  19361. LineBasicMaterial.call( this );
  19362. this.type = 'LineDashedMaterial';
  19363. this.scale = 1;
  19364. this.dashSize = 3;
  19365. this.gapSize = 1;
  19366. this.setValues( parameters );
  19367. }
  19368. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19369. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19370. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19371. LineDashedMaterial.prototype.copy = function ( source ) {
  19372. LineBasicMaterial.prototype.copy.call( this, source );
  19373. this.scale = source.scale;
  19374. this.dashSize = source.dashSize;
  19375. this.gapSize = source.gapSize;
  19376. return this;
  19377. };
  19378. var Materials = /*#__PURE__*/Object.freeze({
  19379. ShadowMaterial: ShadowMaterial,
  19380. SpriteMaterial: SpriteMaterial,
  19381. RawShaderMaterial: RawShaderMaterial,
  19382. ShaderMaterial: ShaderMaterial,
  19383. PointsMaterial: PointsMaterial,
  19384. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19385. MeshStandardMaterial: MeshStandardMaterial,
  19386. MeshPhongMaterial: MeshPhongMaterial,
  19387. MeshToonMaterial: MeshToonMaterial,
  19388. MeshNormalMaterial: MeshNormalMaterial,
  19389. MeshLambertMaterial: MeshLambertMaterial,
  19390. MeshDepthMaterial: MeshDepthMaterial,
  19391. MeshDistanceMaterial: MeshDistanceMaterial,
  19392. MeshBasicMaterial: MeshBasicMaterial,
  19393. MeshMatcapMaterial: MeshMatcapMaterial,
  19394. LineDashedMaterial: LineDashedMaterial,
  19395. LineBasicMaterial: LineBasicMaterial,
  19396. Material: Material
  19397. });
  19398. /**
  19399. * @author tschw
  19400. * @author Ben Houston / http://clara.io/
  19401. * @author David Sarno / http://lighthaus.us/
  19402. */
  19403. var AnimationUtils = {
  19404. // same as Array.prototype.slice, but also works on typed arrays
  19405. arraySlice: function ( array, from, to ) {
  19406. if ( AnimationUtils.isTypedArray( array ) ) {
  19407. // in ios9 array.subarray(from, undefined) will return empty array
  19408. // but array.subarray(from) or array.subarray(from, len) is correct
  19409. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19410. }
  19411. return array.slice( from, to );
  19412. },
  19413. // converts an array to a specific type
  19414. convertArray: function ( array, type, forceClone ) {
  19415. if ( ! array || // let 'undefined' and 'null' pass
  19416. ! forceClone && array.constructor === type ) return array;
  19417. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19418. return new type( array ); // create typed array
  19419. }
  19420. return Array.prototype.slice.call( array ); // create Array
  19421. },
  19422. isTypedArray: function ( object ) {
  19423. return ArrayBuffer.isView( object ) &&
  19424. ! ( object instanceof DataView );
  19425. },
  19426. // returns an array by which times and values can be sorted
  19427. getKeyframeOrder: function ( times ) {
  19428. function compareTime( i, j ) {
  19429. return times[ i ] - times[ j ];
  19430. }
  19431. var n = times.length;
  19432. var result = new Array( n );
  19433. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19434. result.sort( compareTime );
  19435. return result;
  19436. },
  19437. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19438. sortedArray: function ( values, stride, order ) {
  19439. var nValues = values.length;
  19440. var result = new values.constructor( nValues );
  19441. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19442. var srcOffset = order[ i ] * stride;
  19443. for ( var j = 0; j !== stride; ++ j ) {
  19444. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19445. }
  19446. }
  19447. return result;
  19448. },
  19449. // function for parsing AOS keyframe formats
  19450. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19451. var i = 1, key = jsonKeys[ 0 ];
  19452. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19453. key = jsonKeys[ i ++ ];
  19454. }
  19455. if ( key === undefined ) return; // no data
  19456. var value = key[ valuePropertyName ];
  19457. if ( value === undefined ) return; // no data
  19458. if ( Array.isArray( value ) ) {
  19459. do {
  19460. value = key[ valuePropertyName ];
  19461. if ( value !== undefined ) {
  19462. times.push( key.time );
  19463. values.push.apply( values, value ); // push all elements
  19464. }
  19465. key = jsonKeys[ i ++ ];
  19466. } while ( key !== undefined );
  19467. } else if ( value.toArray !== undefined ) {
  19468. // ...assume THREE.Math-ish
  19469. do {
  19470. value = key[ valuePropertyName ];
  19471. if ( value !== undefined ) {
  19472. times.push( key.time );
  19473. value.toArray( values, values.length );
  19474. }
  19475. key = jsonKeys[ i ++ ];
  19476. } while ( key !== undefined );
  19477. } else {
  19478. // otherwise push as-is
  19479. do {
  19480. value = key[ valuePropertyName ];
  19481. if ( value !== undefined ) {
  19482. times.push( key.time );
  19483. values.push( value );
  19484. }
  19485. key = jsonKeys[ i ++ ];
  19486. } while ( key !== undefined );
  19487. }
  19488. }
  19489. };
  19490. /**
  19491. * Abstract base class of interpolants over parametric samples.
  19492. *
  19493. * The parameter domain is one dimensional, typically the time or a path
  19494. * along a curve defined by the data.
  19495. *
  19496. * The sample values can have any dimensionality and derived classes may
  19497. * apply special interpretations to the data.
  19498. *
  19499. * This class provides the interval seek in a Template Method, deferring
  19500. * the actual interpolation to derived classes.
  19501. *
  19502. * Time complexity is O(1) for linear access crossing at most two points
  19503. * and O(log N) for random access, where N is the number of positions.
  19504. *
  19505. * References:
  19506. *
  19507. * http://www.oodesign.com/template-method-pattern.html
  19508. *
  19509. * @author tschw
  19510. */
  19511. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19512. this.parameterPositions = parameterPositions;
  19513. this._cachedIndex = 0;
  19514. this.resultBuffer = resultBuffer !== undefined ?
  19515. resultBuffer : new sampleValues.constructor( sampleSize );
  19516. this.sampleValues = sampleValues;
  19517. this.valueSize = sampleSize;
  19518. }
  19519. Object.assign( Interpolant.prototype, {
  19520. evaluate: function ( t ) {
  19521. var pp = this.parameterPositions,
  19522. i1 = this._cachedIndex,
  19523. t1 = pp[ i1 ],
  19524. t0 = pp[ i1 - 1 ];
  19525. validate_interval: {
  19526. seek: {
  19527. var right;
  19528. linear_scan: {
  19529. //- See http://jsperf.com/comparison-to-undefined/3
  19530. //- slower code:
  19531. //-
  19532. //- if ( t >= t1 || t1 === undefined ) {
  19533. forward_scan: if ( ! ( t < t1 ) ) {
  19534. for ( var giveUpAt = i1 + 2; ; ) {
  19535. if ( t1 === undefined ) {
  19536. if ( t < t0 ) break forward_scan;
  19537. // after end
  19538. i1 = pp.length;
  19539. this._cachedIndex = i1;
  19540. return this.afterEnd_( i1 - 1, t, t0 );
  19541. }
  19542. if ( i1 === giveUpAt ) break; // this loop
  19543. t0 = t1;
  19544. t1 = pp[ ++ i1 ];
  19545. if ( t < t1 ) {
  19546. // we have arrived at the sought interval
  19547. break seek;
  19548. }
  19549. }
  19550. // prepare binary search on the right side of the index
  19551. right = pp.length;
  19552. break linear_scan;
  19553. }
  19554. //- slower code:
  19555. //- if ( t < t0 || t0 === undefined ) {
  19556. if ( ! ( t >= t0 ) ) {
  19557. // looping?
  19558. var t1global = pp[ 1 ];
  19559. if ( t < t1global ) {
  19560. i1 = 2; // + 1, using the scan for the details
  19561. t0 = t1global;
  19562. }
  19563. // linear reverse scan
  19564. for ( var giveUpAt = i1 - 2; ; ) {
  19565. if ( t0 === undefined ) {
  19566. // before start
  19567. this._cachedIndex = 0;
  19568. return this.beforeStart_( 0, t, t1 );
  19569. }
  19570. if ( i1 === giveUpAt ) break; // this loop
  19571. t1 = t0;
  19572. t0 = pp[ -- i1 - 1 ];
  19573. if ( t >= t0 ) {
  19574. // we have arrived at the sought interval
  19575. break seek;
  19576. }
  19577. }
  19578. // prepare binary search on the left side of the index
  19579. right = i1;
  19580. i1 = 0;
  19581. break linear_scan;
  19582. }
  19583. // the interval is valid
  19584. break validate_interval;
  19585. } // linear scan
  19586. // binary search
  19587. while ( i1 < right ) {
  19588. var mid = ( i1 + right ) >>> 1;
  19589. if ( t < pp[ mid ] ) {
  19590. right = mid;
  19591. } else {
  19592. i1 = mid + 1;
  19593. }
  19594. }
  19595. t1 = pp[ i1 ];
  19596. t0 = pp[ i1 - 1 ];
  19597. // check boundary cases, again
  19598. if ( t0 === undefined ) {
  19599. this._cachedIndex = 0;
  19600. return this.beforeStart_( 0, t, t1 );
  19601. }
  19602. if ( t1 === undefined ) {
  19603. i1 = pp.length;
  19604. this._cachedIndex = i1;
  19605. return this.afterEnd_( i1 - 1, t0, t );
  19606. }
  19607. } // seek
  19608. this._cachedIndex = i1;
  19609. this.intervalChanged_( i1, t0, t1 );
  19610. } // validate_interval
  19611. return this.interpolate_( i1, t0, t, t1 );
  19612. },
  19613. settings: null, // optional, subclass-specific settings structure
  19614. // Note: The indirection allows central control of many interpolants.
  19615. // --- Protected interface
  19616. DefaultSettings_: {},
  19617. getSettings_: function () {
  19618. return this.settings || this.DefaultSettings_;
  19619. },
  19620. copySampleValue_: function ( index ) {
  19621. // copies a sample value to the result buffer
  19622. var result = this.resultBuffer,
  19623. values = this.sampleValues,
  19624. stride = this.valueSize,
  19625. offset = index * stride;
  19626. for ( var i = 0; i !== stride; ++ i ) {
  19627. result[ i ] = values[ offset + i ];
  19628. }
  19629. return result;
  19630. },
  19631. // Template methods for derived classes:
  19632. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19633. throw new Error( 'call to abstract method' );
  19634. // implementations shall return this.resultBuffer
  19635. },
  19636. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19637. // empty
  19638. }
  19639. } );
  19640. //!\ DECLARE ALIAS AFTER assign prototype !
  19641. Object.assign( Interpolant.prototype, {
  19642. //( 0, t, t0 ), returns this.resultBuffer
  19643. beforeStart_: Interpolant.prototype.copySampleValue_,
  19644. //( N-1, tN-1, t ), returns this.resultBuffer
  19645. afterEnd_: Interpolant.prototype.copySampleValue_,
  19646. } );
  19647. /**
  19648. * Fast and simple cubic spline interpolant.
  19649. *
  19650. * It was derived from a Hermitian construction setting the first derivative
  19651. * at each sample position to the linear slope between neighboring positions
  19652. * over their parameter interval.
  19653. *
  19654. * @author tschw
  19655. */
  19656. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19657. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19658. this._weightPrev = - 0;
  19659. this._offsetPrev = - 0;
  19660. this._weightNext = - 0;
  19661. this._offsetNext = - 0;
  19662. }
  19663. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19664. constructor: CubicInterpolant,
  19665. DefaultSettings_: {
  19666. endingStart: ZeroCurvatureEnding,
  19667. endingEnd: ZeroCurvatureEnding
  19668. },
  19669. intervalChanged_: function ( i1, t0, t1 ) {
  19670. var pp = this.parameterPositions,
  19671. iPrev = i1 - 2,
  19672. iNext = i1 + 1,
  19673. tPrev = pp[ iPrev ],
  19674. tNext = pp[ iNext ];
  19675. if ( tPrev === undefined ) {
  19676. switch ( this.getSettings_().endingStart ) {
  19677. case ZeroSlopeEnding:
  19678. // f'(t0) = 0
  19679. iPrev = i1;
  19680. tPrev = 2 * t0 - t1;
  19681. break;
  19682. case WrapAroundEnding:
  19683. // use the other end of the curve
  19684. iPrev = pp.length - 2;
  19685. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19686. break;
  19687. default: // ZeroCurvatureEnding
  19688. // f''(t0) = 0 a.k.a. Natural Spline
  19689. iPrev = i1;
  19690. tPrev = t1;
  19691. }
  19692. }
  19693. if ( tNext === undefined ) {
  19694. switch ( this.getSettings_().endingEnd ) {
  19695. case ZeroSlopeEnding:
  19696. // f'(tN) = 0
  19697. iNext = i1;
  19698. tNext = 2 * t1 - t0;
  19699. break;
  19700. case WrapAroundEnding:
  19701. // use the other end of the curve
  19702. iNext = 1;
  19703. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19704. break;
  19705. default: // ZeroCurvatureEnding
  19706. // f''(tN) = 0, a.k.a. Natural Spline
  19707. iNext = i1 - 1;
  19708. tNext = t0;
  19709. }
  19710. }
  19711. var halfDt = ( t1 - t0 ) * 0.5,
  19712. stride = this.valueSize;
  19713. this._weightPrev = halfDt / ( t0 - tPrev );
  19714. this._weightNext = halfDt / ( tNext - t1 );
  19715. this._offsetPrev = iPrev * stride;
  19716. this._offsetNext = iNext * stride;
  19717. },
  19718. interpolate_: function ( i1, t0, t, t1 ) {
  19719. var result = this.resultBuffer,
  19720. values = this.sampleValues,
  19721. stride = this.valueSize,
  19722. o1 = i1 * stride, o0 = o1 - stride,
  19723. oP = this._offsetPrev, oN = this._offsetNext,
  19724. wP = this._weightPrev, wN = this._weightNext,
  19725. p = ( t - t0 ) / ( t1 - t0 ),
  19726. pp = p * p,
  19727. ppp = pp * p;
  19728. // evaluate polynomials
  19729. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  19730. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19731. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19732. var sN = wN * ppp - wN * pp;
  19733. // combine data linearly
  19734. for ( var i = 0; i !== stride; ++ i ) {
  19735. result[ i ] =
  19736. sP * values[ oP + i ] +
  19737. s0 * values[ o0 + i ] +
  19738. s1 * values[ o1 + i ] +
  19739. sN * values[ oN + i ];
  19740. }
  19741. return result;
  19742. }
  19743. } );
  19744. /**
  19745. * @author tschw
  19746. */
  19747. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19748. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19749. }
  19750. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19751. constructor: LinearInterpolant,
  19752. interpolate_: function ( i1, t0, t, t1 ) {
  19753. var result = this.resultBuffer,
  19754. values = this.sampleValues,
  19755. stride = this.valueSize,
  19756. offset1 = i1 * stride,
  19757. offset0 = offset1 - stride,
  19758. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19759. weight0 = 1 - weight1;
  19760. for ( var i = 0; i !== stride; ++ i ) {
  19761. result[ i ] =
  19762. values[ offset0 + i ] * weight0 +
  19763. values[ offset1 + i ] * weight1;
  19764. }
  19765. return result;
  19766. }
  19767. } );
  19768. /**
  19769. *
  19770. * Interpolant that evaluates to the sample value at the position preceeding
  19771. * the parameter.
  19772. *
  19773. * @author tschw
  19774. */
  19775. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19776. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19777. }
  19778. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19779. constructor: DiscreteInterpolant,
  19780. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19781. return this.copySampleValue_( i1 - 1 );
  19782. }
  19783. } );
  19784. /**
  19785. *
  19786. * A timed sequence of keyframes for a specific property.
  19787. *
  19788. *
  19789. * @author Ben Houston / http://clara.io/
  19790. * @author David Sarno / http://lighthaus.us/
  19791. * @author tschw
  19792. */
  19793. function KeyframeTrack( name, times, values, interpolation ) {
  19794. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19795. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19796. this.name = name;
  19797. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19798. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19799. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19800. }
  19801. // Static methods
  19802. Object.assign( KeyframeTrack, {
  19803. // Serialization (in static context, because of constructor invocation
  19804. // and automatic invocation of .toJSON):
  19805. toJSON: function ( track ) {
  19806. var trackType = track.constructor;
  19807. var json;
  19808. // derived classes can define a static toJSON method
  19809. if ( trackType.toJSON !== undefined ) {
  19810. json = trackType.toJSON( track );
  19811. } else {
  19812. // by default, we assume the data can be serialized as-is
  19813. json = {
  19814. 'name': track.name,
  19815. 'times': AnimationUtils.convertArray( track.times, Array ),
  19816. 'values': AnimationUtils.convertArray( track.values, Array )
  19817. };
  19818. var interpolation = track.getInterpolation();
  19819. if ( interpolation !== track.DefaultInterpolation ) {
  19820. json.interpolation = interpolation;
  19821. }
  19822. }
  19823. json.type = track.ValueTypeName; // mandatory
  19824. return json;
  19825. }
  19826. } );
  19827. Object.assign( KeyframeTrack.prototype, {
  19828. constructor: KeyframeTrack,
  19829. TimeBufferType: Float32Array,
  19830. ValueBufferType: Float32Array,
  19831. DefaultInterpolation: InterpolateLinear,
  19832. InterpolantFactoryMethodDiscrete: function ( result ) {
  19833. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19834. },
  19835. InterpolantFactoryMethodLinear: function ( result ) {
  19836. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19837. },
  19838. InterpolantFactoryMethodSmooth: function ( result ) {
  19839. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19840. },
  19841. setInterpolation: function ( interpolation ) {
  19842. var factoryMethod;
  19843. switch ( interpolation ) {
  19844. case InterpolateDiscrete:
  19845. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19846. break;
  19847. case InterpolateLinear:
  19848. factoryMethod = this.InterpolantFactoryMethodLinear;
  19849. break;
  19850. case InterpolateSmooth:
  19851. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19852. break;
  19853. }
  19854. if ( factoryMethod === undefined ) {
  19855. var message = "unsupported interpolation for " +
  19856. this.ValueTypeName + " keyframe track named " + this.name;
  19857. if ( this.createInterpolant === undefined ) {
  19858. // fall back to default, unless the default itself is messed up
  19859. if ( interpolation !== this.DefaultInterpolation ) {
  19860. this.setInterpolation( this.DefaultInterpolation );
  19861. } else {
  19862. throw new Error( message ); // fatal, in this case
  19863. }
  19864. }
  19865. console.warn( 'THREE.KeyframeTrack:', message );
  19866. return this;
  19867. }
  19868. this.createInterpolant = factoryMethod;
  19869. return this;
  19870. },
  19871. getInterpolation: function () {
  19872. switch ( this.createInterpolant ) {
  19873. case this.InterpolantFactoryMethodDiscrete:
  19874. return InterpolateDiscrete;
  19875. case this.InterpolantFactoryMethodLinear:
  19876. return InterpolateLinear;
  19877. case this.InterpolantFactoryMethodSmooth:
  19878. return InterpolateSmooth;
  19879. }
  19880. },
  19881. getValueSize: function () {
  19882. return this.values.length / this.times.length;
  19883. },
  19884. // move all keyframes either forwards or backwards in time
  19885. shift: function ( timeOffset ) {
  19886. if ( timeOffset !== 0.0 ) {
  19887. var times = this.times;
  19888. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19889. times[ i ] += timeOffset;
  19890. }
  19891. }
  19892. return this;
  19893. },
  19894. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19895. scale: function ( timeScale ) {
  19896. if ( timeScale !== 1.0 ) {
  19897. var times = this.times;
  19898. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19899. times[ i ] *= timeScale;
  19900. }
  19901. }
  19902. return this;
  19903. },
  19904. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19905. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19906. trim: function ( startTime, endTime ) {
  19907. var times = this.times,
  19908. nKeys = times.length,
  19909. from = 0,
  19910. to = nKeys - 1;
  19911. while ( from !== nKeys && times[ from ] < startTime ) {
  19912. ++ from;
  19913. }
  19914. while ( to !== - 1 && times[ to ] > endTime ) {
  19915. -- to;
  19916. }
  19917. ++ to; // inclusive -> exclusive bound
  19918. if ( from !== 0 || to !== nKeys ) {
  19919. // empty tracks are forbidden, so keep at least one keyframe
  19920. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  19921. var stride = this.getValueSize();
  19922. this.times = AnimationUtils.arraySlice( times, from, to );
  19923. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19924. }
  19925. return this;
  19926. },
  19927. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19928. validate: function () {
  19929. var valid = true;
  19930. var valueSize = this.getValueSize();
  19931. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19932. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19933. valid = false;
  19934. }
  19935. var times = this.times,
  19936. values = this.values,
  19937. nKeys = times.length;
  19938. if ( nKeys === 0 ) {
  19939. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19940. valid = false;
  19941. }
  19942. var prevTime = null;
  19943. for ( var i = 0; i !== nKeys; i ++ ) {
  19944. var currTime = times[ i ];
  19945. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19946. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19947. valid = false;
  19948. break;
  19949. }
  19950. if ( prevTime !== null && prevTime > currTime ) {
  19951. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  19952. valid = false;
  19953. break;
  19954. }
  19955. prevTime = currTime;
  19956. }
  19957. if ( values !== undefined ) {
  19958. if ( AnimationUtils.isTypedArray( values ) ) {
  19959. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  19960. var value = values[ i ];
  19961. if ( isNaN( value ) ) {
  19962. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  19963. valid = false;
  19964. break;
  19965. }
  19966. }
  19967. }
  19968. }
  19969. return valid;
  19970. },
  19971. // removes equivalent sequential keys as common in morph target sequences
  19972. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  19973. optimize: function () {
  19974. var times = this.times,
  19975. values = this.values,
  19976. stride = this.getValueSize(),
  19977. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  19978. writeIndex = 1,
  19979. lastIndex = times.length - 1;
  19980. for ( var i = 1; i < lastIndex; ++ i ) {
  19981. var keep = false;
  19982. var time = times[ i ];
  19983. var timeNext = times[ i + 1 ];
  19984. // remove adjacent keyframes scheduled at the same time
  19985. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  19986. if ( ! smoothInterpolation ) {
  19987. // remove unnecessary keyframes same as their neighbors
  19988. var offset = i * stride,
  19989. offsetP = offset - stride,
  19990. offsetN = offset + stride;
  19991. for ( var j = 0; j !== stride; ++ j ) {
  19992. var value = values[ offset + j ];
  19993. if ( value !== values[ offsetP + j ] ||
  19994. value !== values[ offsetN + j ] ) {
  19995. keep = true;
  19996. break;
  19997. }
  19998. }
  19999. } else {
  20000. keep = true;
  20001. }
  20002. }
  20003. // in-place compaction
  20004. if ( keep ) {
  20005. if ( i !== writeIndex ) {
  20006. times[ writeIndex ] = times[ i ];
  20007. var readOffset = i * stride,
  20008. writeOffset = writeIndex * stride;
  20009. for ( var j = 0; j !== stride; ++ j ) {
  20010. values[ writeOffset + j ] = values[ readOffset + j ];
  20011. }
  20012. }
  20013. ++ writeIndex;
  20014. }
  20015. }
  20016. // flush last keyframe (compaction looks ahead)
  20017. if ( lastIndex > 0 ) {
  20018. times[ writeIndex ] = times[ lastIndex ];
  20019. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20020. values[ writeOffset + j ] = values[ readOffset + j ];
  20021. }
  20022. ++ writeIndex;
  20023. }
  20024. if ( writeIndex !== times.length ) {
  20025. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20026. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20027. }
  20028. return this;
  20029. },
  20030. clone: function () {
  20031. var times = AnimationUtils.arraySlice( this.times, 0 );
  20032. var values = AnimationUtils.arraySlice( this.values, 0 );
  20033. var TypedKeyframeTrack = this.constructor;
  20034. var track = new TypedKeyframeTrack( this.name, times, values );
  20035. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20036. track.createInterpolant = this.createInterpolant;
  20037. return track;
  20038. }
  20039. } );
  20040. /**
  20041. *
  20042. * A Track of Boolean keyframe values.
  20043. *
  20044. *
  20045. * @author Ben Houston / http://clara.io/
  20046. * @author David Sarno / http://lighthaus.us/
  20047. * @author tschw
  20048. */
  20049. function BooleanKeyframeTrack( name, times, values ) {
  20050. KeyframeTrack.call( this, name, times, values );
  20051. }
  20052. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20053. constructor: BooleanKeyframeTrack,
  20054. ValueTypeName: 'bool',
  20055. ValueBufferType: Array,
  20056. DefaultInterpolation: InterpolateDiscrete,
  20057. InterpolantFactoryMethodLinear: undefined,
  20058. InterpolantFactoryMethodSmooth: undefined
  20059. // Note: Actually this track could have a optimized / compressed
  20060. // representation of a single value and a custom interpolant that
  20061. // computes "firstValue ^ isOdd( index )".
  20062. } );
  20063. /**
  20064. *
  20065. * A Track of keyframe values that represent color.
  20066. *
  20067. *
  20068. * @author Ben Houston / http://clara.io/
  20069. * @author David Sarno / http://lighthaus.us/
  20070. * @author tschw
  20071. */
  20072. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20073. KeyframeTrack.call( this, name, times, values, interpolation );
  20074. }
  20075. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20076. constructor: ColorKeyframeTrack,
  20077. ValueTypeName: 'color'
  20078. // ValueBufferType is inherited
  20079. // DefaultInterpolation is inherited
  20080. // Note: Very basic implementation and nothing special yet.
  20081. // However, this is the place for color space parameterization.
  20082. } );
  20083. /**
  20084. *
  20085. * A Track of numeric keyframe values.
  20086. *
  20087. * @author Ben Houston / http://clara.io/
  20088. * @author David Sarno / http://lighthaus.us/
  20089. * @author tschw
  20090. */
  20091. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20092. KeyframeTrack.call( this, name, times, values, interpolation );
  20093. }
  20094. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20095. constructor: NumberKeyframeTrack,
  20096. ValueTypeName: 'number'
  20097. // ValueBufferType is inherited
  20098. // DefaultInterpolation is inherited
  20099. } );
  20100. /**
  20101. * Spherical linear unit quaternion interpolant.
  20102. *
  20103. * @author tschw
  20104. */
  20105. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20106. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20107. }
  20108. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20109. constructor: QuaternionLinearInterpolant,
  20110. interpolate_: function ( i1, t0, t, t1 ) {
  20111. var result = this.resultBuffer,
  20112. values = this.sampleValues,
  20113. stride = this.valueSize,
  20114. offset = i1 * stride,
  20115. alpha = ( t - t0 ) / ( t1 - t0 );
  20116. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20117. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20118. }
  20119. return result;
  20120. }
  20121. } );
  20122. /**
  20123. *
  20124. * A Track of quaternion keyframe values.
  20125. *
  20126. * @author Ben Houston / http://clara.io/
  20127. * @author David Sarno / http://lighthaus.us/
  20128. * @author tschw
  20129. */
  20130. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20131. KeyframeTrack.call( this, name, times, values, interpolation );
  20132. }
  20133. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20134. constructor: QuaternionKeyframeTrack,
  20135. ValueTypeName: 'quaternion',
  20136. // ValueBufferType is inherited
  20137. DefaultInterpolation: InterpolateLinear,
  20138. InterpolantFactoryMethodLinear: function ( result ) {
  20139. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20140. },
  20141. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20142. } );
  20143. /**
  20144. *
  20145. * A Track that interpolates Strings
  20146. *
  20147. *
  20148. * @author Ben Houston / http://clara.io/
  20149. * @author David Sarno / http://lighthaus.us/
  20150. * @author tschw
  20151. */
  20152. function StringKeyframeTrack( name, times, values, interpolation ) {
  20153. KeyframeTrack.call( this, name, times, values, interpolation );
  20154. }
  20155. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20156. constructor: StringKeyframeTrack,
  20157. ValueTypeName: 'string',
  20158. ValueBufferType: Array,
  20159. DefaultInterpolation: InterpolateDiscrete,
  20160. InterpolantFactoryMethodLinear: undefined,
  20161. InterpolantFactoryMethodSmooth: undefined
  20162. } );
  20163. /**
  20164. *
  20165. * A Track of vectored keyframe values.
  20166. *
  20167. *
  20168. * @author Ben Houston / http://clara.io/
  20169. * @author David Sarno / http://lighthaus.us/
  20170. * @author tschw
  20171. */
  20172. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20173. KeyframeTrack.call( this, name, times, values, interpolation );
  20174. }
  20175. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20176. constructor: VectorKeyframeTrack,
  20177. ValueTypeName: 'vector'
  20178. // ValueBufferType is inherited
  20179. // DefaultInterpolation is inherited
  20180. } );
  20181. /**
  20182. *
  20183. * Reusable set of Tracks that represent an animation.
  20184. *
  20185. * @author Ben Houston / http://clara.io/
  20186. * @author David Sarno / http://lighthaus.us/
  20187. */
  20188. function AnimationClip( name, duration, tracks ) {
  20189. this.name = name;
  20190. this.tracks = tracks;
  20191. this.duration = ( duration !== undefined ) ? duration : - 1;
  20192. this.uuid = _Math.generateUUID();
  20193. // this means it should figure out its duration by scanning the tracks
  20194. if ( this.duration < 0 ) {
  20195. this.resetDuration();
  20196. }
  20197. }
  20198. function getTrackTypeForValueTypeName( typeName ) {
  20199. switch ( typeName.toLowerCase() ) {
  20200. case 'scalar':
  20201. case 'double':
  20202. case 'float':
  20203. case 'number':
  20204. case 'integer':
  20205. return NumberKeyframeTrack;
  20206. case 'vector':
  20207. case 'vector2':
  20208. case 'vector3':
  20209. case 'vector4':
  20210. return VectorKeyframeTrack;
  20211. case 'color':
  20212. return ColorKeyframeTrack;
  20213. case 'quaternion':
  20214. return QuaternionKeyframeTrack;
  20215. case 'bool':
  20216. case 'boolean':
  20217. return BooleanKeyframeTrack;
  20218. case 'string':
  20219. return StringKeyframeTrack;
  20220. }
  20221. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20222. }
  20223. function parseKeyframeTrack( json ) {
  20224. if ( json.type === undefined ) {
  20225. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20226. }
  20227. var trackType = getTrackTypeForValueTypeName( json.type );
  20228. if ( json.times === undefined ) {
  20229. var times = [], values = [];
  20230. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20231. json.times = times;
  20232. json.values = values;
  20233. }
  20234. // derived classes can define a static parse method
  20235. if ( trackType.parse !== undefined ) {
  20236. return trackType.parse( json );
  20237. } else {
  20238. // by default, we assume a constructor compatible with the base
  20239. return new trackType( json.name, json.times, json.values, json.interpolation );
  20240. }
  20241. }
  20242. Object.assign( AnimationClip, {
  20243. parse: function ( json ) {
  20244. var tracks = [],
  20245. jsonTracks = json.tracks,
  20246. frameTime = 1.0 / ( json.fps || 1.0 );
  20247. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20248. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20249. }
  20250. return new AnimationClip( json.name, json.duration, tracks );
  20251. },
  20252. toJSON: function ( clip ) {
  20253. var tracks = [],
  20254. clipTracks = clip.tracks;
  20255. var json = {
  20256. 'name': clip.name,
  20257. 'duration': clip.duration,
  20258. 'tracks': tracks,
  20259. 'uuid': clip.uuid
  20260. };
  20261. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20262. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20263. }
  20264. return json;
  20265. },
  20266. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20267. var numMorphTargets = morphTargetSequence.length;
  20268. var tracks = [];
  20269. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20270. var times = [];
  20271. var values = [];
  20272. times.push(
  20273. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20274. i,
  20275. ( i + 1 ) % numMorphTargets );
  20276. values.push( 0, 1, 0 );
  20277. var order = AnimationUtils.getKeyframeOrder( times );
  20278. times = AnimationUtils.sortedArray( times, 1, order );
  20279. values = AnimationUtils.sortedArray( values, 1, order );
  20280. // if there is a key at the first frame, duplicate it as the
  20281. // last frame as well for perfect loop.
  20282. if ( ! noLoop && times[ 0 ] === 0 ) {
  20283. times.push( numMorphTargets );
  20284. values.push( values[ 0 ] );
  20285. }
  20286. tracks.push(
  20287. new NumberKeyframeTrack(
  20288. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20289. times, values
  20290. ).scale( 1.0 / fps ) );
  20291. }
  20292. return new AnimationClip( name, - 1, tracks );
  20293. },
  20294. findByName: function ( objectOrClipArray, name ) {
  20295. var clipArray = objectOrClipArray;
  20296. if ( ! Array.isArray( objectOrClipArray ) ) {
  20297. var o = objectOrClipArray;
  20298. clipArray = o.geometry && o.geometry.animations || o.animations;
  20299. }
  20300. for ( var i = 0; i < clipArray.length; i ++ ) {
  20301. if ( clipArray[ i ].name === name ) {
  20302. return clipArray[ i ];
  20303. }
  20304. }
  20305. return null;
  20306. },
  20307. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20308. var animationToMorphTargets = {};
  20309. // tested with https://regex101.com/ on trick sequences
  20310. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20311. var pattern = /^([\w-]*?)([\d]+)$/;
  20312. // sort morph target names into animation groups based
  20313. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20314. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20315. var morphTarget = morphTargets[ i ];
  20316. var parts = morphTarget.name.match( pattern );
  20317. if ( parts && parts.length > 1 ) {
  20318. var name = parts[ 1 ];
  20319. var animationMorphTargets = animationToMorphTargets[ name ];
  20320. if ( ! animationMorphTargets ) {
  20321. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20322. }
  20323. animationMorphTargets.push( morphTarget );
  20324. }
  20325. }
  20326. var clips = [];
  20327. for ( var name in animationToMorphTargets ) {
  20328. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20329. }
  20330. return clips;
  20331. },
  20332. // parse the animation.hierarchy format
  20333. parseAnimation: function ( animation, bones ) {
  20334. if ( ! animation ) {
  20335. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20336. return null;
  20337. }
  20338. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20339. // only return track if there are actually keys.
  20340. if ( animationKeys.length !== 0 ) {
  20341. var times = [];
  20342. var values = [];
  20343. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20344. // empty keys are filtered out, so check again
  20345. if ( times.length !== 0 ) {
  20346. destTracks.push( new trackType( trackName, times, values ) );
  20347. }
  20348. }
  20349. };
  20350. var tracks = [];
  20351. var clipName = animation.name || 'default';
  20352. // automatic length determination in AnimationClip.
  20353. var duration = animation.length || - 1;
  20354. var fps = animation.fps || 30;
  20355. var hierarchyTracks = animation.hierarchy || [];
  20356. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20357. var animationKeys = hierarchyTracks[ h ].keys;
  20358. // skip empty tracks
  20359. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20360. // process morph targets
  20361. if ( animationKeys[ 0 ].morphTargets ) {
  20362. // figure out all morph targets used in this track
  20363. var morphTargetNames = {};
  20364. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20365. if ( animationKeys[ k ].morphTargets ) {
  20366. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20367. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20368. }
  20369. }
  20370. }
  20371. // create a track for each morph target with all zero
  20372. // morphTargetInfluences except for the keys in which
  20373. // the morphTarget is named.
  20374. for ( var morphTargetName in morphTargetNames ) {
  20375. var times = [];
  20376. var values = [];
  20377. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20378. var animationKey = animationKeys[ k ];
  20379. times.push( animationKey.time );
  20380. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20381. }
  20382. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20383. }
  20384. duration = morphTargetNames.length * ( fps || 1.0 );
  20385. } else {
  20386. // ...assume skeletal animation
  20387. var boneName = '.bones[' + bones[ h ].name + ']';
  20388. addNonemptyTrack(
  20389. VectorKeyframeTrack, boneName + '.position',
  20390. animationKeys, 'pos', tracks );
  20391. addNonemptyTrack(
  20392. QuaternionKeyframeTrack, boneName + '.quaternion',
  20393. animationKeys, 'rot', tracks );
  20394. addNonemptyTrack(
  20395. VectorKeyframeTrack, boneName + '.scale',
  20396. animationKeys, 'scl', tracks );
  20397. }
  20398. }
  20399. if ( tracks.length === 0 ) {
  20400. return null;
  20401. }
  20402. var clip = new AnimationClip( clipName, duration, tracks );
  20403. return clip;
  20404. }
  20405. } );
  20406. Object.assign( AnimationClip.prototype, {
  20407. resetDuration: function () {
  20408. var tracks = this.tracks, duration = 0;
  20409. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20410. var track = this.tracks[ i ];
  20411. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20412. }
  20413. this.duration = duration;
  20414. return this;
  20415. },
  20416. trim: function () {
  20417. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20418. this.tracks[ i ].trim( 0, this.duration );
  20419. }
  20420. return this;
  20421. },
  20422. validate: function () {
  20423. var valid = true;
  20424. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20425. valid = valid && this.tracks[ i ].validate();
  20426. }
  20427. return valid;
  20428. },
  20429. optimize: function () {
  20430. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20431. this.tracks[ i ].optimize();
  20432. }
  20433. return this;
  20434. },
  20435. clone: function () {
  20436. var tracks = [];
  20437. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20438. tracks.push( this.tracks[ i ].clone() );
  20439. }
  20440. return new AnimationClip( this.name, this.duration, tracks );
  20441. }
  20442. } );
  20443. /**
  20444. * @author mrdoob / http://mrdoob.com/
  20445. */
  20446. var Cache = {
  20447. enabled: false,
  20448. files: {},
  20449. add: function ( key, file ) {
  20450. if ( this.enabled === false ) return;
  20451. // console.log( 'THREE.Cache', 'Adding key:', key );
  20452. this.files[ key ] = file;
  20453. },
  20454. get: function ( key ) {
  20455. if ( this.enabled === false ) return;
  20456. // console.log( 'THREE.Cache', 'Checking key:', key );
  20457. return this.files[ key ];
  20458. },
  20459. remove: function ( key ) {
  20460. delete this.files[ key ];
  20461. },
  20462. clear: function () {
  20463. this.files = {};
  20464. }
  20465. };
  20466. /**
  20467. * @author mrdoob / http://mrdoob.com/
  20468. */
  20469. function LoadingManager( onLoad, onProgress, onError ) {
  20470. var scope = this;
  20471. var isLoading = false;
  20472. var itemsLoaded = 0;
  20473. var itemsTotal = 0;
  20474. var urlModifier = undefined;
  20475. // Refer to #5689 for the reason why we don't set .onStart
  20476. // in the constructor
  20477. this.onStart = undefined;
  20478. this.onLoad = onLoad;
  20479. this.onProgress = onProgress;
  20480. this.onError = onError;
  20481. this.itemStart = function ( url ) {
  20482. itemsTotal ++;
  20483. if ( isLoading === false ) {
  20484. if ( scope.onStart !== undefined ) {
  20485. scope.onStart( url, itemsLoaded, itemsTotal );
  20486. }
  20487. }
  20488. isLoading = true;
  20489. };
  20490. this.itemEnd = function ( url ) {
  20491. itemsLoaded ++;
  20492. if ( scope.onProgress !== undefined ) {
  20493. scope.onProgress( url, itemsLoaded, itemsTotal );
  20494. }
  20495. if ( itemsLoaded === itemsTotal ) {
  20496. isLoading = false;
  20497. if ( scope.onLoad !== undefined ) {
  20498. scope.onLoad();
  20499. }
  20500. }
  20501. };
  20502. this.itemError = function ( url ) {
  20503. if ( scope.onError !== undefined ) {
  20504. scope.onError( url );
  20505. }
  20506. };
  20507. this.resolveURL = function ( url ) {
  20508. if ( urlModifier ) {
  20509. return urlModifier( url );
  20510. }
  20511. return url;
  20512. };
  20513. this.setURLModifier = function ( transform ) {
  20514. urlModifier = transform;
  20515. return this;
  20516. };
  20517. }
  20518. var DefaultLoadingManager = new LoadingManager();
  20519. /**
  20520. * @author mrdoob / http://mrdoob.com/
  20521. */
  20522. var loading = {};
  20523. function FileLoader( manager ) {
  20524. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20525. }
  20526. Object.assign( FileLoader.prototype, {
  20527. load: function ( url, onLoad, onProgress, onError ) {
  20528. if ( url === undefined ) url = '';
  20529. if ( this.path !== undefined ) url = this.path + url;
  20530. url = this.manager.resolveURL( url );
  20531. var scope = this;
  20532. var cached = Cache.get( url );
  20533. if ( cached !== undefined ) {
  20534. scope.manager.itemStart( url );
  20535. setTimeout( function () {
  20536. if ( onLoad ) onLoad( cached );
  20537. scope.manager.itemEnd( url );
  20538. }, 0 );
  20539. return cached;
  20540. }
  20541. // Check if request is duplicate
  20542. if ( loading[ url ] !== undefined ) {
  20543. loading[ url ].push( {
  20544. onLoad: onLoad,
  20545. onProgress: onProgress,
  20546. onError: onError
  20547. } );
  20548. return;
  20549. }
  20550. // Check for data: URI
  20551. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20552. var dataUriRegexResult = url.match( dataUriRegex );
  20553. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20554. if ( dataUriRegexResult ) {
  20555. var mimeType = dataUriRegexResult[ 1 ];
  20556. var isBase64 = !! dataUriRegexResult[ 2 ];
  20557. var data = dataUriRegexResult[ 3 ];
  20558. data = decodeURIComponent( data );
  20559. if ( isBase64 ) data = atob( data );
  20560. try {
  20561. var response;
  20562. var responseType = ( this.responseType || '' ).toLowerCase();
  20563. switch ( responseType ) {
  20564. case 'arraybuffer':
  20565. case 'blob':
  20566. var view = new Uint8Array( data.length );
  20567. for ( var i = 0; i < data.length; i ++ ) {
  20568. view[ i ] = data.charCodeAt( i );
  20569. }
  20570. if ( responseType === 'blob' ) {
  20571. response = new Blob( [ view.buffer ], { type: mimeType } );
  20572. } else {
  20573. response = view.buffer;
  20574. }
  20575. break;
  20576. case 'document':
  20577. var parser = new DOMParser();
  20578. response = parser.parseFromString( data, mimeType );
  20579. break;
  20580. case 'json':
  20581. response = JSON.parse( data );
  20582. break;
  20583. default: // 'text' or other
  20584. response = data;
  20585. break;
  20586. }
  20587. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20588. setTimeout( function () {
  20589. if ( onLoad ) onLoad( response );
  20590. scope.manager.itemEnd( url );
  20591. }, 0 );
  20592. } catch ( error ) {
  20593. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20594. setTimeout( function () {
  20595. if ( onError ) onError( error );
  20596. scope.manager.itemError( url );
  20597. scope.manager.itemEnd( url );
  20598. }, 0 );
  20599. }
  20600. } else {
  20601. // Initialise array for duplicate requests
  20602. loading[ url ] = [];
  20603. loading[ url ].push( {
  20604. onLoad: onLoad,
  20605. onProgress: onProgress,
  20606. onError: onError
  20607. } );
  20608. var request = new XMLHttpRequest();
  20609. request.open( 'GET', url, true );
  20610. request.addEventListener( 'load', function ( event ) {
  20611. var response = this.response;
  20612. Cache.add( url, response );
  20613. var callbacks = loading[ url ];
  20614. delete loading[ url ];
  20615. if ( this.status === 200 || this.status === 0 ) {
  20616. // Some browsers return HTTP Status 0 when using non-http protocol
  20617. // e.g. 'file://' or 'data://'. Handle as success.
  20618. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20619. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20620. var callback = callbacks[ i ];
  20621. if ( callback.onLoad ) callback.onLoad( response );
  20622. }
  20623. scope.manager.itemEnd( url );
  20624. } else {
  20625. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20626. var callback = callbacks[ i ];
  20627. if ( callback.onError ) callback.onError( event );
  20628. }
  20629. scope.manager.itemError( url );
  20630. scope.manager.itemEnd( url );
  20631. }
  20632. }, false );
  20633. request.addEventListener( 'progress', function ( event ) {
  20634. var callbacks = loading[ url ];
  20635. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20636. var callback = callbacks[ i ];
  20637. if ( callback.onProgress ) callback.onProgress( event );
  20638. }
  20639. }, false );
  20640. request.addEventListener( 'error', function ( event ) {
  20641. var callbacks = loading[ url ];
  20642. delete loading[ url ];
  20643. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20644. var callback = callbacks[ i ];
  20645. if ( callback.onError ) callback.onError( event );
  20646. }
  20647. scope.manager.itemError( url );
  20648. scope.manager.itemEnd( url );
  20649. }, false );
  20650. request.addEventListener( 'abort', function ( event ) {
  20651. var callbacks = loading[ url ];
  20652. delete loading[ url ];
  20653. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20654. var callback = callbacks[ i ];
  20655. if ( callback.onError ) callback.onError( event );
  20656. }
  20657. scope.manager.itemError( url );
  20658. scope.manager.itemEnd( url );
  20659. }, false );
  20660. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20661. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20662. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20663. for ( var header in this.requestHeader ) {
  20664. request.setRequestHeader( header, this.requestHeader[ header ] );
  20665. }
  20666. request.send( null );
  20667. }
  20668. scope.manager.itemStart( url );
  20669. return request;
  20670. },
  20671. setPath: function ( value ) {
  20672. this.path = value;
  20673. return this;
  20674. },
  20675. setResponseType: function ( value ) {
  20676. this.responseType = value;
  20677. return this;
  20678. },
  20679. setWithCredentials: function ( value ) {
  20680. this.withCredentials = value;
  20681. return this;
  20682. },
  20683. setMimeType: function ( value ) {
  20684. this.mimeType = value;
  20685. return this;
  20686. },
  20687. setRequestHeader: function ( value ) {
  20688. this.requestHeader = value;
  20689. return this;
  20690. }
  20691. } );
  20692. /**
  20693. * @author bhouston / http://clara.io/
  20694. */
  20695. function AnimationLoader( manager ) {
  20696. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20697. }
  20698. Object.assign( AnimationLoader.prototype, {
  20699. load: function ( url, onLoad, onProgress, onError ) {
  20700. var scope = this;
  20701. var loader = new FileLoader( scope.manager );
  20702. loader.setPath( scope.path );
  20703. loader.load( url, function ( text ) {
  20704. onLoad( scope.parse( JSON.parse( text ) ) );
  20705. }, onProgress, onError );
  20706. },
  20707. parse: function ( json ) {
  20708. var animations = [];
  20709. for ( var i = 0; i < json.length; i ++ ) {
  20710. var clip = AnimationClip.parse( json[ i ] );
  20711. animations.push( clip );
  20712. }
  20713. return animations;
  20714. },
  20715. setPath: function ( value ) {
  20716. this.path = value;
  20717. return this;
  20718. }
  20719. } );
  20720. /**
  20721. * @author mrdoob / http://mrdoob.com/
  20722. *
  20723. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20724. */
  20725. function CompressedTextureLoader( manager ) {
  20726. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20727. // override in sub classes
  20728. this._parser = null;
  20729. }
  20730. Object.assign( CompressedTextureLoader.prototype, {
  20731. load: function ( url, onLoad, onProgress, onError ) {
  20732. var scope = this;
  20733. var images = [];
  20734. var texture = new CompressedTexture();
  20735. texture.image = images;
  20736. var loader = new FileLoader( this.manager );
  20737. loader.setPath( this.path );
  20738. loader.setResponseType( 'arraybuffer' );
  20739. function loadTexture( i ) {
  20740. loader.load( url[ i ], function ( buffer ) {
  20741. var texDatas = scope._parser( buffer, true );
  20742. images[ i ] = {
  20743. width: texDatas.width,
  20744. height: texDatas.height,
  20745. format: texDatas.format,
  20746. mipmaps: texDatas.mipmaps
  20747. };
  20748. loaded += 1;
  20749. if ( loaded === 6 ) {
  20750. if ( texDatas.mipmapCount === 1 )
  20751. texture.minFilter = LinearFilter;
  20752. texture.format = texDatas.format;
  20753. texture.needsUpdate = true;
  20754. if ( onLoad ) onLoad( texture );
  20755. }
  20756. }, onProgress, onError );
  20757. }
  20758. if ( Array.isArray( url ) ) {
  20759. var loaded = 0;
  20760. for ( var i = 0, il = url.length; i < il; ++ i ) {
  20761. loadTexture( i );
  20762. }
  20763. } else {
  20764. // compressed cubemap texture stored in a single DDS file
  20765. loader.load( url, function ( buffer ) {
  20766. var texDatas = scope._parser( buffer, true );
  20767. if ( texDatas.isCubemap ) {
  20768. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20769. for ( var f = 0; f < faces; f ++ ) {
  20770. images[ f ] = { mipmaps: [] };
  20771. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  20772. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20773. images[ f ].format = texDatas.format;
  20774. images[ f ].width = texDatas.width;
  20775. images[ f ].height = texDatas.height;
  20776. }
  20777. }
  20778. } else {
  20779. texture.image.width = texDatas.width;
  20780. texture.image.height = texDatas.height;
  20781. texture.mipmaps = texDatas.mipmaps;
  20782. }
  20783. if ( texDatas.mipmapCount === 1 ) {
  20784. texture.minFilter = LinearFilter;
  20785. }
  20786. texture.format = texDatas.format;
  20787. texture.needsUpdate = true;
  20788. if ( onLoad ) onLoad( texture );
  20789. }, onProgress, onError );
  20790. }
  20791. return texture;
  20792. },
  20793. setPath: function ( value ) {
  20794. this.path = value;
  20795. return this;
  20796. }
  20797. } );
  20798. /**
  20799. * @author Nikos M. / https://github.com/foo123/
  20800. *
  20801. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20802. */
  20803. function DataTextureLoader( manager ) {
  20804. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20805. // override in sub classes
  20806. this._parser = null;
  20807. }
  20808. Object.assign( DataTextureLoader.prototype, {
  20809. load: function ( url, onLoad, onProgress, onError ) {
  20810. var scope = this;
  20811. var texture = new DataTexture();
  20812. var loader = new FileLoader( this.manager );
  20813. loader.setResponseType( 'arraybuffer' );
  20814. loader.setPath( this.path );
  20815. loader.load( url, function ( buffer ) {
  20816. var texData = scope._parser( buffer );
  20817. if ( ! texData ) return;
  20818. if ( texData.image !== undefined ) {
  20819. texture.image = texData.image;
  20820. } else if ( texData.data !== undefined ) {
  20821. texture.image.width = texData.width;
  20822. texture.image.height = texData.height;
  20823. texture.image.data = texData.data;
  20824. }
  20825. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20826. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20827. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20828. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipMapLinearFilter;
  20829. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20830. if ( texData.format !== undefined ) {
  20831. texture.format = texData.format;
  20832. }
  20833. if ( texData.type !== undefined ) {
  20834. texture.type = texData.type;
  20835. }
  20836. if ( texData.mipmaps !== undefined ) {
  20837. texture.mipmaps = texData.mipmaps;
  20838. }
  20839. if ( texData.mipmapCount === 1 ) {
  20840. texture.minFilter = LinearFilter;
  20841. }
  20842. texture.needsUpdate = true;
  20843. if ( onLoad ) onLoad( texture, texData );
  20844. }, onProgress, onError );
  20845. return texture;
  20846. },
  20847. setPath: function ( value ) {
  20848. this.path = value;
  20849. return this;
  20850. }
  20851. } );
  20852. /**
  20853. * @author mrdoob / http://mrdoob.com/
  20854. */
  20855. function ImageLoader( manager ) {
  20856. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20857. }
  20858. Object.assign( ImageLoader.prototype, {
  20859. crossOrigin: 'anonymous',
  20860. load: function ( url, onLoad, onProgress, onError ) {
  20861. if ( url === undefined ) url = '';
  20862. if ( this.path !== undefined ) url = this.path + url;
  20863. url = this.manager.resolveURL( url );
  20864. var scope = this;
  20865. var cached = Cache.get( url );
  20866. if ( cached !== undefined ) {
  20867. scope.manager.itemStart( url );
  20868. setTimeout( function () {
  20869. if ( onLoad ) onLoad( cached );
  20870. scope.manager.itemEnd( url );
  20871. }, 0 );
  20872. return cached;
  20873. }
  20874. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20875. function onImageLoad() {
  20876. image.removeEventListener( 'load', onImageLoad, false );
  20877. image.removeEventListener( 'error', onImageError, false );
  20878. Cache.add( url, this );
  20879. if ( onLoad ) onLoad( this );
  20880. scope.manager.itemEnd( url );
  20881. }
  20882. function onImageError( event ) {
  20883. image.removeEventListener( 'load', onImageLoad, false );
  20884. image.removeEventListener( 'error', onImageError, false );
  20885. if ( onError ) onError( event );
  20886. scope.manager.itemError( url );
  20887. scope.manager.itemEnd( url );
  20888. }
  20889. image.addEventListener( 'load', onImageLoad, false );
  20890. image.addEventListener( 'error', onImageError, false );
  20891. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20892. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20893. }
  20894. scope.manager.itemStart( url );
  20895. image.src = url;
  20896. return image;
  20897. },
  20898. setCrossOrigin: function ( value ) {
  20899. this.crossOrigin = value;
  20900. return this;
  20901. },
  20902. setPath: function ( value ) {
  20903. this.path = value;
  20904. return this;
  20905. }
  20906. } );
  20907. /**
  20908. * @author mrdoob / http://mrdoob.com/
  20909. */
  20910. function CubeTextureLoader( manager ) {
  20911. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20912. }
  20913. Object.assign( CubeTextureLoader.prototype, {
  20914. crossOrigin: 'anonymous',
  20915. load: function ( urls, onLoad, onProgress, onError ) {
  20916. var texture = new CubeTexture();
  20917. var loader = new ImageLoader( this.manager );
  20918. loader.setCrossOrigin( this.crossOrigin );
  20919. loader.setPath( this.path );
  20920. var loaded = 0;
  20921. function loadTexture( i ) {
  20922. loader.load( urls[ i ], function ( image ) {
  20923. texture.images[ i ] = image;
  20924. loaded ++;
  20925. if ( loaded === 6 ) {
  20926. texture.needsUpdate = true;
  20927. if ( onLoad ) onLoad( texture );
  20928. }
  20929. }, undefined, onError );
  20930. }
  20931. for ( var i = 0; i < urls.length; ++ i ) {
  20932. loadTexture( i );
  20933. }
  20934. return texture;
  20935. },
  20936. setCrossOrigin: function ( value ) {
  20937. this.crossOrigin = value;
  20938. return this;
  20939. },
  20940. setPath: function ( value ) {
  20941. this.path = value;
  20942. return this;
  20943. }
  20944. } );
  20945. /**
  20946. * @author mrdoob / http://mrdoob.com/
  20947. */
  20948. function TextureLoader( manager ) {
  20949. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20950. }
  20951. Object.assign( TextureLoader.prototype, {
  20952. crossOrigin: 'anonymous',
  20953. load: function ( url, onLoad, onProgress, onError ) {
  20954. var texture = new Texture();
  20955. var loader = new ImageLoader( this.manager );
  20956. loader.setCrossOrigin( this.crossOrigin );
  20957. loader.setPath( this.path );
  20958. loader.load( url, function ( image ) {
  20959. texture.image = image;
  20960. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20961. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20962. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  20963. texture.needsUpdate = true;
  20964. if ( onLoad !== undefined ) {
  20965. onLoad( texture );
  20966. }
  20967. }, onProgress, onError );
  20968. return texture;
  20969. },
  20970. setCrossOrigin: function ( value ) {
  20971. this.crossOrigin = value;
  20972. return this;
  20973. },
  20974. setPath: function ( value ) {
  20975. this.path = value;
  20976. return this;
  20977. }
  20978. } );
  20979. /**
  20980. * @author zz85 / http://www.lab4games.net/zz85/blog
  20981. * Extensible curve object
  20982. *
  20983. * Some common of curve methods:
  20984. * .getPoint( t, optionalTarget ), .getTangent( t )
  20985. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  20986. * .getPoints(), .getSpacedPoints()
  20987. * .getLength()
  20988. * .updateArcLengths()
  20989. *
  20990. * This following curves inherit from THREE.Curve:
  20991. *
  20992. * -- 2D curves --
  20993. * THREE.ArcCurve
  20994. * THREE.CubicBezierCurve
  20995. * THREE.EllipseCurve
  20996. * THREE.LineCurve
  20997. * THREE.QuadraticBezierCurve
  20998. * THREE.SplineCurve
  20999. *
  21000. * -- 3D curves --
  21001. * THREE.CatmullRomCurve3
  21002. * THREE.CubicBezierCurve3
  21003. * THREE.LineCurve3
  21004. * THREE.QuadraticBezierCurve3
  21005. *
  21006. * A series of curves can be represented as a THREE.CurvePath.
  21007. *
  21008. **/
  21009. /**************************************************************
  21010. * Abstract Curve base class
  21011. **************************************************************/
  21012. function Curve() {
  21013. this.type = 'Curve';
  21014. this.arcLengthDivisions = 200;
  21015. }
  21016. Object.assign( Curve.prototype, {
  21017. // Virtual base class method to overwrite and implement in subclasses
  21018. // - t [0 .. 1]
  21019. getPoint: function ( /* t, optionalTarget */ ) {
  21020. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21021. return null;
  21022. },
  21023. // Get point at relative position in curve according to arc length
  21024. // - u [0 .. 1]
  21025. getPointAt: function ( u, optionalTarget ) {
  21026. var t = this.getUtoTmapping( u );
  21027. return this.getPoint( t, optionalTarget );
  21028. },
  21029. // Get sequence of points using getPoint( t )
  21030. getPoints: function ( divisions ) {
  21031. if ( divisions === undefined ) divisions = 5;
  21032. var points = [];
  21033. for ( var d = 0; d <= divisions; d ++ ) {
  21034. points.push( this.getPoint( d / divisions ) );
  21035. }
  21036. return points;
  21037. },
  21038. // Get sequence of points using getPointAt( u )
  21039. getSpacedPoints: function ( divisions ) {
  21040. if ( divisions === undefined ) divisions = 5;
  21041. var points = [];
  21042. for ( var d = 0; d <= divisions; d ++ ) {
  21043. points.push( this.getPointAt( d / divisions ) );
  21044. }
  21045. return points;
  21046. },
  21047. // Get total curve arc length
  21048. getLength: function () {
  21049. var lengths = this.getLengths();
  21050. return lengths[ lengths.length - 1 ];
  21051. },
  21052. // Get list of cumulative segment lengths
  21053. getLengths: function ( divisions ) {
  21054. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21055. if ( this.cacheArcLengths &&
  21056. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21057. ! this.needsUpdate ) {
  21058. return this.cacheArcLengths;
  21059. }
  21060. this.needsUpdate = false;
  21061. var cache = [];
  21062. var current, last = this.getPoint( 0 );
  21063. var p, sum = 0;
  21064. cache.push( 0 );
  21065. for ( p = 1; p <= divisions; p ++ ) {
  21066. current = this.getPoint( p / divisions );
  21067. sum += current.distanceTo( last );
  21068. cache.push( sum );
  21069. last = current;
  21070. }
  21071. this.cacheArcLengths = cache;
  21072. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21073. },
  21074. updateArcLengths: function () {
  21075. this.needsUpdate = true;
  21076. this.getLengths();
  21077. },
  21078. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21079. getUtoTmapping: function ( u, distance ) {
  21080. var arcLengths = this.getLengths();
  21081. var i = 0, il = arcLengths.length;
  21082. var targetArcLength; // The targeted u distance value to get
  21083. if ( distance ) {
  21084. targetArcLength = distance;
  21085. } else {
  21086. targetArcLength = u * arcLengths[ il - 1 ];
  21087. }
  21088. // binary search for the index with largest value smaller than target u distance
  21089. var low = 0, high = il - 1, comparison;
  21090. while ( low <= high ) {
  21091. 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
  21092. comparison = arcLengths[ i ] - targetArcLength;
  21093. if ( comparison < 0 ) {
  21094. low = i + 1;
  21095. } else if ( comparison > 0 ) {
  21096. high = i - 1;
  21097. } else {
  21098. high = i;
  21099. break;
  21100. // DONE
  21101. }
  21102. }
  21103. i = high;
  21104. if ( arcLengths[ i ] === targetArcLength ) {
  21105. return i / ( il - 1 );
  21106. }
  21107. // we could get finer grain at lengths, or use simple interpolation between two points
  21108. var lengthBefore = arcLengths[ i ];
  21109. var lengthAfter = arcLengths[ i + 1 ];
  21110. var segmentLength = lengthAfter - lengthBefore;
  21111. // determine where we are between the 'before' and 'after' points
  21112. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21113. // add that fractional amount to t
  21114. var t = ( i + segmentFraction ) / ( il - 1 );
  21115. return t;
  21116. },
  21117. // Returns a unit vector tangent at t
  21118. // In case any sub curve does not implement its tangent derivation,
  21119. // 2 points a small delta apart will be used to find its gradient
  21120. // which seems to give a reasonable approximation
  21121. getTangent: function ( t ) {
  21122. var delta = 0.0001;
  21123. var t1 = t - delta;
  21124. var t2 = t + delta;
  21125. // Capping in case of danger
  21126. if ( t1 < 0 ) t1 = 0;
  21127. if ( t2 > 1 ) t2 = 1;
  21128. var pt1 = this.getPoint( t1 );
  21129. var pt2 = this.getPoint( t2 );
  21130. var vec = pt2.clone().sub( pt1 );
  21131. return vec.normalize();
  21132. },
  21133. getTangentAt: function ( u ) {
  21134. var t = this.getUtoTmapping( u );
  21135. return this.getTangent( t );
  21136. },
  21137. computeFrenetFrames: function ( segments, closed ) {
  21138. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21139. var normal = new Vector3();
  21140. var tangents = [];
  21141. var normals = [];
  21142. var binormals = [];
  21143. var vec = new Vector3();
  21144. var mat = new Matrix4();
  21145. var i, u, theta;
  21146. // compute the tangent vectors for each segment on the curve
  21147. for ( i = 0; i <= segments; i ++ ) {
  21148. u = i / segments;
  21149. tangents[ i ] = this.getTangentAt( u );
  21150. tangents[ i ].normalize();
  21151. }
  21152. // select an initial normal vector perpendicular to the first tangent vector,
  21153. // and in the direction of the minimum tangent xyz component
  21154. normals[ 0 ] = new Vector3();
  21155. binormals[ 0 ] = new Vector3();
  21156. var min = Number.MAX_VALUE;
  21157. var tx = Math.abs( tangents[ 0 ].x );
  21158. var ty = Math.abs( tangents[ 0 ].y );
  21159. var tz = Math.abs( tangents[ 0 ].z );
  21160. if ( tx <= min ) {
  21161. min = tx;
  21162. normal.set( 1, 0, 0 );
  21163. }
  21164. if ( ty <= min ) {
  21165. min = ty;
  21166. normal.set( 0, 1, 0 );
  21167. }
  21168. if ( tz <= min ) {
  21169. normal.set( 0, 0, 1 );
  21170. }
  21171. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21172. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21173. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21174. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21175. for ( i = 1; i <= segments; i ++ ) {
  21176. normals[ i ] = normals[ i - 1 ].clone();
  21177. binormals[ i ] = binormals[ i - 1 ].clone();
  21178. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21179. if ( vec.length() > Number.EPSILON ) {
  21180. vec.normalize();
  21181. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21182. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21183. }
  21184. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21185. }
  21186. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21187. if ( closed === true ) {
  21188. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21189. theta /= segments;
  21190. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21191. theta = - theta;
  21192. }
  21193. for ( i = 1; i <= segments; i ++ ) {
  21194. // twist a little...
  21195. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21196. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21197. }
  21198. }
  21199. return {
  21200. tangents: tangents,
  21201. normals: normals,
  21202. binormals: binormals
  21203. };
  21204. },
  21205. clone: function () {
  21206. return new this.constructor().copy( this );
  21207. },
  21208. copy: function ( source ) {
  21209. this.arcLengthDivisions = source.arcLengthDivisions;
  21210. return this;
  21211. },
  21212. toJSON: function () {
  21213. var data = {
  21214. metadata: {
  21215. version: 4.5,
  21216. type: 'Curve',
  21217. generator: 'Curve.toJSON'
  21218. }
  21219. };
  21220. data.arcLengthDivisions = this.arcLengthDivisions;
  21221. data.type = this.type;
  21222. return data;
  21223. },
  21224. fromJSON: function ( json ) {
  21225. this.arcLengthDivisions = json.arcLengthDivisions;
  21226. return this;
  21227. }
  21228. } );
  21229. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21230. Curve.call( this );
  21231. this.type = 'EllipseCurve';
  21232. this.aX = aX || 0;
  21233. this.aY = aY || 0;
  21234. this.xRadius = xRadius || 1;
  21235. this.yRadius = yRadius || 1;
  21236. this.aStartAngle = aStartAngle || 0;
  21237. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21238. this.aClockwise = aClockwise || false;
  21239. this.aRotation = aRotation || 0;
  21240. }
  21241. EllipseCurve.prototype = Object.create( Curve.prototype );
  21242. EllipseCurve.prototype.constructor = EllipseCurve;
  21243. EllipseCurve.prototype.isEllipseCurve = true;
  21244. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21245. var point = optionalTarget || new Vector2();
  21246. var twoPi = Math.PI * 2;
  21247. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21248. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21249. // ensures that deltaAngle is 0 .. 2 PI
  21250. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21251. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21252. if ( deltaAngle < Number.EPSILON ) {
  21253. if ( samePoints ) {
  21254. deltaAngle = 0;
  21255. } else {
  21256. deltaAngle = twoPi;
  21257. }
  21258. }
  21259. if ( this.aClockwise === true && ! samePoints ) {
  21260. if ( deltaAngle === twoPi ) {
  21261. deltaAngle = - twoPi;
  21262. } else {
  21263. deltaAngle = deltaAngle - twoPi;
  21264. }
  21265. }
  21266. var angle = this.aStartAngle + t * deltaAngle;
  21267. var x = this.aX + this.xRadius * Math.cos( angle );
  21268. var y = this.aY + this.yRadius * Math.sin( angle );
  21269. if ( this.aRotation !== 0 ) {
  21270. var cos = Math.cos( this.aRotation );
  21271. var sin = Math.sin( this.aRotation );
  21272. var tx = x - this.aX;
  21273. var ty = y - this.aY;
  21274. // Rotate the point about the center of the ellipse.
  21275. x = tx * cos - ty * sin + this.aX;
  21276. y = tx * sin + ty * cos + this.aY;
  21277. }
  21278. return point.set( x, y );
  21279. };
  21280. EllipseCurve.prototype.copy = function ( source ) {
  21281. Curve.prototype.copy.call( this, source );
  21282. this.aX = source.aX;
  21283. this.aY = source.aY;
  21284. this.xRadius = source.xRadius;
  21285. this.yRadius = source.yRadius;
  21286. this.aStartAngle = source.aStartAngle;
  21287. this.aEndAngle = source.aEndAngle;
  21288. this.aClockwise = source.aClockwise;
  21289. this.aRotation = source.aRotation;
  21290. return this;
  21291. };
  21292. EllipseCurve.prototype.toJSON = function () {
  21293. var data = Curve.prototype.toJSON.call( this );
  21294. data.aX = this.aX;
  21295. data.aY = this.aY;
  21296. data.xRadius = this.xRadius;
  21297. data.yRadius = this.yRadius;
  21298. data.aStartAngle = this.aStartAngle;
  21299. data.aEndAngle = this.aEndAngle;
  21300. data.aClockwise = this.aClockwise;
  21301. data.aRotation = this.aRotation;
  21302. return data;
  21303. };
  21304. EllipseCurve.prototype.fromJSON = function ( json ) {
  21305. Curve.prototype.fromJSON.call( this, json );
  21306. this.aX = json.aX;
  21307. this.aY = json.aY;
  21308. this.xRadius = json.xRadius;
  21309. this.yRadius = json.yRadius;
  21310. this.aStartAngle = json.aStartAngle;
  21311. this.aEndAngle = json.aEndAngle;
  21312. this.aClockwise = json.aClockwise;
  21313. this.aRotation = json.aRotation;
  21314. return this;
  21315. };
  21316. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21317. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21318. this.type = 'ArcCurve';
  21319. }
  21320. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21321. ArcCurve.prototype.constructor = ArcCurve;
  21322. ArcCurve.prototype.isArcCurve = true;
  21323. /**
  21324. * @author zz85 https://github.com/zz85
  21325. *
  21326. * Centripetal CatmullRom Curve - which is useful for avoiding
  21327. * cusps and self-intersections in non-uniform catmull rom curves.
  21328. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21329. *
  21330. * curve.type accepts centripetal(default), chordal and catmullrom
  21331. * curve.tension is used for catmullrom which defaults to 0.5
  21332. */
  21333. /*
  21334. Based on an optimized c++ solution in
  21335. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21336. - http://ideone.com/NoEbVM
  21337. This CubicPoly class could be used for reusing some variables and calculations,
  21338. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21339. which can be placed in CurveUtils.
  21340. */
  21341. function CubicPoly() {
  21342. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21343. /*
  21344. * Compute coefficients for a cubic polynomial
  21345. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21346. * such that
  21347. * p(0) = x0, p(1) = x1
  21348. * and
  21349. * p'(0) = t0, p'(1) = t1.
  21350. */
  21351. function init( x0, x1, t0, t1 ) {
  21352. c0 = x0;
  21353. c1 = t0;
  21354. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21355. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21356. }
  21357. return {
  21358. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21359. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21360. },
  21361. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21362. // compute tangents when parameterized in [t1,t2]
  21363. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21364. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21365. // rescale tangents for parametrization in [0,1]
  21366. t1 *= dt1;
  21367. t2 *= dt1;
  21368. init( x1, x2, t1, t2 );
  21369. },
  21370. calc: function ( t ) {
  21371. var t2 = t * t;
  21372. var t3 = t2 * t;
  21373. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21374. }
  21375. };
  21376. }
  21377. //
  21378. var tmp = new Vector3();
  21379. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21380. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21381. Curve.call( this );
  21382. this.type = 'CatmullRomCurve3';
  21383. this.points = points || [];
  21384. this.closed = closed || false;
  21385. this.curveType = curveType || 'centripetal';
  21386. this.tension = tension || 0.5;
  21387. }
  21388. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21389. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21390. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21391. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21392. var point = optionalTarget || new Vector3();
  21393. var points = this.points;
  21394. var l = points.length;
  21395. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21396. var intPoint = Math.floor( p );
  21397. var weight = p - intPoint;
  21398. if ( this.closed ) {
  21399. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21400. } else if ( weight === 0 && intPoint === l - 1 ) {
  21401. intPoint = l - 2;
  21402. weight = 1;
  21403. }
  21404. var p0, p1, p2, p3; // 4 points
  21405. if ( this.closed || intPoint > 0 ) {
  21406. p0 = points[ ( intPoint - 1 ) % l ];
  21407. } else {
  21408. // extrapolate first point
  21409. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21410. p0 = tmp;
  21411. }
  21412. p1 = points[ intPoint % l ];
  21413. p2 = points[ ( intPoint + 1 ) % l ];
  21414. if ( this.closed || intPoint + 2 < l ) {
  21415. p3 = points[ ( intPoint + 2 ) % l ];
  21416. } else {
  21417. // extrapolate last point
  21418. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21419. p3 = tmp;
  21420. }
  21421. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21422. // init Centripetal / Chordal Catmull-Rom
  21423. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21424. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21425. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21426. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21427. // safety check for repeated points
  21428. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21429. if ( dt0 < 1e-4 ) dt0 = dt1;
  21430. if ( dt2 < 1e-4 ) dt2 = dt1;
  21431. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21432. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21433. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21434. } else if ( this.curveType === 'catmullrom' ) {
  21435. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21436. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21437. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21438. }
  21439. point.set(
  21440. px.calc( weight ),
  21441. py.calc( weight ),
  21442. pz.calc( weight )
  21443. );
  21444. return point;
  21445. };
  21446. CatmullRomCurve3.prototype.copy = function ( source ) {
  21447. Curve.prototype.copy.call( this, source );
  21448. this.points = [];
  21449. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21450. var point = source.points[ i ];
  21451. this.points.push( point.clone() );
  21452. }
  21453. this.closed = source.closed;
  21454. this.curveType = source.curveType;
  21455. this.tension = source.tension;
  21456. return this;
  21457. };
  21458. CatmullRomCurve3.prototype.toJSON = function () {
  21459. var data = Curve.prototype.toJSON.call( this );
  21460. data.points = [];
  21461. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21462. var point = this.points[ i ];
  21463. data.points.push( point.toArray() );
  21464. }
  21465. data.closed = this.closed;
  21466. data.curveType = this.curveType;
  21467. data.tension = this.tension;
  21468. return data;
  21469. };
  21470. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21471. Curve.prototype.fromJSON.call( this, json );
  21472. this.points = [];
  21473. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21474. var point = json.points[ i ];
  21475. this.points.push( new Vector3().fromArray( point ) );
  21476. }
  21477. this.closed = json.closed;
  21478. this.curveType = json.curveType;
  21479. this.tension = json.tension;
  21480. return this;
  21481. };
  21482. /**
  21483. * @author zz85 / http://www.lab4games.net/zz85/blog
  21484. *
  21485. * Bezier Curves formulas obtained from
  21486. * http://en.wikipedia.org/wiki/Bézier_curve
  21487. */
  21488. function CatmullRom( t, p0, p1, p2, p3 ) {
  21489. var v0 = ( p2 - p0 ) * 0.5;
  21490. var v1 = ( p3 - p1 ) * 0.5;
  21491. var t2 = t * t;
  21492. var t3 = t * t2;
  21493. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21494. }
  21495. //
  21496. function QuadraticBezierP0( t, p ) {
  21497. var k = 1 - t;
  21498. return k * k * p;
  21499. }
  21500. function QuadraticBezierP1( t, p ) {
  21501. return 2 * ( 1 - t ) * t * p;
  21502. }
  21503. function QuadraticBezierP2( t, p ) {
  21504. return t * t * p;
  21505. }
  21506. function QuadraticBezier( t, p0, p1, p2 ) {
  21507. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21508. QuadraticBezierP2( t, p2 );
  21509. }
  21510. //
  21511. function CubicBezierP0( t, p ) {
  21512. var k = 1 - t;
  21513. return k * k * k * p;
  21514. }
  21515. function CubicBezierP1( t, p ) {
  21516. var k = 1 - t;
  21517. return 3 * k * k * t * p;
  21518. }
  21519. function CubicBezierP2( t, p ) {
  21520. return 3 * ( 1 - t ) * t * t * p;
  21521. }
  21522. function CubicBezierP3( t, p ) {
  21523. return t * t * t * p;
  21524. }
  21525. function CubicBezier( t, p0, p1, p2, p3 ) {
  21526. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21527. CubicBezierP3( t, p3 );
  21528. }
  21529. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21530. Curve.call( this );
  21531. this.type = 'CubicBezierCurve';
  21532. this.v0 = v0 || new Vector2();
  21533. this.v1 = v1 || new Vector2();
  21534. this.v2 = v2 || new Vector2();
  21535. this.v3 = v3 || new Vector2();
  21536. }
  21537. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21538. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21539. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21540. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21541. var point = optionalTarget || new Vector2();
  21542. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21543. point.set(
  21544. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21545. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21546. );
  21547. return point;
  21548. };
  21549. CubicBezierCurve.prototype.copy = function ( source ) {
  21550. Curve.prototype.copy.call( this, source );
  21551. this.v0.copy( source.v0 );
  21552. this.v1.copy( source.v1 );
  21553. this.v2.copy( source.v2 );
  21554. this.v3.copy( source.v3 );
  21555. return this;
  21556. };
  21557. CubicBezierCurve.prototype.toJSON = function () {
  21558. var data = Curve.prototype.toJSON.call( this );
  21559. data.v0 = this.v0.toArray();
  21560. data.v1 = this.v1.toArray();
  21561. data.v2 = this.v2.toArray();
  21562. data.v3 = this.v3.toArray();
  21563. return data;
  21564. };
  21565. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21566. Curve.prototype.fromJSON.call( this, json );
  21567. this.v0.fromArray( json.v0 );
  21568. this.v1.fromArray( json.v1 );
  21569. this.v2.fromArray( json.v2 );
  21570. this.v3.fromArray( json.v3 );
  21571. return this;
  21572. };
  21573. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21574. Curve.call( this );
  21575. this.type = 'CubicBezierCurve3';
  21576. this.v0 = v0 || new Vector3();
  21577. this.v1 = v1 || new Vector3();
  21578. this.v2 = v2 || new Vector3();
  21579. this.v3 = v3 || new Vector3();
  21580. }
  21581. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21582. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21583. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21584. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21585. var point = optionalTarget || new Vector3();
  21586. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21587. point.set(
  21588. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21589. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21590. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21591. );
  21592. return point;
  21593. };
  21594. CubicBezierCurve3.prototype.copy = function ( source ) {
  21595. Curve.prototype.copy.call( this, source );
  21596. this.v0.copy( source.v0 );
  21597. this.v1.copy( source.v1 );
  21598. this.v2.copy( source.v2 );
  21599. this.v3.copy( source.v3 );
  21600. return this;
  21601. };
  21602. CubicBezierCurve3.prototype.toJSON = function () {
  21603. var data = Curve.prototype.toJSON.call( this );
  21604. data.v0 = this.v0.toArray();
  21605. data.v1 = this.v1.toArray();
  21606. data.v2 = this.v2.toArray();
  21607. data.v3 = this.v3.toArray();
  21608. return data;
  21609. };
  21610. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21611. Curve.prototype.fromJSON.call( this, json );
  21612. this.v0.fromArray( json.v0 );
  21613. this.v1.fromArray( json.v1 );
  21614. this.v2.fromArray( json.v2 );
  21615. this.v3.fromArray( json.v3 );
  21616. return this;
  21617. };
  21618. function LineCurve( v1, v2 ) {
  21619. Curve.call( this );
  21620. this.type = 'LineCurve';
  21621. this.v1 = v1 || new Vector2();
  21622. this.v2 = v2 || new Vector2();
  21623. }
  21624. LineCurve.prototype = Object.create( Curve.prototype );
  21625. LineCurve.prototype.constructor = LineCurve;
  21626. LineCurve.prototype.isLineCurve = true;
  21627. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21628. var point = optionalTarget || new Vector2();
  21629. if ( t === 1 ) {
  21630. point.copy( this.v2 );
  21631. } else {
  21632. point.copy( this.v2 ).sub( this.v1 );
  21633. point.multiplyScalar( t ).add( this.v1 );
  21634. }
  21635. return point;
  21636. };
  21637. // Line curve is linear, so we can overwrite default getPointAt
  21638. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21639. return this.getPoint( u, optionalTarget );
  21640. };
  21641. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21642. var tangent = this.v2.clone().sub( this.v1 );
  21643. return tangent.normalize();
  21644. };
  21645. LineCurve.prototype.copy = function ( source ) {
  21646. Curve.prototype.copy.call( this, source );
  21647. this.v1.copy( source.v1 );
  21648. this.v2.copy( source.v2 );
  21649. return this;
  21650. };
  21651. LineCurve.prototype.toJSON = function () {
  21652. var data = Curve.prototype.toJSON.call( this );
  21653. data.v1 = this.v1.toArray();
  21654. data.v2 = this.v2.toArray();
  21655. return data;
  21656. };
  21657. LineCurve.prototype.fromJSON = function ( json ) {
  21658. Curve.prototype.fromJSON.call( this, json );
  21659. this.v1.fromArray( json.v1 );
  21660. this.v2.fromArray( json.v2 );
  21661. return this;
  21662. };
  21663. function LineCurve3( v1, v2 ) {
  21664. Curve.call( this );
  21665. this.type = 'LineCurve3';
  21666. this.v1 = v1 || new Vector3();
  21667. this.v2 = v2 || new Vector3();
  21668. }
  21669. LineCurve3.prototype = Object.create( Curve.prototype );
  21670. LineCurve3.prototype.constructor = LineCurve3;
  21671. LineCurve3.prototype.isLineCurve3 = true;
  21672. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21673. var point = optionalTarget || new Vector3();
  21674. if ( t === 1 ) {
  21675. point.copy( this.v2 );
  21676. } else {
  21677. point.copy( this.v2 ).sub( this.v1 );
  21678. point.multiplyScalar( t ).add( this.v1 );
  21679. }
  21680. return point;
  21681. };
  21682. // Line curve is linear, so we can overwrite default getPointAt
  21683. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21684. return this.getPoint( u, optionalTarget );
  21685. };
  21686. LineCurve3.prototype.copy = function ( source ) {
  21687. Curve.prototype.copy.call( this, source );
  21688. this.v1.copy( source.v1 );
  21689. this.v2.copy( source.v2 );
  21690. return this;
  21691. };
  21692. LineCurve3.prototype.toJSON = function () {
  21693. var data = Curve.prototype.toJSON.call( this );
  21694. data.v1 = this.v1.toArray();
  21695. data.v2 = this.v2.toArray();
  21696. return data;
  21697. };
  21698. LineCurve3.prototype.fromJSON = function ( json ) {
  21699. Curve.prototype.fromJSON.call( this, json );
  21700. this.v1.fromArray( json.v1 );
  21701. this.v2.fromArray( json.v2 );
  21702. return this;
  21703. };
  21704. function QuadraticBezierCurve( v0, v1, v2 ) {
  21705. Curve.call( this );
  21706. this.type = 'QuadraticBezierCurve';
  21707. this.v0 = v0 || new Vector2();
  21708. this.v1 = v1 || new Vector2();
  21709. this.v2 = v2 || new Vector2();
  21710. }
  21711. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21712. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21713. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21714. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21715. var point = optionalTarget || new Vector2();
  21716. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21717. point.set(
  21718. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21719. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21720. );
  21721. return point;
  21722. };
  21723. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21724. Curve.prototype.copy.call( this, source );
  21725. this.v0.copy( source.v0 );
  21726. this.v1.copy( source.v1 );
  21727. this.v2.copy( source.v2 );
  21728. return this;
  21729. };
  21730. QuadraticBezierCurve.prototype.toJSON = function () {
  21731. var data = Curve.prototype.toJSON.call( this );
  21732. data.v0 = this.v0.toArray();
  21733. data.v1 = this.v1.toArray();
  21734. data.v2 = this.v2.toArray();
  21735. return data;
  21736. };
  21737. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21738. Curve.prototype.fromJSON.call( this, json );
  21739. this.v0.fromArray( json.v0 );
  21740. this.v1.fromArray( json.v1 );
  21741. this.v2.fromArray( json.v2 );
  21742. return this;
  21743. };
  21744. function QuadraticBezierCurve3( v0, v1, v2 ) {
  21745. Curve.call( this );
  21746. this.type = 'QuadraticBezierCurve3';
  21747. this.v0 = v0 || new Vector3();
  21748. this.v1 = v1 || new Vector3();
  21749. this.v2 = v2 || new Vector3();
  21750. }
  21751. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21752. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21753. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21754. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21755. var point = optionalTarget || new Vector3();
  21756. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21757. point.set(
  21758. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21759. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21760. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21761. );
  21762. return point;
  21763. };
  21764. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21765. Curve.prototype.copy.call( this, source );
  21766. this.v0.copy( source.v0 );
  21767. this.v1.copy( source.v1 );
  21768. this.v2.copy( source.v2 );
  21769. return this;
  21770. };
  21771. QuadraticBezierCurve3.prototype.toJSON = function () {
  21772. var data = Curve.prototype.toJSON.call( this );
  21773. data.v0 = this.v0.toArray();
  21774. data.v1 = this.v1.toArray();
  21775. data.v2 = this.v2.toArray();
  21776. return data;
  21777. };
  21778. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21779. Curve.prototype.fromJSON.call( this, json );
  21780. this.v0.fromArray( json.v0 );
  21781. this.v1.fromArray( json.v1 );
  21782. this.v2.fromArray( json.v2 );
  21783. return this;
  21784. };
  21785. function SplineCurve( points /* array of Vector2 */ ) {
  21786. Curve.call( this );
  21787. this.type = 'SplineCurve';
  21788. this.points = points || [];
  21789. }
  21790. SplineCurve.prototype = Object.create( Curve.prototype );
  21791. SplineCurve.prototype.constructor = SplineCurve;
  21792. SplineCurve.prototype.isSplineCurve = true;
  21793. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21794. var point = optionalTarget || new Vector2();
  21795. var points = this.points;
  21796. var p = ( points.length - 1 ) * t;
  21797. var intPoint = Math.floor( p );
  21798. var weight = p - intPoint;
  21799. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21800. var p1 = points[ intPoint ];
  21801. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21802. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21803. point.set(
  21804. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21805. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21806. );
  21807. return point;
  21808. };
  21809. SplineCurve.prototype.copy = function ( source ) {
  21810. Curve.prototype.copy.call( this, source );
  21811. this.points = [];
  21812. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21813. var point = source.points[ i ];
  21814. this.points.push( point.clone() );
  21815. }
  21816. return this;
  21817. };
  21818. SplineCurve.prototype.toJSON = function () {
  21819. var data = Curve.prototype.toJSON.call( this );
  21820. data.points = [];
  21821. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21822. var point = this.points[ i ];
  21823. data.points.push( point.toArray() );
  21824. }
  21825. return data;
  21826. };
  21827. SplineCurve.prototype.fromJSON = function ( json ) {
  21828. Curve.prototype.fromJSON.call( this, json );
  21829. this.points = [];
  21830. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21831. var point = json.points[ i ];
  21832. this.points.push( new Vector2().fromArray( point ) );
  21833. }
  21834. return this;
  21835. };
  21836. var Curves = /*#__PURE__*/Object.freeze({
  21837. ArcCurve: ArcCurve,
  21838. CatmullRomCurve3: CatmullRomCurve3,
  21839. CubicBezierCurve: CubicBezierCurve,
  21840. CubicBezierCurve3: CubicBezierCurve3,
  21841. EllipseCurve: EllipseCurve,
  21842. LineCurve: LineCurve,
  21843. LineCurve3: LineCurve3,
  21844. QuadraticBezierCurve: QuadraticBezierCurve,
  21845. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21846. SplineCurve: SplineCurve
  21847. });
  21848. /**
  21849. * @author zz85 / http://www.lab4games.net/zz85/blog
  21850. *
  21851. **/
  21852. /**************************************************************
  21853. * Curved Path - a curve path is simply a array of connected
  21854. * curves, but retains the api of a curve
  21855. **************************************************************/
  21856. function CurvePath() {
  21857. Curve.call( this );
  21858. this.type = 'CurvePath';
  21859. this.curves = [];
  21860. this.autoClose = false; // Automatically closes the path
  21861. }
  21862. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21863. constructor: CurvePath,
  21864. add: function ( curve ) {
  21865. this.curves.push( curve );
  21866. },
  21867. closePath: function () {
  21868. // Add a line curve if start and end of lines are not connected
  21869. var startPoint = this.curves[ 0 ].getPoint( 0 );
  21870. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21871. if ( ! startPoint.equals( endPoint ) ) {
  21872. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21873. }
  21874. },
  21875. // To get accurate point with reference to
  21876. // entire path distance at time t,
  21877. // following has to be done:
  21878. // 1. Length of each sub path have to be known
  21879. // 2. Locate and identify type of curve
  21880. // 3. Get t for the curve
  21881. // 4. Return curve.getPointAt(t')
  21882. getPoint: function ( t ) {
  21883. var d = t * this.getLength();
  21884. var curveLengths = this.getCurveLengths();
  21885. var i = 0;
  21886. // To think about boundaries points.
  21887. while ( i < curveLengths.length ) {
  21888. if ( curveLengths[ i ] >= d ) {
  21889. var diff = curveLengths[ i ] - d;
  21890. var curve = this.curves[ i ];
  21891. var segmentLength = curve.getLength();
  21892. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21893. return curve.getPointAt( u );
  21894. }
  21895. i ++;
  21896. }
  21897. return null;
  21898. // loop where sum != 0, sum > d , sum+1 <d
  21899. },
  21900. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21901. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21902. // getPoint() depends on getLength
  21903. getLength: function () {
  21904. var lens = this.getCurveLengths();
  21905. return lens[ lens.length - 1 ];
  21906. },
  21907. // cacheLengths must be recalculated.
  21908. updateArcLengths: function () {
  21909. this.needsUpdate = true;
  21910. this.cacheLengths = null;
  21911. this.getCurveLengths();
  21912. },
  21913. // Compute lengths and cache them
  21914. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21915. getCurveLengths: function () {
  21916. // We use cache values if curves and cache array are same length
  21917. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21918. return this.cacheLengths;
  21919. }
  21920. // Get length of sub-curve
  21921. // Push sums into cached array
  21922. var lengths = [], sums = 0;
  21923. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21924. sums += this.curves[ i ].getLength();
  21925. lengths.push( sums );
  21926. }
  21927. this.cacheLengths = lengths;
  21928. return lengths;
  21929. },
  21930. getSpacedPoints: function ( divisions ) {
  21931. if ( divisions === undefined ) divisions = 40;
  21932. var points = [];
  21933. for ( var i = 0; i <= divisions; i ++ ) {
  21934. points.push( this.getPoint( i / divisions ) );
  21935. }
  21936. if ( this.autoClose ) {
  21937. points.push( points[ 0 ] );
  21938. }
  21939. return points;
  21940. },
  21941. getPoints: function ( divisions ) {
  21942. divisions = divisions || 12;
  21943. var points = [], last;
  21944. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21945. var curve = curves[ i ];
  21946. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21947. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21948. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21949. : divisions;
  21950. var pts = curve.getPoints( resolution );
  21951. for ( var j = 0; j < pts.length; j ++ ) {
  21952. var point = pts[ j ];
  21953. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21954. points.push( point );
  21955. last = point;
  21956. }
  21957. }
  21958. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21959. points.push( points[ 0 ] );
  21960. }
  21961. return points;
  21962. },
  21963. copy: function ( source ) {
  21964. Curve.prototype.copy.call( this, source );
  21965. this.curves = [];
  21966. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  21967. var curve = source.curves[ i ];
  21968. this.curves.push( curve.clone() );
  21969. }
  21970. this.autoClose = source.autoClose;
  21971. return this;
  21972. },
  21973. toJSON: function () {
  21974. var data = Curve.prototype.toJSON.call( this );
  21975. data.autoClose = this.autoClose;
  21976. data.curves = [];
  21977. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21978. var curve = this.curves[ i ];
  21979. data.curves.push( curve.toJSON() );
  21980. }
  21981. return data;
  21982. },
  21983. fromJSON: function ( json ) {
  21984. Curve.prototype.fromJSON.call( this, json );
  21985. this.autoClose = json.autoClose;
  21986. this.curves = [];
  21987. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  21988. var curve = json.curves[ i ];
  21989. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  21990. }
  21991. return this;
  21992. }
  21993. } );
  21994. /**
  21995. * @author zz85 / http://www.lab4games.net/zz85/blog
  21996. * Creates free form 2d path using series of points, lines or curves.
  21997. **/
  21998. function Path( points ) {
  21999. CurvePath.call( this );
  22000. this.type = 'Path';
  22001. this.currentPoint = new Vector2();
  22002. if ( points ) {
  22003. this.setFromPoints( points );
  22004. }
  22005. }
  22006. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22007. constructor: Path,
  22008. setFromPoints: function ( points ) {
  22009. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22010. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22011. this.lineTo( points[ i ].x, points[ i ].y );
  22012. }
  22013. },
  22014. moveTo: function ( x, y ) {
  22015. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22016. },
  22017. lineTo: function ( x, y ) {
  22018. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22019. this.curves.push( curve );
  22020. this.currentPoint.set( x, y );
  22021. },
  22022. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22023. var curve = new QuadraticBezierCurve(
  22024. this.currentPoint.clone(),
  22025. new Vector2( aCPx, aCPy ),
  22026. new Vector2( aX, aY )
  22027. );
  22028. this.curves.push( curve );
  22029. this.currentPoint.set( aX, aY );
  22030. },
  22031. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22032. var curve = new CubicBezierCurve(
  22033. this.currentPoint.clone(),
  22034. new Vector2( aCP1x, aCP1y ),
  22035. new Vector2( aCP2x, aCP2y ),
  22036. new Vector2( aX, aY )
  22037. );
  22038. this.curves.push( curve );
  22039. this.currentPoint.set( aX, aY );
  22040. },
  22041. splineThru: function ( pts /*Array of Vector*/ ) {
  22042. var npts = [ this.currentPoint.clone() ].concat( pts );
  22043. var curve = new SplineCurve( npts );
  22044. this.curves.push( curve );
  22045. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22046. },
  22047. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22048. var x0 = this.currentPoint.x;
  22049. var y0 = this.currentPoint.y;
  22050. this.absarc( aX + x0, aY + y0, aRadius,
  22051. aStartAngle, aEndAngle, aClockwise );
  22052. },
  22053. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22054. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22055. },
  22056. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22057. var x0 = this.currentPoint.x;
  22058. var y0 = this.currentPoint.y;
  22059. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22060. },
  22061. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22062. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22063. if ( this.curves.length > 0 ) {
  22064. // if a previous curve is present, attempt to join
  22065. var firstPoint = curve.getPoint( 0 );
  22066. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22067. this.lineTo( firstPoint.x, firstPoint.y );
  22068. }
  22069. }
  22070. this.curves.push( curve );
  22071. var lastPoint = curve.getPoint( 1 );
  22072. this.currentPoint.copy( lastPoint );
  22073. },
  22074. copy: function ( source ) {
  22075. CurvePath.prototype.copy.call( this, source );
  22076. this.currentPoint.copy( source.currentPoint );
  22077. return this;
  22078. },
  22079. toJSON: function () {
  22080. var data = CurvePath.prototype.toJSON.call( this );
  22081. data.currentPoint = this.currentPoint.toArray();
  22082. return data;
  22083. },
  22084. fromJSON: function ( json ) {
  22085. CurvePath.prototype.fromJSON.call( this, json );
  22086. this.currentPoint.fromArray( json.currentPoint );
  22087. return this;
  22088. }
  22089. } );
  22090. /**
  22091. * @author zz85 / http://www.lab4games.net/zz85/blog
  22092. * Defines a 2d shape plane using paths.
  22093. **/
  22094. // STEP 1 Create a path.
  22095. // STEP 2 Turn path into shape.
  22096. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22097. // STEP 3a - Extract points from each shape, turn to vertices
  22098. // STEP 3b - Triangulate each shape, add faces.
  22099. function Shape( points ) {
  22100. Path.call( this, points );
  22101. this.uuid = _Math.generateUUID();
  22102. this.type = 'Shape';
  22103. this.holes = [];
  22104. }
  22105. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22106. constructor: Shape,
  22107. getPointsHoles: function ( divisions ) {
  22108. var holesPts = [];
  22109. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22110. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22111. }
  22112. return holesPts;
  22113. },
  22114. // get points of shape and holes (keypoints based on segments parameter)
  22115. extractPoints: function ( divisions ) {
  22116. return {
  22117. shape: this.getPoints( divisions ),
  22118. holes: this.getPointsHoles( divisions )
  22119. };
  22120. },
  22121. copy: function ( source ) {
  22122. Path.prototype.copy.call( this, source );
  22123. this.holes = [];
  22124. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22125. var hole = source.holes[ i ];
  22126. this.holes.push( hole.clone() );
  22127. }
  22128. return this;
  22129. },
  22130. toJSON: function () {
  22131. var data = Path.prototype.toJSON.call( this );
  22132. data.uuid = this.uuid;
  22133. data.holes = [];
  22134. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22135. var hole = this.holes[ i ];
  22136. data.holes.push( hole.toJSON() );
  22137. }
  22138. return data;
  22139. },
  22140. fromJSON: function ( json ) {
  22141. Path.prototype.fromJSON.call( this, json );
  22142. this.uuid = json.uuid;
  22143. this.holes = [];
  22144. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22145. var hole = json.holes[ i ];
  22146. this.holes.push( new Path().fromJSON( hole ) );
  22147. }
  22148. return this;
  22149. }
  22150. } );
  22151. /**
  22152. * @author mrdoob / http://mrdoob.com/
  22153. * @author alteredq / http://alteredqualia.com/
  22154. */
  22155. function Light( color, intensity ) {
  22156. Object3D.call( this );
  22157. this.type = 'Light';
  22158. this.color = new Color( color );
  22159. this.intensity = intensity !== undefined ? intensity : 1;
  22160. this.receiveShadow = undefined;
  22161. }
  22162. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22163. constructor: Light,
  22164. isLight: true,
  22165. copy: function ( source ) {
  22166. Object3D.prototype.copy.call( this, source );
  22167. this.color.copy( source.color );
  22168. this.intensity = source.intensity;
  22169. return this;
  22170. },
  22171. toJSON: function ( meta ) {
  22172. var data = Object3D.prototype.toJSON.call( this, meta );
  22173. data.object.color = this.color.getHex();
  22174. data.object.intensity = this.intensity;
  22175. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22176. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22177. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22178. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22179. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22180. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22181. return data;
  22182. }
  22183. } );
  22184. /**
  22185. * @author alteredq / http://alteredqualia.com/
  22186. */
  22187. function HemisphereLight( skyColor, groundColor, intensity ) {
  22188. Light.call( this, skyColor, intensity );
  22189. this.type = 'HemisphereLight';
  22190. this.castShadow = undefined;
  22191. this.position.copy( Object3D.DefaultUp );
  22192. this.updateMatrix();
  22193. this.groundColor = new Color( groundColor );
  22194. }
  22195. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22196. constructor: HemisphereLight,
  22197. isHemisphereLight: true,
  22198. copy: function ( source ) {
  22199. Light.prototype.copy.call( this, source );
  22200. this.groundColor.copy( source.groundColor );
  22201. return this;
  22202. }
  22203. } );
  22204. /**
  22205. * @author mrdoob / http://mrdoob.com/
  22206. */
  22207. function LightShadow( camera ) {
  22208. this.camera = camera;
  22209. this.bias = 0;
  22210. this.radius = 1;
  22211. this.mapSize = new Vector2( 512, 512 );
  22212. this.map = null;
  22213. this.matrix = new Matrix4();
  22214. }
  22215. Object.assign( LightShadow.prototype, {
  22216. copy: function ( source ) {
  22217. this.camera = source.camera.clone();
  22218. this.bias = source.bias;
  22219. this.radius = source.radius;
  22220. this.mapSize.copy( source.mapSize );
  22221. return this;
  22222. },
  22223. clone: function () {
  22224. return new this.constructor().copy( this );
  22225. },
  22226. toJSON: function () {
  22227. var object = {};
  22228. if ( this.bias !== 0 ) object.bias = this.bias;
  22229. if ( this.radius !== 1 ) object.radius = this.radius;
  22230. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22231. object.camera = this.camera.toJSON( false ).object;
  22232. delete object.camera.matrix;
  22233. return object;
  22234. }
  22235. } );
  22236. /**
  22237. * @author mrdoob / http://mrdoob.com/
  22238. */
  22239. function SpotLightShadow() {
  22240. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22241. }
  22242. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22243. constructor: SpotLightShadow,
  22244. isSpotLightShadow: true,
  22245. update: function ( light ) {
  22246. var camera = this.camera;
  22247. var fov = _Math.RAD2DEG * 2 * light.angle;
  22248. var aspect = this.mapSize.width / this.mapSize.height;
  22249. var far = light.distance || camera.far;
  22250. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22251. camera.fov = fov;
  22252. camera.aspect = aspect;
  22253. camera.far = far;
  22254. camera.updateProjectionMatrix();
  22255. }
  22256. }
  22257. } );
  22258. /**
  22259. * @author alteredq / http://alteredqualia.com/
  22260. */
  22261. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22262. Light.call( this, color, intensity );
  22263. this.type = 'SpotLight';
  22264. this.position.copy( Object3D.DefaultUp );
  22265. this.updateMatrix();
  22266. this.target = new Object3D();
  22267. Object.defineProperty( this, 'power', {
  22268. get: function () {
  22269. // intensity = power per solid angle.
  22270. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22271. return this.intensity * Math.PI;
  22272. },
  22273. set: function ( power ) {
  22274. // intensity = power per solid angle.
  22275. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22276. this.intensity = power / Math.PI;
  22277. }
  22278. } );
  22279. this.distance = ( distance !== undefined ) ? distance : 0;
  22280. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22281. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22282. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22283. this.shadow = new SpotLightShadow();
  22284. }
  22285. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22286. constructor: SpotLight,
  22287. isSpotLight: true,
  22288. copy: function ( source ) {
  22289. Light.prototype.copy.call( this, source );
  22290. this.distance = source.distance;
  22291. this.angle = source.angle;
  22292. this.penumbra = source.penumbra;
  22293. this.decay = source.decay;
  22294. this.target = source.target.clone();
  22295. this.shadow = source.shadow.clone();
  22296. return this;
  22297. }
  22298. } );
  22299. /**
  22300. * @author mrdoob / http://mrdoob.com/
  22301. */
  22302. function PointLight( color, intensity, distance, decay ) {
  22303. Light.call( this, color, intensity );
  22304. this.type = 'PointLight';
  22305. Object.defineProperty( this, 'power', {
  22306. get: function () {
  22307. // intensity = power per solid angle.
  22308. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22309. return this.intensity * 4 * Math.PI;
  22310. },
  22311. set: function ( power ) {
  22312. // intensity = power per solid angle.
  22313. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22314. this.intensity = power / ( 4 * Math.PI );
  22315. }
  22316. } );
  22317. this.distance = ( distance !== undefined ) ? distance : 0;
  22318. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22319. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22320. }
  22321. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22322. constructor: PointLight,
  22323. isPointLight: true,
  22324. copy: function ( source ) {
  22325. Light.prototype.copy.call( this, source );
  22326. this.distance = source.distance;
  22327. this.decay = source.decay;
  22328. this.shadow = source.shadow.clone();
  22329. return this;
  22330. }
  22331. } );
  22332. /**
  22333. * @author alteredq / http://alteredqualia.com/
  22334. * @author arose / http://github.com/arose
  22335. */
  22336. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22337. Camera.call( this );
  22338. this.type = 'OrthographicCamera';
  22339. this.zoom = 1;
  22340. this.view = null;
  22341. this.left = ( left !== undefined ) ? left : - 1;
  22342. this.right = ( right !== undefined ) ? right : 1;
  22343. this.top = ( top !== undefined ) ? top : 1;
  22344. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22345. this.near = ( near !== undefined ) ? near : 0.1;
  22346. this.far = ( far !== undefined ) ? far : 2000;
  22347. this.updateProjectionMatrix();
  22348. }
  22349. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22350. constructor: OrthographicCamera,
  22351. isOrthographicCamera: true,
  22352. copy: function ( source, recursive ) {
  22353. Camera.prototype.copy.call( this, source, recursive );
  22354. this.left = source.left;
  22355. this.right = source.right;
  22356. this.top = source.top;
  22357. this.bottom = source.bottom;
  22358. this.near = source.near;
  22359. this.far = source.far;
  22360. this.zoom = source.zoom;
  22361. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22362. return this;
  22363. },
  22364. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22365. if ( this.view === null ) {
  22366. this.view = {
  22367. enabled: true,
  22368. fullWidth: 1,
  22369. fullHeight: 1,
  22370. offsetX: 0,
  22371. offsetY: 0,
  22372. width: 1,
  22373. height: 1
  22374. };
  22375. }
  22376. this.view.enabled = true;
  22377. this.view.fullWidth = fullWidth;
  22378. this.view.fullHeight = fullHeight;
  22379. this.view.offsetX = x;
  22380. this.view.offsetY = y;
  22381. this.view.width = width;
  22382. this.view.height = height;
  22383. this.updateProjectionMatrix();
  22384. },
  22385. clearViewOffset: function () {
  22386. if ( this.view !== null ) {
  22387. this.view.enabled = false;
  22388. }
  22389. this.updateProjectionMatrix();
  22390. },
  22391. updateProjectionMatrix: function () {
  22392. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22393. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22394. var cx = ( this.right + this.left ) / 2;
  22395. var cy = ( this.top + this.bottom ) / 2;
  22396. var left = cx - dx;
  22397. var right = cx + dx;
  22398. var top = cy + dy;
  22399. var bottom = cy - dy;
  22400. if ( this.view !== null && this.view.enabled ) {
  22401. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22402. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22403. var scaleW = ( this.right - this.left ) / this.view.width;
  22404. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22405. left += scaleW * ( this.view.offsetX / zoomW );
  22406. right = left + scaleW * ( this.view.width / zoomW );
  22407. top -= scaleH * ( this.view.offsetY / zoomH );
  22408. bottom = top - scaleH * ( this.view.height / zoomH );
  22409. }
  22410. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22411. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22412. },
  22413. toJSON: function ( meta ) {
  22414. var data = Object3D.prototype.toJSON.call( this, meta );
  22415. data.object.zoom = this.zoom;
  22416. data.object.left = this.left;
  22417. data.object.right = this.right;
  22418. data.object.top = this.top;
  22419. data.object.bottom = this.bottom;
  22420. data.object.near = this.near;
  22421. data.object.far = this.far;
  22422. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22423. return data;
  22424. }
  22425. } );
  22426. /**
  22427. * @author mrdoob / http://mrdoob.com/
  22428. */
  22429. function DirectionalLightShadow( ) {
  22430. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22431. }
  22432. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22433. constructor: DirectionalLightShadow
  22434. } );
  22435. /**
  22436. * @author mrdoob / http://mrdoob.com/
  22437. * @author alteredq / http://alteredqualia.com/
  22438. */
  22439. function DirectionalLight( color, intensity ) {
  22440. Light.call( this, color, intensity );
  22441. this.type = 'DirectionalLight';
  22442. this.position.copy( Object3D.DefaultUp );
  22443. this.updateMatrix();
  22444. this.target = new Object3D();
  22445. this.shadow = new DirectionalLightShadow();
  22446. }
  22447. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22448. constructor: DirectionalLight,
  22449. isDirectionalLight: true,
  22450. copy: function ( source ) {
  22451. Light.prototype.copy.call( this, source );
  22452. this.target = source.target.clone();
  22453. this.shadow = source.shadow.clone();
  22454. return this;
  22455. }
  22456. } );
  22457. /**
  22458. * @author mrdoob / http://mrdoob.com/
  22459. */
  22460. function AmbientLight( color, intensity ) {
  22461. Light.call( this, color, intensity );
  22462. this.type = 'AmbientLight';
  22463. this.castShadow = undefined;
  22464. }
  22465. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22466. constructor: AmbientLight,
  22467. isAmbientLight: true
  22468. } );
  22469. /**
  22470. * @author abelnation / http://github.com/abelnation
  22471. */
  22472. function RectAreaLight( color, intensity, width, height ) {
  22473. Light.call( this, color, intensity );
  22474. this.type = 'RectAreaLight';
  22475. this.width = ( width !== undefined ) ? width : 10;
  22476. this.height = ( height !== undefined ) ? height : 10;
  22477. }
  22478. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22479. constructor: RectAreaLight,
  22480. isRectAreaLight: true,
  22481. copy: function ( source ) {
  22482. Light.prototype.copy.call( this, source );
  22483. this.width = source.width;
  22484. this.height = source.height;
  22485. return this;
  22486. },
  22487. toJSON: function ( meta ) {
  22488. var data = Light.prototype.toJSON.call( this, meta );
  22489. data.object.width = this.width;
  22490. data.object.height = this.height;
  22491. return data;
  22492. }
  22493. } );
  22494. /**
  22495. * @author mrdoob / http://mrdoob.com/
  22496. */
  22497. function MaterialLoader( manager ) {
  22498. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22499. this.textures = {};
  22500. }
  22501. Object.assign( MaterialLoader.prototype, {
  22502. load: function ( url, onLoad, onProgress, onError ) {
  22503. var scope = this;
  22504. var loader = new FileLoader( scope.manager );
  22505. loader.setPath( scope.path );
  22506. loader.load( url, function ( text ) {
  22507. onLoad( scope.parse( JSON.parse( text ) ) );
  22508. }, onProgress, onError );
  22509. },
  22510. parse: function ( json ) {
  22511. var textures = this.textures;
  22512. function getTexture( name ) {
  22513. if ( textures[ name ] === undefined ) {
  22514. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22515. }
  22516. return textures[ name ];
  22517. }
  22518. var material = new Materials[ json.type ]();
  22519. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22520. if ( json.name !== undefined ) material.name = json.name;
  22521. if ( json.color !== undefined ) material.color.setHex( json.color );
  22522. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22523. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22524. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22525. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22526. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22527. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22528. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22529. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22530. if ( json.fog !== undefined ) material.fog = json.fog;
  22531. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22532. if ( json.blending !== undefined ) material.blending = json.blending;
  22533. if ( json.combine !== undefined ) material.combine = json.combine;
  22534. if ( json.side !== undefined ) material.side = json.side;
  22535. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22536. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22537. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22538. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22539. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22540. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22541. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22542. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22543. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22544. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22545. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22546. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22547. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22548. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22549. if ( json.scale !== undefined ) material.scale = json.scale;
  22550. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22551. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22552. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22553. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22554. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22555. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22556. if ( json.visible !== undefined ) material.visible = json.visible;
  22557. if ( json.userData !== undefined ) material.userData = json.userData;
  22558. // Shader Material
  22559. if ( json.uniforms !== undefined ) {
  22560. for ( var name in json.uniforms ) {
  22561. var uniform = json.uniforms[ name ];
  22562. material.uniforms[ name ] = {};
  22563. switch ( uniform.type ) {
  22564. case 't':
  22565. material.uniforms[ name ].value = getTexture( uniform.value );
  22566. break;
  22567. case 'c':
  22568. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22569. break;
  22570. case 'v2':
  22571. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22572. break;
  22573. case 'v3':
  22574. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22575. break;
  22576. case 'v4':
  22577. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22578. break;
  22579. case 'm3':
  22580. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22581. case 'm4':
  22582. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22583. break;
  22584. default:
  22585. material.uniforms[ name ].value = uniform.value;
  22586. }
  22587. }
  22588. }
  22589. if ( json.defines !== undefined ) material.defines = json.defines;
  22590. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22591. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22592. if ( json.extensions !== undefined ) {
  22593. for ( var key in json.extensions ) {
  22594. material.extensions[ key ] = json.extensions[ key ];
  22595. }
  22596. }
  22597. // Deprecated
  22598. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22599. // for PointsMaterial
  22600. if ( json.size !== undefined ) material.size = json.size;
  22601. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22602. // maps
  22603. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22604. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22605. if ( json.alphaMap !== undefined ) {
  22606. material.alphaMap = getTexture( json.alphaMap );
  22607. material.transparent = true;
  22608. }
  22609. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22610. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22611. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22612. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22613. if ( json.normalScale !== undefined ) {
  22614. var normalScale = json.normalScale;
  22615. if ( Array.isArray( normalScale ) === false ) {
  22616. // Blender exporter used to export a scalar. See #7459
  22617. normalScale = [ normalScale, normalScale ];
  22618. }
  22619. material.normalScale = new Vector2().fromArray( normalScale );
  22620. }
  22621. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22622. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22623. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22624. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22625. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22626. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22627. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22628. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22629. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22630. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22631. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22632. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22633. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22634. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22635. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22636. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22637. return material;
  22638. },
  22639. setPath: function ( value ) {
  22640. this.path = value;
  22641. return this;
  22642. },
  22643. setTextures: function ( value ) {
  22644. this.textures = value;
  22645. return this;
  22646. }
  22647. } );
  22648. /**
  22649. * @author Don McCurdy / https://www.donmccurdy.com
  22650. */
  22651. var LoaderUtils = {
  22652. decodeText: function ( array ) {
  22653. if ( typeof TextDecoder !== 'undefined' ) {
  22654. return new TextDecoder().decode( array );
  22655. }
  22656. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22657. // throws a "maximum call stack size exceeded" error for large arrays.
  22658. var s = '';
  22659. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22660. // Implicitly assumes little-endian.
  22661. s += String.fromCharCode( array[ i ] );
  22662. }
  22663. // Merges multi-byte utf-8 characters.
  22664. return decodeURIComponent( escape( s ) );
  22665. },
  22666. extractUrlBase: function ( url ) {
  22667. var index = url.lastIndexOf( '/' );
  22668. if ( index === - 1 ) return './';
  22669. return url.substr( 0, index + 1 );
  22670. }
  22671. };
  22672. /**
  22673. * @author mrdoob / http://mrdoob.com/
  22674. */
  22675. function BufferGeometryLoader( manager ) {
  22676. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22677. }
  22678. Object.assign( BufferGeometryLoader.prototype, {
  22679. load: function ( url, onLoad, onProgress, onError ) {
  22680. var scope = this;
  22681. var loader = new FileLoader( scope.manager );
  22682. loader.setPath( scope.path );
  22683. loader.load( url, function ( text ) {
  22684. onLoad( scope.parse( JSON.parse( text ) ) );
  22685. }, onProgress, onError );
  22686. },
  22687. parse: function ( json ) {
  22688. var geometry = new BufferGeometry();
  22689. var index = json.data.index;
  22690. if ( index !== undefined ) {
  22691. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  22692. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22693. }
  22694. var attributes = json.data.attributes;
  22695. for ( var key in attributes ) {
  22696. var attribute = attributes[ key ];
  22697. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22698. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22699. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22700. geometry.addAttribute( key, bufferAttribute );
  22701. }
  22702. var morphAttributes = json.data.morphAttributes;
  22703. if ( morphAttributes ) {
  22704. for ( var key in morphAttributes ) {
  22705. var attributeArray = morphAttributes[ key ];
  22706. var array = [];
  22707. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  22708. var attribute = attributeArray[ i ];
  22709. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22710. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22711. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22712. array.push( bufferAttribute );
  22713. }
  22714. geometry.morphAttributes[ key ] = array;
  22715. }
  22716. }
  22717. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22718. if ( groups !== undefined ) {
  22719. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  22720. var group = groups[ i ];
  22721. geometry.addGroup( group.start, group.count, group.materialIndex );
  22722. }
  22723. }
  22724. var boundingSphere = json.data.boundingSphere;
  22725. if ( boundingSphere !== undefined ) {
  22726. var center = new Vector3();
  22727. if ( boundingSphere.center !== undefined ) {
  22728. center.fromArray( boundingSphere.center );
  22729. }
  22730. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22731. }
  22732. if ( json.name ) geometry.name = json.name;
  22733. if ( json.userData ) geometry.userData = json.userData;
  22734. return geometry;
  22735. },
  22736. setPath: function ( value ) {
  22737. this.path = value;
  22738. return this;
  22739. }
  22740. } );
  22741. var TYPED_ARRAYS = {
  22742. Int8Array: Int8Array,
  22743. Uint8Array: Uint8Array,
  22744. // Workaround for IE11 pre KB2929437. See #11440
  22745. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  22746. Int16Array: Int16Array,
  22747. Uint16Array: Uint16Array,
  22748. Int32Array: Int32Array,
  22749. Uint32Array: Uint32Array,
  22750. Float32Array: Float32Array,
  22751. Float64Array: Float64Array
  22752. };
  22753. /**
  22754. * @author mrdoob / http://mrdoob.com/
  22755. */
  22756. function ObjectLoader( manager ) {
  22757. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22758. this.resourcePath = '';
  22759. }
  22760. Object.assign( ObjectLoader.prototype, {
  22761. crossOrigin: 'anonymous',
  22762. load: function ( url, onLoad, onProgress, onError ) {
  22763. var scope = this;
  22764. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22765. this.resourcePath = this.resourcePath || path;
  22766. var loader = new FileLoader( scope.manager );
  22767. loader.setPath( this.path );
  22768. loader.load( url, function ( text ) {
  22769. var json = null;
  22770. try {
  22771. json = JSON.parse( text );
  22772. } catch ( error ) {
  22773. if ( onError !== undefined ) onError( error );
  22774. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22775. return;
  22776. }
  22777. var metadata = json.metadata;
  22778. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22779. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22780. return;
  22781. }
  22782. scope.parse( json, onLoad );
  22783. }, onProgress, onError );
  22784. },
  22785. setPath: function ( value ) {
  22786. this.path = value;
  22787. return this;
  22788. },
  22789. setResourcePath: function ( value ) {
  22790. this.resourcePath = value;
  22791. return this;
  22792. },
  22793. setCrossOrigin: function ( value ) {
  22794. this.crossOrigin = value;
  22795. return this;
  22796. },
  22797. parse: function ( json, onLoad ) {
  22798. var shapes = this.parseShape( json.shapes );
  22799. var geometries = this.parseGeometries( json.geometries, shapes );
  22800. var images = this.parseImages( json.images, function () {
  22801. if ( onLoad !== undefined ) onLoad( object );
  22802. } );
  22803. var textures = this.parseTextures( json.textures, images );
  22804. var materials = this.parseMaterials( json.materials, textures );
  22805. var object = this.parseObject( json.object, geometries, materials );
  22806. if ( json.animations ) {
  22807. object.animations = this.parseAnimations( json.animations );
  22808. }
  22809. if ( json.images === undefined || json.images.length === 0 ) {
  22810. if ( onLoad !== undefined ) onLoad( object );
  22811. }
  22812. return object;
  22813. },
  22814. parseShape: function ( json ) {
  22815. var shapes = {};
  22816. if ( json !== undefined ) {
  22817. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22818. var shape = new Shape().fromJSON( json[ i ] );
  22819. shapes[ shape.uuid ] = shape;
  22820. }
  22821. }
  22822. return shapes;
  22823. },
  22824. parseGeometries: function ( json, shapes ) {
  22825. var geometries = {};
  22826. if ( json !== undefined ) {
  22827. var bufferGeometryLoader = new BufferGeometryLoader();
  22828. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22829. var geometry;
  22830. var data = json[ i ];
  22831. switch ( data.type ) {
  22832. case 'PlaneGeometry':
  22833. case 'PlaneBufferGeometry':
  22834. geometry = new Geometries[ data.type ](
  22835. data.width,
  22836. data.height,
  22837. data.widthSegments,
  22838. data.heightSegments
  22839. );
  22840. break;
  22841. case 'BoxGeometry':
  22842. case 'BoxBufferGeometry':
  22843. case 'CubeGeometry': // backwards compatible
  22844. geometry = new Geometries[ data.type ](
  22845. data.width,
  22846. data.height,
  22847. data.depth,
  22848. data.widthSegments,
  22849. data.heightSegments,
  22850. data.depthSegments
  22851. );
  22852. break;
  22853. case 'CircleGeometry':
  22854. case 'CircleBufferGeometry':
  22855. geometry = new Geometries[ data.type ](
  22856. data.radius,
  22857. data.segments,
  22858. data.thetaStart,
  22859. data.thetaLength
  22860. );
  22861. break;
  22862. case 'CylinderGeometry':
  22863. case 'CylinderBufferGeometry':
  22864. geometry = new Geometries[ data.type ](
  22865. data.radiusTop,
  22866. data.radiusBottom,
  22867. data.height,
  22868. data.radialSegments,
  22869. data.heightSegments,
  22870. data.openEnded,
  22871. data.thetaStart,
  22872. data.thetaLength
  22873. );
  22874. break;
  22875. case 'ConeGeometry':
  22876. case 'ConeBufferGeometry':
  22877. geometry = new Geometries[ data.type ](
  22878. data.radius,
  22879. data.height,
  22880. data.radialSegments,
  22881. data.heightSegments,
  22882. data.openEnded,
  22883. data.thetaStart,
  22884. data.thetaLength
  22885. );
  22886. break;
  22887. case 'SphereGeometry':
  22888. case 'SphereBufferGeometry':
  22889. geometry = new Geometries[ data.type ](
  22890. data.radius,
  22891. data.widthSegments,
  22892. data.heightSegments,
  22893. data.phiStart,
  22894. data.phiLength,
  22895. data.thetaStart,
  22896. data.thetaLength
  22897. );
  22898. break;
  22899. case 'DodecahedronGeometry':
  22900. case 'DodecahedronBufferGeometry':
  22901. case 'IcosahedronGeometry':
  22902. case 'IcosahedronBufferGeometry':
  22903. case 'OctahedronGeometry':
  22904. case 'OctahedronBufferGeometry':
  22905. case 'TetrahedronGeometry':
  22906. case 'TetrahedronBufferGeometry':
  22907. geometry = new Geometries[ data.type ](
  22908. data.radius,
  22909. data.detail
  22910. );
  22911. break;
  22912. case 'RingGeometry':
  22913. case 'RingBufferGeometry':
  22914. geometry = new Geometries[ data.type ](
  22915. data.innerRadius,
  22916. data.outerRadius,
  22917. data.thetaSegments,
  22918. data.phiSegments,
  22919. data.thetaStart,
  22920. data.thetaLength
  22921. );
  22922. break;
  22923. case 'TorusGeometry':
  22924. case 'TorusBufferGeometry':
  22925. geometry = new Geometries[ data.type ](
  22926. data.radius,
  22927. data.tube,
  22928. data.radialSegments,
  22929. data.tubularSegments,
  22930. data.arc
  22931. );
  22932. break;
  22933. case 'TorusKnotGeometry':
  22934. case 'TorusKnotBufferGeometry':
  22935. geometry = new Geometries[ data.type ](
  22936. data.radius,
  22937. data.tube,
  22938. data.tubularSegments,
  22939. data.radialSegments,
  22940. data.p,
  22941. data.q
  22942. );
  22943. break;
  22944. case 'TubeGeometry':
  22945. case 'TubeBufferGeometry':
  22946. // This only works for built-in curves (e.g. CatmullRomCurve3).
  22947. // User defined curves or instances of CurvePath will not be deserialized.
  22948. geometry = new Geometries[ data.type ](
  22949. new Curves[ data.path.type ]().fromJSON( data.path ),
  22950. data.tubularSegments,
  22951. data.radius,
  22952. data.radialSegments,
  22953. data.closed
  22954. );
  22955. break;
  22956. case 'LatheGeometry':
  22957. case 'LatheBufferGeometry':
  22958. geometry = new Geometries[ data.type ](
  22959. data.points,
  22960. data.segments,
  22961. data.phiStart,
  22962. data.phiLength
  22963. );
  22964. break;
  22965. case 'PolyhedronGeometry':
  22966. case 'PolyhedronBufferGeometry':
  22967. geometry = new Geometries[ data.type ](
  22968. data.vertices,
  22969. data.indices,
  22970. data.radius,
  22971. data.details
  22972. );
  22973. break;
  22974. case 'ShapeGeometry':
  22975. case 'ShapeBufferGeometry':
  22976. var geometryShapes = [];
  22977. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22978. var shape = shapes[ data.shapes[ j ] ];
  22979. geometryShapes.push( shape );
  22980. }
  22981. geometry = new Geometries[ data.type ](
  22982. geometryShapes,
  22983. data.curveSegments
  22984. );
  22985. break;
  22986. case 'ExtrudeGeometry':
  22987. case 'ExtrudeBufferGeometry':
  22988. var geometryShapes = [];
  22989. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22990. var shape = shapes[ data.shapes[ j ] ];
  22991. geometryShapes.push( shape );
  22992. }
  22993. var extrudePath = data.options.extrudePath;
  22994. if ( extrudePath !== undefined ) {
  22995. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  22996. }
  22997. geometry = new Geometries[ data.type ](
  22998. geometryShapes,
  22999. data.options
  23000. );
  23001. break;
  23002. case 'BufferGeometry':
  23003. geometry = bufferGeometryLoader.parse( data );
  23004. break;
  23005. case 'Geometry':
  23006. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23007. var geometryLoader = new THREE.LegacyJSONLoader();
  23008. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23009. } else {
  23010. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23011. }
  23012. break;
  23013. default:
  23014. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23015. continue;
  23016. }
  23017. geometry.uuid = data.uuid;
  23018. if ( data.name !== undefined ) geometry.name = data.name;
  23019. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23020. geometries[ data.uuid ] = geometry;
  23021. }
  23022. }
  23023. return geometries;
  23024. },
  23025. parseMaterials: function ( json, textures ) {
  23026. var cache = {}; // MultiMaterial
  23027. var materials = {};
  23028. if ( json !== undefined ) {
  23029. var loader = new MaterialLoader();
  23030. loader.setTextures( textures );
  23031. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23032. var data = json[ i ];
  23033. if ( data.type === 'MultiMaterial' ) {
  23034. // Deprecated
  23035. var array = [];
  23036. for ( var j = 0; j < data.materials.length; j ++ ) {
  23037. var material = data.materials[ j ];
  23038. if ( cache[ material.uuid ] === undefined ) {
  23039. cache[ material.uuid ] = loader.parse( material );
  23040. }
  23041. array.push( cache[ material.uuid ] );
  23042. }
  23043. materials[ data.uuid ] = array;
  23044. } else {
  23045. if ( cache[ data.uuid ] === undefined ) {
  23046. cache[ data.uuid ] = loader.parse( data );
  23047. }
  23048. materials[ data.uuid ] = cache[ data.uuid ];
  23049. }
  23050. }
  23051. }
  23052. return materials;
  23053. },
  23054. parseAnimations: function ( json ) {
  23055. var animations = [];
  23056. for ( var i = 0; i < json.length; i ++ ) {
  23057. var data = json[ i ];
  23058. var clip = AnimationClip.parse( data );
  23059. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23060. animations.push( clip );
  23061. }
  23062. return animations;
  23063. },
  23064. parseImages: function ( json, onLoad ) {
  23065. var scope = this;
  23066. var images = {};
  23067. function loadImage( url ) {
  23068. scope.manager.itemStart( url );
  23069. return loader.load( url, function () {
  23070. scope.manager.itemEnd( url );
  23071. }, undefined, function () {
  23072. scope.manager.itemError( url );
  23073. scope.manager.itemEnd( url );
  23074. } );
  23075. }
  23076. if ( json !== undefined && json.length > 0 ) {
  23077. var manager = new LoadingManager( onLoad );
  23078. var loader = new ImageLoader( manager );
  23079. loader.setCrossOrigin( this.crossOrigin );
  23080. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23081. var image = json[ i ];
  23082. var url = image.url;
  23083. if ( Array.isArray( url ) ) {
  23084. // load array of images e.g CubeTexture
  23085. images[ image.uuid ] = [];
  23086. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23087. var currentUrl = url[ j ];
  23088. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23089. images[ image.uuid ].push( loadImage( path ) );
  23090. }
  23091. } else {
  23092. // load single image
  23093. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23094. images[ image.uuid ] = loadImage( path );
  23095. }
  23096. }
  23097. }
  23098. return images;
  23099. },
  23100. parseTextures: function ( json, images ) {
  23101. function parseConstant( value, type ) {
  23102. if ( typeof value === 'number' ) return value;
  23103. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23104. return type[ value ];
  23105. }
  23106. var textures = {};
  23107. if ( json !== undefined ) {
  23108. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23109. var data = json[ i ];
  23110. if ( data.image === undefined ) {
  23111. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23112. }
  23113. if ( images[ data.image ] === undefined ) {
  23114. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23115. }
  23116. var texture;
  23117. if ( Array.isArray( images[ data.image ] ) ) {
  23118. texture = new CubeTexture( images[ data.image ] );
  23119. } else {
  23120. texture = new Texture( images[ data.image ] );
  23121. }
  23122. texture.needsUpdate = true;
  23123. texture.uuid = data.uuid;
  23124. if ( data.name !== undefined ) texture.name = data.name;
  23125. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23126. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23127. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23128. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23129. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23130. if ( data.wrap !== undefined ) {
  23131. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23132. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23133. }
  23134. if ( data.format !== undefined ) texture.format = data.format;
  23135. if ( data.type !== undefined ) texture.type = data.type;
  23136. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23137. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23138. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23139. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23140. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23141. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23142. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23143. textures[ data.uuid ] = texture;
  23144. }
  23145. }
  23146. return textures;
  23147. },
  23148. parseObject: function ( data, geometries, materials ) {
  23149. var object;
  23150. function getGeometry( name ) {
  23151. if ( geometries[ name ] === undefined ) {
  23152. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23153. }
  23154. return geometries[ name ];
  23155. }
  23156. function getMaterial( name ) {
  23157. if ( name === undefined ) return undefined;
  23158. if ( Array.isArray( name ) ) {
  23159. var array = [];
  23160. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23161. var uuid = name[ i ];
  23162. if ( materials[ uuid ] === undefined ) {
  23163. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23164. }
  23165. array.push( materials[ uuid ] );
  23166. }
  23167. return array;
  23168. }
  23169. if ( materials[ name ] === undefined ) {
  23170. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23171. }
  23172. return materials[ name ];
  23173. }
  23174. switch ( data.type ) {
  23175. case 'Scene':
  23176. object = new Scene();
  23177. if ( data.background !== undefined ) {
  23178. if ( Number.isInteger( data.background ) ) {
  23179. object.background = new Color( data.background );
  23180. }
  23181. }
  23182. if ( data.fog !== undefined ) {
  23183. if ( data.fog.type === 'Fog' ) {
  23184. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23185. } else if ( data.fog.type === 'FogExp2' ) {
  23186. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23187. }
  23188. }
  23189. break;
  23190. case 'PerspectiveCamera':
  23191. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23192. if ( data.focus !== undefined ) object.focus = data.focus;
  23193. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23194. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23195. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23196. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23197. break;
  23198. case 'OrthographicCamera':
  23199. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23200. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23201. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23202. break;
  23203. case 'AmbientLight':
  23204. object = new AmbientLight( data.color, data.intensity );
  23205. break;
  23206. case 'DirectionalLight':
  23207. object = new DirectionalLight( data.color, data.intensity );
  23208. break;
  23209. case 'PointLight':
  23210. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23211. break;
  23212. case 'RectAreaLight':
  23213. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23214. break;
  23215. case 'SpotLight':
  23216. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23217. break;
  23218. case 'HemisphereLight':
  23219. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23220. break;
  23221. case 'SkinnedMesh':
  23222. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23223. case 'Mesh':
  23224. var geometry = getGeometry( data.geometry );
  23225. var material = getMaterial( data.material );
  23226. if ( geometry.bones && geometry.bones.length > 0 ) {
  23227. object = new SkinnedMesh( geometry, material );
  23228. } else {
  23229. object = new Mesh( geometry, material );
  23230. }
  23231. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23232. break;
  23233. case 'LOD':
  23234. object = new LOD();
  23235. break;
  23236. case 'Line':
  23237. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23238. break;
  23239. case 'LineLoop':
  23240. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23241. break;
  23242. case 'LineSegments':
  23243. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23244. break;
  23245. case 'PointCloud':
  23246. case 'Points':
  23247. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23248. break;
  23249. case 'Sprite':
  23250. object = new Sprite( getMaterial( data.material ) );
  23251. break;
  23252. case 'Group':
  23253. object = new Group();
  23254. break;
  23255. default:
  23256. object = new Object3D();
  23257. }
  23258. object.uuid = data.uuid;
  23259. if ( data.name !== undefined ) object.name = data.name;
  23260. if ( data.matrix !== undefined ) {
  23261. object.matrix.fromArray( data.matrix );
  23262. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23263. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23264. } else {
  23265. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23266. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23267. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23268. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23269. }
  23270. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23271. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23272. if ( data.shadow ) {
  23273. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23274. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23275. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23276. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23277. }
  23278. if ( data.visible !== undefined ) object.visible = data.visible;
  23279. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23280. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23281. if ( data.userData !== undefined ) object.userData = data.userData;
  23282. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23283. if ( data.children !== undefined ) {
  23284. var children = data.children;
  23285. for ( var i = 0; i < children.length; i ++ ) {
  23286. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23287. }
  23288. }
  23289. if ( data.type === 'LOD' ) {
  23290. var levels = data.levels;
  23291. for ( var l = 0; l < levels.length; l ++ ) {
  23292. var level = levels[ l ];
  23293. var child = object.getObjectByProperty( 'uuid', level.object );
  23294. if ( child !== undefined ) {
  23295. object.addLevel( child, level.distance );
  23296. }
  23297. }
  23298. }
  23299. return object;
  23300. }
  23301. } );
  23302. var TEXTURE_MAPPING = {
  23303. UVMapping: UVMapping,
  23304. CubeReflectionMapping: CubeReflectionMapping,
  23305. CubeRefractionMapping: CubeRefractionMapping,
  23306. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23307. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23308. SphericalReflectionMapping: SphericalReflectionMapping,
  23309. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23310. CubeUVRefractionMapping: CubeUVRefractionMapping
  23311. };
  23312. var TEXTURE_WRAPPING = {
  23313. RepeatWrapping: RepeatWrapping,
  23314. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23315. MirroredRepeatWrapping: MirroredRepeatWrapping
  23316. };
  23317. var TEXTURE_FILTER = {
  23318. NearestFilter: NearestFilter,
  23319. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  23320. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  23321. LinearFilter: LinearFilter,
  23322. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  23323. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  23324. };
  23325. /**
  23326. * @author thespite / http://clicktorelease.com/
  23327. */
  23328. function ImageBitmapLoader( manager ) {
  23329. if ( typeof createImageBitmap === 'undefined' ) {
  23330. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23331. }
  23332. if ( typeof fetch === 'undefined' ) {
  23333. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23334. }
  23335. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23336. this.options = undefined;
  23337. }
  23338. ImageBitmapLoader.prototype = {
  23339. constructor: ImageBitmapLoader,
  23340. setOptions: function setOptions( options ) {
  23341. this.options = options;
  23342. return this;
  23343. },
  23344. load: function ( url, onLoad, onProgress, onError ) {
  23345. if ( url === undefined ) url = '';
  23346. if ( this.path !== undefined ) url = this.path + url;
  23347. url = this.manager.resolveURL( url );
  23348. var scope = this;
  23349. var cached = Cache.get( url );
  23350. if ( cached !== undefined ) {
  23351. scope.manager.itemStart( url );
  23352. setTimeout( function () {
  23353. if ( onLoad ) onLoad( cached );
  23354. scope.manager.itemEnd( url );
  23355. }, 0 );
  23356. return cached;
  23357. }
  23358. fetch( url ).then( function ( res ) {
  23359. return res.blob();
  23360. } ).then( function ( blob ) {
  23361. if ( scope.options === undefined ) {
  23362. // Workaround for FireFox. It causes an error if you pass options.
  23363. return createImageBitmap( blob );
  23364. } else {
  23365. return createImageBitmap( blob, scope.options );
  23366. }
  23367. } ).then( function ( imageBitmap ) {
  23368. Cache.add( url, imageBitmap );
  23369. if ( onLoad ) onLoad( imageBitmap );
  23370. scope.manager.itemEnd( url );
  23371. } ).catch( function ( e ) {
  23372. if ( onError ) onError( e );
  23373. scope.manager.itemError( url );
  23374. scope.manager.itemEnd( url );
  23375. } );
  23376. scope.manager.itemStart( url );
  23377. },
  23378. setCrossOrigin: function ( /* value */ ) {
  23379. return this;
  23380. },
  23381. setPath: function ( value ) {
  23382. this.path = value;
  23383. return this;
  23384. }
  23385. };
  23386. /**
  23387. * @author zz85 / http://www.lab4games.net/zz85/blog
  23388. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23389. **/
  23390. function ShapePath() {
  23391. this.type = 'ShapePath';
  23392. this.color = new Color();
  23393. this.subPaths = [];
  23394. this.currentPath = null;
  23395. }
  23396. Object.assign( ShapePath.prototype, {
  23397. moveTo: function ( x, y ) {
  23398. this.currentPath = new Path();
  23399. this.subPaths.push( this.currentPath );
  23400. this.currentPath.moveTo( x, y );
  23401. },
  23402. lineTo: function ( x, y ) {
  23403. this.currentPath.lineTo( x, y );
  23404. },
  23405. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23406. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23407. },
  23408. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23409. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23410. },
  23411. splineThru: function ( pts ) {
  23412. this.currentPath.splineThru( pts );
  23413. },
  23414. toShapes: function ( isCCW, noHoles ) {
  23415. function toShapesNoHoles( inSubpaths ) {
  23416. var shapes = [];
  23417. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23418. var tmpPath = inSubpaths[ i ];
  23419. var tmpShape = new Shape();
  23420. tmpShape.curves = tmpPath.curves;
  23421. shapes.push( tmpShape );
  23422. }
  23423. return shapes;
  23424. }
  23425. function isPointInsidePolygon( inPt, inPolygon ) {
  23426. var polyLen = inPolygon.length;
  23427. // inPt on polygon contour => immediate success or
  23428. // toggling of inside/outside at every single! intersection point of an edge
  23429. // with the horizontal line through inPt, left of inPt
  23430. // not counting lowerY endpoints of edges and whole edges on that line
  23431. var inside = false;
  23432. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23433. var edgeLowPt = inPolygon[ p ];
  23434. var edgeHighPt = inPolygon[ q ];
  23435. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23436. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23437. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23438. // not parallel
  23439. if ( edgeDy < 0 ) {
  23440. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23441. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23442. }
  23443. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23444. if ( inPt.y === edgeLowPt.y ) {
  23445. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23446. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23447. } else {
  23448. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23449. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23450. if ( perpEdge < 0 ) continue;
  23451. inside = ! inside; // true intersection left of inPt
  23452. }
  23453. } else {
  23454. // parallel or collinear
  23455. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23456. // edge lies on the same horizontal line as inPt
  23457. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23458. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23459. // continue;
  23460. }
  23461. }
  23462. return inside;
  23463. }
  23464. var isClockWise = ShapeUtils.isClockWise;
  23465. var subPaths = this.subPaths;
  23466. if ( subPaths.length === 0 ) return [];
  23467. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23468. var solid, tmpPath, tmpShape, shapes = [];
  23469. if ( subPaths.length === 1 ) {
  23470. tmpPath = subPaths[ 0 ];
  23471. tmpShape = new Shape();
  23472. tmpShape.curves = tmpPath.curves;
  23473. shapes.push( tmpShape );
  23474. return shapes;
  23475. }
  23476. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23477. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23478. // console.log("Holes first", holesFirst);
  23479. var betterShapeHoles = [];
  23480. var newShapes = [];
  23481. var newShapeHoles = [];
  23482. var mainIdx = 0;
  23483. var tmpPoints;
  23484. newShapes[ mainIdx ] = undefined;
  23485. newShapeHoles[ mainIdx ] = [];
  23486. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23487. tmpPath = subPaths[ i ];
  23488. tmpPoints = tmpPath.getPoints();
  23489. solid = isClockWise( tmpPoints );
  23490. solid = isCCW ? ! solid : solid;
  23491. if ( solid ) {
  23492. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23493. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23494. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23495. if ( holesFirst ) mainIdx ++;
  23496. newShapeHoles[ mainIdx ] = [];
  23497. //console.log('cw', i);
  23498. } else {
  23499. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23500. //console.log('ccw', i);
  23501. }
  23502. }
  23503. // only Holes? -> probably all Shapes with wrong orientation
  23504. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23505. if ( newShapes.length > 1 ) {
  23506. var ambiguous = false;
  23507. var toChange = [];
  23508. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23509. betterShapeHoles[ sIdx ] = [];
  23510. }
  23511. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23512. var sho = newShapeHoles[ sIdx ];
  23513. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23514. var ho = sho[ hIdx ];
  23515. var hole_unassigned = true;
  23516. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23517. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23518. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23519. if ( hole_unassigned ) {
  23520. hole_unassigned = false;
  23521. betterShapeHoles[ s2Idx ].push( ho );
  23522. } else {
  23523. ambiguous = true;
  23524. }
  23525. }
  23526. }
  23527. if ( hole_unassigned ) {
  23528. betterShapeHoles[ sIdx ].push( ho );
  23529. }
  23530. }
  23531. }
  23532. // console.log("ambiguous: ", ambiguous);
  23533. if ( toChange.length > 0 ) {
  23534. // console.log("to change: ", toChange);
  23535. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23536. }
  23537. }
  23538. var tmpHoles;
  23539. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23540. tmpShape = newShapes[ i ].s;
  23541. shapes.push( tmpShape );
  23542. tmpHoles = newShapeHoles[ i ];
  23543. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23544. tmpShape.holes.push( tmpHoles[ j ].h );
  23545. }
  23546. }
  23547. //console.log("shape", shapes);
  23548. return shapes;
  23549. }
  23550. } );
  23551. /**
  23552. * @author zz85 / http://www.lab4games.net/zz85/blog
  23553. * @author mrdoob / http://mrdoob.com/
  23554. */
  23555. function Font( data ) {
  23556. this.type = 'Font';
  23557. this.data = data;
  23558. }
  23559. Object.assign( Font.prototype, {
  23560. isFont: true,
  23561. generateShapes: function ( text, size ) {
  23562. if ( size === undefined ) size = 100;
  23563. var shapes = [];
  23564. var paths = createPaths( text, size, this.data );
  23565. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23566. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23567. }
  23568. return shapes;
  23569. }
  23570. } );
  23571. function createPaths( text, size, data ) {
  23572. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23573. var scale = size / data.resolution;
  23574. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23575. var paths = [];
  23576. var offsetX = 0, offsetY = 0;
  23577. for ( var i = 0; i < chars.length; i ++ ) {
  23578. var char = chars[ i ];
  23579. if ( char === '\n' ) {
  23580. offsetX = 0;
  23581. offsetY -= line_height;
  23582. } else {
  23583. var ret = createPath( char, scale, offsetX, offsetY, data );
  23584. offsetX += ret.offsetX;
  23585. paths.push( ret.path );
  23586. }
  23587. }
  23588. return paths;
  23589. }
  23590. function createPath( char, scale, offsetX, offsetY, data ) {
  23591. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23592. if ( ! glyph ) return;
  23593. var path = new ShapePath();
  23594. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23595. if ( glyph.o ) {
  23596. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23597. for ( var i = 0, l = outline.length; i < l; ) {
  23598. var action = outline[ i ++ ];
  23599. switch ( action ) {
  23600. case 'm': // moveTo
  23601. x = outline[ i ++ ] * scale + offsetX;
  23602. y = outline[ i ++ ] * scale + offsetY;
  23603. path.moveTo( x, y );
  23604. break;
  23605. case 'l': // lineTo
  23606. x = outline[ i ++ ] * scale + offsetX;
  23607. y = outline[ i ++ ] * scale + offsetY;
  23608. path.lineTo( x, y );
  23609. break;
  23610. case 'q': // quadraticCurveTo
  23611. cpx = outline[ i ++ ] * scale + offsetX;
  23612. cpy = outline[ i ++ ] * scale + offsetY;
  23613. cpx1 = outline[ i ++ ] * scale + offsetX;
  23614. cpy1 = outline[ i ++ ] * scale + offsetY;
  23615. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23616. break;
  23617. case 'b': // bezierCurveTo
  23618. cpx = outline[ i ++ ] * scale + offsetX;
  23619. cpy = outline[ i ++ ] * scale + offsetY;
  23620. cpx1 = outline[ i ++ ] * scale + offsetX;
  23621. cpy1 = outline[ i ++ ] * scale + offsetY;
  23622. cpx2 = outline[ i ++ ] * scale + offsetX;
  23623. cpy2 = outline[ i ++ ] * scale + offsetY;
  23624. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23625. break;
  23626. }
  23627. }
  23628. }
  23629. return { offsetX: glyph.ha * scale, path: path };
  23630. }
  23631. /**
  23632. * @author mrdoob / http://mrdoob.com/
  23633. */
  23634. function FontLoader( manager ) {
  23635. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23636. }
  23637. Object.assign( FontLoader.prototype, {
  23638. load: function ( url, onLoad, onProgress, onError ) {
  23639. var scope = this;
  23640. var loader = new FileLoader( this.manager );
  23641. loader.setPath( this.path );
  23642. loader.load( url, function ( text ) {
  23643. var json;
  23644. try {
  23645. json = JSON.parse( text );
  23646. } catch ( e ) {
  23647. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23648. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23649. }
  23650. var font = scope.parse( json );
  23651. if ( onLoad ) onLoad( font );
  23652. }, onProgress, onError );
  23653. },
  23654. parse: function ( json ) {
  23655. return new Font( json );
  23656. },
  23657. setPath: function ( value ) {
  23658. this.path = value;
  23659. return this;
  23660. }
  23661. } );
  23662. /**
  23663. * @author alteredq / http://alteredqualia.com/
  23664. */
  23665. function Loader() {}
  23666. Loader.Handlers = {
  23667. handlers: [],
  23668. add: function ( regex, loader ) {
  23669. this.handlers.push( regex, loader );
  23670. },
  23671. get: function ( file ) {
  23672. var handlers = this.handlers;
  23673. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  23674. var regex = handlers[ i ];
  23675. var loader = handlers[ i + 1 ];
  23676. if ( regex.test( file ) ) {
  23677. return loader;
  23678. }
  23679. }
  23680. return null;
  23681. }
  23682. };
  23683. Object.assign( Loader.prototype, {
  23684. crossOrigin: 'anonymous',
  23685. onLoadStart: function () {},
  23686. onLoadProgress: function () {},
  23687. onLoadComplete: function () {},
  23688. initMaterials: function ( materials, texturePath, crossOrigin ) {
  23689. var array = [];
  23690. for ( var i = 0; i < materials.length; ++ i ) {
  23691. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  23692. }
  23693. return array;
  23694. },
  23695. createMaterial: ( function () {
  23696. var BlendingMode = {
  23697. NoBlending: NoBlending,
  23698. NormalBlending: NormalBlending,
  23699. AdditiveBlending: AdditiveBlending,
  23700. SubtractiveBlending: SubtractiveBlending,
  23701. MultiplyBlending: MultiplyBlending,
  23702. CustomBlending: CustomBlending
  23703. };
  23704. var color = new Color();
  23705. var textureLoader = new TextureLoader();
  23706. var materialLoader = new MaterialLoader();
  23707. return function createMaterial( m, texturePath, crossOrigin ) {
  23708. // convert from old material format
  23709. var textures = {};
  23710. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  23711. var fullPath = texturePath + path;
  23712. var loader = Loader.Handlers.get( fullPath );
  23713. var texture;
  23714. if ( loader !== null ) {
  23715. texture = loader.load( fullPath );
  23716. } else {
  23717. textureLoader.setCrossOrigin( crossOrigin );
  23718. texture = textureLoader.load( fullPath );
  23719. }
  23720. if ( repeat !== undefined ) {
  23721. texture.repeat.fromArray( repeat );
  23722. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  23723. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  23724. }
  23725. if ( offset !== undefined ) {
  23726. texture.offset.fromArray( offset );
  23727. }
  23728. if ( wrap !== undefined ) {
  23729. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  23730. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  23731. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  23732. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  23733. }
  23734. if ( anisotropy !== undefined ) {
  23735. texture.anisotropy = anisotropy;
  23736. }
  23737. var uuid = _Math.generateUUID();
  23738. textures[ uuid ] = texture;
  23739. return uuid;
  23740. }
  23741. //
  23742. var json = {
  23743. uuid: _Math.generateUUID(),
  23744. type: 'MeshLambertMaterial'
  23745. };
  23746. for ( var name in m ) {
  23747. var value = m[ name ];
  23748. switch ( name ) {
  23749. case 'DbgColor':
  23750. case 'DbgIndex':
  23751. case 'opticalDensity':
  23752. case 'illumination':
  23753. break;
  23754. case 'DbgName':
  23755. json.name = value;
  23756. break;
  23757. case 'blending':
  23758. json.blending = BlendingMode[ value ];
  23759. break;
  23760. case 'colorAmbient':
  23761. case 'mapAmbient':
  23762. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  23763. break;
  23764. case 'colorDiffuse':
  23765. json.color = color.fromArray( value ).getHex();
  23766. break;
  23767. case 'colorSpecular':
  23768. json.specular = color.fromArray( value ).getHex();
  23769. break;
  23770. case 'colorEmissive':
  23771. json.emissive = color.fromArray( value ).getHex();
  23772. break;
  23773. case 'specularCoef':
  23774. json.shininess = value;
  23775. break;
  23776. case 'shading':
  23777. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  23778. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  23779. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  23780. break;
  23781. case 'mapDiffuse':
  23782. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  23783. break;
  23784. case 'mapDiffuseRepeat':
  23785. case 'mapDiffuseOffset':
  23786. case 'mapDiffuseWrap':
  23787. case 'mapDiffuseAnisotropy':
  23788. break;
  23789. case 'mapEmissive':
  23790. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  23791. break;
  23792. case 'mapEmissiveRepeat':
  23793. case 'mapEmissiveOffset':
  23794. case 'mapEmissiveWrap':
  23795. case 'mapEmissiveAnisotropy':
  23796. break;
  23797. case 'mapLight':
  23798. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  23799. break;
  23800. case 'mapLightRepeat':
  23801. case 'mapLightOffset':
  23802. case 'mapLightWrap':
  23803. case 'mapLightAnisotropy':
  23804. break;
  23805. case 'mapAO':
  23806. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  23807. break;
  23808. case 'mapAORepeat':
  23809. case 'mapAOOffset':
  23810. case 'mapAOWrap':
  23811. case 'mapAOAnisotropy':
  23812. break;
  23813. case 'mapBump':
  23814. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  23815. break;
  23816. case 'mapBumpScale':
  23817. json.bumpScale = value;
  23818. break;
  23819. case 'mapBumpRepeat':
  23820. case 'mapBumpOffset':
  23821. case 'mapBumpWrap':
  23822. case 'mapBumpAnisotropy':
  23823. break;
  23824. case 'mapNormal':
  23825. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  23826. break;
  23827. case 'mapNormalFactor':
  23828. json.normalScale = value;
  23829. break;
  23830. case 'mapNormalRepeat':
  23831. case 'mapNormalOffset':
  23832. case 'mapNormalWrap':
  23833. case 'mapNormalAnisotropy':
  23834. break;
  23835. case 'mapSpecular':
  23836. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  23837. break;
  23838. case 'mapSpecularRepeat':
  23839. case 'mapSpecularOffset':
  23840. case 'mapSpecularWrap':
  23841. case 'mapSpecularAnisotropy':
  23842. break;
  23843. case 'mapMetalness':
  23844. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  23845. break;
  23846. case 'mapMetalnessRepeat':
  23847. case 'mapMetalnessOffset':
  23848. case 'mapMetalnessWrap':
  23849. case 'mapMetalnessAnisotropy':
  23850. break;
  23851. case 'mapRoughness':
  23852. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  23853. break;
  23854. case 'mapRoughnessRepeat':
  23855. case 'mapRoughnessOffset':
  23856. case 'mapRoughnessWrap':
  23857. case 'mapRoughnessAnisotropy':
  23858. break;
  23859. case 'mapAlpha':
  23860. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  23861. break;
  23862. case 'mapAlphaRepeat':
  23863. case 'mapAlphaOffset':
  23864. case 'mapAlphaWrap':
  23865. case 'mapAlphaAnisotropy':
  23866. break;
  23867. case 'flipSided':
  23868. json.side = BackSide;
  23869. break;
  23870. case 'doubleSided':
  23871. json.side = DoubleSide;
  23872. break;
  23873. case 'transparency':
  23874. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  23875. json.opacity = value;
  23876. break;
  23877. case 'depthTest':
  23878. case 'depthWrite':
  23879. case 'colorWrite':
  23880. case 'opacity':
  23881. case 'reflectivity':
  23882. case 'transparent':
  23883. case 'visible':
  23884. case 'wireframe':
  23885. json[ name ] = value;
  23886. break;
  23887. case 'vertexColors':
  23888. if ( value === true ) json.vertexColors = VertexColors;
  23889. if ( value === 'face' ) json.vertexColors = FaceColors;
  23890. break;
  23891. default:
  23892. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  23893. break;
  23894. }
  23895. }
  23896. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  23897. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  23898. if ( json.opacity < 1 ) json.transparent = true;
  23899. materialLoader.setTextures( textures );
  23900. return materialLoader.parse( json );
  23901. };
  23902. } )()
  23903. } );
  23904. /**
  23905. * @author mrdoob / http://mrdoob.com/
  23906. */
  23907. var context;
  23908. var AudioContext = {
  23909. getContext: function () {
  23910. if ( context === undefined ) {
  23911. context = new ( window.AudioContext || window.webkitAudioContext )();
  23912. }
  23913. return context;
  23914. },
  23915. setContext: function ( value ) {
  23916. context = value;
  23917. }
  23918. };
  23919. /**
  23920. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23921. */
  23922. function AudioLoader( manager ) {
  23923. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23924. }
  23925. Object.assign( AudioLoader.prototype, {
  23926. load: function ( url, onLoad, onProgress, onError ) {
  23927. var loader = new FileLoader( this.manager );
  23928. loader.setResponseType( 'arraybuffer' );
  23929. loader.setPath( this.path );
  23930. loader.load( url, function ( buffer ) {
  23931. // Create a copy of the buffer. The `decodeAudioData` method
  23932. // detaches the buffer when complete, preventing reuse.
  23933. var bufferCopy = buffer.slice( 0 );
  23934. var context = AudioContext.getContext();
  23935. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  23936. onLoad( audioBuffer );
  23937. } );
  23938. }, onProgress, onError );
  23939. },
  23940. setPath: function ( value ) {
  23941. this.path = value;
  23942. return this;
  23943. }
  23944. } );
  23945. /**
  23946. * @author bhouston / http://clara.io
  23947. * @author WestLangley / http://github.com/WestLangley
  23948. *
  23949. * Primary reference:
  23950. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23951. *
  23952. * Secondary reference:
  23953. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23954. */
  23955. // 3-band SH defined by 9 coefficients
  23956. function SphericalHarmonics3() {
  23957. this.coefficients = [];
  23958. for ( var i = 0; i < 9; i ++ ) {
  23959. this.coefficients.push( new Vector3() );
  23960. }
  23961. }
  23962. Object.assign( SphericalHarmonics3.prototype, {
  23963. isSphericalHarmonics3: true,
  23964. set: function ( coefficients ) {
  23965. for ( var i = 0; i < 9; i ++ ) {
  23966. this.coefficients[ i ].copy( coefficients[ i ] );
  23967. }
  23968. return this;
  23969. },
  23970. zero: function () {
  23971. for ( var i = 0; i < 9; i ++ ) {
  23972. this.coefficients[ i ].set( 0, 0, 0 );
  23973. }
  23974. return this;
  23975. },
  23976. // get the radiance in the direction of the normal
  23977. // target is a Vector3
  23978. getAt: function ( normal, target ) {
  23979. // normal is assumed to be unit length
  23980. var x = normal.x, y = normal.y, z = normal.z;
  23981. var coeff = this.coefficients;
  23982. // band 0
  23983. target = coeff[ 0 ] * 0.282095;
  23984. // band 1
  23985. target += coeff[ 1 ] * 0.488603 * y;
  23986. target += coeff[ 2 ] * 0.488603 * z;
  23987. target += coeff[ 3 ] * 0.488603 * x;
  23988. // band 2
  23989. target += coeff[ 4 ] * 1.092548 * ( x * y );
  23990. target += coeff[ 5 ] * 1.092548 * ( y * z );
  23991. target += coeff[ 6 ] * 0.315392 * ( 3.0 * z * z - 1.0 );
  23992. target += coeff[ 7 ] * 1.092548 * ( x * z );
  23993. target += coeff[ 8 ] * 0.546274 * ( x * x - y * y );
  23994. return target;
  23995. },
  23996. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23997. // target is a Vector3
  23998. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23999. getIrradianceAt: function ( normal, target ) {
  24000. // normal is assumed to be unit length
  24001. var x = normal.x, y = normal.y, z = normal.z;
  24002. var coeff = this.coefficients;
  24003. // band 0
  24004. target = coeff[ 0 ] * 0.886227; // π * 0.282095
  24005. // band 1
  24006. target += coeff[ 1 ] * 2.0 * 0.511664 * y; // ( 2 * π / 3 ) * 0.488603
  24007. target += coeff[ 2 ] * 2.0 * 0.511664 * z;
  24008. target += coeff[ 3 ] * 2.0 * 0.511664 * x;
  24009. // band 2
  24010. target += coeff[ 4 ] * 2.0 * 0.429043 * x * y; // ( π / 4 ) * 1.092548
  24011. target += coeff[ 5 ] * 2.0 * 0.429043 * y * z;
  24012. target += coeff[ 6 ] * ( 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24013. target += coeff[ 7 ] * 2.0 * 0.429043 * x * z;
  24014. target += coeff[ 8 ] * 0.429043 * ( x * x - y * y ); // ( π / 4 ) * 0.546274
  24015. return target;
  24016. },
  24017. add: function ( sh ) {
  24018. for ( var i = 0; i < 9; i ++ ) {
  24019. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24020. }
  24021. return this;
  24022. },
  24023. scale: function ( s ) {
  24024. for ( var i = 0; i < 9; i ++ ) {
  24025. this.coefficients[ i ].multiplyScalar( s );
  24026. }
  24027. return this;
  24028. },
  24029. lerp: function ( sh, alpha ) {
  24030. for ( var i = 0; i < 9; i ++ ) {
  24031. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24032. }
  24033. return this;
  24034. },
  24035. equals: function ( sh ) {
  24036. for ( var i = 0; i < 9; i ++ ) {
  24037. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24038. return false;
  24039. }
  24040. }
  24041. return true;
  24042. },
  24043. copy: function ( sh ) {
  24044. return this.set( sh.coefficients );
  24045. },
  24046. clone: function () {
  24047. return new this.constructor().copy( this );
  24048. },
  24049. fromArray: function ( array ) {
  24050. var coefficients = this.coefficients;
  24051. for ( var i = 0; i < 9; i ++ ) {
  24052. coefficients[ i ].fromArray( array, i * 3 );
  24053. }
  24054. return this;
  24055. },
  24056. toArray: function () {
  24057. var array = [];
  24058. var coefficients = this.coefficients;
  24059. for ( var i = 0; i < 9; i ++ ) {
  24060. coefficients[ i ].toArray( array, i * 3 );
  24061. }
  24062. return array;
  24063. }
  24064. } );
  24065. Object.assign( SphericalHarmonics3, {
  24066. // evaluate the basis functions
  24067. // shBasis is an Array[ 9 ]
  24068. getBasisAt: function ( normal, shBasis ) {
  24069. // normal is assumed to be unit length
  24070. var x = normal.x, y = normal.y, z = normal.z;
  24071. // band 0
  24072. shBasis[ 0 ] = 0.282095;
  24073. // band 1
  24074. shBasis[ 1 ] = 0.488603 * y;
  24075. shBasis[ 2 ] = 0.488603 * z;
  24076. shBasis[ 3 ] = 0.488603 * x;
  24077. // band 2
  24078. shBasis[ 4 ] = 1.092548 * x * y;
  24079. shBasis[ 5 ] = 1.092548 * y * z;
  24080. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24081. shBasis[ 7 ] = 1.092548 * x * z;
  24082. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24083. }
  24084. } );
  24085. /**
  24086. * @author WestLangley / http://github.com/WestLangley
  24087. */
  24088. // A LightProbe is a source of indirect-diffuse light
  24089. function LightProbe( color, intensity ) {
  24090. Light.call( this, color, intensity );
  24091. this.sh = new SphericalHarmonics3();
  24092. this.sh.coefficients[ 0 ].set( 1, 1, 1 );
  24093. this.type = 'LightProbe';
  24094. }
  24095. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24096. constructor: LightProbe,
  24097. isLightProbe: true,
  24098. // https://www.ppsloan.org/publications/StupidSH36.pdf
  24099. setFromCubeTexture: function ( cubeTexture ) {
  24100. var norm, lengthSq, weight, totalWeight = 0;
  24101. var coord = new Vector3();
  24102. var dir = new Vector3();
  24103. var color = new Color();
  24104. var shBasis = [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
  24105. var shCoefficients = this.sh.coefficients;
  24106. for ( var faceIndex = 0; faceIndex < 6; faceIndex ++ ) {
  24107. var image = cubeTexture.image[ faceIndex ];
  24108. var width = image.width;
  24109. var height = image.height;
  24110. var canvas = document.createElement( 'canvas' );
  24111. canvas.width = width;
  24112. canvas.height = height;
  24113. var context = canvas.getContext( '2d' );
  24114. context.drawImage( image, 0, 0, width, height );
  24115. var imageData = context.getImageData( 0, 0, width, height );
  24116. var data = imageData.data;
  24117. var imageWidth = imageData.width; // assumed to be square
  24118. var pixelSize = 2 / imageWidth;
  24119. for ( var i = 0, il = data.length; i < il; i += 4 ) { // RGBA assumed
  24120. // pixel color
  24121. color.setRGB( data[ i ] / 255, data[ i + 1 ] / 255, data[ i + 2 ] / 255 );
  24122. // convert to linear color space
  24123. color.copySRGBToLinear( color );
  24124. // pixel coordinate on unit cube
  24125. var pixelIndex = i / 4;
  24126. var col = - 1 + ( pixelIndex % imageWidth + 0.5 ) * pixelSize;
  24127. var row = 1 - ( Math.floor( pixelIndex / imageWidth ) + 0.5 ) * pixelSize;
  24128. switch ( faceIndex ) {
  24129. case 0: coord.set( - 1, row, - col ); break;
  24130. case 1: coord.set( 1, row, col ); break;
  24131. case 2: coord.set( - col, 1, - row ); break;
  24132. case 3: coord.set( - col, - 1, row ); break;
  24133. case 4: coord.set( - col, row, 1 ); break;
  24134. case 5: coord.set( col, row, - 1 ); break;
  24135. }
  24136. // weight assigned to this pixel
  24137. lengthSq = coord.lengthSq();
  24138. weight = 4 / ( Math.sqrt( lengthSq ) * lengthSq );
  24139. totalWeight += weight;
  24140. // direction vector to this pixel
  24141. dir.copy( coord ).normalize();
  24142. // evaluate SH basis functions in direction dir
  24143. SphericalHarmonics3.getBasisAt( dir, shBasis );
  24144. // accummuulate
  24145. for ( var j = 0; j < 9; j ++ ) {
  24146. shCoefficients[ j ].x += shBasis[ j ] * color.r * weight;
  24147. shCoefficients[ j ].y += shBasis[ j ] * color.g * weight;
  24148. shCoefficients[ j ].z += shBasis[ j ] * color.b * weight;
  24149. }
  24150. }
  24151. }
  24152. // normalize
  24153. norm = ( 4 * Math.PI ) / totalWeight;
  24154. for ( var j = 0; j < 9; j ++ ) {
  24155. shCoefficients[ j ].x *= norm;
  24156. shCoefficients[ j ].y *= norm;
  24157. shCoefficients[ j ].z *= norm;
  24158. }
  24159. },
  24160. copy: function ( source ) {
  24161. Light.prototype.copy.call( this, source );
  24162. this.sh.copy( source.sh );
  24163. return this;
  24164. },
  24165. toJSON: function ( meta ) {
  24166. var data = Light.prototype.toJSON.call( this, meta );
  24167. //data.sh = this.sh.toArray(); // todo
  24168. return data;
  24169. }
  24170. } );
  24171. /**
  24172. * @author mrdoob / http://mrdoob.com/
  24173. */
  24174. function StereoCamera() {
  24175. this.type = 'StereoCamera';
  24176. this.aspect = 1;
  24177. this.eyeSep = 0.064;
  24178. this.cameraL = new PerspectiveCamera();
  24179. this.cameraL.layers.enable( 1 );
  24180. this.cameraL.matrixAutoUpdate = false;
  24181. this.cameraR = new PerspectiveCamera();
  24182. this.cameraR.layers.enable( 2 );
  24183. this.cameraR.matrixAutoUpdate = false;
  24184. }
  24185. Object.assign( StereoCamera.prototype, {
  24186. update: ( function () {
  24187. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  24188. var eyeRight = new Matrix4();
  24189. var eyeLeft = new Matrix4();
  24190. return function update( camera ) {
  24191. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  24192. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  24193. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  24194. if ( needsUpdate ) {
  24195. instance = this;
  24196. focus = camera.focus;
  24197. fov = camera.fov;
  24198. aspect = camera.aspect * this.aspect;
  24199. near = camera.near;
  24200. far = camera.far;
  24201. zoom = camera.zoom;
  24202. // Off-axis stereoscopic effect based on
  24203. // http://paulbourke.net/stereographics/stereorender/
  24204. var projectionMatrix = camera.projectionMatrix.clone();
  24205. eyeSep = this.eyeSep / 2;
  24206. var eyeSepOnProjection = eyeSep * near / focus;
  24207. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  24208. var xmin, xmax;
  24209. // translate xOffset
  24210. eyeLeft.elements[ 12 ] = - eyeSep;
  24211. eyeRight.elements[ 12 ] = eyeSep;
  24212. // for left eye
  24213. xmin = - ymax * aspect + eyeSepOnProjection;
  24214. xmax = ymax * aspect + eyeSepOnProjection;
  24215. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24216. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24217. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24218. // for right eye
  24219. xmin = - ymax * aspect - eyeSepOnProjection;
  24220. xmax = ymax * aspect - eyeSepOnProjection;
  24221. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24222. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24223. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24224. }
  24225. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  24226. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  24227. };
  24228. } )()
  24229. } );
  24230. /**
  24231. * Camera for rendering cube maps
  24232. * - renders scene into axis-aligned cube
  24233. *
  24234. * @author alteredq / http://alteredqualia.com/
  24235. */
  24236. var fov = 90, aspect = 1;
  24237. function CubeCamera( near, far, cubeResolution, options ) {
  24238. Object3D.call( this );
  24239. this.type = 'CubeCamera';
  24240. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  24241. cameraPX.up.set( 0, - 1, 0 );
  24242. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  24243. this.add( cameraPX );
  24244. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  24245. cameraNX.up.set( 0, - 1, 0 );
  24246. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  24247. this.add( cameraNX );
  24248. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  24249. cameraPY.up.set( 0, 0, 1 );
  24250. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  24251. this.add( cameraPY );
  24252. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  24253. cameraNY.up.set( 0, 0, - 1 );
  24254. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  24255. this.add( cameraNY );
  24256. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  24257. cameraPZ.up.set( 0, - 1, 0 );
  24258. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  24259. this.add( cameraPZ );
  24260. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  24261. cameraNZ.up.set( 0, - 1, 0 );
  24262. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  24263. this.add( cameraNZ );
  24264. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  24265. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  24266. this.renderTarget.texture.name = "CubeCamera";
  24267. this.update = function ( renderer, scene ) {
  24268. if ( this.parent === null ) this.updateMatrixWorld();
  24269. var currentRenderTarget = renderer.getRenderTarget();
  24270. var renderTarget = this.renderTarget;
  24271. var generateMipmaps = renderTarget.texture.generateMipmaps;
  24272. renderTarget.texture.generateMipmaps = false;
  24273. renderer.setRenderTarget( renderTarget, 0 );
  24274. renderer.render( scene, cameraPX );
  24275. renderer.setRenderTarget( renderTarget, 1 );
  24276. renderer.render( scene, cameraNX );
  24277. renderer.setRenderTarget( renderTarget, 2 );
  24278. renderer.render( scene, cameraPY );
  24279. renderer.setRenderTarget( renderTarget, 3 );
  24280. renderer.render( scene, cameraNY );
  24281. renderer.setRenderTarget( renderTarget, 4 );
  24282. renderer.render( scene, cameraPZ );
  24283. renderTarget.texture.generateMipmaps = generateMipmaps;
  24284. renderer.setRenderTarget( renderTarget, 5 );
  24285. renderer.render( scene, cameraNZ );
  24286. renderer.setRenderTarget( currentRenderTarget );
  24287. };
  24288. this.clear = function ( renderer, color, depth, stencil ) {
  24289. var currentRenderTarget = renderer.getRenderTarget();
  24290. var renderTarget = this.renderTarget;
  24291. for ( var i = 0; i < 6; i ++ ) {
  24292. renderer.setRenderTarget( renderTarget, i );
  24293. renderer.clear( color, depth, stencil );
  24294. }
  24295. renderer.setRenderTarget( currentRenderTarget );
  24296. };
  24297. }
  24298. CubeCamera.prototype = Object.create( Object3D.prototype );
  24299. CubeCamera.prototype.constructor = CubeCamera;
  24300. /**
  24301. * @author alteredq / http://alteredqualia.com/
  24302. */
  24303. function Clock( autoStart ) {
  24304. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24305. this.startTime = 0;
  24306. this.oldTime = 0;
  24307. this.elapsedTime = 0;
  24308. this.running = false;
  24309. }
  24310. Object.assign( Clock.prototype, {
  24311. start: function () {
  24312. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24313. this.oldTime = this.startTime;
  24314. this.elapsedTime = 0;
  24315. this.running = true;
  24316. },
  24317. stop: function () {
  24318. this.getElapsedTime();
  24319. this.running = false;
  24320. this.autoStart = false;
  24321. },
  24322. getElapsedTime: function () {
  24323. this.getDelta();
  24324. return this.elapsedTime;
  24325. },
  24326. getDelta: function () {
  24327. var diff = 0;
  24328. if ( this.autoStart && ! this.running ) {
  24329. this.start();
  24330. return 0;
  24331. }
  24332. if ( this.running ) {
  24333. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24334. diff = ( newTime - this.oldTime ) / 1000;
  24335. this.oldTime = newTime;
  24336. this.elapsedTime += diff;
  24337. }
  24338. return diff;
  24339. }
  24340. } );
  24341. /**
  24342. * @author mrdoob / http://mrdoob.com/
  24343. */
  24344. function AudioListener() {
  24345. Object3D.call( this );
  24346. this.type = 'AudioListener';
  24347. this.context = AudioContext.getContext();
  24348. this.gain = this.context.createGain();
  24349. this.gain.connect( this.context.destination );
  24350. this.filter = null;
  24351. this.timeDelta = 0;
  24352. }
  24353. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24354. constructor: AudioListener,
  24355. getInput: function () {
  24356. return this.gain;
  24357. },
  24358. removeFilter: function ( ) {
  24359. if ( this.filter !== null ) {
  24360. this.gain.disconnect( this.filter );
  24361. this.filter.disconnect( this.context.destination );
  24362. this.gain.connect( this.context.destination );
  24363. this.filter = null;
  24364. }
  24365. return this;
  24366. },
  24367. getFilter: function () {
  24368. return this.filter;
  24369. },
  24370. setFilter: function ( value ) {
  24371. if ( this.filter !== null ) {
  24372. this.gain.disconnect( this.filter );
  24373. this.filter.disconnect( this.context.destination );
  24374. } else {
  24375. this.gain.disconnect( this.context.destination );
  24376. }
  24377. this.filter = value;
  24378. this.gain.connect( this.filter );
  24379. this.filter.connect( this.context.destination );
  24380. return this;
  24381. },
  24382. getMasterVolume: function () {
  24383. return this.gain.gain.value;
  24384. },
  24385. setMasterVolume: function ( value ) {
  24386. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24387. return this;
  24388. },
  24389. updateMatrixWorld: ( function () {
  24390. var position = new Vector3();
  24391. var quaternion = new Quaternion();
  24392. var scale = new Vector3();
  24393. var orientation = new Vector3();
  24394. var clock = new Clock();
  24395. return function updateMatrixWorld( force ) {
  24396. Object3D.prototype.updateMatrixWorld.call( this, force );
  24397. var listener = this.context.listener;
  24398. var up = this.up;
  24399. this.timeDelta = clock.getDelta();
  24400. this.matrixWorld.decompose( position, quaternion, scale );
  24401. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24402. if ( listener.positionX ) {
  24403. // code path for Chrome (see #14393)
  24404. var endTime = this.context.currentTime + this.timeDelta;
  24405. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24406. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24407. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24408. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24409. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24410. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24411. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24412. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24413. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24414. } else {
  24415. listener.setPosition( position.x, position.y, position.z );
  24416. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24417. }
  24418. };
  24419. } )()
  24420. } );
  24421. /**
  24422. * @author mrdoob / http://mrdoob.com/
  24423. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24424. */
  24425. function Audio( listener ) {
  24426. Object3D.call( this );
  24427. this.type = 'Audio';
  24428. this.listener = listener;
  24429. this.context = listener.context;
  24430. this.gain = this.context.createGain();
  24431. this.gain.connect( listener.getInput() );
  24432. this.autoplay = false;
  24433. this.buffer = null;
  24434. this.detune = 0;
  24435. this.loop = false;
  24436. this.startTime = 0;
  24437. this.offset = 0;
  24438. this.playbackRate = 1;
  24439. this.isPlaying = false;
  24440. this.hasPlaybackControl = true;
  24441. this.sourceType = 'empty';
  24442. this.filters = [];
  24443. }
  24444. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24445. constructor: Audio,
  24446. getOutput: function () {
  24447. return this.gain;
  24448. },
  24449. setNodeSource: function ( audioNode ) {
  24450. this.hasPlaybackControl = false;
  24451. this.sourceType = 'audioNode';
  24452. this.source = audioNode;
  24453. this.connect();
  24454. return this;
  24455. },
  24456. setMediaElementSource: function ( mediaElement ) {
  24457. this.hasPlaybackControl = false;
  24458. this.sourceType = 'mediaNode';
  24459. this.source = this.context.createMediaElementSource( mediaElement );
  24460. this.connect();
  24461. return this;
  24462. },
  24463. setBuffer: function ( audioBuffer ) {
  24464. this.buffer = audioBuffer;
  24465. this.sourceType = 'buffer';
  24466. if ( this.autoplay ) this.play();
  24467. return this;
  24468. },
  24469. play: function () {
  24470. if ( this.isPlaying === true ) {
  24471. console.warn( 'THREE.Audio: Audio is already playing.' );
  24472. return;
  24473. }
  24474. if ( this.hasPlaybackControl === false ) {
  24475. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24476. return;
  24477. }
  24478. var source = this.context.createBufferSource();
  24479. source.buffer = this.buffer;
  24480. source.loop = this.loop;
  24481. source.onended = this.onEnded.bind( this );
  24482. this.startTime = this.context.currentTime;
  24483. source.start( this.startTime, this.offset );
  24484. this.isPlaying = true;
  24485. this.source = source;
  24486. this.setDetune( this.detune );
  24487. this.setPlaybackRate( this.playbackRate );
  24488. return this.connect();
  24489. },
  24490. pause: function () {
  24491. if ( this.hasPlaybackControl === false ) {
  24492. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24493. return;
  24494. }
  24495. if ( this.isPlaying === true ) {
  24496. this.source.stop();
  24497. this.source.onended = null;
  24498. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24499. this.isPlaying = false;
  24500. }
  24501. return this;
  24502. },
  24503. stop: function () {
  24504. if ( this.hasPlaybackControl === false ) {
  24505. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24506. return;
  24507. }
  24508. this.source.stop();
  24509. this.source.onended = null;
  24510. this.offset = 0;
  24511. this.isPlaying = false;
  24512. return this;
  24513. },
  24514. connect: function () {
  24515. if ( this.filters.length > 0 ) {
  24516. this.source.connect( this.filters[ 0 ] );
  24517. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24518. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24519. }
  24520. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24521. } else {
  24522. this.source.connect( this.getOutput() );
  24523. }
  24524. return this;
  24525. },
  24526. disconnect: function () {
  24527. if ( this.filters.length > 0 ) {
  24528. this.source.disconnect( this.filters[ 0 ] );
  24529. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24530. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24531. }
  24532. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24533. } else {
  24534. this.source.disconnect( this.getOutput() );
  24535. }
  24536. return this;
  24537. },
  24538. getFilters: function () {
  24539. return this.filters;
  24540. },
  24541. setFilters: function ( value ) {
  24542. if ( ! value ) value = [];
  24543. if ( this.isPlaying === true ) {
  24544. this.disconnect();
  24545. this.filters = value;
  24546. this.connect();
  24547. } else {
  24548. this.filters = value;
  24549. }
  24550. return this;
  24551. },
  24552. setDetune: function ( value ) {
  24553. this.detune = value;
  24554. if ( this.source.detune === undefined ) return; // only set detune when available
  24555. if ( this.isPlaying === true ) {
  24556. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24557. }
  24558. return this;
  24559. },
  24560. getDetune: function () {
  24561. return this.detune;
  24562. },
  24563. getFilter: function () {
  24564. return this.getFilters()[ 0 ];
  24565. },
  24566. setFilter: function ( filter ) {
  24567. return this.setFilters( filter ? [ filter ] : [] );
  24568. },
  24569. setPlaybackRate: function ( value ) {
  24570. if ( this.hasPlaybackControl === false ) {
  24571. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24572. return;
  24573. }
  24574. this.playbackRate = value;
  24575. if ( this.isPlaying === true ) {
  24576. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24577. }
  24578. return this;
  24579. },
  24580. getPlaybackRate: function () {
  24581. return this.playbackRate;
  24582. },
  24583. onEnded: function () {
  24584. this.isPlaying = false;
  24585. },
  24586. getLoop: function () {
  24587. if ( this.hasPlaybackControl === false ) {
  24588. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24589. return false;
  24590. }
  24591. return this.loop;
  24592. },
  24593. setLoop: function ( value ) {
  24594. if ( this.hasPlaybackControl === false ) {
  24595. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24596. return;
  24597. }
  24598. this.loop = value;
  24599. if ( this.isPlaying === true ) {
  24600. this.source.loop = this.loop;
  24601. }
  24602. return this;
  24603. },
  24604. getVolume: function () {
  24605. return this.gain.gain.value;
  24606. },
  24607. setVolume: function ( value ) {
  24608. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24609. return this;
  24610. }
  24611. } );
  24612. /**
  24613. * @author mrdoob / http://mrdoob.com/
  24614. */
  24615. function PositionalAudio( listener ) {
  24616. Audio.call( this, listener );
  24617. this.panner = this.context.createPanner();
  24618. this.panner.connect( this.gain );
  24619. }
  24620. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24621. constructor: PositionalAudio,
  24622. getOutput: function () {
  24623. return this.panner;
  24624. },
  24625. getRefDistance: function () {
  24626. return this.panner.refDistance;
  24627. },
  24628. setRefDistance: function ( value ) {
  24629. this.panner.refDistance = value;
  24630. return this;
  24631. },
  24632. getRolloffFactor: function () {
  24633. return this.panner.rolloffFactor;
  24634. },
  24635. setRolloffFactor: function ( value ) {
  24636. this.panner.rolloffFactor = value;
  24637. return this;
  24638. },
  24639. getDistanceModel: function () {
  24640. return this.panner.distanceModel;
  24641. },
  24642. setDistanceModel: function ( value ) {
  24643. this.panner.distanceModel = value;
  24644. return this;
  24645. },
  24646. getMaxDistance: function () {
  24647. return this.panner.maxDistance;
  24648. },
  24649. setMaxDistance: function ( value ) {
  24650. this.panner.maxDistance = value;
  24651. return this;
  24652. },
  24653. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24654. this.panner.coneInnerAngle = coneInnerAngle;
  24655. this.panner.coneOuterAngle = coneOuterAngle;
  24656. this.panner.coneOuterGain = coneOuterGain;
  24657. return this;
  24658. },
  24659. updateMatrixWorld: ( function () {
  24660. var position = new Vector3();
  24661. var quaternion = new Quaternion();
  24662. var scale = new Vector3();
  24663. var orientation = new Vector3();
  24664. return function updateMatrixWorld( force ) {
  24665. Object3D.prototype.updateMatrixWorld.call( this, force );
  24666. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24667. this.matrixWorld.decompose( position, quaternion, scale );
  24668. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24669. var panner = this.panner;
  24670. if ( panner.positionX ) {
  24671. // code path for Chrome and Firefox (see #14393)
  24672. var endTime = this.context.currentTime + this.listener.timeDelta;
  24673. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24674. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24675. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24676. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24677. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24678. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24679. } else {
  24680. panner.setPosition( position.x, position.y, position.z );
  24681. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24682. }
  24683. };
  24684. } )()
  24685. } );
  24686. /**
  24687. * @author mrdoob / http://mrdoob.com/
  24688. */
  24689. function AudioAnalyser( audio, fftSize ) {
  24690. this.analyser = audio.context.createAnalyser();
  24691. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24692. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24693. audio.getOutput().connect( this.analyser );
  24694. }
  24695. Object.assign( AudioAnalyser.prototype, {
  24696. getFrequencyData: function () {
  24697. this.analyser.getByteFrequencyData( this.data );
  24698. return this.data;
  24699. },
  24700. getAverageFrequency: function () {
  24701. var value = 0, data = this.getFrequencyData();
  24702. for ( var i = 0; i < data.length; i ++ ) {
  24703. value += data[ i ];
  24704. }
  24705. return value / data.length;
  24706. }
  24707. } );
  24708. /**
  24709. *
  24710. * Buffered scene graph property that allows weighted accumulation.
  24711. *
  24712. *
  24713. * @author Ben Houston / http://clara.io/
  24714. * @author David Sarno / http://lighthaus.us/
  24715. * @author tschw
  24716. */
  24717. function PropertyMixer( binding, typeName, valueSize ) {
  24718. this.binding = binding;
  24719. this.valueSize = valueSize;
  24720. var bufferType = Float64Array,
  24721. mixFunction;
  24722. switch ( typeName ) {
  24723. case 'quaternion':
  24724. mixFunction = this._slerp;
  24725. break;
  24726. case 'string':
  24727. case 'bool':
  24728. bufferType = Array;
  24729. mixFunction = this._select;
  24730. break;
  24731. default:
  24732. mixFunction = this._lerp;
  24733. }
  24734. this.buffer = new bufferType( valueSize * 4 );
  24735. // layout: [ incoming | accu0 | accu1 | orig ]
  24736. //
  24737. // interpolators can use .buffer as their .result
  24738. // the data then goes to 'incoming'
  24739. //
  24740. // 'accu0' and 'accu1' are used frame-interleaved for
  24741. // the cumulative result and are compared to detect
  24742. // changes
  24743. //
  24744. // 'orig' stores the original state of the property
  24745. this._mixBufferRegion = mixFunction;
  24746. this.cumulativeWeight = 0;
  24747. this.useCount = 0;
  24748. this.referenceCount = 0;
  24749. }
  24750. Object.assign( PropertyMixer.prototype, {
  24751. // accumulate data in the 'incoming' region into 'accu<i>'
  24752. accumulate: function ( accuIndex, weight ) {
  24753. // note: happily accumulating nothing when weight = 0, the caller knows
  24754. // the weight and shouldn't have made the call in the first place
  24755. var buffer = this.buffer,
  24756. stride = this.valueSize,
  24757. offset = accuIndex * stride + stride,
  24758. currentWeight = this.cumulativeWeight;
  24759. if ( currentWeight === 0 ) {
  24760. // accuN := incoming * weight
  24761. for ( var i = 0; i !== stride; ++ i ) {
  24762. buffer[ offset + i ] = buffer[ i ];
  24763. }
  24764. currentWeight = weight;
  24765. } else {
  24766. // accuN := accuN + incoming * weight
  24767. currentWeight += weight;
  24768. var mix = weight / currentWeight;
  24769. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24770. }
  24771. this.cumulativeWeight = currentWeight;
  24772. },
  24773. // apply the state of 'accu<i>' to the binding when accus differ
  24774. apply: function ( accuIndex ) {
  24775. var stride = this.valueSize,
  24776. buffer = this.buffer,
  24777. offset = accuIndex * stride + stride,
  24778. weight = this.cumulativeWeight,
  24779. binding = this.binding;
  24780. this.cumulativeWeight = 0;
  24781. if ( weight < 1 ) {
  24782. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24783. var originalValueOffset = stride * 3;
  24784. this._mixBufferRegion(
  24785. buffer, offset, originalValueOffset, 1 - weight, stride );
  24786. }
  24787. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  24788. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24789. // value has changed -> update scene graph
  24790. binding.setValue( buffer, offset );
  24791. break;
  24792. }
  24793. }
  24794. },
  24795. // remember the state of the bound property and copy it to both accus
  24796. saveOriginalState: function () {
  24797. var binding = this.binding;
  24798. var buffer = this.buffer,
  24799. stride = this.valueSize,
  24800. originalValueOffset = stride * 3;
  24801. binding.getValue( buffer, originalValueOffset );
  24802. // accu[0..1] := orig -- initially detect changes against the original
  24803. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24804. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24805. }
  24806. this.cumulativeWeight = 0;
  24807. },
  24808. // apply the state previously taken via 'saveOriginalState' to the binding
  24809. restoreOriginalState: function () {
  24810. var originalValueOffset = this.valueSize * 3;
  24811. this.binding.setValue( this.buffer, originalValueOffset );
  24812. },
  24813. // mix functions
  24814. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24815. if ( t >= 0.5 ) {
  24816. for ( var i = 0; i !== stride; ++ i ) {
  24817. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24818. }
  24819. }
  24820. },
  24821. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24822. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24823. },
  24824. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24825. var s = 1 - t;
  24826. for ( var i = 0; i !== stride; ++ i ) {
  24827. var j = dstOffset + i;
  24828. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24829. }
  24830. }
  24831. } );
  24832. /**
  24833. *
  24834. * A reference to a real property in the scene graph.
  24835. *
  24836. *
  24837. * @author Ben Houston / http://clara.io/
  24838. * @author David Sarno / http://lighthaus.us/
  24839. * @author tschw
  24840. */
  24841. // Characters [].:/ are reserved for track binding syntax.
  24842. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24843. function Composite( targetGroup, path, optionalParsedPath ) {
  24844. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24845. this._targetGroup = targetGroup;
  24846. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24847. }
  24848. Object.assign( Composite.prototype, {
  24849. getValue: function ( array, offset ) {
  24850. this.bind(); // bind all binding
  24851. var firstValidIndex = this._targetGroup.nCachedObjects_,
  24852. binding = this._bindings[ firstValidIndex ];
  24853. // and only call .getValue on the first
  24854. if ( binding !== undefined ) binding.getValue( array, offset );
  24855. },
  24856. setValue: function ( array, offset ) {
  24857. var bindings = this._bindings;
  24858. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24859. bindings[ i ].setValue( array, offset );
  24860. }
  24861. },
  24862. bind: function () {
  24863. var bindings = this._bindings;
  24864. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24865. bindings[ i ].bind();
  24866. }
  24867. },
  24868. unbind: function () {
  24869. var bindings = this._bindings;
  24870. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24871. bindings[ i ].unbind();
  24872. }
  24873. }
  24874. } );
  24875. function PropertyBinding( rootNode, path, parsedPath ) {
  24876. this.path = path;
  24877. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24878. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24879. this.rootNode = rootNode;
  24880. }
  24881. Object.assign( PropertyBinding, {
  24882. Composite: Composite,
  24883. create: function ( root, path, parsedPath ) {
  24884. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24885. return new PropertyBinding( root, path, parsedPath );
  24886. } else {
  24887. return new PropertyBinding.Composite( root, path, parsedPath );
  24888. }
  24889. },
  24890. /**
  24891. * Replaces spaces with underscores and removes unsupported characters from
  24892. * node names, to ensure compatibility with parseTrackName().
  24893. *
  24894. * @param {string} name Node name to be sanitized.
  24895. * @return {string}
  24896. */
  24897. sanitizeNodeName: ( function () {
  24898. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  24899. return function sanitizeNodeName( name ) {
  24900. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  24901. };
  24902. }() ),
  24903. parseTrackName: function () {
  24904. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24905. // only latin characters, and the unicode \p{L} is not yet supported. So
  24906. // instead, we exclude reserved characters and match everything else.
  24907. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  24908. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24909. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24910. // be matched to parse the rest of the track name.
  24911. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  24912. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24913. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  24914. // Object on target node, and accessor. May not contain reserved
  24915. // characters. Accessor may contain any character except closing bracket.
  24916. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  24917. // Property and accessor. May not contain reserved characters. Accessor may
  24918. // contain any non-bracket characters.
  24919. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  24920. var trackRe = new RegExp( ''
  24921. + '^'
  24922. + directoryRe
  24923. + nodeRe
  24924. + objectRe
  24925. + propertyRe
  24926. + '$'
  24927. );
  24928. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24929. return function parseTrackName( trackName ) {
  24930. var matches = trackRe.exec( trackName );
  24931. if ( ! matches ) {
  24932. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24933. }
  24934. var results = {
  24935. // directoryName: matches[ 1 ], // (tschw) currently unused
  24936. nodeName: matches[ 2 ],
  24937. objectName: matches[ 3 ],
  24938. objectIndex: matches[ 4 ],
  24939. propertyName: matches[ 5 ], // required
  24940. propertyIndex: matches[ 6 ]
  24941. };
  24942. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24943. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24944. var objectName = results.nodeName.substring( lastDot + 1 );
  24945. // Object names must be checked against a whitelist. Otherwise, there
  24946. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24947. // 'bar' could be the objectName, or part of a nodeName (which can
  24948. // include '.' characters).
  24949. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24950. results.nodeName = results.nodeName.substring( 0, lastDot );
  24951. results.objectName = objectName;
  24952. }
  24953. }
  24954. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24955. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24956. }
  24957. return results;
  24958. };
  24959. }(),
  24960. findNode: function ( root, nodeName ) {
  24961. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24962. return root;
  24963. }
  24964. // search into skeleton bones.
  24965. if ( root.skeleton ) {
  24966. var bone = root.skeleton.getBoneByName( nodeName );
  24967. if ( bone !== undefined ) {
  24968. return bone;
  24969. }
  24970. }
  24971. // search into node subtree.
  24972. if ( root.children ) {
  24973. var searchNodeSubtree = function ( children ) {
  24974. for ( var i = 0; i < children.length; i ++ ) {
  24975. var childNode = children[ i ];
  24976. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24977. return childNode;
  24978. }
  24979. var result = searchNodeSubtree( childNode.children );
  24980. if ( result ) return result;
  24981. }
  24982. return null;
  24983. };
  24984. var subTreeNode = searchNodeSubtree( root.children );
  24985. if ( subTreeNode ) {
  24986. return subTreeNode;
  24987. }
  24988. }
  24989. return null;
  24990. }
  24991. } );
  24992. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24993. // these are used to "bind" a nonexistent property
  24994. _getValue_unavailable: function () {},
  24995. _setValue_unavailable: function () {},
  24996. BindingType: {
  24997. Direct: 0,
  24998. EntireArray: 1,
  24999. ArrayElement: 2,
  25000. HasFromToArray: 3
  25001. },
  25002. Versioning: {
  25003. None: 0,
  25004. NeedsUpdate: 1,
  25005. MatrixWorldNeedsUpdate: 2
  25006. },
  25007. GetterByBindingType: [
  25008. function getValue_direct( buffer, offset ) {
  25009. buffer[ offset ] = this.node[ this.propertyName ];
  25010. },
  25011. function getValue_array( buffer, offset ) {
  25012. var source = this.resolvedProperty;
  25013. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25014. buffer[ offset ++ ] = source[ i ];
  25015. }
  25016. },
  25017. function getValue_arrayElement( buffer, offset ) {
  25018. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25019. },
  25020. function getValue_toArray( buffer, offset ) {
  25021. this.resolvedProperty.toArray( buffer, offset );
  25022. }
  25023. ],
  25024. SetterByBindingTypeAndVersioning: [
  25025. [
  25026. // Direct
  25027. function setValue_direct( buffer, offset ) {
  25028. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25029. },
  25030. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25031. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25032. this.targetObject.needsUpdate = true;
  25033. },
  25034. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25035. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25036. this.targetObject.matrixWorldNeedsUpdate = true;
  25037. }
  25038. ], [
  25039. // EntireArray
  25040. function setValue_array( buffer, offset ) {
  25041. var dest = this.resolvedProperty;
  25042. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25043. dest[ i ] = buffer[ offset ++ ];
  25044. }
  25045. },
  25046. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25047. var dest = this.resolvedProperty;
  25048. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25049. dest[ i ] = buffer[ offset ++ ];
  25050. }
  25051. this.targetObject.needsUpdate = true;
  25052. },
  25053. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25054. var dest = this.resolvedProperty;
  25055. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25056. dest[ i ] = buffer[ offset ++ ];
  25057. }
  25058. this.targetObject.matrixWorldNeedsUpdate = true;
  25059. }
  25060. ], [
  25061. // ArrayElement
  25062. function setValue_arrayElement( buffer, offset ) {
  25063. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25064. },
  25065. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25066. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25067. this.targetObject.needsUpdate = true;
  25068. },
  25069. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25070. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25071. this.targetObject.matrixWorldNeedsUpdate = true;
  25072. }
  25073. ], [
  25074. // HasToFromArray
  25075. function setValue_fromArray( buffer, offset ) {
  25076. this.resolvedProperty.fromArray( buffer, offset );
  25077. },
  25078. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25079. this.resolvedProperty.fromArray( buffer, offset );
  25080. this.targetObject.needsUpdate = true;
  25081. },
  25082. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25083. this.resolvedProperty.fromArray( buffer, offset );
  25084. this.targetObject.matrixWorldNeedsUpdate = true;
  25085. }
  25086. ]
  25087. ],
  25088. getValue: function getValue_unbound( targetArray, offset ) {
  25089. this.bind();
  25090. this.getValue( targetArray, offset );
  25091. // Note: This class uses a State pattern on a per-method basis:
  25092. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25093. // prototype version of these methods with one that represents
  25094. // the bound state. When the property is not found, the methods
  25095. // become no-ops.
  25096. },
  25097. setValue: function getValue_unbound( sourceArray, offset ) {
  25098. this.bind();
  25099. this.setValue( sourceArray, offset );
  25100. },
  25101. // create getter / setter pair for a property in the scene graph
  25102. bind: function () {
  25103. var targetObject = this.node,
  25104. parsedPath = this.parsedPath,
  25105. objectName = parsedPath.objectName,
  25106. propertyName = parsedPath.propertyName,
  25107. propertyIndex = parsedPath.propertyIndex;
  25108. if ( ! targetObject ) {
  25109. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25110. this.node = targetObject;
  25111. }
  25112. // set fail state so we can just 'return' on error
  25113. this.getValue = this._getValue_unavailable;
  25114. this.setValue = this._setValue_unavailable;
  25115. // ensure there is a value node
  25116. if ( ! targetObject ) {
  25117. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25118. return;
  25119. }
  25120. if ( objectName ) {
  25121. var objectIndex = parsedPath.objectIndex;
  25122. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25123. switch ( objectName ) {
  25124. case 'materials':
  25125. if ( ! targetObject.material ) {
  25126. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25127. return;
  25128. }
  25129. if ( ! targetObject.material.materials ) {
  25130. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25131. return;
  25132. }
  25133. targetObject = targetObject.material.materials;
  25134. break;
  25135. case 'bones':
  25136. if ( ! targetObject.skeleton ) {
  25137. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25138. return;
  25139. }
  25140. // potential future optimization: skip this if propertyIndex is already an integer
  25141. // and convert the integer string to a true integer.
  25142. targetObject = targetObject.skeleton.bones;
  25143. // support resolving morphTarget names into indices.
  25144. for ( var i = 0; i < targetObject.length; i ++ ) {
  25145. if ( targetObject[ i ].name === objectIndex ) {
  25146. objectIndex = i;
  25147. break;
  25148. }
  25149. }
  25150. break;
  25151. default:
  25152. if ( targetObject[ objectName ] === undefined ) {
  25153. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25154. return;
  25155. }
  25156. targetObject = targetObject[ objectName ];
  25157. }
  25158. if ( objectIndex !== undefined ) {
  25159. if ( targetObject[ objectIndex ] === undefined ) {
  25160. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25161. return;
  25162. }
  25163. targetObject = targetObject[ objectIndex ];
  25164. }
  25165. }
  25166. // resolve property
  25167. var nodeProperty = targetObject[ propertyName ];
  25168. if ( nodeProperty === undefined ) {
  25169. var nodeName = parsedPath.nodeName;
  25170. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25171. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25172. return;
  25173. }
  25174. // determine versioning scheme
  25175. var versioning = this.Versioning.None;
  25176. this.targetObject = targetObject;
  25177. if ( targetObject.needsUpdate !== undefined ) { // material
  25178. versioning = this.Versioning.NeedsUpdate;
  25179. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25180. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25181. }
  25182. // determine how the property gets bound
  25183. var bindingType = this.BindingType.Direct;
  25184. if ( propertyIndex !== undefined ) {
  25185. // access a sub element of the property array (only primitives are supported right now)
  25186. if ( propertyName === "morphTargetInfluences" ) {
  25187. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25188. // support resolving morphTarget names into indices.
  25189. if ( ! targetObject.geometry ) {
  25190. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25191. return;
  25192. }
  25193. if ( targetObject.geometry.isBufferGeometry ) {
  25194. if ( ! targetObject.geometry.morphAttributes ) {
  25195. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25196. return;
  25197. }
  25198. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25199. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25200. propertyIndex = i;
  25201. break;
  25202. }
  25203. }
  25204. } else {
  25205. if ( ! targetObject.geometry.morphTargets ) {
  25206. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25207. return;
  25208. }
  25209. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25210. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25211. propertyIndex = i;
  25212. break;
  25213. }
  25214. }
  25215. }
  25216. }
  25217. bindingType = this.BindingType.ArrayElement;
  25218. this.resolvedProperty = nodeProperty;
  25219. this.propertyIndex = propertyIndex;
  25220. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25221. // must use copy for Object3D.Euler/Quaternion
  25222. bindingType = this.BindingType.HasFromToArray;
  25223. this.resolvedProperty = nodeProperty;
  25224. } else if ( Array.isArray( nodeProperty ) ) {
  25225. bindingType = this.BindingType.EntireArray;
  25226. this.resolvedProperty = nodeProperty;
  25227. } else {
  25228. this.propertyName = propertyName;
  25229. }
  25230. // select getter / setter
  25231. this.getValue = this.GetterByBindingType[ bindingType ];
  25232. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25233. },
  25234. unbind: function () {
  25235. this.node = null;
  25236. // back to the prototype version of getValue / setValue
  25237. // note: avoiding to mutate the shape of 'this' via 'delete'
  25238. this.getValue = this._getValue_unbound;
  25239. this.setValue = this._setValue_unbound;
  25240. }
  25241. } );
  25242. //!\ DECLARE ALIAS AFTER assign prototype !
  25243. Object.assign( PropertyBinding.prototype, {
  25244. // initial state of these methods that calls 'bind'
  25245. _getValue_unbound: PropertyBinding.prototype.getValue,
  25246. _setValue_unbound: PropertyBinding.prototype.setValue,
  25247. } );
  25248. /**
  25249. *
  25250. * A group of objects that receives a shared animation state.
  25251. *
  25252. * Usage:
  25253. *
  25254. * - Add objects you would otherwise pass as 'root' to the
  25255. * constructor or the .clipAction method of AnimationMixer.
  25256. *
  25257. * - Instead pass this object as 'root'.
  25258. *
  25259. * - You can also add and remove objects later when the mixer
  25260. * is running.
  25261. *
  25262. * Note:
  25263. *
  25264. * Objects of this class appear as one object to the mixer,
  25265. * so cache control of the individual objects must be done
  25266. * on the group.
  25267. *
  25268. * Limitation:
  25269. *
  25270. * - The animated properties must be compatible among the
  25271. * all objects in the group.
  25272. *
  25273. * - A single property can either be controlled through a
  25274. * target group or directly, but not both.
  25275. *
  25276. * @author tschw
  25277. */
  25278. function AnimationObjectGroup() {
  25279. this.uuid = _Math.generateUUID();
  25280. // cached objects followed by the active ones
  25281. this._objects = Array.prototype.slice.call( arguments );
  25282. this.nCachedObjects_ = 0; // threshold
  25283. // note: read by PropertyBinding.Composite
  25284. var indices = {};
  25285. this._indicesByUUID = indices; // for bookkeeping
  25286. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25287. indices[ arguments[ i ].uuid ] = i;
  25288. }
  25289. this._paths = []; // inside: string
  25290. this._parsedPaths = []; // inside: { we don't care, here }
  25291. this._bindings = []; // inside: Array< PropertyBinding >
  25292. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25293. var scope = this;
  25294. this.stats = {
  25295. objects: {
  25296. get total() {
  25297. return scope._objects.length;
  25298. },
  25299. get inUse() {
  25300. return this.total - scope.nCachedObjects_;
  25301. }
  25302. },
  25303. get bindingsPerObject() {
  25304. return scope._bindings.length;
  25305. }
  25306. };
  25307. }
  25308. Object.assign( AnimationObjectGroup.prototype, {
  25309. isAnimationObjectGroup: true,
  25310. add: function () {
  25311. var objects = this._objects,
  25312. nObjects = objects.length,
  25313. nCachedObjects = this.nCachedObjects_,
  25314. indicesByUUID = this._indicesByUUID,
  25315. paths = this._paths,
  25316. parsedPaths = this._parsedPaths,
  25317. bindings = this._bindings,
  25318. nBindings = bindings.length,
  25319. knownObject = undefined;
  25320. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25321. var object = arguments[ i ],
  25322. uuid = object.uuid,
  25323. index = indicesByUUID[ uuid ];
  25324. if ( index === undefined ) {
  25325. // unknown object -> add it to the ACTIVE region
  25326. index = nObjects ++;
  25327. indicesByUUID[ uuid ] = index;
  25328. objects.push( object );
  25329. // accounting is done, now do the same for all bindings
  25330. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25331. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25332. }
  25333. } else if ( index < nCachedObjects ) {
  25334. knownObject = objects[ index ];
  25335. // move existing object to the ACTIVE region
  25336. var firstActiveIndex = -- nCachedObjects,
  25337. lastCachedObject = objects[ firstActiveIndex ];
  25338. indicesByUUID[ lastCachedObject.uuid ] = index;
  25339. objects[ index ] = lastCachedObject;
  25340. indicesByUUID[ uuid ] = firstActiveIndex;
  25341. objects[ firstActiveIndex ] = object;
  25342. // accounting is done, now do the same for all bindings
  25343. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25344. var bindingsForPath = bindings[ j ],
  25345. lastCached = bindingsForPath[ firstActiveIndex ],
  25346. binding = bindingsForPath[ index ];
  25347. bindingsForPath[ index ] = lastCached;
  25348. if ( binding === undefined ) {
  25349. // since we do not bother to create new bindings
  25350. // for objects that are cached, the binding may
  25351. // or may not exist
  25352. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25353. }
  25354. bindingsForPath[ firstActiveIndex ] = binding;
  25355. }
  25356. } else if ( objects[ index ] !== knownObject ) {
  25357. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25358. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25359. } // else the object is already where we want it to be
  25360. } // for arguments
  25361. this.nCachedObjects_ = nCachedObjects;
  25362. },
  25363. remove: function () {
  25364. var objects = this._objects,
  25365. nCachedObjects = this.nCachedObjects_,
  25366. indicesByUUID = this._indicesByUUID,
  25367. bindings = this._bindings,
  25368. nBindings = bindings.length;
  25369. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25370. var object = arguments[ i ],
  25371. uuid = object.uuid,
  25372. index = indicesByUUID[ uuid ];
  25373. if ( index !== undefined && index >= nCachedObjects ) {
  25374. // move existing object into the CACHED region
  25375. var lastCachedIndex = nCachedObjects ++,
  25376. firstActiveObject = objects[ lastCachedIndex ];
  25377. indicesByUUID[ firstActiveObject.uuid ] = index;
  25378. objects[ index ] = firstActiveObject;
  25379. indicesByUUID[ uuid ] = lastCachedIndex;
  25380. objects[ lastCachedIndex ] = object;
  25381. // accounting is done, now do the same for all bindings
  25382. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25383. var bindingsForPath = bindings[ j ],
  25384. firstActive = bindingsForPath[ lastCachedIndex ],
  25385. binding = bindingsForPath[ index ];
  25386. bindingsForPath[ index ] = firstActive;
  25387. bindingsForPath[ lastCachedIndex ] = binding;
  25388. }
  25389. }
  25390. } // for arguments
  25391. this.nCachedObjects_ = nCachedObjects;
  25392. },
  25393. // remove & forget
  25394. uncache: function () {
  25395. var objects = this._objects,
  25396. nObjects = objects.length,
  25397. nCachedObjects = this.nCachedObjects_,
  25398. indicesByUUID = this._indicesByUUID,
  25399. bindings = this._bindings,
  25400. nBindings = bindings.length;
  25401. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25402. var object = arguments[ i ],
  25403. uuid = object.uuid,
  25404. index = indicesByUUID[ uuid ];
  25405. if ( index !== undefined ) {
  25406. delete indicesByUUID[ uuid ];
  25407. if ( index < nCachedObjects ) {
  25408. // object is cached, shrink the CACHED region
  25409. var firstActiveIndex = -- nCachedObjects,
  25410. lastCachedObject = objects[ firstActiveIndex ],
  25411. lastIndex = -- nObjects,
  25412. lastObject = objects[ lastIndex ];
  25413. // last cached object takes this object's place
  25414. indicesByUUID[ lastCachedObject.uuid ] = index;
  25415. objects[ index ] = lastCachedObject;
  25416. // last object goes to the activated slot and pop
  25417. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25418. objects[ firstActiveIndex ] = lastObject;
  25419. objects.pop();
  25420. // accounting is done, now do the same for all bindings
  25421. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25422. var bindingsForPath = bindings[ j ],
  25423. lastCached = bindingsForPath[ firstActiveIndex ],
  25424. last = bindingsForPath[ lastIndex ];
  25425. bindingsForPath[ index ] = lastCached;
  25426. bindingsForPath[ firstActiveIndex ] = last;
  25427. bindingsForPath.pop();
  25428. }
  25429. } else {
  25430. // object is active, just swap with the last and pop
  25431. var lastIndex = -- nObjects,
  25432. lastObject = objects[ lastIndex ];
  25433. indicesByUUID[ lastObject.uuid ] = index;
  25434. objects[ index ] = lastObject;
  25435. objects.pop();
  25436. // accounting is done, now do the same for all bindings
  25437. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25438. var bindingsForPath = bindings[ j ];
  25439. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25440. bindingsForPath.pop();
  25441. }
  25442. } // cached or active
  25443. } // if object is known
  25444. } // for arguments
  25445. this.nCachedObjects_ = nCachedObjects;
  25446. },
  25447. // Internal interface used by befriended PropertyBinding.Composite:
  25448. subscribe_: function ( path, parsedPath ) {
  25449. // returns an array of bindings for the given path that is changed
  25450. // according to the contained objects in the group
  25451. var indicesByPath = this._bindingsIndicesByPath,
  25452. index = indicesByPath[ path ],
  25453. bindings = this._bindings;
  25454. if ( index !== undefined ) return bindings[ index ];
  25455. var paths = this._paths,
  25456. parsedPaths = this._parsedPaths,
  25457. objects = this._objects,
  25458. nObjects = objects.length,
  25459. nCachedObjects = this.nCachedObjects_,
  25460. bindingsForPath = new Array( nObjects );
  25461. index = bindings.length;
  25462. indicesByPath[ path ] = index;
  25463. paths.push( path );
  25464. parsedPaths.push( parsedPath );
  25465. bindings.push( bindingsForPath );
  25466. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25467. var object = objects[ i ];
  25468. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25469. }
  25470. return bindingsForPath;
  25471. },
  25472. unsubscribe_: function ( path ) {
  25473. // tells the group to forget about a property path and no longer
  25474. // update the array previously obtained with 'subscribe_'
  25475. var indicesByPath = this._bindingsIndicesByPath,
  25476. index = indicesByPath[ path ];
  25477. if ( index !== undefined ) {
  25478. var paths = this._paths,
  25479. parsedPaths = this._parsedPaths,
  25480. bindings = this._bindings,
  25481. lastBindingsIndex = bindings.length - 1,
  25482. lastBindings = bindings[ lastBindingsIndex ],
  25483. lastBindingsPath = path[ lastBindingsIndex ];
  25484. indicesByPath[ lastBindingsPath ] = index;
  25485. bindings[ index ] = lastBindings;
  25486. bindings.pop();
  25487. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25488. parsedPaths.pop();
  25489. paths[ index ] = paths[ lastBindingsIndex ];
  25490. paths.pop();
  25491. }
  25492. }
  25493. } );
  25494. /**
  25495. *
  25496. * Action provided by AnimationMixer for scheduling clip playback on specific
  25497. * objects.
  25498. *
  25499. * @author Ben Houston / http://clara.io/
  25500. * @author David Sarno / http://lighthaus.us/
  25501. * @author tschw
  25502. *
  25503. */
  25504. function AnimationAction( mixer, clip, localRoot ) {
  25505. this._mixer = mixer;
  25506. this._clip = clip;
  25507. this._localRoot = localRoot || null;
  25508. var tracks = clip.tracks,
  25509. nTracks = tracks.length,
  25510. interpolants = new Array( nTracks );
  25511. var interpolantSettings = {
  25512. endingStart: ZeroCurvatureEnding,
  25513. endingEnd: ZeroCurvatureEnding
  25514. };
  25515. for ( var i = 0; i !== nTracks; ++ i ) {
  25516. var interpolant = tracks[ i ].createInterpolant( null );
  25517. interpolants[ i ] = interpolant;
  25518. interpolant.settings = interpolantSettings;
  25519. }
  25520. this._interpolantSettings = interpolantSettings;
  25521. this._interpolants = interpolants; // bound by the mixer
  25522. // inside: PropertyMixer (managed by the mixer)
  25523. this._propertyBindings = new Array( nTracks );
  25524. this._cacheIndex = null; // for the memory manager
  25525. this._byClipCacheIndex = null; // for the memory manager
  25526. this._timeScaleInterpolant = null;
  25527. this._weightInterpolant = null;
  25528. this.loop = LoopRepeat;
  25529. this._loopCount = - 1;
  25530. // global mixer time when the action is to be started
  25531. // it's set back to 'null' upon start of the action
  25532. this._startTime = null;
  25533. // scaled local time of the action
  25534. // gets clamped or wrapped to 0..clip.duration according to loop
  25535. this.time = 0;
  25536. this.timeScale = 1;
  25537. this._effectiveTimeScale = 1;
  25538. this.weight = 1;
  25539. this._effectiveWeight = 1;
  25540. this.repetitions = Infinity; // no. of repetitions when looping
  25541. this.paused = false; // true -> zero effective time scale
  25542. this.enabled = true; // false -> zero effective weight
  25543. this.clampWhenFinished = false;// keep feeding the last frame?
  25544. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25545. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25546. }
  25547. Object.assign( AnimationAction.prototype, {
  25548. // State & Scheduling
  25549. play: function () {
  25550. this._mixer._activateAction( this );
  25551. return this;
  25552. },
  25553. stop: function () {
  25554. this._mixer._deactivateAction( this );
  25555. return this.reset();
  25556. },
  25557. reset: function () {
  25558. this.paused = false;
  25559. this.enabled = true;
  25560. this.time = 0; // restart clip
  25561. this._loopCount = - 1;// forget previous loops
  25562. this._startTime = null;// forget scheduling
  25563. return this.stopFading().stopWarping();
  25564. },
  25565. isRunning: function () {
  25566. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25567. this._startTime === null && this._mixer._isActiveAction( this );
  25568. },
  25569. // return true when play has been called
  25570. isScheduled: function () {
  25571. return this._mixer._isActiveAction( this );
  25572. },
  25573. startAt: function ( time ) {
  25574. this._startTime = time;
  25575. return this;
  25576. },
  25577. setLoop: function ( mode, repetitions ) {
  25578. this.loop = mode;
  25579. this.repetitions = repetitions;
  25580. return this;
  25581. },
  25582. // Weight
  25583. // set the weight stopping any scheduled fading
  25584. // although .enabled = false yields an effective weight of zero, this
  25585. // method does *not* change .enabled, because it would be confusing
  25586. setEffectiveWeight: function ( weight ) {
  25587. this.weight = weight;
  25588. // note: same logic as when updated at runtime
  25589. this._effectiveWeight = this.enabled ? weight : 0;
  25590. return this.stopFading();
  25591. },
  25592. // return the weight considering fading and .enabled
  25593. getEffectiveWeight: function () {
  25594. return this._effectiveWeight;
  25595. },
  25596. fadeIn: function ( duration ) {
  25597. return this._scheduleFading( duration, 0, 1 );
  25598. },
  25599. fadeOut: function ( duration ) {
  25600. return this._scheduleFading( duration, 1, 0 );
  25601. },
  25602. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25603. fadeOutAction.fadeOut( duration );
  25604. this.fadeIn( duration );
  25605. if ( warp ) {
  25606. var fadeInDuration = this._clip.duration,
  25607. fadeOutDuration = fadeOutAction._clip.duration,
  25608. startEndRatio = fadeOutDuration / fadeInDuration,
  25609. endStartRatio = fadeInDuration / fadeOutDuration;
  25610. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25611. this.warp( endStartRatio, 1.0, duration );
  25612. }
  25613. return this;
  25614. },
  25615. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25616. return fadeInAction.crossFadeFrom( this, duration, warp );
  25617. },
  25618. stopFading: function () {
  25619. var weightInterpolant = this._weightInterpolant;
  25620. if ( weightInterpolant !== null ) {
  25621. this._weightInterpolant = null;
  25622. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25623. }
  25624. return this;
  25625. },
  25626. // Time Scale Control
  25627. // set the time scale stopping any scheduled warping
  25628. // although .paused = true yields an effective time scale of zero, this
  25629. // method does *not* change .paused, because it would be confusing
  25630. setEffectiveTimeScale: function ( timeScale ) {
  25631. this.timeScale = timeScale;
  25632. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25633. return this.stopWarping();
  25634. },
  25635. // return the time scale considering warping and .paused
  25636. getEffectiveTimeScale: function () {
  25637. return this._effectiveTimeScale;
  25638. },
  25639. setDuration: function ( duration ) {
  25640. this.timeScale = this._clip.duration / duration;
  25641. return this.stopWarping();
  25642. },
  25643. syncWith: function ( action ) {
  25644. this.time = action.time;
  25645. this.timeScale = action.timeScale;
  25646. return this.stopWarping();
  25647. },
  25648. halt: function ( duration ) {
  25649. return this.warp( this._effectiveTimeScale, 0, duration );
  25650. },
  25651. warp: function ( startTimeScale, endTimeScale, duration ) {
  25652. var mixer = this._mixer, now = mixer.time,
  25653. interpolant = this._timeScaleInterpolant,
  25654. timeScale = this.timeScale;
  25655. if ( interpolant === null ) {
  25656. interpolant = mixer._lendControlInterpolant();
  25657. this._timeScaleInterpolant = interpolant;
  25658. }
  25659. var times = interpolant.parameterPositions,
  25660. values = interpolant.sampleValues;
  25661. times[ 0 ] = now;
  25662. times[ 1 ] = now + duration;
  25663. values[ 0 ] = startTimeScale / timeScale;
  25664. values[ 1 ] = endTimeScale / timeScale;
  25665. return this;
  25666. },
  25667. stopWarping: function () {
  25668. var timeScaleInterpolant = this._timeScaleInterpolant;
  25669. if ( timeScaleInterpolant !== null ) {
  25670. this._timeScaleInterpolant = null;
  25671. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25672. }
  25673. return this;
  25674. },
  25675. // Object Accessors
  25676. getMixer: function () {
  25677. return this._mixer;
  25678. },
  25679. getClip: function () {
  25680. return this._clip;
  25681. },
  25682. getRoot: function () {
  25683. return this._localRoot || this._mixer._root;
  25684. },
  25685. // Interna
  25686. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25687. // called by the mixer
  25688. if ( ! this.enabled ) {
  25689. // call ._updateWeight() to update ._effectiveWeight
  25690. this._updateWeight( time );
  25691. return;
  25692. }
  25693. var startTime = this._startTime;
  25694. if ( startTime !== null ) {
  25695. // check for scheduled start of action
  25696. var timeRunning = ( time - startTime ) * timeDirection;
  25697. if ( timeRunning < 0 || timeDirection === 0 ) {
  25698. return; // yet to come / don't decide when delta = 0
  25699. }
  25700. // start
  25701. this._startTime = null; // unschedule
  25702. deltaTime = timeDirection * timeRunning;
  25703. }
  25704. // apply time scale and advance time
  25705. deltaTime *= this._updateTimeScale( time );
  25706. var clipTime = this._updateTime( deltaTime );
  25707. // note: _updateTime may disable the action resulting in
  25708. // an effective weight of 0
  25709. var weight = this._updateWeight( time );
  25710. if ( weight > 0 ) {
  25711. var interpolants = this._interpolants;
  25712. var propertyMixers = this._propertyBindings;
  25713. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25714. interpolants[ j ].evaluate( clipTime );
  25715. propertyMixers[ j ].accumulate( accuIndex, weight );
  25716. }
  25717. }
  25718. },
  25719. _updateWeight: function ( time ) {
  25720. var weight = 0;
  25721. if ( this.enabled ) {
  25722. weight = this.weight;
  25723. var interpolant = this._weightInterpolant;
  25724. if ( interpolant !== null ) {
  25725. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25726. weight *= interpolantValue;
  25727. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25728. this.stopFading();
  25729. if ( interpolantValue === 0 ) {
  25730. // faded out, disable
  25731. this.enabled = false;
  25732. }
  25733. }
  25734. }
  25735. }
  25736. this._effectiveWeight = weight;
  25737. return weight;
  25738. },
  25739. _updateTimeScale: function ( time ) {
  25740. var timeScale = 0;
  25741. if ( ! this.paused ) {
  25742. timeScale = this.timeScale;
  25743. var interpolant = this._timeScaleInterpolant;
  25744. if ( interpolant !== null ) {
  25745. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25746. timeScale *= interpolantValue;
  25747. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25748. this.stopWarping();
  25749. if ( timeScale === 0 ) {
  25750. // motion has halted, pause
  25751. this.paused = true;
  25752. } else {
  25753. // warp done - apply final time scale
  25754. this.timeScale = timeScale;
  25755. }
  25756. }
  25757. }
  25758. }
  25759. this._effectiveTimeScale = timeScale;
  25760. return timeScale;
  25761. },
  25762. _updateTime: function ( deltaTime ) {
  25763. var time = this.time + deltaTime;
  25764. var duration = this._clip.duration;
  25765. var loop = this.loop;
  25766. var loopCount = this._loopCount;
  25767. var pingPong = ( loop === LoopPingPong );
  25768. if ( deltaTime === 0 ) {
  25769. if ( loopCount === - 1 ) return time;
  25770. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25771. }
  25772. if ( loop === LoopOnce ) {
  25773. if ( loopCount === - 1 ) {
  25774. // just started
  25775. this._loopCount = 0;
  25776. this._setEndings( true, true, false );
  25777. }
  25778. handle_stop: {
  25779. if ( time >= duration ) {
  25780. time = duration;
  25781. } else if ( time < 0 ) {
  25782. time = 0;
  25783. } else break handle_stop;
  25784. if ( this.clampWhenFinished ) this.paused = true;
  25785. else this.enabled = false;
  25786. this._mixer.dispatchEvent( {
  25787. type: 'finished', action: this,
  25788. direction: deltaTime < 0 ? - 1 : 1
  25789. } );
  25790. }
  25791. } else { // repetitive Repeat or PingPong
  25792. if ( loopCount === - 1 ) {
  25793. // just started
  25794. if ( deltaTime >= 0 ) {
  25795. loopCount = 0;
  25796. this._setEndings( true, this.repetitions === 0, pingPong );
  25797. } else {
  25798. // when looping in reverse direction, the initial
  25799. // transition through zero counts as a repetition,
  25800. // so leave loopCount at -1
  25801. this._setEndings( this.repetitions === 0, true, pingPong );
  25802. }
  25803. }
  25804. if ( time >= duration || time < 0 ) {
  25805. // wrap around
  25806. var loopDelta = Math.floor( time / duration ); // signed
  25807. time -= duration * loopDelta;
  25808. loopCount += Math.abs( loopDelta );
  25809. var pending = this.repetitions - loopCount;
  25810. if ( pending <= 0 ) {
  25811. // have to stop (switch state, clamp time, fire event)
  25812. if ( this.clampWhenFinished ) this.paused = true;
  25813. else this.enabled = false;
  25814. time = deltaTime > 0 ? duration : 0;
  25815. this._mixer.dispatchEvent( {
  25816. type: 'finished', action: this,
  25817. direction: deltaTime > 0 ? 1 : - 1
  25818. } );
  25819. } else {
  25820. // keep running
  25821. if ( pending === 1 ) {
  25822. // entering the last round
  25823. var atStart = deltaTime < 0;
  25824. this._setEndings( atStart, ! atStart, pingPong );
  25825. } else {
  25826. this._setEndings( false, false, pingPong );
  25827. }
  25828. this._loopCount = loopCount;
  25829. this._mixer.dispatchEvent( {
  25830. type: 'loop', action: this, loopDelta: loopDelta
  25831. } );
  25832. }
  25833. }
  25834. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25835. // invert time for the "pong round"
  25836. this.time = time;
  25837. return duration - time;
  25838. }
  25839. }
  25840. this.time = time;
  25841. return time;
  25842. },
  25843. _setEndings: function ( atStart, atEnd, pingPong ) {
  25844. var settings = this._interpolantSettings;
  25845. if ( pingPong ) {
  25846. settings.endingStart = ZeroSlopeEnding;
  25847. settings.endingEnd = ZeroSlopeEnding;
  25848. } else {
  25849. // assuming for LoopOnce atStart == atEnd == true
  25850. if ( atStart ) {
  25851. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25852. } else {
  25853. settings.endingStart = WrapAroundEnding;
  25854. }
  25855. if ( atEnd ) {
  25856. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25857. } else {
  25858. settings.endingEnd = WrapAroundEnding;
  25859. }
  25860. }
  25861. },
  25862. _scheduleFading: function ( duration, weightNow, weightThen ) {
  25863. var mixer = this._mixer, now = mixer.time,
  25864. interpolant = this._weightInterpolant;
  25865. if ( interpolant === null ) {
  25866. interpolant = mixer._lendControlInterpolant();
  25867. this._weightInterpolant = interpolant;
  25868. }
  25869. var times = interpolant.parameterPositions,
  25870. values = interpolant.sampleValues;
  25871. times[ 0 ] = now;
  25872. values[ 0 ] = weightNow;
  25873. times[ 1 ] = now + duration;
  25874. values[ 1 ] = weightThen;
  25875. return this;
  25876. }
  25877. } );
  25878. /**
  25879. *
  25880. * Player for AnimationClips.
  25881. *
  25882. *
  25883. * @author Ben Houston / http://clara.io/
  25884. * @author David Sarno / http://lighthaus.us/
  25885. * @author tschw
  25886. */
  25887. function AnimationMixer( root ) {
  25888. this._root = root;
  25889. this._initMemoryManager();
  25890. this._accuIndex = 0;
  25891. this.time = 0;
  25892. this.timeScale = 1.0;
  25893. }
  25894. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  25895. constructor: AnimationMixer,
  25896. _bindAction: function ( action, prototypeAction ) {
  25897. var root = action._localRoot || this._root,
  25898. tracks = action._clip.tracks,
  25899. nTracks = tracks.length,
  25900. bindings = action._propertyBindings,
  25901. interpolants = action._interpolants,
  25902. rootUuid = root.uuid,
  25903. bindingsByRoot = this._bindingsByRootAndName,
  25904. bindingsByName = bindingsByRoot[ rootUuid ];
  25905. if ( bindingsByName === undefined ) {
  25906. bindingsByName = {};
  25907. bindingsByRoot[ rootUuid ] = bindingsByName;
  25908. }
  25909. for ( var i = 0; i !== nTracks; ++ i ) {
  25910. var track = tracks[ i ],
  25911. trackName = track.name,
  25912. binding = bindingsByName[ trackName ];
  25913. if ( binding !== undefined ) {
  25914. bindings[ i ] = binding;
  25915. } else {
  25916. binding = bindings[ i ];
  25917. if ( binding !== undefined ) {
  25918. // existing binding, make sure the cache knows
  25919. if ( binding._cacheIndex === null ) {
  25920. ++ binding.referenceCount;
  25921. this._addInactiveBinding( binding, rootUuid, trackName );
  25922. }
  25923. continue;
  25924. }
  25925. var path = prototypeAction && prototypeAction.
  25926. _propertyBindings[ i ].binding.parsedPath;
  25927. binding = new PropertyMixer(
  25928. PropertyBinding.create( root, trackName, path ),
  25929. track.ValueTypeName, track.getValueSize() );
  25930. ++ binding.referenceCount;
  25931. this._addInactiveBinding( binding, rootUuid, trackName );
  25932. bindings[ i ] = binding;
  25933. }
  25934. interpolants[ i ].resultBuffer = binding.buffer;
  25935. }
  25936. },
  25937. _activateAction: function ( action ) {
  25938. if ( ! this._isActiveAction( action ) ) {
  25939. if ( action._cacheIndex === null ) {
  25940. // this action has been forgotten by the cache, but the user
  25941. // appears to be still using it -> rebind
  25942. var rootUuid = ( action._localRoot || this._root ).uuid,
  25943. clipUuid = action._clip.uuid,
  25944. actionsForClip = this._actionsByClip[ clipUuid ];
  25945. this._bindAction( action,
  25946. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25947. this._addInactiveAction( action, clipUuid, rootUuid );
  25948. }
  25949. var bindings = action._propertyBindings;
  25950. // increment reference counts / sort out state
  25951. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25952. var binding = bindings[ i ];
  25953. if ( binding.useCount ++ === 0 ) {
  25954. this._lendBinding( binding );
  25955. binding.saveOriginalState();
  25956. }
  25957. }
  25958. this._lendAction( action );
  25959. }
  25960. },
  25961. _deactivateAction: function ( action ) {
  25962. if ( this._isActiveAction( action ) ) {
  25963. var bindings = action._propertyBindings;
  25964. // decrement reference counts / sort out state
  25965. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25966. var binding = bindings[ i ];
  25967. if ( -- binding.useCount === 0 ) {
  25968. binding.restoreOriginalState();
  25969. this._takeBackBinding( binding );
  25970. }
  25971. }
  25972. this._takeBackAction( action );
  25973. }
  25974. },
  25975. // Memory manager
  25976. _initMemoryManager: function () {
  25977. this._actions = []; // 'nActiveActions' followed by inactive ones
  25978. this._nActiveActions = 0;
  25979. this._actionsByClip = {};
  25980. // inside:
  25981. // {
  25982. // knownActions: Array< AnimationAction > - used as prototypes
  25983. // actionByRoot: AnimationAction - lookup
  25984. // }
  25985. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25986. this._nActiveBindings = 0;
  25987. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25988. this._controlInterpolants = []; // same game as above
  25989. this._nActiveControlInterpolants = 0;
  25990. var scope = this;
  25991. this.stats = {
  25992. actions: {
  25993. get total() {
  25994. return scope._actions.length;
  25995. },
  25996. get inUse() {
  25997. return scope._nActiveActions;
  25998. }
  25999. },
  26000. bindings: {
  26001. get total() {
  26002. return scope._bindings.length;
  26003. },
  26004. get inUse() {
  26005. return scope._nActiveBindings;
  26006. }
  26007. },
  26008. controlInterpolants: {
  26009. get total() {
  26010. return scope._controlInterpolants.length;
  26011. },
  26012. get inUse() {
  26013. return scope._nActiveControlInterpolants;
  26014. }
  26015. }
  26016. };
  26017. },
  26018. // Memory management for AnimationAction objects
  26019. _isActiveAction: function ( action ) {
  26020. var index = action._cacheIndex;
  26021. return index !== null && index < this._nActiveActions;
  26022. },
  26023. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26024. var actions = this._actions,
  26025. actionsByClip = this._actionsByClip,
  26026. actionsForClip = actionsByClip[ clipUuid ];
  26027. if ( actionsForClip === undefined ) {
  26028. actionsForClip = {
  26029. knownActions: [ action ],
  26030. actionByRoot: {}
  26031. };
  26032. action._byClipCacheIndex = 0;
  26033. actionsByClip[ clipUuid ] = actionsForClip;
  26034. } else {
  26035. var knownActions = actionsForClip.knownActions;
  26036. action._byClipCacheIndex = knownActions.length;
  26037. knownActions.push( action );
  26038. }
  26039. action._cacheIndex = actions.length;
  26040. actions.push( action );
  26041. actionsForClip.actionByRoot[ rootUuid ] = action;
  26042. },
  26043. _removeInactiveAction: function ( action ) {
  26044. var actions = this._actions,
  26045. lastInactiveAction = actions[ actions.length - 1 ],
  26046. cacheIndex = action._cacheIndex;
  26047. lastInactiveAction._cacheIndex = cacheIndex;
  26048. actions[ cacheIndex ] = lastInactiveAction;
  26049. actions.pop();
  26050. action._cacheIndex = null;
  26051. var clipUuid = action._clip.uuid,
  26052. actionsByClip = this._actionsByClip,
  26053. actionsForClip = actionsByClip[ clipUuid ],
  26054. knownActionsForClip = actionsForClip.knownActions,
  26055. lastKnownAction =
  26056. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26057. byClipCacheIndex = action._byClipCacheIndex;
  26058. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26059. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26060. knownActionsForClip.pop();
  26061. action._byClipCacheIndex = null;
  26062. var actionByRoot = actionsForClip.actionByRoot,
  26063. rootUuid = ( action._localRoot || this._root ).uuid;
  26064. delete actionByRoot[ rootUuid ];
  26065. if ( knownActionsForClip.length === 0 ) {
  26066. delete actionsByClip[ clipUuid ];
  26067. }
  26068. this._removeInactiveBindingsForAction( action );
  26069. },
  26070. _removeInactiveBindingsForAction: function ( action ) {
  26071. var bindings = action._propertyBindings;
  26072. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26073. var binding = bindings[ i ];
  26074. if ( -- binding.referenceCount === 0 ) {
  26075. this._removeInactiveBinding( binding );
  26076. }
  26077. }
  26078. },
  26079. _lendAction: function ( action ) {
  26080. // [ active actions | inactive actions ]
  26081. // [ active actions >| inactive actions ]
  26082. // s a
  26083. // <-swap->
  26084. // a s
  26085. var actions = this._actions,
  26086. prevIndex = action._cacheIndex,
  26087. lastActiveIndex = this._nActiveActions ++,
  26088. firstInactiveAction = actions[ lastActiveIndex ];
  26089. action._cacheIndex = lastActiveIndex;
  26090. actions[ lastActiveIndex ] = action;
  26091. firstInactiveAction._cacheIndex = prevIndex;
  26092. actions[ prevIndex ] = firstInactiveAction;
  26093. },
  26094. _takeBackAction: function ( action ) {
  26095. // [ active actions | inactive actions ]
  26096. // [ active actions |< inactive actions ]
  26097. // a s
  26098. // <-swap->
  26099. // s a
  26100. var actions = this._actions,
  26101. prevIndex = action._cacheIndex,
  26102. firstInactiveIndex = -- this._nActiveActions,
  26103. lastActiveAction = actions[ firstInactiveIndex ];
  26104. action._cacheIndex = firstInactiveIndex;
  26105. actions[ firstInactiveIndex ] = action;
  26106. lastActiveAction._cacheIndex = prevIndex;
  26107. actions[ prevIndex ] = lastActiveAction;
  26108. },
  26109. // Memory management for PropertyMixer objects
  26110. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26111. var bindingsByRoot = this._bindingsByRootAndName,
  26112. bindingByName = bindingsByRoot[ rootUuid ],
  26113. bindings = this._bindings;
  26114. if ( bindingByName === undefined ) {
  26115. bindingByName = {};
  26116. bindingsByRoot[ rootUuid ] = bindingByName;
  26117. }
  26118. bindingByName[ trackName ] = binding;
  26119. binding._cacheIndex = bindings.length;
  26120. bindings.push( binding );
  26121. },
  26122. _removeInactiveBinding: function ( binding ) {
  26123. var bindings = this._bindings,
  26124. propBinding = binding.binding,
  26125. rootUuid = propBinding.rootNode.uuid,
  26126. trackName = propBinding.path,
  26127. bindingsByRoot = this._bindingsByRootAndName,
  26128. bindingByName = bindingsByRoot[ rootUuid ],
  26129. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26130. cacheIndex = binding._cacheIndex;
  26131. lastInactiveBinding._cacheIndex = cacheIndex;
  26132. bindings[ cacheIndex ] = lastInactiveBinding;
  26133. bindings.pop();
  26134. delete bindingByName[ trackName ];
  26135. remove_empty_map: {
  26136. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  26137. delete bindingsByRoot[ rootUuid ];
  26138. }
  26139. },
  26140. _lendBinding: function ( binding ) {
  26141. var bindings = this._bindings,
  26142. prevIndex = binding._cacheIndex,
  26143. lastActiveIndex = this._nActiveBindings ++,
  26144. firstInactiveBinding = bindings[ lastActiveIndex ];
  26145. binding._cacheIndex = lastActiveIndex;
  26146. bindings[ lastActiveIndex ] = binding;
  26147. firstInactiveBinding._cacheIndex = prevIndex;
  26148. bindings[ prevIndex ] = firstInactiveBinding;
  26149. },
  26150. _takeBackBinding: function ( binding ) {
  26151. var bindings = this._bindings,
  26152. prevIndex = binding._cacheIndex,
  26153. firstInactiveIndex = -- this._nActiveBindings,
  26154. lastActiveBinding = bindings[ firstInactiveIndex ];
  26155. binding._cacheIndex = firstInactiveIndex;
  26156. bindings[ firstInactiveIndex ] = binding;
  26157. lastActiveBinding._cacheIndex = prevIndex;
  26158. bindings[ prevIndex ] = lastActiveBinding;
  26159. },
  26160. // Memory management of Interpolants for weight and time scale
  26161. _lendControlInterpolant: function () {
  26162. var interpolants = this._controlInterpolants,
  26163. lastActiveIndex = this._nActiveControlInterpolants ++,
  26164. interpolant = interpolants[ lastActiveIndex ];
  26165. if ( interpolant === undefined ) {
  26166. interpolant = new LinearInterpolant(
  26167. new Float32Array( 2 ), new Float32Array( 2 ),
  26168. 1, this._controlInterpolantsResultBuffer );
  26169. interpolant.__cacheIndex = lastActiveIndex;
  26170. interpolants[ lastActiveIndex ] = interpolant;
  26171. }
  26172. return interpolant;
  26173. },
  26174. _takeBackControlInterpolant: function ( interpolant ) {
  26175. var interpolants = this._controlInterpolants,
  26176. prevIndex = interpolant.__cacheIndex,
  26177. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26178. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26179. interpolant.__cacheIndex = firstInactiveIndex;
  26180. interpolants[ firstInactiveIndex ] = interpolant;
  26181. lastActiveInterpolant.__cacheIndex = prevIndex;
  26182. interpolants[ prevIndex ] = lastActiveInterpolant;
  26183. },
  26184. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26185. // return an action for a clip optionally using a custom root target
  26186. // object (this method allocates a lot of dynamic memory in case a
  26187. // previously unknown clip/root combination is specified)
  26188. clipAction: function ( clip, optionalRoot ) {
  26189. var root = optionalRoot || this._root,
  26190. rootUuid = root.uuid,
  26191. clipObject = typeof clip === 'string' ?
  26192. AnimationClip.findByName( root, clip ) : clip,
  26193. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26194. actionsForClip = this._actionsByClip[ clipUuid ],
  26195. prototypeAction = null;
  26196. if ( actionsForClip !== undefined ) {
  26197. var existingAction =
  26198. actionsForClip.actionByRoot[ rootUuid ];
  26199. if ( existingAction !== undefined ) {
  26200. return existingAction;
  26201. }
  26202. // we know the clip, so we don't have to parse all
  26203. // the bindings again but can just copy
  26204. prototypeAction = actionsForClip.knownActions[ 0 ];
  26205. // also, take the clip from the prototype action
  26206. if ( clipObject === null )
  26207. clipObject = prototypeAction._clip;
  26208. }
  26209. // clip must be known when specified via string
  26210. if ( clipObject === null ) return null;
  26211. // allocate all resources required to run it
  26212. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26213. this._bindAction( newAction, prototypeAction );
  26214. // and make the action known to the memory manager
  26215. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26216. return newAction;
  26217. },
  26218. // get an existing action
  26219. existingAction: function ( clip, optionalRoot ) {
  26220. var root = optionalRoot || this._root,
  26221. rootUuid = root.uuid,
  26222. clipObject = typeof clip === 'string' ?
  26223. AnimationClip.findByName( root, clip ) : clip,
  26224. clipUuid = clipObject ? clipObject.uuid : clip,
  26225. actionsForClip = this._actionsByClip[ clipUuid ];
  26226. if ( actionsForClip !== undefined ) {
  26227. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26228. }
  26229. return null;
  26230. },
  26231. // deactivates all previously scheduled actions
  26232. stopAllAction: function () {
  26233. var actions = this._actions,
  26234. nActions = this._nActiveActions,
  26235. bindings = this._bindings,
  26236. nBindings = this._nActiveBindings;
  26237. this._nActiveActions = 0;
  26238. this._nActiveBindings = 0;
  26239. for ( var i = 0; i !== nActions; ++ i ) {
  26240. actions[ i ].reset();
  26241. }
  26242. for ( var i = 0; i !== nBindings; ++ i ) {
  26243. bindings[ i ].useCount = 0;
  26244. }
  26245. return this;
  26246. },
  26247. // advance the time and update apply the animation
  26248. update: function ( deltaTime ) {
  26249. deltaTime *= this.timeScale;
  26250. var actions = this._actions,
  26251. nActions = this._nActiveActions,
  26252. time = this.time += deltaTime,
  26253. timeDirection = Math.sign( deltaTime ),
  26254. accuIndex = this._accuIndex ^= 1;
  26255. // run active actions
  26256. for ( var i = 0; i !== nActions; ++ i ) {
  26257. var action = actions[ i ];
  26258. action._update( time, deltaTime, timeDirection, accuIndex );
  26259. }
  26260. // update scene graph
  26261. var bindings = this._bindings,
  26262. nBindings = this._nActiveBindings;
  26263. for ( var i = 0; i !== nBindings; ++ i ) {
  26264. bindings[ i ].apply( accuIndex );
  26265. }
  26266. return this;
  26267. },
  26268. // return this mixer's root target object
  26269. getRoot: function () {
  26270. return this._root;
  26271. },
  26272. // free all resources specific to a particular clip
  26273. uncacheClip: function ( clip ) {
  26274. var actions = this._actions,
  26275. clipUuid = clip.uuid,
  26276. actionsByClip = this._actionsByClip,
  26277. actionsForClip = actionsByClip[ clipUuid ];
  26278. if ( actionsForClip !== undefined ) {
  26279. // note: just calling _removeInactiveAction would mess up the
  26280. // iteration state and also require updating the state we can
  26281. // just throw away
  26282. var actionsToRemove = actionsForClip.knownActions;
  26283. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26284. var action = actionsToRemove[ i ];
  26285. this._deactivateAction( action );
  26286. var cacheIndex = action._cacheIndex,
  26287. lastInactiveAction = actions[ actions.length - 1 ];
  26288. action._cacheIndex = null;
  26289. action._byClipCacheIndex = null;
  26290. lastInactiveAction._cacheIndex = cacheIndex;
  26291. actions[ cacheIndex ] = lastInactiveAction;
  26292. actions.pop();
  26293. this._removeInactiveBindingsForAction( action );
  26294. }
  26295. delete actionsByClip[ clipUuid ];
  26296. }
  26297. },
  26298. // free all resources specific to a particular root target object
  26299. uncacheRoot: function ( root ) {
  26300. var rootUuid = root.uuid,
  26301. actionsByClip = this._actionsByClip;
  26302. for ( var clipUuid in actionsByClip ) {
  26303. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26304. action = actionByRoot[ rootUuid ];
  26305. if ( action !== undefined ) {
  26306. this._deactivateAction( action );
  26307. this._removeInactiveAction( action );
  26308. }
  26309. }
  26310. var bindingsByRoot = this._bindingsByRootAndName,
  26311. bindingByName = bindingsByRoot[ rootUuid ];
  26312. if ( bindingByName !== undefined ) {
  26313. for ( var trackName in bindingByName ) {
  26314. var binding = bindingByName[ trackName ];
  26315. binding.restoreOriginalState();
  26316. this._removeInactiveBinding( binding );
  26317. }
  26318. }
  26319. },
  26320. // remove a targeted clip from the cache
  26321. uncacheAction: function ( clip, optionalRoot ) {
  26322. var action = this.existingAction( clip, optionalRoot );
  26323. if ( action !== null ) {
  26324. this._deactivateAction( action );
  26325. this._removeInactiveAction( action );
  26326. }
  26327. }
  26328. } );
  26329. /**
  26330. * @author mrdoob / http://mrdoob.com/
  26331. */
  26332. function Uniform( value ) {
  26333. if ( typeof value === 'string' ) {
  26334. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26335. value = arguments[ 1 ];
  26336. }
  26337. this.value = value;
  26338. }
  26339. Uniform.prototype.clone = function () {
  26340. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26341. };
  26342. /**
  26343. * @author benaadams / https://twitter.com/ben_a_adams
  26344. */
  26345. function InstancedBufferGeometry() {
  26346. BufferGeometry.call( this );
  26347. this.type = 'InstancedBufferGeometry';
  26348. this.maxInstancedCount = undefined;
  26349. }
  26350. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  26351. constructor: InstancedBufferGeometry,
  26352. isInstancedBufferGeometry: true,
  26353. copy: function ( source ) {
  26354. BufferGeometry.prototype.copy.call( this, source );
  26355. this.maxInstancedCount = source.maxInstancedCount;
  26356. return this;
  26357. },
  26358. clone: function () {
  26359. return new this.constructor().copy( this );
  26360. }
  26361. } );
  26362. /**
  26363. * @author benaadams / https://twitter.com/ben_a_adams
  26364. */
  26365. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26366. InterleavedBuffer.call( this, array, stride );
  26367. this.meshPerAttribute = meshPerAttribute || 1;
  26368. }
  26369. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26370. constructor: InstancedInterleavedBuffer,
  26371. isInstancedInterleavedBuffer: true,
  26372. copy: function ( source ) {
  26373. InterleavedBuffer.prototype.copy.call( this, source );
  26374. this.meshPerAttribute = source.meshPerAttribute;
  26375. return this;
  26376. }
  26377. } );
  26378. /**
  26379. * @author benaadams / https://twitter.com/ben_a_adams
  26380. */
  26381. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  26382. if ( typeof ( normalized ) === 'number' ) {
  26383. meshPerAttribute = normalized;
  26384. normalized = false;
  26385. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  26386. }
  26387. BufferAttribute.call( this, array, itemSize, normalized );
  26388. this.meshPerAttribute = meshPerAttribute || 1;
  26389. }
  26390. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  26391. constructor: InstancedBufferAttribute,
  26392. isInstancedBufferAttribute: true,
  26393. copy: function ( source ) {
  26394. BufferAttribute.prototype.copy.call( this, source );
  26395. this.meshPerAttribute = source.meshPerAttribute;
  26396. return this;
  26397. }
  26398. } );
  26399. /**
  26400. * @author mrdoob / http://mrdoob.com/
  26401. * @author bhouston / http://clara.io/
  26402. * @author stephomi / http://stephaneginier.com/
  26403. */
  26404. function Raycaster( origin, direction, near, far ) {
  26405. this.ray = new Ray( origin, direction );
  26406. // direction is assumed to be normalized (for accurate distance calculations)
  26407. this.near = near || 0;
  26408. this.far = far || Infinity;
  26409. this.params = {
  26410. Mesh: {},
  26411. Line: {},
  26412. LOD: {},
  26413. Points: { threshold: 1 },
  26414. Sprite: {}
  26415. };
  26416. Object.defineProperties( this.params, {
  26417. PointCloud: {
  26418. get: function () {
  26419. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26420. return this.Points;
  26421. }
  26422. }
  26423. } );
  26424. }
  26425. function ascSort( a, b ) {
  26426. return a.distance - b.distance;
  26427. }
  26428. function intersectObject( object, raycaster, intersects, recursive ) {
  26429. if ( object.visible === false ) return;
  26430. object.raycast( raycaster, intersects );
  26431. if ( recursive === true ) {
  26432. var children = object.children;
  26433. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26434. intersectObject( children[ i ], raycaster, intersects, true );
  26435. }
  26436. }
  26437. }
  26438. Object.assign( Raycaster.prototype, {
  26439. linePrecision: 1,
  26440. set: function ( origin, direction ) {
  26441. // direction is assumed to be normalized (for accurate distance calculations)
  26442. this.ray.set( origin, direction );
  26443. },
  26444. setFromCamera: function ( coords, camera ) {
  26445. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26446. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26447. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26448. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26449. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26450. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26451. } else {
  26452. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26453. }
  26454. },
  26455. intersectObject: function ( object, recursive, optionalTarget ) {
  26456. var intersects = optionalTarget || [];
  26457. intersectObject( object, this, intersects, recursive );
  26458. intersects.sort( ascSort );
  26459. return intersects;
  26460. },
  26461. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26462. var intersects = optionalTarget || [];
  26463. if ( Array.isArray( objects ) === false ) {
  26464. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26465. return intersects;
  26466. }
  26467. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26468. intersectObject( objects[ i ], this, intersects, recursive );
  26469. }
  26470. intersects.sort( ascSort );
  26471. return intersects;
  26472. }
  26473. } );
  26474. /**
  26475. * @author bhouston / http://clara.io
  26476. * @author WestLangley / http://github.com/WestLangley
  26477. *
  26478. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26479. *
  26480. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26481. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26482. */
  26483. function Spherical( radius, phi, theta ) {
  26484. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26485. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26486. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26487. return this;
  26488. }
  26489. Object.assign( Spherical.prototype, {
  26490. set: function ( radius, phi, theta ) {
  26491. this.radius = radius;
  26492. this.phi = phi;
  26493. this.theta = theta;
  26494. return this;
  26495. },
  26496. clone: function () {
  26497. return new this.constructor().copy( this );
  26498. },
  26499. copy: function ( other ) {
  26500. this.radius = other.radius;
  26501. this.phi = other.phi;
  26502. this.theta = other.theta;
  26503. return this;
  26504. },
  26505. // restrict phi to be betwee EPS and PI-EPS
  26506. makeSafe: function () {
  26507. var EPS = 0.000001;
  26508. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26509. return this;
  26510. },
  26511. setFromVector3: function ( v ) {
  26512. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26513. },
  26514. setFromCartesianCoords: function ( x, y, z ) {
  26515. this.radius = Math.sqrt( x * x + y * y + z * z );
  26516. if ( this.radius === 0 ) {
  26517. this.theta = 0;
  26518. this.phi = 0;
  26519. } else {
  26520. this.theta = Math.atan2( x, z );
  26521. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26522. }
  26523. return this;
  26524. }
  26525. } );
  26526. /**
  26527. * @author Mugen87 / https://github.com/Mugen87
  26528. *
  26529. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26530. *
  26531. */
  26532. function Cylindrical( radius, theta, y ) {
  26533. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26534. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26535. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26536. return this;
  26537. }
  26538. Object.assign( Cylindrical.prototype, {
  26539. set: function ( radius, theta, y ) {
  26540. this.radius = radius;
  26541. this.theta = theta;
  26542. this.y = y;
  26543. return this;
  26544. },
  26545. clone: function () {
  26546. return new this.constructor().copy( this );
  26547. },
  26548. copy: function ( other ) {
  26549. this.radius = other.radius;
  26550. this.theta = other.theta;
  26551. this.y = other.y;
  26552. return this;
  26553. },
  26554. setFromVector3: function ( v ) {
  26555. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26556. },
  26557. setFromCartesianCoords: function ( x, y, z ) {
  26558. this.radius = Math.sqrt( x * x + z * z );
  26559. this.theta = Math.atan2( x, z );
  26560. this.y = y;
  26561. return this;
  26562. }
  26563. } );
  26564. /**
  26565. * @author bhouston / http://clara.io
  26566. */
  26567. function Box2( min, max ) {
  26568. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26569. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26570. }
  26571. Object.assign( Box2.prototype, {
  26572. set: function ( min, max ) {
  26573. this.min.copy( min );
  26574. this.max.copy( max );
  26575. return this;
  26576. },
  26577. setFromPoints: function ( points ) {
  26578. this.makeEmpty();
  26579. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26580. this.expandByPoint( points[ i ] );
  26581. }
  26582. return this;
  26583. },
  26584. setFromCenterAndSize: function () {
  26585. var v1 = new Vector2();
  26586. return function setFromCenterAndSize( center, size ) {
  26587. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26588. this.min.copy( center ).sub( halfSize );
  26589. this.max.copy( center ).add( halfSize );
  26590. return this;
  26591. };
  26592. }(),
  26593. clone: function () {
  26594. return new this.constructor().copy( this );
  26595. },
  26596. copy: function ( box ) {
  26597. this.min.copy( box.min );
  26598. this.max.copy( box.max );
  26599. return this;
  26600. },
  26601. makeEmpty: function () {
  26602. this.min.x = this.min.y = + Infinity;
  26603. this.max.x = this.max.y = - Infinity;
  26604. return this;
  26605. },
  26606. isEmpty: function () {
  26607. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26608. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26609. },
  26610. getCenter: function ( target ) {
  26611. if ( target === undefined ) {
  26612. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26613. target = new Vector2();
  26614. }
  26615. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26616. },
  26617. getSize: function ( target ) {
  26618. if ( target === undefined ) {
  26619. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26620. target = new Vector2();
  26621. }
  26622. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26623. },
  26624. expandByPoint: function ( point ) {
  26625. this.min.min( point );
  26626. this.max.max( point );
  26627. return this;
  26628. },
  26629. expandByVector: function ( vector ) {
  26630. this.min.sub( vector );
  26631. this.max.add( vector );
  26632. return this;
  26633. },
  26634. expandByScalar: function ( scalar ) {
  26635. this.min.addScalar( - scalar );
  26636. this.max.addScalar( scalar );
  26637. return this;
  26638. },
  26639. containsPoint: function ( point ) {
  26640. return point.x < this.min.x || point.x > this.max.x ||
  26641. point.y < this.min.y || point.y > this.max.y ? false : true;
  26642. },
  26643. containsBox: function ( box ) {
  26644. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26645. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26646. },
  26647. getParameter: function ( point, target ) {
  26648. // This can potentially have a divide by zero if the box
  26649. // has a size dimension of 0.
  26650. if ( target === undefined ) {
  26651. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26652. target = new Vector2();
  26653. }
  26654. return target.set(
  26655. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26656. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26657. );
  26658. },
  26659. intersectsBox: function ( box ) {
  26660. // using 4 splitting planes to rule out intersections
  26661. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26662. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26663. },
  26664. clampPoint: function ( point, target ) {
  26665. if ( target === undefined ) {
  26666. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26667. target = new Vector2();
  26668. }
  26669. return target.copy( point ).clamp( this.min, this.max );
  26670. },
  26671. distanceToPoint: function () {
  26672. var v1 = new Vector2();
  26673. return function distanceToPoint( point ) {
  26674. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26675. return clampedPoint.sub( point ).length();
  26676. };
  26677. }(),
  26678. intersect: function ( box ) {
  26679. this.min.max( box.min );
  26680. this.max.min( box.max );
  26681. return this;
  26682. },
  26683. union: function ( box ) {
  26684. this.min.min( box.min );
  26685. this.max.max( box.max );
  26686. return this;
  26687. },
  26688. translate: function ( offset ) {
  26689. this.min.add( offset );
  26690. this.max.add( offset );
  26691. return this;
  26692. },
  26693. equals: function ( box ) {
  26694. return box.min.equals( this.min ) && box.max.equals( this.max );
  26695. }
  26696. } );
  26697. /**
  26698. * @author bhouston / http://clara.io
  26699. */
  26700. function Line3( start, end ) {
  26701. this.start = ( start !== undefined ) ? start : new Vector3();
  26702. this.end = ( end !== undefined ) ? end : new Vector3();
  26703. }
  26704. Object.assign( Line3.prototype, {
  26705. set: function ( start, end ) {
  26706. this.start.copy( start );
  26707. this.end.copy( end );
  26708. return this;
  26709. },
  26710. clone: function () {
  26711. return new this.constructor().copy( this );
  26712. },
  26713. copy: function ( line ) {
  26714. this.start.copy( line.start );
  26715. this.end.copy( line.end );
  26716. return this;
  26717. },
  26718. getCenter: function ( target ) {
  26719. if ( target === undefined ) {
  26720. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26721. target = new Vector3();
  26722. }
  26723. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26724. },
  26725. delta: function ( target ) {
  26726. if ( target === undefined ) {
  26727. console.warn( 'THREE.Line3: .delta() target is now required' );
  26728. target = new Vector3();
  26729. }
  26730. return target.subVectors( this.end, this.start );
  26731. },
  26732. distanceSq: function () {
  26733. return this.start.distanceToSquared( this.end );
  26734. },
  26735. distance: function () {
  26736. return this.start.distanceTo( this.end );
  26737. },
  26738. at: function ( t, target ) {
  26739. if ( target === undefined ) {
  26740. console.warn( 'THREE.Line3: .at() target is now required' );
  26741. target = new Vector3();
  26742. }
  26743. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26744. },
  26745. closestPointToPointParameter: function () {
  26746. var startP = new Vector3();
  26747. var startEnd = new Vector3();
  26748. return function closestPointToPointParameter( point, clampToLine ) {
  26749. startP.subVectors( point, this.start );
  26750. startEnd.subVectors( this.end, this.start );
  26751. var startEnd2 = startEnd.dot( startEnd );
  26752. var startEnd_startP = startEnd.dot( startP );
  26753. var t = startEnd_startP / startEnd2;
  26754. if ( clampToLine ) {
  26755. t = _Math.clamp( t, 0, 1 );
  26756. }
  26757. return t;
  26758. };
  26759. }(),
  26760. closestPointToPoint: function ( point, clampToLine, target ) {
  26761. var t = this.closestPointToPointParameter( point, clampToLine );
  26762. if ( target === undefined ) {
  26763. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26764. target = new Vector3();
  26765. }
  26766. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26767. },
  26768. applyMatrix4: function ( matrix ) {
  26769. this.start.applyMatrix4( matrix );
  26770. this.end.applyMatrix4( matrix );
  26771. return this;
  26772. },
  26773. equals: function ( line ) {
  26774. return line.start.equals( this.start ) && line.end.equals( this.end );
  26775. }
  26776. } );
  26777. /**
  26778. * @author alteredq / http://alteredqualia.com/
  26779. */
  26780. function ImmediateRenderObject( material ) {
  26781. Object3D.call( this );
  26782. this.material = material;
  26783. this.render = function ( /* renderCallback */ ) {};
  26784. }
  26785. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26786. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26787. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26788. /**
  26789. * @author mrdoob / http://mrdoob.com/
  26790. * @author WestLangley / http://github.com/WestLangley
  26791. */
  26792. function VertexNormalsHelper( object, size, hex, linewidth ) {
  26793. this.object = object;
  26794. this.size = ( size !== undefined ) ? size : 1;
  26795. var color = ( hex !== undefined ) ? hex : 0xff0000;
  26796. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26797. //
  26798. var nNormals = 0;
  26799. var objGeometry = this.object.geometry;
  26800. if ( objGeometry && objGeometry.isGeometry ) {
  26801. nNormals = objGeometry.faces.length * 3;
  26802. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26803. nNormals = objGeometry.attributes.normal.count;
  26804. }
  26805. //
  26806. var geometry = new BufferGeometry();
  26807. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26808. geometry.addAttribute( 'position', positions );
  26809. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26810. //
  26811. this.matrixAutoUpdate = false;
  26812. this.update();
  26813. }
  26814. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26815. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  26816. VertexNormalsHelper.prototype.update = ( function () {
  26817. var v1 = new Vector3();
  26818. var v2 = new Vector3();
  26819. var normalMatrix = new Matrix3();
  26820. return function update() {
  26821. var keys = [ 'a', 'b', 'c' ];
  26822. this.object.updateMatrixWorld( true );
  26823. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26824. var matrixWorld = this.object.matrixWorld;
  26825. var position = this.geometry.attributes.position;
  26826. //
  26827. var objGeometry = this.object.geometry;
  26828. if ( objGeometry && objGeometry.isGeometry ) {
  26829. var vertices = objGeometry.vertices;
  26830. var faces = objGeometry.faces;
  26831. var idx = 0;
  26832. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26833. var face = faces[ i ];
  26834. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26835. var vertex = vertices[ face[ keys[ j ] ] ];
  26836. var normal = face.vertexNormals[ j ];
  26837. v1.copy( vertex ).applyMatrix4( matrixWorld );
  26838. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26839. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26840. idx = idx + 1;
  26841. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26842. idx = idx + 1;
  26843. }
  26844. }
  26845. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26846. var objPos = objGeometry.attributes.position;
  26847. var objNorm = objGeometry.attributes.normal;
  26848. var idx = 0;
  26849. // for simplicity, ignore index and drawcalls, and render every normal
  26850. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  26851. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  26852. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  26853. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26854. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26855. idx = idx + 1;
  26856. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26857. idx = idx + 1;
  26858. }
  26859. }
  26860. position.needsUpdate = true;
  26861. };
  26862. }() );
  26863. /**
  26864. * @author alteredq / http://alteredqualia.com/
  26865. * @author mrdoob / http://mrdoob.com/
  26866. * @author WestLangley / http://github.com/WestLangley
  26867. */
  26868. function SpotLightHelper( light, color ) {
  26869. Object3D.call( this );
  26870. this.light = light;
  26871. this.light.updateMatrixWorld();
  26872. this.matrix = light.matrixWorld;
  26873. this.matrixAutoUpdate = false;
  26874. this.color = color;
  26875. var geometry = new BufferGeometry();
  26876. var positions = [
  26877. 0, 0, 0, 0, 0, 1,
  26878. 0, 0, 0, 1, 0, 1,
  26879. 0, 0, 0, - 1, 0, 1,
  26880. 0, 0, 0, 0, 1, 1,
  26881. 0, 0, 0, 0, - 1, 1
  26882. ];
  26883. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26884. var p1 = ( i / l ) * Math.PI * 2;
  26885. var p2 = ( j / l ) * Math.PI * 2;
  26886. positions.push(
  26887. Math.cos( p1 ), Math.sin( p1 ), 1,
  26888. Math.cos( p2 ), Math.sin( p2 ), 1
  26889. );
  26890. }
  26891. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26892. var material = new LineBasicMaterial( { fog: false } );
  26893. this.cone = new LineSegments( geometry, material );
  26894. this.add( this.cone );
  26895. this.update();
  26896. }
  26897. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  26898. SpotLightHelper.prototype.constructor = SpotLightHelper;
  26899. SpotLightHelper.prototype.dispose = function () {
  26900. this.cone.geometry.dispose();
  26901. this.cone.material.dispose();
  26902. };
  26903. SpotLightHelper.prototype.update = function () {
  26904. var vector = new Vector3();
  26905. return function update() {
  26906. this.light.updateMatrixWorld();
  26907. var coneLength = this.light.distance ? this.light.distance : 1000;
  26908. var coneWidth = coneLength * Math.tan( this.light.angle );
  26909. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26910. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  26911. this.cone.lookAt( vector );
  26912. if ( this.color !== undefined ) {
  26913. this.cone.material.color.set( this.color );
  26914. } else {
  26915. this.cone.material.color.copy( this.light.color );
  26916. }
  26917. };
  26918. }();
  26919. /**
  26920. * @author Sean Griffin / http://twitter.com/sgrif
  26921. * @author Michael Guerrero / http://realitymeltdown.com
  26922. * @author mrdoob / http://mrdoob.com/
  26923. * @author ikerr / http://verold.com
  26924. * @author Mugen87 / https://github.com/Mugen87
  26925. */
  26926. function getBoneList( object ) {
  26927. var boneList = [];
  26928. if ( object && object.isBone ) {
  26929. boneList.push( object );
  26930. }
  26931. for ( var i = 0; i < object.children.length; i ++ ) {
  26932. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  26933. }
  26934. return boneList;
  26935. }
  26936. function SkeletonHelper( object ) {
  26937. var bones = getBoneList( object );
  26938. var geometry = new BufferGeometry();
  26939. var vertices = [];
  26940. var colors = [];
  26941. var color1 = new Color( 0, 0, 1 );
  26942. var color2 = new Color( 0, 1, 0 );
  26943. for ( var i = 0; i < bones.length; i ++ ) {
  26944. var bone = bones[ i ];
  26945. if ( bone.parent && bone.parent.isBone ) {
  26946. vertices.push( 0, 0, 0 );
  26947. vertices.push( 0, 0, 0 );
  26948. colors.push( color1.r, color1.g, color1.b );
  26949. colors.push( color2.r, color2.g, color2.b );
  26950. }
  26951. }
  26952. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26953. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26954. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  26955. LineSegments.call( this, geometry, material );
  26956. this.root = object;
  26957. this.bones = bones;
  26958. this.matrix = object.matrixWorld;
  26959. this.matrixAutoUpdate = false;
  26960. }
  26961. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  26962. SkeletonHelper.prototype.constructor = SkeletonHelper;
  26963. SkeletonHelper.prototype.updateMatrixWorld = function () {
  26964. var vector = new Vector3();
  26965. var boneMatrix = new Matrix4();
  26966. var matrixWorldInv = new Matrix4();
  26967. return function updateMatrixWorld( force ) {
  26968. var bones = this.bones;
  26969. var geometry = this.geometry;
  26970. var position = geometry.getAttribute( 'position' );
  26971. matrixWorldInv.getInverse( this.root.matrixWorld );
  26972. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  26973. var bone = bones[ i ];
  26974. if ( bone.parent && bone.parent.isBone ) {
  26975. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  26976. vector.setFromMatrixPosition( boneMatrix );
  26977. position.setXYZ( j, vector.x, vector.y, vector.z );
  26978. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  26979. vector.setFromMatrixPosition( boneMatrix );
  26980. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  26981. j += 2;
  26982. }
  26983. }
  26984. geometry.getAttribute( 'position' ).needsUpdate = true;
  26985. Object3D.prototype.updateMatrixWorld.call( this, force );
  26986. };
  26987. }();
  26988. /**
  26989. * @author alteredq / http://alteredqualia.com/
  26990. * @author mrdoob / http://mrdoob.com/
  26991. */
  26992. function PointLightHelper( light, sphereSize, color ) {
  26993. this.light = light;
  26994. this.light.updateMatrixWorld();
  26995. this.color = color;
  26996. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  26997. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26998. Mesh.call( this, geometry, material );
  26999. this.matrix = this.light.matrixWorld;
  27000. this.matrixAutoUpdate = false;
  27001. this.update();
  27002. /*
  27003. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27004. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27005. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27006. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27007. var d = light.distance;
  27008. if ( d === 0.0 ) {
  27009. this.lightDistance.visible = false;
  27010. } else {
  27011. this.lightDistance.scale.set( d, d, d );
  27012. }
  27013. this.add( this.lightDistance );
  27014. */
  27015. }
  27016. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27017. PointLightHelper.prototype.constructor = PointLightHelper;
  27018. PointLightHelper.prototype.dispose = function () {
  27019. this.geometry.dispose();
  27020. this.material.dispose();
  27021. };
  27022. PointLightHelper.prototype.update = function () {
  27023. if ( this.color !== undefined ) {
  27024. this.material.color.set( this.color );
  27025. } else {
  27026. this.material.color.copy( this.light.color );
  27027. }
  27028. /*
  27029. var d = this.light.distance;
  27030. if ( d === 0.0 ) {
  27031. this.lightDistance.visible = false;
  27032. } else {
  27033. this.lightDistance.visible = true;
  27034. this.lightDistance.scale.set( d, d, d );
  27035. }
  27036. */
  27037. };
  27038. /**
  27039. * @author abelnation / http://github.com/abelnation
  27040. * @author Mugen87 / http://github.com/Mugen87
  27041. * @author WestLangley / http://github.com/WestLangley
  27042. *
  27043. * This helper must be added as a child of the light
  27044. */
  27045. function RectAreaLightHelper( light, color ) {
  27046. this.type = 'RectAreaLightHelper';
  27047. this.light = light;
  27048. this.color = color; // optional hardwired color for the helper
  27049. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27050. var geometry = new BufferGeometry();
  27051. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27052. geometry.computeBoundingSphere();
  27053. var material = new LineBasicMaterial( { fog: false } );
  27054. Line.call( this, geometry, material );
  27055. //
  27056. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27057. var geometry2 = new BufferGeometry();
  27058. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27059. geometry2.computeBoundingSphere();
  27060. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27061. this.update();
  27062. }
  27063. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27064. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27065. RectAreaLightHelper.prototype.update = function () {
  27066. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27067. if ( this.color !== undefined ) {
  27068. this.material.color.set( this.color );
  27069. this.children[ 0 ].material.color.set( this.color );
  27070. } else {
  27071. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27072. // prevent hue shift
  27073. var c = this.material.color;
  27074. var max = Math.max( c.r, c.g, c.b );
  27075. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27076. this.children[ 0 ].material.color.copy( this.material.color );
  27077. }
  27078. };
  27079. RectAreaLightHelper.prototype.dispose = function () {
  27080. this.geometry.dispose();
  27081. this.material.dispose();
  27082. this.children[ 0 ].geometry.dispose();
  27083. this.children[ 0 ].material.dispose();
  27084. };
  27085. /**
  27086. * @author alteredq / http://alteredqualia.com/
  27087. * @author mrdoob / http://mrdoob.com/
  27088. * @author Mugen87 / https://github.com/Mugen87
  27089. */
  27090. function HemisphereLightHelper( light, size, color ) {
  27091. Object3D.call( this );
  27092. this.light = light;
  27093. this.light.updateMatrixWorld();
  27094. this.matrix = light.matrixWorld;
  27095. this.matrixAutoUpdate = false;
  27096. this.color = color;
  27097. var geometry = new OctahedronBufferGeometry( size );
  27098. geometry.rotateY( Math.PI * 0.5 );
  27099. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27100. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27101. var position = geometry.getAttribute( 'position' );
  27102. var colors = new Float32Array( position.count * 3 );
  27103. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27104. this.add( new Mesh( geometry, this.material ) );
  27105. this.update();
  27106. }
  27107. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27108. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27109. HemisphereLightHelper.prototype.dispose = function () {
  27110. this.children[ 0 ].geometry.dispose();
  27111. this.children[ 0 ].material.dispose();
  27112. };
  27113. HemisphereLightHelper.prototype.update = function () {
  27114. var vector = new Vector3();
  27115. var color1 = new Color();
  27116. var color2 = new Color();
  27117. return function update() {
  27118. var mesh = this.children[ 0 ];
  27119. if ( this.color !== undefined ) {
  27120. this.material.color.set( this.color );
  27121. } else {
  27122. var colors = mesh.geometry.getAttribute( 'color' );
  27123. color1.copy( this.light.color );
  27124. color2.copy( this.light.groundColor );
  27125. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27126. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  27127. colors.setXYZ( i, color.r, color.g, color.b );
  27128. }
  27129. colors.needsUpdate = true;
  27130. }
  27131. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27132. };
  27133. }();
  27134. /**
  27135. * @author mrdoob / http://mrdoob.com/
  27136. */
  27137. function GridHelper( size, divisions, color1, color2 ) {
  27138. size = size || 10;
  27139. divisions = divisions || 10;
  27140. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27141. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27142. var center = divisions / 2;
  27143. var step = size / divisions;
  27144. var halfSize = size / 2;
  27145. var vertices = [], colors = [];
  27146. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27147. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27148. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27149. var color = i === center ? color1 : color2;
  27150. color.toArray( colors, j ); j += 3;
  27151. color.toArray( colors, j ); j += 3;
  27152. color.toArray( colors, j ); j += 3;
  27153. color.toArray( colors, j ); j += 3;
  27154. }
  27155. var geometry = new BufferGeometry();
  27156. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27157. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27158. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27159. LineSegments.call( this, geometry, material );
  27160. }
  27161. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27162. constructor: GridHelper,
  27163. copy: function ( source ) {
  27164. LineSegments.prototype.copy.call( this, source );
  27165. this.geometry.copy( source.geometry );
  27166. this.material.copy( source.material );
  27167. return this;
  27168. },
  27169. clone: function () {
  27170. return new this.constructor().copy( this );
  27171. }
  27172. } );
  27173. /**
  27174. * @author mrdoob / http://mrdoob.com/
  27175. * @author Mugen87 / http://github.com/Mugen87
  27176. * @author Hectate / http://www.github.com/Hectate
  27177. */
  27178. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27179. radius = radius || 10;
  27180. radials = radials || 16;
  27181. circles = circles || 8;
  27182. divisions = divisions || 64;
  27183. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27184. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27185. var vertices = [];
  27186. var colors = [];
  27187. var x, z;
  27188. var v, i, j, r, color;
  27189. // create the radials
  27190. for ( i = 0; i <= radials; i ++ ) {
  27191. v = ( i / radials ) * ( Math.PI * 2 );
  27192. x = Math.sin( v ) * radius;
  27193. z = Math.cos( v ) * radius;
  27194. vertices.push( 0, 0, 0 );
  27195. vertices.push( x, 0, z );
  27196. color = ( i & 1 ) ? color1 : color2;
  27197. colors.push( color.r, color.g, color.b );
  27198. colors.push( color.r, color.g, color.b );
  27199. }
  27200. // create the circles
  27201. for ( i = 0; i <= circles; i ++ ) {
  27202. color = ( i & 1 ) ? color1 : color2;
  27203. r = radius - ( radius / circles * i );
  27204. for ( j = 0; j < divisions; j ++ ) {
  27205. // first vertex
  27206. v = ( j / divisions ) * ( Math.PI * 2 );
  27207. x = Math.sin( v ) * r;
  27208. z = Math.cos( v ) * r;
  27209. vertices.push( x, 0, z );
  27210. colors.push( color.r, color.g, color.b );
  27211. // second vertex
  27212. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27213. x = Math.sin( v ) * r;
  27214. z = Math.cos( v ) * r;
  27215. vertices.push( x, 0, z );
  27216. colors.push( color.r, color.g, color.b );
  27217. }
  27218. }
  27219. var geometry = new BufferGeometry();
  27220. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27221. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27222. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27223. LineSegments.call( this, geometry, material );
  27224. }
  27225. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27226. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27227. /**
  27228. * @author Mugen87 / http://github.com/Mugen87
  27229. */
  27230. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27231. this.audio = audio;
  27232. this.range = range || 1;
  27233. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27234. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27235. var geometry = new BufferGeometry();
  27236. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27237. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27238. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27239. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27240. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27241. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27242. this.update();
  27243. }
  27244. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27245. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27246. PositionalAudioHelper.prototype.update = function () {
  27247. var audio = this.audio;
  27248. var range = this.range;
  27249. var divisionsInnerAngle = this.divisionsInnerAngle;
  27250. var divisionsOuterAngle = this.divisionsOuterAngle;
  27251. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27252. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27253. var halfConeInnerAngle = coneInnerAngle / 2;
  27254. var halfConeOuterAngle = coneOuterAngle / 2;
  27255. var start = 0;
  27256. var count = 0;
  27257. var i, stride;
  27258. var geometry = this.geometry;
  27259. var positionAttribute = geometry.attributes.position;
  27260. geometry.clearGroups();
  27261. //
  27262. function generateSegment( from, to, divisions, materialIndex ) {
  27263. var step = ( to - from ) / divisions;
  27264. positionAttribute.setXYZ( start, 0, 0, 0 );
  27265. count ++;
  27266. for ( i = from; i < to; i += step ) {
  27267. stride = start + count;
  27268. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27269. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27270. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27271. count += 3;
  27272. }
  27273. geometry.addGroup( start, count, materialIndex );
  27274. start += count;
  27275. count = 0;
  27276. }
  27277. //
  27278. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27279. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27280. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27281. //
  27282. positionAttribute.needsUpdate = true;
  27283. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27284. };
  27285. PositionalAudioHelper.prototype.dispose = function () {
  27286. this.geometry.dispose();
  27287. this.material[ 0 ].dispose();
  27288. this.material[ 1 ].dispose();
  27289. };
  27290. /**
  27291. * @author mrdoob / http://mrdoob.com/
  27292. * @author WestLangley / http://github.com/WestLangley
  27293. */
  27294. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27295. // FaceNormalsHelper only supports THREE.Geometry
  27296. this.object = object;
  27297. this.size = ( size !== undefined ) ? size : 1;
  27298. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27299. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27300. //
  27301. var nNormals = 0;
  27302. var objGeometry = this.object.geometry;
  27303. if ( objGeometry && objGeometry.isGeometry ) {
  27304. nNormals = objGeometry.faces.length;
  27305. } else {
  27306. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27307. }
  27308. //
  27309. var geometry = new BufferGeometry();
  27310. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27311. geometry.addAttribute( 'position', positions );
  27312. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27313. //
  27314. this.matrixAutoUpdate = false;
  27315. this.update();
  27316. }
  27317. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27318. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27319. FaceNormalsHelper.prototype.update = ( function () {
  27320. var v1 = new Vector3();
  27321. var v2 = new Vector3();
  27322. var normalMatrix = new Matrix3();
  27323. return function update() {
  27324. this.object.updateMatrixWorld( true );
  27325. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27326. var matrixWorld = this.object.matrixWorld;
  27327. var position = this.geometry.attributes.position;
  27328. //
  27329. var objGeometry = this.object.geometry;
  27330. var vertices = objGeometry.vertices;
  27331. var faces = objGeometry.faces;
  27332. var idx = 0;
  27333. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27334. var face = faces[ i ];
  27335. var normal = face.normal;
  27336. v1.copy( vertices[ face.a ] )
  27337. .add( vertices[ face.b ] )
  27338. .add( vertices[ face.c ] )
  27339. .divideScalar( 3 )
  27340. .applyMatrix4( matrixWorld );
  27341. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27342. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27343. idx = idx + 1;
  27344. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27345. idx = idx + 1;
  27346. }
  27347. position.needsUpdate = true;
  27348. };
  27349. }() );
  27350. /**
  27351. * @author alteredq / http://alteredqualia.com/
  27352. * @author mrdoob / http://mrdoob.com/
  27353. * @author WestLangley / http://github.com/WestLangley
  27354. */
  27355. function DirectionalLightHelper( light, size, color ) {
  27356. Object3D.call( this );
  27357. this.light = light;
  27358. this.light.updateMatrixWorld();
  27359. this.matrix = light.matrixWorld;
  27360. this.matrixAutoUpdate = false;
  27361. this.color = color;
  27362. if ( size === undefined ) size = 1;
  27363. var geometry = new BufferGeometry();
  27364. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27365. - size, size, 0,
  27366. size, size, 0,
  27367. size, - size, 0,
  27368. - size, - size, 0,
  27369. - size, size, 0
  27370. ], 3 ) );
  27371. var material = new LineBasicMaterial( { fog: false } );
  27372. this.lightPlane = new Line( geometry, material );
  27373. this.add( this.lightPlane );
  27374. geometry = new BufferGeometry();
  27375. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27376. this.targetLine = new Line( geometry, material );
  27377. this.add( this.targetLine );
  27378. this.update();
  27379. }
  27380. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27381. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27382. DirectionalLightHelper.prototype.dispose = function () {
  27383. this.lightPlane.geometry.dispose();
  27384. this.lightPlane.material.dispose();
  27385. this.targetLine.geometry.dispose();
  27386. this.targetLine.material.dispose();
  27387. };
  27388. DirectionalLightHelper.prototype.update = function () {
  27389. var v1 = new Vector3();
  27390. var v2 = new Vector3();
  27391. var v3 = new Vector3();
  27392. return function update() {
  27393. v1.setFromMatrixPosition( this.light.matrixWorld );
  27394. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27395. v3.subVectors( v2, v1 );
  27396. this.lightPlane.lookAt( v2 );
  27397. if ( this.color !== undefined ) {
  27398. this.lightPlane.material.color.set( this.color );
  27399. this.targetLine.material.color.set( this.color );
  27400. } else {
  27401. this.lightPlane.material.color.copy( this.light.color );
  27402. this.targetLine.material.color.copy( this.light.color );
  27403. }
  27404. this.targetLine.lookAt( v2 );
  27405. this.targetLine.scale.z = v3.length();
  27406. };
  27407. }();
  27408. /**
  27409. * @author alteredq / http://alteredqualia.com/
  27410. * @author Mugen87 / https://github.com/Mugen87
  27411. *
  27412. * - shows frustum, line of sight and up of the camera
  27413. * - suitable for fast updates
  27414. * - based on frustum visualization in lightgl.js shadowmap example
  27415. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27416. */
  27417. function CameraHelper( camera ) {
  27418. var geometry = new BufferGeometry();
  27419. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27420. var vertices = [];
  27421. var colors = [];
  27422. var pointMap = {};
  27423. // colors
  27424. var colorFrustum = new Color( 0xffaa00 );
  27425. var colorCone = new Color( 0xff0000 );
  27426. var colorUp = new Color( 0x00aaff );
  27427. var colorTarget = new Color( 0xffffff );
  27428. var colorCross = new Color( 0x333333 );
  27429. // near
  27430. addLine( 'n1', 'n2', colorFrustum );
  27431. addLine( 'n2', 'n4', colorFrustum );
  27432. addLine( 'n4', 'n3', colorFrustum );
  27433. addLine( 'n3', 'n1', colorFrustum );
  27434. // far
  27435. addLine( 'f1', 'f2', colorFrustum );
  27436. addLine( 'f2', 'f4', colorFrustum );
  27437. addLine( 'f4', 'f3', colorFrustum );
  27438. addLine( 'f3', 'f1', colorFrustum );
  27439. // sides
  27440. addLine( 'n1', 'f1', colorFrustum );
  27441. addLine( 'n2', 'f2', colorFrustum );
  27442. addLine( 'n3', 'f3', colorFrustum );
  27443. addLine( 'n4', 'f4', colorFrustum );
  27444. // cone
  27445. addLine( 'p', 'n1', colorCone );
  27446. addLine( 'p', 'n2', colorCone );
  27447. addLine( 'p', 'n3', colorCone );
  27448. addLine( 'p', 'n4', colorCone );
  27449. // up
  27450. addLine( 'u1', 'u2', colorUp );
  27451. addLine( 'u2', 'u3', colorUp );
  27452. addLine( 'u3', 'u1', colorUp );
  27453. // target
  27454. addLine( 'c', 't', colorTarget );
  27455. addLine( 'p', 'c', colorCross );
  27456. // cross
  27457. addLine( 'cn1', 'cn2', colorCross );
  27458. addLine( 'cn3', 'cn4', colorCross );
  27459. addLine( 'cf1', 'cf2', colorCross );
  27460. addLine( 'cf3', 'cf4', colorCross );
  27461. function addLine( a, b, color ) {
  27462. addPoint( a, color );
  27463. addPoint( b, color );
  27464. }
  27465. function addPoint( id, color ) {
  27466. vertices.push( 0, 0, 0 );
  27467. colors.push( color.r, color.g, color.b );
  27468. if ( pointMap[ id ] === undefined ) {
  27469. pointMap[ id ] = [];
  27470. }
  27471. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27472. }
  27473. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27474. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27475. LineSegments.call( this, geometry, material );
  27476. this.camera = camera;
  27477. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27478. this.matrix = camera.matrixWorld;
  27479. this.matrixAutoUpdate = false;
  27480. this.pointMap = pointMap;
  27481. this.update();
  27482. }
  27483. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27484. CameraHelper.prototype.constructor = CameraHelper;
  27485. CameraHelper.prototype.update = function () {
  27486. var geometry, pointMap;
  27487. var vector = new Vector3();
  27488. var camera = new Camera();
  27489. function setPoint( point, x, y, z ) {
  27490. vector.set( x, y, z ).unproject( camera );
  27491. var points = pointMap[ point ];
  27492. if ( points !== undefined ) {
  27493. var position = geometry.getAttribute( 'position' );
  27494. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27495. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27496. }
  27497. }
  27498. }
  27499. return function update() {
  27500. geometry = this.geometry;
  27501. pointMap = this.pointMap;
  27502. var w = 1, h = 1;
  27503. // we need just camera projection matrix inverse
  27504. // world matrix must be identity
  27505. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27506. // center / target
  27507. setPoint( 'c', 0, 0, - 1 );
  27508. setPoint( 't', 0, 0, 1 );
  27509. // near
  27510. setPoint( 'n1', - w, - h, - 1 );
  27511. setPoint( 'n2', w, - h, - 1 );
  27512. setPoint( 'n3', - w, h, - 1 );
  27513. setPoint( 'n4', w, h, - 1 );
  27514. // far
  27515. setPoint( 'f1', - w, - h, 1 );
  27516. setPoint( 'f2', w, - h, 1 );
  27517. setPoint( 'f3', - w, h, 1 );
  27518. setPoint( 'f4', w, h, 1 );
  27519. // up
  27520. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27521. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27522. setPoint( 'u3', 0, h * 2, - 1 );
  27523. // cross
  27524. setPoint( 'cf1', - w, 0, 1 );
  27525. setPoint( 'cf2', w, 0, 1 );
  27526. setPoint( 'cf3', 0, - h, 1 );
  27527. setPoint( 'cf4', 0, h, 1 );
  27528. setPoint( 'cn1', - w, 0, - 1 );
  27529. setPoint( 'cn2', w, 0, - 1 );
  27530. setPoint( 'cn3', 0, - h, - 1 );
  27531. setPoint( 'cn4', 0, h, - 1 );
  27532. geometry.getAttribute( 'position' ).needsUpdate = true;
  27533. };
  27534. }();
  27535. /**
  27536. * @author mrdoob / http://mrdoob.com/
  27537. * @author Mugen87 / http://github.com/Mugen87
  27538. */
  27539. function BoxHelper( object, color ) {
  27540. this.object = object;
  27541. if ( color === undefined ) color = 0xffff00;
  27542. 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 ] );
  27543. var positions = new Float32Array( 8 * 3 );
  27544. var geometry = new BufferGeometry();
  27545. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27546. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27547. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27548. this.matrixAutoUpdate = false;
  27549. this.update();
  27550. }
  27551. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27552. BoxHelper.prototype.constructor = BoxHelper;
  27553. BoxHelper.prototype.update = ( function () {
  27554. var box = new Box3();
  27555. return function update( object ) {
  27556. if ( object !== undefined ) {
  27557. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27558. }
  27559. if ( this.object !== undefined ) {
  27560. box.setFromObject( this.object );
  27561. }
  27562. if ( box.isEmpty() ) return;
  27563. var min = box.min;
  27564. var max = box.max;
  27565. /*
  27566. 5____4
  27567. 1/___0/|
  27568. | 6__|_7
  27569. 2/___3/
  27570. 0: max.x, max.y, max.z
  27571. 1: min.x, max.y, max.z
  27572. 2: min.x, min.y, max.z
  27573. 3: max.x, min.y, max.z
  27574. 4: max.x, max.y, min.z
  27575. 5: min.x, max.y, min.z
  27576. 6: min.x, min.y, min.z
  27577. 7: max.x, min.y, min.z
  27578. */
  27579. var position = this.geometry.attributes.position;
  27580. var array = position.array;
  27581. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27582. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27583. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27584. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27585. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27586. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27587. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27588. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27589. position.needsUpdate = true;
  27590. this.geometry.computeBoundingSphere();
  27591. };
  27592. } )();
  27593. BoxHelper.prototype.setFromObject = function ( object ) {
  27594. this.object = object;
  27595. this.update();
  27596. return this;
  27597. };
  27598. BoxHelper.prototype.copy = function ( source ) {
  27599. LineSegments.prototype.copy.call( this, source );
  27600. this.object = source.object;
  27601. return this;
  27602. };
  27603. BoxHelper.prototype.clone = function () {
  27604. return new this.constructor().copy( this );
  27605. };
  27606. /**
  27607. * @author WestLangley / http://github.com/WestLangley
  27608. */
  27609. function Box3Helper( box, hex ) {
  27610. this.type = 'Box3Helper';
  27611. this.box = box;
  27612. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27613. 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 ] );
  27614. 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 ];
  27615. var geometry = new BufferGeometry();
  27616. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27617. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27618. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27619. this.geometry.computeBoundingSphere();
  27620. }
  27621. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27622. Box3Helper.prototype.constructor = Box3Helper;
  27623. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27624. var box = this.box;
  27625. if ( box.isEmpty() ) return;
  27626. box.getCenter( this.position );
  27627. box.getSize( this.scale );
  27628. this.scale.multiplyScalar( 0.5 );
  27629. Object3D.prototype.updateMatrixWorld.call( this, force );
  27630. };
  27631. /**
  27632. * @author WestLangley / http://github.com/WestLangley
  27633. */
  27634. function PlaneHelper( plane, size, hex ) {
  27635. this.type = 'PlaneHelper';
  27636. this.plane = plane;
  27637. this.size = ( size === undefined ) ? 1 : size;
  27638. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27639. 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 ];
  27640. var geometry = new BufferGeometry();
  27641. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27642. geometry.computeBoundingSphere();
  27643. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27644. //
  27645. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27646. var geometry2 = new BufferGeometry();
  27647. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27648. geometry2.computeBoundingSphere();
  27649. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27650. }
  27651. PlaneHelper.prototype = Object.create( Line.prototype );
  27652. PlaneHelper.prototype.constructor = PlaneHelper;
  27653. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27654. var scale = - this.plane.constant;
  27655. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27656. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27657. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27658. this.lookAt( this.plane.normal );
  27659. Object3D.prototype.updateMatrixWorld.call( this, force );
  27660. };
  27661. /**
  27662. * @author WestLangley / http://github.com/WestLangley
  27663. * @author zz85 / http://github.com/zz85
  27664. * @author bhouston / http://clara.io
  27665. *
  27666. * Creates an arrow for visualizing directions
  27667. *
  27668. * Parameters:
  27669. * dir - Vector3
  27670. * origin - Vector3
  27671. * length - Number
  27672. * color - color in hex value
  27673. * headLength - Number
  27674. * headWidth - Number
  27675. */
  27676. var lineGeometry, coneGeometry;
  27677. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27678. // dir is assumed to be normalized
  27679. Object3D.call( this );
  27680. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  27681. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  27682. if ( length === undefined ) length = 1;
  27683. if ( color === undefined ) color = 0xffff00;
  27684. if ( headLength === undefined ) headLength = 0.2 * length;
  27685. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27686. if ( lineGeometry === undefined ) {
  27687. lineGeometry = new BufferGeometry();
  27688. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27689. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  27690. coneGeometry.translate( 0, - 0.5, 0 );
  27691. }
  27692. this.position.copy( origin );
  27693. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  27694. this.line.matrixAutoUpdate = false;
  27695. this.add( this.line );
  27696. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  27697. this.cone.matrixAutoUpdate = false;
  27698. this.add( this.cone );
  27699. this.setDirection( dir );
  27700. this.setLength( length, headLength, headWidth );
  27701. }
  27702. ArrowHelper.prototype = Object.create( Object3D.prototype );
  27703. ArrowHelper.prototype.constructor = ArrowHelper;
  27704. ArrowHelper.prototype.setDirection = ( function () {
  27705. var axis = new Vector3();
  27706. var radians;
  27707. return function setDirection( dir ) {
  27708. // dir is assumed to be normalized
  27709. if ( dir.y > 0.99999 ) {
  27710. this.quaternion.set( 0, 0, 0, 1 );
  27711. } else if ( dir.y < - 0.99999 ) {
  27712. this.quaternion.set( 1, 0, 0, 0 );
  27713. } else {
  27714. axis.set( dir.z, 0, - dir.x ).normalize();
  27715. radians = Math.acos( dir.y );
  27716. this.quaternion.setFromAxisAngle( axis, radians );
  27717. }
  27718. };
  27719. }() );
  27720. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  27721. if ( headLength === undefined ) headLength = 0.2 * length;
  27722. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27723. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  27724. this.line.updateMatrix();
  27725. this.cone.scale.set( headWidth, headLength, headWidth );
  27726. this.cone.position.y = length;
  27727. this.cone.updateMatrix();
  27728. };
  27729. ArrowHelper.prototype.setColor = function ( color ) {
  27730. this.line.material.color.copy( color );
  27731. this.cone.material.color.copy( color );
  27732. };
  27733. ArrowHelper.prototype.copy = function ( source ) {
  27734. Object3D.prototype.copy.call( this, source, false );
  27735. this.line.copy( source.line );
  27736. this.cone.copy( source.cone );
  27737. return this;
  27738. };
  27739. ArrowHelper.prototype.clone = function () {
  27740. return new this.constructor().copy( this );
  27741. };
  27742. /**
  27743. * @author sroucheray / http://sroucheray.org/
  27744. * @author mrdoob / http://mrdoob.com/
  27745. */
  27746. function AxesHelper( size ) {
  27747. size = size || 1;
  27748. var vertices = [
  27749. 0, 0, 0, size, 0, 0,
  27750. 0, 0, 0, 0, size, 0,
  27751. 0, 0, 0, 0, 0, size
  27752. ];
  27753. var colors = [
  27754. 1, 0, 0, 1, 0.6, 0,
  27755. 0, 1, 0, 0.6, 1, 0,
  27756. 0, 0, 1, 0, 0.6, 1
  27757. ];
  27758. var geometry = new BufferGeometry();
  27759. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27760. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27761. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27762. LineSegments.call( this, geometry, material );
  27763. }
  27764. AxesHelper.prototype = Object.create( LineSegments.prototype );
  27765. AxesHelper.prototype.constructor = AxesHelper;
  27766. /**
  27767. * @author mrdoob / http://mrdoob.com/
  27768. */
  27769. function Face4( a, b, c, d, normal, color, materialIndex ) {
  27770. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  27771. return new Face3( a, b, c, normal, color, materialIndex );
  27772. }
  27773. var LineStrip = 0;
  27774. var LinePieces = 1;
  27775. function MeshFaceMaterial( materials ) {
  27776. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27777. return materials;
  27778. }
  27779. function MultiMaterial( materials ) {
  27780. if ( materials === undefined ) materials = [];
  27781. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27782. materials.isMultiMaterial = true;
  27783. materials.materials = materials;
  27784. materials.clone = function () {
  27785. return materials.slice();
  27786. };
  27787. return materials;
  27788. }
  27789. function PointCloud( geometry, material ) {
  27790. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27791. return new Points( geometry, material );
  27792. }
  27793. function Particle( material ) {
  27794. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27795. return new Sprite( material );
  27796. }
  27797. function ParticleSystem( geometry, material ) {
  27798. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27799. return new Points( geometry, material );
  27800. }
  27801. function PointCloudMaterial( parameters ) {
  27802. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27803. return new PointsMaterial( parameters );
  27804. }
  27805. function ParticleBasicMaterial( parameters ) {
  27806. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27807. return new PointsMaterial( parameters );
  27808. }
  27809. function ParticleSystemMaterial( parameters ) {
  27810. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27811. return new PointsMaterial( parameters );
  27812. }
  27813. function Vertex( x, y, z ) {
  27814. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27815. return new Vector3( x, y, z );
  27816. }
  27817. //
  27818. function DynamicBufferAttribute( array, itemSize ) {
  27819. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  27820. return new BufferAttribute( array, itemSize ).setDynamic( true );
  27821. }
  27822. function Int8Attribute( array, itemSize ) {
  27823. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27824. return new Int8BufferAttribute( array, itemSize );
  27825. }
  27826. function Uint8Attribute( array, itemSize ) {
  27827. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27828. return new Uint8BufferAttribute( array, itemSize );
  27829. }
  27830. function Uint8ClampedAttribute( array, itemSize ) {
  27831. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27832. return new Uint8ClampedBufferAttribute( array, itemSize );
  27833. }
  27834. function Int16Attribute( array, itemSize ) {
  27835. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27836. return new Int16BufferAttribute( array, itemSize );
  27837. }
  27838. function Uint16Attribute( array, itemSize ) {
  27839. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27840. return new Uint16BufferAttribute( array, itemSize );
  27841. }
  27842. function Int32Attribute( array, itemSize ) {
  27843. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  27844. return new Int32BufferAttribute( array, itemSize );
  27845. }
  27846. function Uint32Attribute( array, itemSize ) {
  27847. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  27848. return new Uint32BufferAttribute( array, itemSize );
  27849. }
  27850. function Float32Attribute( array, itemSize ) {
  27851. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  27852. return new Float32BufferAttribute( array, itemSize );
  27853. }
  27854. function Float64Attribute( array, itemSize ) {
  27855. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  27856. return new Float64BufferAttribute( array, itemSize );
  27857. }
  27858. //
  27859. Curve.create = function ( construct, getPoint ) {
  27860. console.log( 'THREE.Curve.create() has been deprecated' );
  27861. construct.prototype = Object.create( Curve.prototype );
  27862. construct.prototype.constructor = construct;
  27863. construct.prototype.getPoint = getPoint;
  27864. return construct;
  27865. };
  27866. //
  27867. Object.assign( CurvePath.prototype, {
  27868. createPointsGeometry: function ( divisions ) {
  27869. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27870. // generate geometry from path points (for Line or Points objects)
  27871. var pts = this.getPoints( divisions );
  27872. return this.createGeometry( pts );
  27873. },
  27874. createSpacedPointsGeometry: function ( divisions ) {
  27875. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27876. // generate geometry from equidistant sampling along the path
  27877. var pts = this.getSpacedPoints( divisions );
  27878. return this.createGeometry( pts );
  27879. },
  27880. createGeometry: function ( points ) {
  27881. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27882. var geometry = new Geometry();
  27883. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27884. var point = points[ i ];
  27885. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  27886. }
  27887. return geometry;
  27888. }
  27889. } );
  27890. //
  27891. Object.assign( Path.prototype, {
  27892. fromPoints: function ( points ) {
  27893. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  27894. this.setFromPoints( points );
  27895. }
  27896. } );
  27897. //
  27898. function ClosedSplineCurve3( points ) {
  27899. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27900. CatmullRomCurve3.call( this, points );
  27901. this.type = 'catmullrom';
  27902. this.closed = true;
  27903. }
  27904. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27905. //
  27906. function SplineCurve3( points ) {
  27907. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27908. CatmullRomCurve3.call( this, points );
  27909. this.type = 'catmullrom';
  27910. }
  27911. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27912. //
  27913. function Spline( points ) {
  27914. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  27915. CatmullRomCurve3.call( this, points );
  27916. this.type = 'catmullrom';
  27917. }
  27918. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  27919. Object.assign( Spline.prototype, {
  27920. initFromArray: function ( /* a */ ) {
  27921. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  27922. },
  27923. getControlPointsArray: function ( /* optionalTarget */ ) {
  27924. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  27925. },
  27926. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  27927. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  27928. }
  27929. } );
  27930. //
  27931. function AxisHelper( size ) {
  27932. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  27933. return new AxesHelper( size );
  27934. }
  27935. function BoundingBoxHelper( object, color ) {
  27936. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  27937. return new BoxHelper( object, color );
  27938. }
  27939. function EdgesHelper( object, hex ) {
  27940. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  27941. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27942. }
  27943. GridHelper.prototype.setColors = function () {
  27944. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  27945. };
  27946. SkeletonHelper.prototype.update = function () {
  27947. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  27948. };
  27949. function WireframeHelper( object, hex ) {
  27950. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  27951. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27952. }
  27953. //
  27954. Object.assign( Loader.prototype, {
  27955. extractUrlBase: function ( url ) {
  27956. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  27957. return LoaderUtils.extractUrlBase( url );
  27958. }
  27959. } );
  27960. function XHRLoader( manager ) {
  27961. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  27962. return new FileLoader( manager );
  27963. }
  27964. function BinaryTextureLoader( manager ) {
  27965. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  27966. return new DataTextureLoader( manager );
  27967. }
  27968. Object.assign( ObjectLoader.prototype, {
  27969. setTexturePath: function ( value ) {
  27970. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  27971. return this.setResourcePath( value );
  27972. }
  27973. } );
  27974. //
  27975. Object.assign( Box2.prototype, {
  27976. center: function ( optionalTarget ) {
  27977. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  27978. return this.getCenter( optionalTarget );
  27979. },
  27980. empty: function () {
  27981. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  27982. return this.isEmpty();
  27983. },
  27984. isIntersectionBox: function ( box ) {
  27985. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27986. return this.intersectsBox( box );
  27987. },
  27988. size: function ( optionalTarget ) {
  27989. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  27990. return this.getSize( optionalTarget );
  27991. }
  27992. } );
  27993. Object.assign( Box3.prototype, {
  27994. center: function ( optionalTarget ) {
  27995. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  27996. return this.getCenter( optionalTarget );
  27997. },
  27998. empty: function () {
  27999. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28000. return this.isEmpty();
  28001. },
  28002. isIntersectionBox: function ( box ) {
  28003. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28004. return this.intersectsBox( box );
  28005. },
  28006. isIntersectionSphere: function ( sphere ) {
  28007. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28008. return this.intersectsSphere( sphere );
  28009. },
  28010. size: function ( optionalTarget ) {
  28011. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28012. return this.getSize( optionalTarget );
  28013. }
  28014. } );
  28015. Line3.prototype.center = function ( optionalTarget ) {
  28016. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28017. return this.getCenter( optionalTarget );
  28018. };
  28019. Object.assign( _Math, {
  28020. random16: function () {
  28021. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28022. return Math.random();
  28023. },
  28024. nearestPowerOfTwo: function ( value ) {
  28025. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28026. return _Math.floorPowerOfTwo( value );
  28027. },
  28028. nextPowerOfTwo: function ( value ) {
  28029. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28030. return _Math.ceilPowerOfTwo( value );
  28031. }
  28032. } );
  28033. Object.assign( Matrix3.prototype, {
  28034. flattenToArrayOffset: function ( array, offset ) {
  28035. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28036. return this.toArray( array, offset );
  28037. },
  28038. multiplyVector3: function ( vector ) {
  28039. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28040. return vector.applyMatrix3( this );
  28041. },
  28042. multiplyVector3Array: function ( /* a */ ) {
  28043. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28044. },
  28045. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28046. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28047. return this.applyToBufferAttribute( buffer );
  28048. },
  28049. applyToVector3Array: function ( /* array, offset, length */ ) {
  28050. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28051. }
  28052. } );
  28053. Object.assign( Matrix4.prototype, {
  28054. extractPosition: function ( m ) {
  28055. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28056. return this.copyPosition( m );
  28057. },
  28058. flattenToArrayOffset: function ( array, offset ) {
  28059. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28060. return this.toArray( array, offset );
  28061. },
  28062. getPosition: function () {
  28063. var v1;
  28064. return function getPosition() {
  28065. if ( v1 === undefined ) v1 = new Vector3();
  28066. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28067. return v1.setFromMatrixColumn( this, 3 );
  28068. };
  28069. }(),
  28070. setRotationFromQuaternion: function ( q ) {
  28071. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28072. return this.makeRotationFromQuaternion( q );
  28073. },
  28074. multiplyToArray: function () {
  28075. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28076. },
  28077. multiplyVector3: function ( vector ) {
  28078. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28079. return vector.applyMatrix4( this );
  28080. },
  28081. multiplyVector4: function ( vector ) {
  28082. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28083. return vector.applyMatrix4( this );
  28084. },
  28085. multiplyVector3Array: function ( /* a */ ) {
  28086. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28087. },
  28088. rotateAxis: function ( v ) {
  28089. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28090. v.transformDirection( this );
  28091. },
  28092. crossVector: function ( vector ) {
  28093. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28094. return vector.applyMatrix4( this );
  28095. },
  28096. translate: function () {
  28097. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28098. },
  28099. rotateX: function () {
  28100. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28101. },
  28102. rotateY: function () {
  28103. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28104. },
  28105. rotateZ: function () {
  28106. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28107. },
  28108. rotateByAxis: function () {
  28109. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28110. },
  28111. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28112. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28113. return this.applyToBufferAttribute( buffer );
  28114. },
  28115. applyToVector3Array: function ( /* array, offset, length */ ) {
  28116. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28117. },
  28118. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28119. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28120. return this.makePerspective( left, right, top, bottom, near, far );
  28121. }
  28122. } );
  28123. Plane.prototype.isIntersectionLine = function ( line ) {
  28124. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28125. return this.intersectsLine( line );
  28126. };
  28127. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28128. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28129. return vector.applyQuaternion( this );
  28130. };
  28131. Object.assign( Ray.prototype, {
  28132. isIntersectionBox: function ( box ) {
  28133. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28134. return this.intersectsBox( box );
  28135. },
  28136. isIntersectionPlane: function ( plane ) {
  28137. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28138. return this.intersectsPlane( plane );
  28139. },
  28140. isIntersectionSphere: function ( sphere ) {
  28141. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28142. return this.intersectsSphere( sphere );
  28143. }
  28144. } );
  28145. Object.assign( Triangle.prototype, {
  28146. area: function () {
  28147. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28148. return this.getArea();
  28149. },
  28150. barycoordFromPoint: function ( point, target ) {
  28151. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28152. return this.getBarycoord( point, target );
  28153. },
  28154. midpoint: function ( target ) {
  28155. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28156. return this.getMidpoint( target );
  28157. },
  28158. normal: function ( target ) {
  28159. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28160. return this.getNormal( target );
  28161. },
  28162. plane: function ( target ) {
  28163. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28164. return this.getPlane( target );
  28165. }
  28166. } );
  28167. Object.assign( Triangle, {
  28168. barycoordFromPoint: function ( point, a, b, c, target ) {
  28169. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28170. return Triangle.getBarycoord( point, a, b, c, target );
  28171. },
  28172. normal: function ( a, b, c, target ) {
  28173. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28174. return Triangle.getNormal( a, b, c, target );
  28175. }
  28176. } );
  28177. Object.assign( Shape.prototype, {
  28178. extractAllPoints: function ( divisions ) {
  28179. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28180. return this.extractPoints( divisions );
  28181. },
  28182. extrude: function ( options ) {
  28183. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28184. return new ExtrudeGeometry( this, options );
  28185. },
  28186. makeGeometry: function ( options ) {
  28187. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28188. return new ShapeGeometry( this, options );
  28189. }
  28190. } );
  28191. Object.assign( Vector2.prototype, {
  28192. fromAttribute: function ( attribute, index, offset ) {
  28193. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28194. return this.fromBufferAttribute( attribute, index, offset );
  28195. },
  28196. distanceToManhattan: function ( v ) {
  28197. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28198. return this.manhattanDistanceTo( v );
  28199. },
  28200. lengthManhattan: function () {
  28201. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28202. return this.manhattanLength();
  28203. }
  28204. } );
  28205. Object.assign( Vector3.prototype, {
  28206. setEulerFromRotationMatrix: function () {
  28207. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28208. },
  28209. setEulerFromQuaternion: function () {
  28210. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28211. },
  28212. getPositionFromMatrix: function ( m ) {
  28213. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28214. return this.setFromMatrixPosition( m );
  28215. },
  28216. getScaleFromMatrix: function ( m ) {
  28217. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28218. return this.setFromMatrixScale( m );
  28219. },
  28220. getColumnFromMatrix: function ( index, matrix ) {
  28221. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28222. return this.setFromMatrixColumn( matrix, index );
  28223. },
  28224. applyProjection: function ( m ) {
  28225. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28226. return this.applyMatrix4( m );
  28227. },
  28228. fromAttribute: function ( attribute, index, offset ) {
  28229. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28230. return this.fromBufferAttribute( attribute, index, offset );
  28231. },
  28232. distanceToManhattan: function ( v ) {
  28233. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28234. return this.manhattanDistanceTo( v );
  28235. },
  28236. lengthManhattan: function () {
  28237. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28238. return this.manhattanLength();
  28239. }
  28240. } );
  28241. Object.assign( Vector4.prototype, {
  28242. fromAttribute: function ( attribute, index, offset ) {
  28243. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28244. return this.fromBufferAttribute( attribute, index, offset );
  28245. },
  28246. lengthManhattan: function () {
  28247. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28248. return this.manhattanLength();
  28249. }
  28250. } );
  28251. //
  28252. Object.assign( Geometry.prototype, {
  28253. computeTangents: function () {
  28254. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28255. },
  28256. computeLineDistances: function () {
  28257. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28258. }
  28259. } );
  28260. Object.assign( Object3D.prototype, {
  28261. getChildByName: function ( name ) {
  28262. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28263. return this.getObjectByName( name );
  28264. },
  28265. renderDepth: function () {
  28266. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28267. },
  28268. translate: function ( distance, axis ) {
  28269. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28270. return this.translateOnAxis( axis, distance );
  28271. },
  28272. getWorldRotation: function () {
  28273. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28274. }
  28275. } );
  28276. Object.defineProperties( Object3D.prototype, {
  28277. eulerOrder: {
  28278. get: function () {
  28279. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28280. return this.rotation.order;
  28281. },
  28282. set: function ( value ) {
  28283. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28284. this.rotation.order = value;
  28285. }
  28286. },
  28287. useQuaternion: {
  28288. get: function () {
  28289. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28290. },
  28291. set: function () {
  28292. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28293. }
  28294. }
  28295. } );
  28296. Object.defineProperties( LOD.prototype, {
  28297. objects: {
  28298. get: function () {
  28299. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28300. return this.levels;
  28301. }
  28302. }
  28303. } );
  28304. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28305. get: function () {
  28306. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28307. },
  28308. set: function () {
  28309. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28310. }
  28311. } );
  28312. SkinnedMesh.prototype.initBones = function () {
  28313. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28314. };
  28315. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28316. get: function () {
  28317. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28318. return this.arcLengthDivisions;
  28319. },
  28320. set: function ( value ) {
  28321. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28322. this.arcLengthDivisions = value;
  28323. }
  28324. } );
  28325. //
  28326. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28327. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28328. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28329. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28330. this.setFocalLength( focalLength );
  28331. };
  28332. //
  28333. Object.defineProperties( Light.prototype, {
  28334. onlyShadow: {
  28335. set: function () {
  28336. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28337. }
  28338. },
  28339. shadowCameraFov: {
  28340. set: function ( value ) {
  28341. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28342. this.shadow.camera.fov = value;
  28343. }
  28344. },
  28345. shadowCameraLeft: {
  28346. set: function ( value ) {
  28347. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28348. this.shadow.camera.left = value;
  28349. }
  28350. },
  28351. shadowCameraRight: {
  28352. set: function ( value ) {
  28353. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28354. this.shadow.camera.right = value;
  28355. }
  28356. },
  28357. shadowCameraTop: {
  28358. set: function ( value ) {
  28359. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28360. this.shadow.camera.top = value;
  28361. }
  28362. },
  28363. shadowCameraBottom: {
  28364. set: function ( value ) {
  28365. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28366. this.shadow.camera.bottom = value;
  28367. }
  28368. },
  28369. shadowCameraNear: {
  28370. set: function ( value ) {
  28371. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28372. this.shadow.camera.near = value;
  28373. }
  28374. },
  28375. shadowCameraFar: {
  28376. set: function ( value ) {
  28377. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28378. this.shadow.camera.far = value;
  28379. }
  28380. },
  28381. shadowCameraVisible: {
  28382. set: function () {
  28383. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28384. }
  28385. },
  28386. shadowBias: {
  28387. set: function ( value ) {
  28388. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28389. this.shadow.bias = value;
  28390. }
  28391. },
  28392. shadowDarkness: {
  28393. set: function () {
  28394. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28395. }
  28396. },
  28397. shadowMapWidth: {
  28398. set: function ( value ) {
  28399. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28400. this.shadow.mapSize.width = value;
  28401. }
  28402. },
  28403. shadowMapHeight: {
  28404. set: function ( value ) {
  28405. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28406. this.shadow.mapSize.height = value;
  28407. }
  28408. }
  28409. } );
  28410. //
  28411. Object.defineProperties( BufferAttribute.prototype, {
  28412. length: {
  28413. get: function () {
  28414. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28415. return this.array.length;
  28416. }
  28417. },
  28418. copyIndicesArray: function ( /* indices */ ) {
  28419. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28420. }
  28421. } );
  28422. Object.assign( BufferGeometry.prototype, {
  28423. addIndex: function ( index ) {
  28424. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28425. this.setIndex( index );
  28426. },
  28427. addDrawCall: function ( start, count, indexOffset ) {
  28428. if ( indexOffset !== undefined ) {
  28429. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28430. }
  28431. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28432. this.addGroup( start, count );
  28433. },
  28434. clearDrawCalls: function () {
  28435. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28436. this.clearGroups();
  28437. },
  28438. computeTangents: function () {
  28439. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28440. },
  28441. computeOffsets: function () {
  28442. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28443. }
  28444. } );
  28445. Object.defineProperties( BufferGeometry.prototype, {
  28446. drawcalls: {
  28447. get: function () {
  28448. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28449. return this.groups;
  28450. }
  28451. },
  28452. offsets: {
  28453. get: function () {
  28454. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28455. return this.groups;
  28456. }
  28457. }
  28458. } );
  28459. //
  28460. Object.assign( ExtrudeBufferGeometry.prototype, {
  28461. getArrays: function () {
  28462. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28463. },
  28464. addShapeList: function () {
  28465. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28466. },
  28467. addShape: function () {
  28468. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28469. }
  28470. } );
  28471. //
  28472. Object.defineProperties( Uniform.prototype, {
  28473. dynamic: {
  28474. set: function () {
  28475. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28476. }
  28477. },
  28478. onUpdate: {
  28479. value: function () {
  28480. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28481. return this;
  28482. }
  28483. }
  28484. } );
  28485. //
  28486. Object.defineProperties( Material.prototype, {
  28487. wrapAround: {
  28488. get: function () {
  28489. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28490. },
  28491. set: function () {
  28492. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28493. }
  28494. },
  28495. overdraw: {
  28496. get: function () {
  28497. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28498. },
  28499. set: function () {
  28500. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28501. }
  28502. },
  28503. wrapRGB: {
  28504. get: function () {
  28505. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28506. return new Color();
  28507. }
  28508. },
  28509. shading: {
  28510. get: function () {
  28511. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28512. },
  28513. set: function ( value ) {
  28514. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28515. this.flatShading = ( value === FlatShading );
  28516. }
  28517. }
  28518. } );
  28519. Object.defineProperties( MeshPhongMaterial.prototype, {
  28520. metal: {
  28521. get: function () {
  28522. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28523. return false;
  28524. },
  28525. set: function () {
  28526. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28527. }
  28528. }
  28529. } );
  28530. Object.defineProperties( ShaderMaterial.prototype, {
  28531. derivatives: {
  28532. get: function () {
  28533. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28534. return this.extensions.derivatives;
  28535. },
  28536. set: function ( value ) {
  28537. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28538. this.extensions.derivatives = value;
  28539. }
  28540. }
  28541. } );
  28542. //
  28543. Object.assign( WebGLRenderer.prototype, {
  28544. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28545. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28546. this.setRenderTarget( renderTarget );
  28547. this.clear( color, depth, stencil );
  28548. },
  28549. animate: function ( callback ) {
  28550. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28551. this.setAnimationLoop( callback );
  28552. },
  28553. getCurrentRenderTarget: function () {
  28554. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28555. return this.getRenderTarget();
  28556. },
  28557. getMaxAnisotropy: function () {
  28558. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28559. return this.capabilities.getMaxAnisotropy();
  28560. },
  28561. getPrecision: function () {
  28562. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28563. return this.capabilities.precision;
  28564. },
  28565. resetGLState: function () {
  28566. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28567. return this.state.reset();
  28568. },
  28569. supportsFloatTextures: function () {
  28570. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28571. return this.extensions.get( 'OES_texture_float' );
  28572. },
  28573. supportsHalfFloatTextures: function () {
  28574. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28575. return this.extensions.get( 'OES_texture_half_float' );
  28576. },
  28577. supportsStandardDerivatives: function () {
  28578. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28579. return this.extensions.get( 'OES_standard_derivatives' );
  28580. },
  28581. supportsCompressedTextureS3TC: function () {
  28582. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28583. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28584. },
  28585. supportsCompressedTexturePVRTC: function () {
  28586. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28587. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28588. },
  28589. supportsBlendMinMax: function () {
  28590. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28591. return this.extensions.get( 'EXT_blend_minmax' );
  28592. },
  28593. supportsVertexTextures: function () {
  28594. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28595. return this.capabilities.vertexTextures;
  28596. },
  28597. supportsInstancedArrays: function () {
  28598. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28599. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28600. },
  28601. enableScissorTest: function ( boolean ) {
  28602. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28603. this.setScissorTest( boolean );
  28604. },
  28605. initMaterial: function () {
  28606. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28607. },
  28608. addPrePlugin: function () {
  28609. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28610. },
  28611. addPostPlugin: function () {
  28612. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28613. },
  28614. updateShadowMap: function () {
  28615. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28616. },
  28617. setFaceCulling: function () {
  28618. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28619. },
  28620. allocTextureUnit: function () {
  28621. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28622. },
  28623. setTexture: function () {
  28624. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28625. },
  28626. setTexture2D: function () {
  28627. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28628. },
  28629. setTextureCube: function () {
  28630. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28631. }
  28632. } );
  28633. Object.defineProperties( WebGLRenderer.prototype, {
  28634. shadowMapEnabled: {
  28635. get: function () {
  28636. return this.shadowMap.enabled;
  28637. },
  28638. set: function ( value ) {
  28639. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28640. this.shadowMap.enabled = value;
  28641. }
  28642. },
  28643. shadowMapType: {
  28644. get: function () {
  28645. return this.shadowMap.type;
  28646. },
  28647. set: function ( value ) {
  28648. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28649. this.shadowMap.type = value;
  28650. }
  28651. },
  28652. shadowMapCullFace: {
  28653. get: function () {
  28654. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28655. return undefined;
  28656. },
  28657. set: function ( /* value */ ) {
  28658. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28659. }
  28660. }
  28661. } );
  28662. Object.defineProperties( WebGLShadowMap.prototype, {
  28663. cullFace: {
  28664. get: function () {
  28665. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28666. return undefined;
  28667. },
  28668. set: function ( /* cullFace */ ) {
  28669. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28670. }
  28671. },
  28672. renderReverseSided: {
  28673. get: function () {
  28674. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28675. return undefined;
  28676. },
  28677. set: function () {
  28678. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28679. }
  28680. },
  28681. renderSingleSided: {
  28682. get: function () {
  28683. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28684. return undefined;
  28685. },
  28686. set: function () {
  28687. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28688. }
  28689. }
  28690. } );
  28691. //
  28692. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  28693. activeCubeFace: {
  28694. set: function ( /* value */ ) {
  28695. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  28696. }
  28697. },
  28698. activeMipMapLevel: {
  28699. set: function ( /* value */ ) {
  28700. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  28701. }
  28702. }
  28703. } );
  28704. //
  28705. Object.defineProperties( WebGLRenderTarget.prototype, {
  28706. wrapS: {
  28707. get: function () {
  28708. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28709. return this.texture.wrapS;
  28710. },
  28711. set: function ( value ) {
  28712. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28713. this.texture.wrapS = value;
  28714. }
  28715. },
  28716. wrapT: {
  28717. get: function () {
  28718. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28719. return this.texture.wrapT;
  28720. },
  28721. set: function ( value ) {
  28722. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28723. this.texture.wrapT = value;
  28724. }
  28725. },
  28726. magFilter: {
  28727. get: function () {
  28728. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28729. return this.texture.magFilter;
  28730. },
  28731. set: function ( value ) {
  28732. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28733. this.texture.magFilter = value;
  28734. }
  28735. },
  28736. minFilter: {
  28737. get: function () {
  28738. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28739. return this.texture.minFilter;
  28740. },
  28741. set: function ( value ) {
  28742. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28743. this.texture.minFilter = value;
  28744. }
  28745. },
  28746. anisotropy: {
  28747. get: function () {
  28748. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28749. return this.texture.anisotropy;
  28750. },
  28751. set: function ( value ) {
  28752. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28753. this.texture.anisotropy = value;
  28754. }
  28755. },
  28756. offset: {
  28757. get: function () {
  28758. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28759. return this.texture.offset;
  28760. },
  28761. set: function ( value ) {
  28762. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28763. this.texture.offset = value;
  28764. }
  28765. },
  28766. repeat: {
  28767. get: function () {
  28768. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28769. return this.texture.repeat;
  28770. },
  28771. set: function ( value ) {
  28772. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28773. this.texture.repeat = value;
  28774. }
  28775. },
  28776. format: {
  28777. get: function () {
  28778. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28779. return this.texture.format;
  28780. },
  28781. set: function ( value ) {
  28782. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28783. this.texture.format = value;
  28784. }
  28785. },
  28786. type: {
  28787. get: function () {
  28788. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28789. return this.texture.type;
  28790. },
  28791. set: function ( value ) {
  28792. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28793. this.texture.type = value;
  28794. }
  28795. },
  28796. generateMipmaps: {
  28797. get: function () {
  28798. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28799. return this.texture.generateMipmaps;
  28800. },
  28801. set: function ( value ) {
  28802. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28803. this.texture.generateMipmaps = value;
  28804. }
  28805. }
  28806. } );
  28807. //
  28808. Object.defineProperties( WebVRManager.prototype, {
  28809. standing: {
  28810. set: function ( /* value */ ) {
  28811. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  28812. }
  28813. },
  28814. userHeight: {
  28815. set: function ( /* value */ ) {
  28816. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  28817. }
  28818. }
  28819. } );
  28820. //
  28821. Audio.prototype.load = function ( file ) {
  28822. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  28823. var scope = this;
  28824. var audioLoader = new AudioLoader();
  28825. audioLoader.load( file, function ( buffer ) {
  28826. scope.setBuffer( buffer );
  28827. } );
  28828. return this;
  28829. };
  28830. AudioAnalyser.prototype.getData = function () {
  28831. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  28832. return this.getFrequencyData();
  28833. };
  28834. //
  28835. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  28836. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  28837. return this.update( renderer, scene );
  28838. };
  28839. //
  28840. var GeometryUtils = {
  28841. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  28842. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  28843. var matrix;
  28844. if ( geometry2.isMesh ) {
  28845. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  28846. matrix = geometry2.matrix;
  28847. geometry2 = geometry2.geometry;
  28848. }
  28849. geometry1.merge( geometry2, matrix, materialIndexOffset );
  28850. },
  28851. center: function ( geometry ) {
  28852. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  28853. return geometry.center();
  28854. }
  28855. };
  28856. ImageUtils.crossOrigin = undefined;
  28857. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  28858. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  28859. var loader = new TextureLoader();
  28860. loader.setCrossOrigin( this.crossOrigin );
  28861. var texture = loader.load( url, onLoad, undefined, onError );
  28862. if ( mapping ) texture.mapping = mapping;
  28863. return texture;
  28864. };
  28865. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  28866. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  28867. var loader = new CubeTextureLoader();
  28868. loader.setCrossOrigin( this.crossOrigin );
  28869. var texture = loader.load( urls, onLoad, undefined, onError );
  28870. if ( mapping ) texture.mapping = mapping;
  28871. return texture;
  28872. };
  28873. ImageUtils.loadCompressedTexture = function () {
  28874. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  28875. };
  28876. ImageUtils.loadCompressedTextureCube = function () {
  28877. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  28878. };
  28879. //
  28880. function Projector() {
  28881. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  28882. this.projectVector = function ( vector, camera ) {
  28883. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  28884. vector.project( camera );
  28885. };
  28886. this.unprojectVector = function ( vector, camera ) {
  28887. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  28888. vector.unproject( camera );
  28889. };
  28890. this.pickingRay = function () {
  28891. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  28892. };
  28893. }
  28894. //
  28895. function CanvasRenderer() {
  28896. console.error( 'THREE.CanvasRenderer has been removed' );
  28897. }
  28898. //
  28899. function JSONLoader() {
  28900. console.error( 'THREE.JSONLoader has been removed.' );
  28901. }
  28902. //
  28903. var SceneUtils = {
  28904. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  28905. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28906. },
  28907. detach: function ( /* child, parent, scene */ ) {
  28908. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28909. },
  28910. attach: function ( /* child, scene, parent */ ) {
  28911. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28912. }
  28913. };
  28914. //
  28915. function LensFlare() {
  28916. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  28917. }
  28918. export { WebGLMultisampleRenderTarget, WebGLRenderTargetCube, WebGLRenderTarget, WebGLRenderer, ShaderLib, UniformsLib, UniformsUtils, ShaderChunk, FogExp2, Fog, Scene, Sprite, LOD, SkinnedMesh, Skeleton, Bone, Mesh, LineSegments, LineLoop, Line, Points, Group, VideoTexture, DataTexture, DataTexture2DArray, DataTexture3D, CompressedTexture, CubeTexture, CanvasTexture, DepthTexture, Texture, AnimationLoader, CompressedTextureLoader, DataTextureLoader, CubeTextureLoader, TextureLoader, ObjectLoader, MaterialLoader, BufferGeometryLoader, DefaultLoadingManager, LoadingManager, ImageLoader, ImageBitmapLoader, FontLoader, FileLoader, Loader, LoaderUtils, Cache, AudioLoader, SpotLightShadow, SpotLight, PointLight, RectAreaLight, HemisphereLight, DirectionalLightShadow, DirectionalLight, AmbientLight, LightShadow, Light, LightProbe, StereoCamera, PerspectiveCamera, OrthographicCamera, CubeCamera, ArrayCamera, Camera, AudioListener, PositionalAudio, AudioContext, AudioAnalyser, Audio, VectorKeyframeTrack, StringKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, ColorKeyframeTrack, BooleanKeyframeTrack, PropertyMixer, PropertyBinding, KeyframeTrack, AnimationUtils, AnimationObjectGroup, AnimationMixer, AnimationClip, Uniform, InstancedBufferGeometry, BufferGeometry, Geometry, InterleavedBufferAttribute, InstancedInterleavedBuffer, InterleavedBuffer, InstancedBufferAttribute, Face3, Object3D, Raycaster, Layers, EventDispatcher, Clock, QuaternionLinearInterpolant, LinearInterpolant, DiscreteInterpolant, CubicInterpolant, Interpolant, Triangle, _Math as Math, Spherical, Cylindrical, Plane, Frustum, Sphere, Ray, Matrix4, Matrix3, Box3, Box2, Line3, Euler, Vector4, Vector3, Vector2, Quaternion, Color, SphericalHarmonics3, ImmediateRenderObject, VertexNormalsHelper, SpotLightHelper, SkeletonHelper, PointLightHelper, RectAreaLightHelper, HemisphereLightHelper, GridHelper, PolarGridHelper, PositionalAudioHelper, FaceNormalsHelper, DirectionalLightHelper, CameraHelper, BoxHelper, Box3Helper, PlaneHelper, ArrowHelper, AxesHelper, Shape, Path, ShapePath, Font, CurvePath, Curve, ImageUtils, ShapeUtils, WebGLUtils, WireframeGeometry, ParametricGeometry, ParametricBufferGeometry, TetrahedronGeometry, TetrahedronBufferGeometry, OctahedronGeometry, OctahedronBufferGeometry, IcosahedronGeometry, IcosahedronBufferGeometry, DodecahedronGeometry, DodecahedronBufferGeometry, PolyhedronGeometry, PolyhedronBufferGeometry, TubeGeometry, TubeBufferGeometry, TorusKnotGeometry, TorusKnotBufferGeometry, TorusGeometry, TorusBufferGeometry, TextGeometry, TextBufferGeometry, SphereGeometry, SphereBufferGeometry, RingGeometry, RingBufferGeometry, PlaneGeometry, PlaneBufferGeometry, LatheGeometry, LatheBufferGeometry, ShapeGeometry, ShapeBufferGeometry, ExtrudeGeometry, ExtrudeBufferGeometry, EdgesGeometry, ConeGeometry, ConeBufferGeometry, CylinderGeometry, CylinderBufferGeometry, CircleGeometry, CircleBufferGeometry, BoxGeometry, BoxGeometry as CubeGeometry, BoxBufferGeometry, ShadowMaterial, SpriteMaterial, RawShaderMaterial, ShaderMaterial, PointsMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshPhongMaterial, MeshToonMaterial, MeshNormalMaterial, MeshLambertMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshBasicMaterial, MeshMatcapMaterial, LineDashedMaterial, LineBasicMaterial, Material, Float64BufferAttribute, Float32BufferAttribute, Uint32BufferAttribute, Int32BufferAttribute, Uint16BufferAttribute, Int16BufferAttribute, Uint8ClampedBufferAttribute, Uint8BufferAttribute, Int8BufferAttribute, BufferAttribute, ArcCurve, CatmullRomCurve3, CubicBezierCurve, CubicBezierCurve3, EllipseCurve, LineCurve, LineCurve3, QuadraticBezierCurve, QuadraticBezierCurve3, SplineCurve, REVISION, MOUSE, CullFaceNone, CullFaceBack, CullFaceFront, CullFaceFrontBack, FrontFaceDirectionCW, FrontFaceDirectionCCW, BasicShadowMap, PCFShadowMap, PCFSoftShadowMap, FrontSide, BackSide, DoubleSide, FlatShading, SmoothShading, NoColors, FaceColors, VertexColors, NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor, NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth, MultiplyOperation, MixOperation, AddOperation, NoToneMapping, LinearToneMapping, ReinhardToneMapping, Uncharted2ToneMapping, CineonToneMapping, ACESFilmicToneMapping, UVMapping, CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, SphericalReflectionMapping, CubeUVReflectionMapping, CubeUVRefractionMapping, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter, LinearFilter, LinearMipMapNearestFilter, LinearMipMapLinearFilter, UnsignedByteType, ByteType, ShortType, UnsignedShortType, IntType, UnsignedIntType, FloatType, HalfFloatType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedInt248Type, AlphaFormat, RGBFormat, RGBAFormat, LuminanceFormat, LuminanceAlphaFormat, RGBEFormat, DepthFormat, DepthStencilFormat, RedFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_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_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, LoopOnce, LoopRepeat, LoopPingPong, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, ZeroCurvatureEnding, ZeroSlopeEnding, WrapAroundEnding, TrianglesDrawMode, TriangleStripDrawMode, TriangleFanDrawMode, LinearEncoding, sRGBEncoding, GammaEncoding, RGBEEncoding, LogLuvEncoding, RGBM7Encoding, RGBM16Encoding, RGBDEncoding, BasicDepthPacking, RGBADepthPacking, TangentSpaceNormalMap, ObjectSpaceNormalMap, Face4, LineStrip, LinePieces, MeshFaceMaterial, MultiMaterial, PointCloud, Particle, ParticleSystem, PointCloudMaterial, ParticleBasicMaterial, ParticleSystemMaterial, Vertex, DynamicBufferAttribute, Int8Attribute, Uint8Attribute, Uint8ClampedAttribute, Int16Attribute, Uint16Attribute, Int32Attribute, Uint32Attribute, Float32Attribute, Float64Attribute, ClosedSplineCurve3, SplineCurve3, Spline, AxisHelper, BoundingBoxHelper, EdgesHelper, WireframeHelper, XHRLoader, BinaryTextureLoader, GeometryUtils, Projector, CanvasRenderer, JSONLoader, SceneUtils, LensFlare };