three.module.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998
  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 = '108dev';
  96. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  97. var TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  98. var CullFaceNone = 0;
  99. var CullFaceBack = 1;
  100. var CullFaceFront = 2;
  101. var CullFaceFrontBack = 3;
  102. var FrontFaceDirectionCW = 0;
  103. var FrontFaceDirectionCCW = 1;
  104. var BasicShadowMap = 0;
  105. var PCFShadowMap = 1;
  106. var PCFSoftShadowMap = 2;
  107. var FrontSide = 0;
  108. var BackSide = 1;
  109. var DoubleSide = 2;
  110. var FlatShading = 1;
  111. var SmoothShading = 2;
  112. var NoColors = 0;
  113. var FaceColors = 1;
  114. var VertexColors = 2;
  115. var NoBlending = 0;
  116. var NormalBlending = 1;
  117. var AdditiveBlending = 2;
  118. var SubtractiveBlending = 3;
  119. var MultiplyBlending = 4;
  120. var CustomBlending = 5;
  121. var AddEquation = 100;
  122. var SubtractEquation = 101;
  123. var ReverseSubtractEquation = 102;
  124. var MinEquation = 103;
  125. var MaxEquation = 104;
  126. var ZeroFactor = 200;
  127. var OneFactor = 201;
  128. var SrcColorFactor = 202;
  129. var OneMinusSrcColorFactor = 203;
  130. var SrcAlphaFactor = 204;
  131. var OneMinusSrcAlphaFactor = 205;
  132. var DstAlphaFactor = 206;
  133. var OneMinusDstAlphaFactor = 207;
  134. var DstColorFactor = 208;
  135. var OneMinusDstColorFactor = 209;
  136. var SrcAlphaSaturateFactor = 210;
  137. var NeverDepth = 0;
  138. var AlwaysDepth = 1;
  139. var LessDepth = 2;
  140. var LessEqualDepth = 3;
  141. var EqualDepth = 4;
  142. var GreaterEqualDepth = 5;
  143. var GreaterDepth = 6;
  144. var NotEqualDepth = 7;
  145. var MultiplyOperation = 0;
  146. var MixOperation = 1;
  147. var AddOperation = 2;
  148. var NoToneMapping = 0;
  149. var LinearToneMapping = 1;
  150. var ReinhardToneMapping = 2;
  151. var Uncharted2ToneMapping = 3;
  152. var CineonToneMapping = 4;
  153. var ACESFilmicToneMapping = 5;
  154. var UVMapping = 300;
  155. var CubeReflectionMapping = 301;
  156. var CubeRefractionMapping = 302;
  157. var EquirectangularReflectionMapping = 303;
  158. var EquirectangularRefractionMapping = 304;
  159. var SphericalReflectionMapping = 305;
  160. var CubeUVReflectionMapping = 306;
  161. var CubeUVRefractionMapping = 307;
  162. var RepeatWrapping = 1000;
  163. var ClampToEdgeWrapping = 1001;
  164. var MirroredRepeatWrapping = 1002;
  165. var NearestFilter = 1003;
  166. var NearestMipmapNearestFilter = 1004;
  167. var NearestMipMapNearestFilter = 1004;
  168. var NearestMipmapLinearFilter = 1005;
  169. var NearestMipMapLinearFilter = 1005;
  170. var LinearFilter = 1006;
  171. var LinearMipmapNearestFilter = 1007;
  172. var LinearMipMapNearestFilter = 1007;
  173. var LinearMipmapLinearFilter = 1008;
  174. var LinearMipMapLinearFilter = 1008;
  175. var UnsignedByteType = 1009;
  176. var ByteType = 1010;
  177. var ShortType = 1011;
  178. var UnsignedShortType = 1012;
  179. var IntType = 1013;
  180. var UnsignedIntType = 1014;
  181. var FloatType = 1015;
  182. var HalfFloatType = 1016;
  183. var UnsignedShort4444Type = 1017;
  184. var UnsignedShort5551Type = 1018;
  185. var UnsignedShort565Type = 1019;
  186. var UnsignedInt248Type = 1020;
  187. var AlphaFormat = 1021;
  188. var RGBFormat = 1022;
  189. var RGBAFormat = 1023;
  190. var LuminanceFormat = 1024;
  191. var LuminanceAlphaFormat = 1025;
  192. var RGBEFormat = RGBAFormat;
  193. var DepthFormat = 1026;
  194. var DepthStencilFormat = 1027;
  195. var RedFormat = 1028;
  196. var RGB_S3TC_DXT1_Format = 33776;
  197. var RGBA_S3TC_DXT1_Format = 33777;
  198. var RGBA_S3TC_DXT3_Format = 33778;
  199. var RGBA_S3TC_DXT5_Format = 33779;
  200. var RGB_PVRTC_4BPPV1_Format = 35840;
  201. var RGB_PVRTC_2BPPV1_Format = 35841;
  202. var RGBA_PVRTC_4BPPV1_Format = 35842;
  203. var RGBA_PVRTC_2BPPV1_Format = 35843;
  204. var RGB_ETC1_Format = 36196;
  205. var RGBA_ASTC_4x4_Format = 37808;
  206. var RGBA_ASTC_5x4_Format = 37809;
  207. var RGBA_ASTC_5x5_Format = 37810;
  208. var RGBA_ASTC_6x5_Format = 37811;
  209. var RGBA_ASTC_6x6_Format = 37812;
  210. var RGBA_ASTC_8x5_Format = 37813;
  211. var RGBA_ASTC_8x6_Format = 37814;
  212. var RGBA_ASTC_8x8_Format = 37815;
  213. var RGBA_ASTC_10x5_Format = 37816;
  214. var RGBA_ASTC_10x6_Format = 37817;
  215. var RGBA_ASTC_10x8_Format = 37818;
  216. var RGBA_ASTC_10x10_Format = 37819;
  217. var RGBA_ASTC_12x10_Format = 37820;
  218. var RGBA_ASTC_12x12_Format = 37821;
  219. var LoopOnce = 2200;
  220. var LoopRepeat = 2201;
  221. var LoopPingPong = 2202;
  222. var InterpolateDiscrete = 2300;
  223. var InterpolateLinear = 2301;
  224. var InterpolateSmooth = 2302;
  225. var ZeroCurvatureEnding = 2400;
  226. var ZeroSlopeEnding = 2401;
  227. var WrapAroundEnding = 2402;
  228. var TrianglesDrawMode = 0;
  229. var TriangleStripDrawMode = 1;
  230. var TriangleFanDrawMode = 2;
  231. var LinearEncoding = 3000;
  232. var sRGBEncoding = 3001;
  233. var GammaEncoding = 3007;
  234. var RGBEEncoding = 3002;
  235. var LogLuvEncoding = 3003;
  236. var RGBM7Encoding = 3004;
  237. var RGBM16Encoding = 3005;
  238. var RGBDEncoding = 3006;
  239. var BasicDepthPacking = 3200;
  240. var RGBADepthPacking = 3201;
  241. var TangentSpaceNormalMap = 0;
  242. var ObjectSpaceNormalMap = 1;
  243. var ZeroStencilOp = 0;
  244. var KeepStencilOp = 7680;
  245. var ReplaceStencilOp = 7681;
  246. var IncrementStencilOp = 7682;
  247. var DecrementStencilOp = 7683;
  248. var IncrementWrapStencilOp = 34055;
  249. var DecrementWrapStencilOp = 34056;
  250. var InvertStencilOp = 5386;
  251. var NeverStencilFunc = 512;
  252. var LessStencilFunc = 513;
  253. var EqualStencilFunc = 514;
  254. var LessEqualStencilFunc = 515;
  255. var GreaterStencilFunc = 516;
  256. var NotEqualStencilFunc = 517;
  257. var GreaterEqualStencilFunc = 518;
  258. var AlwaysStencilFunc = 519;
  259. /**
  260. * @author alteredq / http://alteredqualia.com/
  261. * @author mrdoob / http://mrdoob.com/
  262. */
  263. var _lut = [];
  264. for ( var i = 0; i < 256; i ++ ) {
  265. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  266. }
  267. var _Math = {
  268. DEG2RAD: Math.PI / 180,
  269. RAD2DEG: 180 / Math.PI,
  270. generateUUID: function () {
  271. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  272. var d0 = Math.random() * 0xffffffff | 0;
  273. var d1 = Math.random() * 0xffffffff | 0;
  274. var d2 = Math.random() * 0xffffffff | 0;
  275. var d3 = Math.random() * 0xffffffff | 0;
  276. var uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  277. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  278. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  279. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  280. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  281. return uuid.toUpperCase();
  282. },
  283. clamp: function ( value, min, max ) {
  284. return Math.max( min, Math.min( max, value ) );
  285. },
  286. // compute euclidian modulo of m % n
  287. // https://en.wikipedia.org/wiki/Modulo_operation
  288. euclideanModulo: function ( n, m ) {
  289. return ( ( n % m ) + m ) % m;
  290. },
  291. // Linear mapping from range <a1, a2> to range <b1, b2>
  292. mapLinear: function ( x, a1, a2, b1, b2 ) {
  293. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  294. },
  295. // https://en.wikipedia.org/wiki/Linear_interpolation
  296. lerp: function ( x, y, t ) {
  297. return ( 1 - t ) * x + t * y;
  298. },
  299. // http://en.wikipedia.org/wiki/Smoothstep
  300. smoothstep: function ( x, min, max ) {
  301. if ( x <= min ) return 0;
  302. if ( x >= max ) return 1;
  303. x = ( x - min ) / ( max - min );
  304. return x * x * ( 3 - 2 * x );
  305. },
  306. smootherstep: function ( x, min, max ) {
  307. if ( x <= min ) return 0;
  308. if ( x >= max ) return 1;
  309. x = ( x - min ) / ( max - min );
  310. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  311. },
  312. // Random integer from <low, high> interval
  313. randInt: function ( low, high ) {
  314. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  315. },
  316. // Random float from <low, high> interval
  317. randFloat: function ( low, high ) {
  318. return low + Math.random() * ( high - low );
  319. },
  320. // Random float from <-range/2, range/2> interval
  321. randFloatSpread: function ( range ) {
  322. return range * ( 0.5 - Math.random() );
  323. },
  324. degToRad: function ( degrees ) {
  325. return degrees * _Math.DEG2RAD;
  326. },
  327. radToDeg: function ( radians ) {
  328. return radians * _Math.RAD2DEG;
  329. },
  330. isPowerOfTwo: function ( value ) {
  331. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  332. },
  333. ceilPowerOfTwo: function ( value ) {
  334. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  335. },
  336. floorPowerOfTwo: function ( value ) {
  337. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  338. }
  339. };
  340. /**
  341. * @author mrdoob / http://mrdoob.com/
  342. * @author philogb / http://blog.thejit.org/
  343. * @author egraether / http://egraether.com/
  344. * @author zz85 / http://www.lab4games.net/zz85/blog
  345. */
  346. function Vector2( x, y ) {
  347. this.x = x || 0;
  348. this.y = y || 0;
  349. }
  350. Object.defineProperties( Vector2.prototype, {
  351. "width": {
  352. get: function () {
  353. return this.x;
  354. },
  355. set: function ( value ) {
  356. this.x = value;
  357. }
  358. },
  359. "height": {
  360. get: function () {
  361. return this.y;
  362. },
  363. set: function ( value ) {
  364. this.y = value;
  365. }
  366. }
  367. } );
  368. Object.assign( Vector2.prototype, {
  369. isVector2: true,
  370. set: function ( x, y ) {
  371. this.x = x;
  372. this.y = y;
  373. return this;
  374. },
  375. setScalar: function ( scalar ) {
  376. this.x = scalar;
  377. this.y = scalar;
  378. return this;
  379. },
  380. setX: function ( x ) {
  381. this.x = x;
  382. return this;
  383. },
  384. setY: function ( y ) {
  385. this.y = y;
  386. return this;
  387. },
  388. setComponent: function ( index, value ) {
  389. switch ( index ) {
  390. case 0: this.x = value; break;
  391. case 1: this.y = value; break;
  392. default: throw new Error( 'index is out of range: ' + index );
  393. }
  394. return this;
  395. },
  396. getComponent: function ( index ) {
  397. switch ( index ) {
  398. case 0: return this.x;
  399. case 1: return this.y;
  400. default: throw new Error( 'index is out of range: ' + index );
  401. }
  402. },
  403. clone: function () {
  404. return new this.constructor( this.x, this.y );
  405. },
  406. copy: function ( v ) {
  407. this.x = v.x;
  408. this.y = v.y;
  409. return this;
  410. },
  411. add: function ( v, w ) {
  412. if ( w !== undefined ) {
  413. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  414. return this.addVectors( v, w );
  415. }
  416. this.x += v.x;
  417. this.y += v.y;
  418. return this;
  419. },
  420. addScalar: function ( s ) {
  421. this.x += s;
  422. this.y += s;
  423. return this;
  424. },
  425. addVectors: function ( a, b ) {
  426. this.x = a.x + b.x;
  427. this.y = a.y + b.y;
  428. return this;
  429. },
  430. addScaledVector: function ( v, s ) {
  431. this.x += v.x * s;
  432. this.y += v.y * s;
  433. return this;
  434. },
  435. sub: function ( v, w ) {
  436. if ( w !== undefined ) {
  437. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  438. return this.subVectors( v, w );
  439. }
  440. this.x -= v.x;
  441. this.y -= v.y;
  442. return this;
  443. },
  444. subScalar: function ( s ) {
  445. this.x -= s;
  446. this.y -= s;
  447. return this;
  448. },
  449. subVectors: function ( a, b ) {
  450. this.x = a.x - b.x;
  451. this.y = a.y - b.y;
  452. return this;
  453. },
  454. multiply: function ( v ) {
  455. this.x *= v.x;
  456. this.y *= v.y;
  457. return this;
  458. },
  459. multiplyScalar: function ( scalar ) {
  460. this.x *= scalar;
  461. this.y *= scalar;
  462. return this;
  463. },
  464. divide: function ( v ) {
  465. this.x /= v.x;
  466. this.y /= v.y;
  467. return this;
  468. },
  469. divideScalar: function ( scalar ) {
  470. return this.multiplyScalar( 1 / scalar );
  471. },
  472. applyMatrix3: function ( m ) {
  473. var x = this.x, y = this.y;
  474. var e = m.elements;
  475. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  476. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  477. return this;
  478. },
  479. min: function ( v ) {
  480. this.x = Math.min( this.x, v.x );
  481. this.y = Math.min( this.y, v.y );
  482. return this;
  483. },
  484. max: function ( v ) {
  485. this.x = Math.max( this.x, v.x );
  486. this.y = Math.max( this.y, v.y );
  487. return this;
  488. },
  489. clamp: function ( min, max ) {
  490. // assumes min < max, componentwise
  491. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  492. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  493. return this;
  494. },
  495. clampScalar: function ( minVal, maxVal ) {
  496. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  497. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  498. return this;
  499. },
  500. clampLength: function ( min, max ) {
  501. var length = this.length();
  502. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  503. },
  504. floor: function () {
  505. this.x = Math.floor( this.x );
  506. this.y = Math.floor( this.y );
  507. return this;
  508. },
  509. ceil: function () {
  510. this.x = Math.ceil( this.x );
  511. this.y = Math.ceil( this.y );
  512. return this;
  513. },
  514. round: function () {
  515. this.x = Math.round( this.x );
  516. this.y = Math.round( this.y );
  517. return this;
  518. },
  519. roundToZero: function () {
  520. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  521. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  522. return this;
  523. },
  524. negate: function () {
  525. this.x = - this.x;
  526. this.y = - this.y;
  527. return this;
  528. },
  529. dot: function ( v ) {
  530. return this.x * v.x + this.y * v.y;
  531. },
  532. cross: function ( v ) {
  533. return this.x * v.y - this.y * v.x;
  534. },
  535. lengthSq: function () {
  536. return this.x * this.x + this.y * this.y;
  537. },
  538. length: function () {
  539. return Math.sqrt( this.x * this.x + this.y * this.y );
  540. },
  541. manhattanLength: function () {
  542. return Math.abs( this.x ) + Math.abs( this.y );
  543. },
  544. normalize: function () {
  545. return this.divideScalar( this.length() || 1 );
  546. },
  547. angle: function () {
  548. // computes the angle in radians with respect to the positive x-axis
  549. var angle = Math.atan2( this.y, this.x );
  550. if ( angle < 0 ) angle += 2 * Math.PI;
  551. return angle;
  552. },
  553. distanceTo: function ( v ) {
  554. return Math.sqrt( this.distanceToSquared( v ) );
  555. },
  556. distanceToSquared: function ( v ) {
  557. var dx = this.x - v.x, dy = this.y - v.y;
  558. return dx * dx + dy * dy;
  559. },
  560. manhattanDistanceTo: function ( v ) {
  561. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  562. },
  563. setLength: function ( length ) {
  564. return this.normalize().multiplyScalar( length );
  565. },
  566. lerp: function ( v, alpha ) {
  567. this.x += ( v.x - this.x ) * alpha;
  568. this.y += ( v.y - this.y ) * alpha;
  569. return this;
  570. },
  571. lerpVectors: function ( v1, v2, alpha ) {
  572. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  573. },
  574. equals: function ( v ) {
  575. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  576. },
  577. fromArray: function ( array, offset ) {
  578. if ( offset === undefined ) offset = 0;
  579. this.x = array[ offset ];
  580. this.y = array[ offset + 1 ];
  581. return this;
  582. },
  583. toArray: function ( array, offset ) {
  584. if ( array === undefined ) array = [];
  585. if ( offset === undefined ) offset = 0;
  586. array[ offset ] = this.x;
  587. array[ offset + 1 ] = this.y;
  588. return array;
  589. },
  590. fromBufferAttribute: function ( attribute, index, offset ) {
  591. if ( offset !== undefined ) {
  592. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  593. }
  594. this.x = attribute.getX( index );
  595. this.y = attribute.getY( index );
  596. return this;
  597. },
  598. rotateAround: function ( center, angle ) {
  599. var c = Math.cos( angle ), s = Math.sin( angle );
  600. var x = this.x - center.x;
  601. var y = this.y - center.y;
  602. this.x = x * c - y * s + center.x;
  603. this.y = x * s + y * c + center.y;
  604. return this;
  605. }
  606. } );
  607. /**
  608. * @author mikael emtinger / http://gomo.se/
  609. * @author alteredq / http://alteredqualia.com/
  610. * @author WestLangley / http://github.com/WestLangley
  611. * @author bhouston / http://clara.io
  612. */
  613. function Quaternion( x, y, z, w ) {
  614. this._x = x || 0;
  615. this._y = y || 0;
  616. this._z = z || 0;
  617. this._w = ( w !== undefined ) ? w : 1;
  618. }
  619. Object.assign( Quaternion, {
  620. slerp: function ( qa, qb, qm, t ) {
  621. return qm.copy( qa ).slerp( qb, t );
  622. },
  623. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  624. // fuzz-free, array-based Quaternion SLERP operation
  625. var x0 = src0[ srcOffset0 + 0 ],
  626. y0 = src0[ srcOffset0 + 1 ],
  627. z0 = src0[ srcOffset0 + 2 ],
  628. w0 = src0[ srcOffset0 + 3 ],
  629. x1 = src1[ srcOffset1 + 0 ],
  630. y1 = src1[ srcOffset1 + 1 ],
  631. z1 = src1[ srcOffset1 + 2 ],
  632. w1 = src1[ srcOffset1 + 3 ];
  633. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  634. var s = 1 - t,
  635. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  636. dir = ( cos >= 0 ? 1 : - 1 ),
  637. sqrSin = 1 - cos * cos;
  638. // Skip the Slerp for tiny steps to avoid numeric problems:
  639. if ( sqrSin > Number.EPSILON ) {
  640. var sin = Math.sqrt( sqrSin ),
  641. len = Math.atan2( sin, cos * dir );
  642. s = Math.sin( s * len ) / sin;
  643. t = Math.sin( t * len ) / sin;
  644. }
  645. var tDir = t * dir;
  646. x0 = x0 * s + x1 * tDir;
  647. y0 = y0 * s + y1 * tDir;
  648. z0 = z0 * s + z1 * tDir;
  649. w0 = w0 * s + w1 * tDir;
  650. // Normalize in case we just did a lerp:
  651. if ( s === 1 - t ) {
  652. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  653. x0 *= f;
  654. y0 *= f;
  655. z0 *= f;
  656. w0 *= f;
  657. }
  658. }
  659. dst[ dstOffset ] = x0;
  660. dst[ dstOffset + 1 ] = y0;
  661. dst[ dstOffset + 2 ] = z0;
  662. dst[ dstOffset + 3 ] = w0;
  663. }
  664. } );
  665. Object.defineProperties( Quaternion.prototype, {
  666. x: {
  667. get: function () {
  668. return this._x;
  669. },
  670. set: function ( value ) {
  671. this._x = value;
  672. this._onChangeCallback();
  673. }
  674. },
  675. y: {
  676. get: function () {
  677. return this._y;
  678. },
  679. set: function ( value ) {
  680. this._y = value;
  681. this._onChangeCallback();
  682. }
  683. },
  684. z: {
  685. get: function () {
  686. return this._z;
  687. },
  688. set: function ( value ) {
  689. this._z = value;
  690. this._onChangeCallback();
  691. }
  692. },
  693. w: {
  694. get: function () {
  695. return this._w;
  696. },
  697. set: function ( value ) {
  698. this._w = value;
  699. this._onChangeCallback();
  700. }
  701. }
  702. } );
  703. Object.assign( Quaternion.prototype, {
  704. isQuaternion: true,
  705. set: function ( x, y, z, w ) {
  706. this._x = x;
  707. this._y = y;
  708. this._z = z;
  709. this._w = w;
  710. this._onChangeCallback();
  711. return this;
  712. },
  713. clone: function () {
  714. return new this.constructor( this._x, this._y, this._z, this._w );
  715. },
  716. copy: function ( quaternion ) {
  717. this._x = quaternion.x;
  718. this._y = quaternion.y;
  719. this._z = quaternion.z;
  720. this._w = quaternion.w;
  721. this._onChangeCallback();
  722. return this;
  723. },
  724. setFromEuler: function ( euler, update ) {
  725. if ( ! ( euler && euler.isEuler ) ) {
  726. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  727. }
  728. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  729. // http://www.mathworks.com/matlabcentral/fileexchange/
  730. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  731. // content/SpinCalc.m
  732. var cos = Math.cos;
  733. var sin = Math.sin;
  734. var c1 = cos( x / 2 );
  735. var c2 = cos( y / 2 );
  736. var c3 = cos( z / 2 );
  737. var s1 = sin( x / 2 );
  738. var s2 = sin( y / 2 );
  739. var s3 = sin( z / 2 );
  740. if ( order === 'XYZ' ) {
  741. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  742. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  743. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  744. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  745. } else if ( order === 'YXZ' ) {
  746. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  747. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  748. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  749. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  750. } else if ( order === 'ZXY' ) {
  751. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  752. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  753. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  754. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  755. } else if ( order === 'ZYX' ) {
  756. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  757. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  758. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  759. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  760. } else if ( order === 'YZX' ) {
  761. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  762. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  763. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  764. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  765. } else if ( order === 'XZY' ) {
  766. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  767. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  768. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  769. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  770. }
  771. if ( update !== false ) this._onChangeCallback();
  772. return this;
  773. },
  774. setFromAxisAngle: function ( axis, angle ) {
  775. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  776. // assumes axis is normalized
  777. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  778. this._x = axis.x * s;
  779. this._y = axis.y * s;
  780. this._z = axis.z * s;
  781. this._w = Math.cos( halfAngle );
  782. this._onChangeCallback();
  783. return this;
  784. },
  785. setFromRotationMatrix: function ( m ) {
  786. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  787. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  788. var te = m.elements,
  789. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  790. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  791. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  792. trace = m11 + m22 + m33,
  793. s;
  794. if ( trace > 0 ) {
  795. s = 0.5 / Math.sqrt( trace + 1.0 );
  796. this._w = 0.25 / s;
  797. this._x = ( m32 - m23 ) * s;
  798. this._y = ( m13 - m31 ) * s;
  799. this._z = ( m21 - m12 ) * s;
  800. } else if ( m11 > m22 && m11 > m33 ) {
  801. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  802. this._w = ( m32 - m23 ) / s;
  803. this._x = 0.25 * s;
  804. this._y = ( m12 + m21 ) / s;
  805. this._z = ( m13 + m31 ) / s;
  806. } else if ( m22 > m33 ) {
  807. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  808. this._w = ( m13 - m31 ) / s;
  809. this._x = ( m12 + m21 ) / s;
  810. this._y = 0.25 * s;
  811. this._z = ( m23 + m32 ) / s;
  812. } else {
  813. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  814. this._w = ( m21 - m12 ) / s;
  815. this._x = ( m13 + m31 ) / s;
  816. this._y = ( m23 + m32 ) / s;
  817. this._z = 0.25 * s;
  818. }
  819. this._onChangeCallback();
  820. return this;
  821. },
  822. setFromUnitVectors: function ( vFrom, vTo ) {
  823. // assumes direction vectors vFrom and vTo are normalized
  824. var EPS = 0.000001;
  825. var r = vFrom.dot( vTo ) + 1;
  826. if ( r < EPS ) {
  827. r = 0;
  828. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  829. this._x = - vFrom.y;
  830. this._y = vFrom.x;
  831. this._z = 0;
  832. this._w = r;
  833. } else {
  834. this._x = 0;
  835. this._y = - vFrom.z;
  836. this._z = vFrom.y;
  837. this._w = r;
  838. }
  839. } else {
  840. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  841. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  842. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  843. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  844. this._w = r;
  845. }
  846. return this.normalize();
  847. },
  848. angleTo: function ( q ) {
  849. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  850. },
  851. rotateTowards: function ( q, step ) {
  852. var angle = this.angleTo( q );
  853. if ( angle === 0 ) return this;
  854. var t = Math.min( 1, step / angle );
  855. this.slerp( q, t );
  856. return this;
  857. },
  858. inverse: function () {
  859. // quaternion is assumed to have unit length
  860. return this.conjugate();
  861. },
  862. conjugate: function () {
  863. this._x *= - 1;
  864. this._y *= - 1;
  865. this._z *= - 1;
  866. this._onChangeCallback();
  867. return this;
  868. },
  869. dot: function ( v ) {
  870. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  871. },
  872. lengthSq: function () {
  873. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  874. },
  875. length: function () {
  876. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  877. },
  878. normalize: function () {
  879. var l = this.length();
  880. if ( l === 0 ) {
  881. this._x = 0;
  882. this._y = 0;
  883. this._z = 0;
  884. this._w = 1;
  885. } else {
  886. l = 1 / l;
  887. this._x = this._x * l;
  888. this._y = this._y * l;
  889. this._z = this._z * l;
  890. this._w = this._w * l;
  891. }
  892. this._onChangeCallback();
  893. return this;
  894. },
  895. multiply: function ( q, p ) {
  896. if ( p !== undefined ) {
  897. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  898. return this.multiplyQuaternions( q, p );
  899. }
  900. return this.multiplyQuaternions( this, q );
  901. },
  902. premultiply: function ( q ) {
  903. return this.multiplyQuaternions( q, this );
  904. },
  905. multiplyQuaternions: function ( a, b ) {
  906. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  907. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  908. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  909. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  910. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  911. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  912. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  913. this._onChangeCallback();
  914. return this;
  915. },
  916. slerp: function ( qb, t ) {
  917. if ( t === 0 ) return this;
  918. if ( t === 1 ) return this.copy( qb );
  919. var x = this._x, y = this._y, z = this._z, w = this._w;
  920. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  921. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  922. if ( cosHalfTheta < 0 ) {
  923. this._w = - qb._w;
  924. this._x = - qb._x;
  925. this._y = - qb._y;
  926. this._z = - qb._z;
  927. cosHalfTheta = - cosHalfTheta;
  928. } else {
  929. this.copy( qb );
  930. }
  931. if ( cosHalfTheta >= 1.0 ) {
  932. this._w = w;
  933. this._x = x;
  934. this._y = y;
  935. this._z = z;
  936. return this;
  937. }
  938. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  939. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  940. var s = 1 - t;
  941. this._w = s * w + t * this._w;
  942. this._x = s * x + t * this._x;
  943. this._y = s * y + t * this._y;
  944. this._z = s * z + t * this._z;
  945. this.normalize();
  946. this._onChangeCallback();
  947. return this;
  948. }
  949. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  950. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  951. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  952. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  953. this._w = ( w * ratioA + this._w * ratioB );
  954. this._x = ( x * ratioA + this._x * ratioB );
  955. this._y = ( y * ratioA + this._y * ratioB );
  956. this._z = ( z * ratioA + this._z * ratioB );
  957. this._onChangeCallback();
  958. return this;
  959. },
  960. equals: function ( quaternion ) {
  961. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  962. },
  963. fromArray: function ( array, offset ) {
  964. if ( offset === undefined ) offset = 0;
  965. this._x = array[ offset ];
  966. this._y = array[ offset + 1 ];
  967. this._z = array[ offset + 2 ];
  968. this._w = array[ offset + 3 ];
  969. this._onChangeCallback();
  970. return this;
  971. },
  972. toArray: function ( array, offset ) {
  973. if ( array === undefined ) array = [];
  974. if ( offset === undefined ) offset = 0;
  975. array[ offset ] = this._x;
  976. array[ offset + 1 ] = this._y;
  977. array[ offset + 2 ] = this._z;
  978. array[ offset + 3 ] = this._w;
  979. return array;
  980. },
  981. _onChange: function ( callback ) {
  982. this._onChangeCallback = callback;
  983. return this;
  984. },
  985. _onChangeCallback: function () {}
  986. } );
  987. /**
  988. * @author mrdoob / http://mrdoob.com/
  989. * @author kile / http://kile.stravaganza.org/
  990. * @author philogb / http://blog.thejit.org/
  991. * @author mikael emtinger / http://gomo.se/
  992. * @author egraether / http://egraether.com/
  993. * @author WestLangley / http://github.com/WestLangley
  994. */
  995. var _vector, _quaternion;
  996. function Vector3( x, y, z ) {
  997. this.x = x || 0;
  998. this.y = y || 0;
  999. this.z = z || 0;
  1000. }
  1001. Object.assign( Vector3.prototype, {
  1002. isVector3: true,
  1003. set: function ( x, y, z ) {
  1004. this.x = x;
  1005. this.y = y;
  1006. this.z = z;
  1007. return this;
  1008. },
  1009. setScalar: function ( scalar ) {
  1010. this.x = scalar;
  1011. this.y = scalar;
  1012. this.z = scalar;
  1013. return this;
  1014. },
  1015. setX: function ( x ) {
  1016. this.x = x;
  1017. return this;
  1018. },
  1019. setY: function ( y ) {
  1020. this.y = y;
  1021. return this;
  1022. },
  1023. setZ: function ( z ) {
  1024. this.z = z;
  1025. return this;
  1026. },
  1027. setComponent: function ( index, value ) {
  1028. switch ( index ) {
  1029. case 0: this.x = value; break;
  1030. case 1: this.y = value; break;
  1031. case 2: this.z = value; break;
  1032. default: throw new Error( 'index is out of range: ' + index );
  1033. }
  1034. return this;
  1035. },
  1036. getComponent: function ( index ) {
  1037. switch ( index ) {
  1038. case 0: return this.x;
  1039. case 1: return this.y;
  1040. case 2: return this.z;
  1041. default: throw new Error( 'index is out of range: ' + index );
  1042. }
  1043. },
  1044. clone: function () {
  1045. return new this.constructor( this.x, this.y, this.z );
  1046. },
  1047. copy: function ( v ) {
  1048. this.x = v.x;
  1049. this.y = v.y;
  1050. this.z = v.z;
  1051. return this;
  1052. },
  1053. add: function ( v, w ) {
  1054. if ( w !== undefined ) {
  1055. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1056. return this.addVectors( v, w );
  1057. }
  1058. this.x += v.x;
  1059. this.y += v.y;
  1060. this.z += v.z;
  1061. return this;
  1062. },
  1063. addScalar: function ( s ) {
  1064. this.x += s;
  1065. this.y += s;
  1066. this.z += s;
  1067. return this;
  1068. },
  1069. addVectors: function ( a, b ) {
  1070. this.x = a.x + b.x;
  1071. this.y = a.y + b.y;
  1072. this.z = a.z + b.z;
  1073. return this;
  1074. },
  1075. addScaledVector: function ( v, s ) {
  1076. this.x += v.x * s;
  1077. this.y += v.y * s;
  1078. this.z += v.z * s;
  1079. return this;
  1080. },
  1081. sub: function ( v, w ) {
  1082. if ( w !== undefined ) {
  1083. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1084. return this.subVectors( v, w );
  1085. }
  1086. this.x -= v.x;
  1087. this.y -= v.y;
  1088. this.z -= v.z;
  1089. return this;
  1090. },
  1091. subScalar: function ( s ) {
  1092. this.x -= s;
  1093. this.y -= s;
  1094. this.z -= s;
  1095. return this;
  1096. },
  1097. subVectors: 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. multiply: function ( v, w ) {
  1104. if ( w !== undefined ) {
  1105. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1106. return this.multiplyVectors( v, w );
  1107. }
  1108. this.x *= v.x;
  1109. this.y *= v.y;
  1110. this.z *= v.z;
  1111. return this;
  1112. },
  1113. multiplyScalar: function ( scalar ) {
  1114. this.x *= scalar;
  1115. this.y *= scalar;
  1116. this.z *= scalar;
  1117. return this;
  1118. },
  1119. multiplyVectors: function ( a, b ) {
  1120. this.x = a.x * b.x;
  1121. this.y = a.y * b.y;
  1122. this.z = a.z * b.z;
  1123. return this;
  1124. },
  1125. applyEuler: function ( euler ) {
  1126. if ( _quaternion === undefined ) _quaternion = new Quaternion();
  1127. if ( ! ( euler && euler.isEuler ) ) {
  1128. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1129. }
  1130. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  1131. },
  1132. applyAxisAngle: function ( axis, angle ) {
  1133. if ( _quaternion === undefined ) _quaternion = new Quaternion();
  1134. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  1135. },
  1136. applyMatrix3: function ( m ) {
  1137. var x = this.x, y = this.y, z = this.z;
  1138. var e = m.elements;
  1139. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1140. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1141. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1142. return this;
  1143. },
  1144. applyMatrix4: function ( m ) {
  1145. var x = this.x, y = this.y, z = this.z;
  1146. var e = m.elements;
  1147. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1148. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1149. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1150. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1151. return this;
  1152. },
  1153. applyQuaternion: function ( q ) {
  1154. var x = this.x, y = this.y, z = this.z;
  1155. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1156. // calculate quat * vector
  1157. var ix = qw * x + qy * z - qz * y;
  1158. var iy = qw * y + qz * x - qx * z;
  1159. var iz = qw * z + qx * y - qy * x;
  1160. var iw = - qx * x - qy * y - qz * z;
  1161. // calculate result * inverse quat
  1162. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1163. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1164. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1165. return this;
  1166. },
  1167. project: function ( camera ) {
  1168. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1169. },
  1170. unproject: function ( camera ) {
  1171. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1172. },
  1173. transformDirection: function ( m ) {
  1174. // input: THREE.Matrix4 affine matrix
  1175. // vector interpreted as a direction
  1176. var x = this.x, y = this.y, z = this.z;
  1177. var e = m.elements;
  1178. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1179. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1180. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1181. return this.normalize();
  1182. },
  1183. divide: function ( v ) {
  1184. this.x /= v.x;
  1185. this.y /= v.y;
  1186. this.z /= v.z;
  1187. return this;
  1188. },
  1189. divideScalar: function ( scalar ) {
  1190. return this.multiplyScalar( 1 / scalar );
  1191. },
  1192. min: function ( v ) {
  1193. this.x = Math.min( this.x, v.x );
  1194. this.y = Math.min( this.y, v.y );
  1195. this.z = Math.min( this.z, v.z );
  1196. return this;
  1197. },
  1198. max: function ( v ) {
  1199. this.x = Math.max( this.x, v.x );
  1200. this.y = Math.max( this.y, v.y );
  1201. this.z = Math.max( this.z, v.z );
  1202. return this;
  1203. },
  1204. clamp: function ( min, max ) {
  1205. // assumes min < max, componentwise
  1206. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1207. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1208. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1209. return this;
  1210. },
  1211. clampScalar: function ( minVal, maxVal ) {
  1212. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1213. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1214. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1215. return this;
  1216. },
  1217. clampLength: function ( min, max ) {
  1218. var length = this.length();
  1219. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1220. },
  1221. floor: function () {
  1222. this.x = Math.floor( this.x );
  1223. this.y = Math.floor( this.y );
  1224. this.z = Math.floor( this.z );
  1225. return this;
  1226. },
  1227. ceil: function () {
  1228. this.x = Math.ceil( this.x );
  1229. this.y = Math.ceil( this.y );
  1230. this.z = Math.ceil( this.z );
  1231. return this;
  1232. },
  1233. round: function () {
  1234. this.x = Math.round( this.x );
  1235. this.y = Math.round( this.y );
  1236. this.z = Math.round( this.z );
  1237. return this;
  1238. },
  1239. roundToZero: function () {
  1240. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1241. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1242. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1243. return this;
  1244. },
  1245. negate: function () {
  1246. this.x = - this.x;
  1247. this.y = - this.y;
  1248. this.z = - this.z;
  1249. return this;
  1250. },
  1251. dot: function ( v ) {
  1252. return this.x * v.x + this.y * v.y + this.z * v.z;
  1253. },
  1254. // TODO lengthSquared?
  1255. lengthSq: function () {
  1256. return this.x * this.x + this.y * this.y + this.z * this.z;
  1257. },
  1258. length: function () {
  1259. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1260. },
  1261. manhattanLength: function () {
  1262. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1263. },
  1264. normalize: function () {
  1265. return this.divideScalar( this.length() || 1 );
  1266. },
  1267. setLength: function ( length ) {
  1268. return this.normalize().multiplyScalar( length );
  1269. },
  1270. lerp: function ( v, alpha ) {
  1271. this.x += ( v.x - this.x ) * alpha;
  1272. this.y += ( v.y - this.y ) * alpha;
  1273. this.z += ( v.z - this.z ) * alpha;
  1274. return this;
  1275. },
  1276. lerpVectors: function ( v1, v2, alpha ) {
  1277. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1278. },
  1279. cross: function ( v, w ) {
  1280. if ( w !== undefined ) {
  1281. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1282. return this.crossVectors( v, w );
  1283. }
  1284. return this.crossVectors( this, v );
  1285. },
  1286. crossVectors: function ( a, b ) {
  1287. var ax = a.x, ay = a.y, az = a.z;
  1288. var bx = b.x, by = b.y, bz = b.z;
  1289. this.x = ay * bz - az * by;
  1290. this.y = az * bx - ax * bz;
  1291. this.z = ax * by - ay * bx;
  1292. return this;
  1293. },
  1294. projectOnVector: function ( vector ) {
  1295. var scalar = vector.dot( this ) / vector.lengthSq();
  1296. return this.copy( vector ).multiplyScalar( scalar );
  1297. },
  1298. projectOnPlane: function ( planeNormal ) {
  1299. if ( _vector === undefined ) _vector = new Vector3();
  1300. _vector.copy( this ).projectOnVector( planeNormal );
  1301. return this.sub( _vector );
  1302. },
  1303. reflect: function ( normal ) {
  1304. if ( _vector === undefined ) _vector = new Vector3();
  1305. // reflect incident vector off plane orthogonal to normal
  1306. // normal is assumed to have unit length
  1307. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1308. },
  1309. angleTo: function ( v ) {
  1310. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1311. // clamp, to handle numerical problems
  1312. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1313. },
  1314. distanceTo: function ( v ) {
  1315. return Math.sqrt( this.distanceToSquared( v ) );
  1316. },
  1317. distanceToSquared: function ( v ) {
  1318. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1319. return dx * dx + dy * dy + dz * dz;
  1320. },
  1321. manhattanDistanceTo: function ( v ) {
  1322. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1323. },
  1324. setFromSpherical: function ( s ) {
  1325. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1326. },
  1327. setFromSphericalCoords: function ( radius, phi, theta ) {
  1328. var sinPhiRadius = Math.sin( phi ) * radius;
  1329. this.x = sinPhiRadius * Math.sin( theta );
  1330. this.y = Math.cos( phi ) * radius;
  1331. this.z = sinPhiRadius * Math.cos( theta );
  1332. return this;
  1333. },
  1334. setFromCylindrical: function ( c ) {
  1335. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1336. },
  1337. setFromCylindricalCoords: function ( radius, theta, y ) {
  1338. this.x = radius * Math.sin( theta );
  1339. this.y = y;
  1340. this.z = radius * Math.cos( theta );
  1341. return this;
  1342. },
  1343. setFromMatrixPosition: function ( m ) {
  1344. var e = m.elements;
  1345. this.x = e[ 12 ];
  1346. this.y = e[ 13 ];
  1347. this.z = e[ 14 ];
  1348. return this;
  1349. },
  1350. setFromMatrixScale: function ( m ) {
  1351. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1352. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1353. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1354. this.x = sx;
  1355. this.y = sy;
  1356. this.z = sz;
  1357. return this;
  1358. },
  1359. setFromMatrixColumn: function ( m, index ) {
  1360. return this.fromArray( m.elements, index * 4 );
  1361. },
  1362. equals: function ( v ) {
  1363. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1364. },
  1365. fromArray: function ( array, offset ) {
  1366. if ( offset === undefined ) offset = 0;
  1367. this.x = array[ offset ];
  1368. this.y = array[ offset + 1 ];
  1369. this.z = array[ offset + 2 ];
  1370. return this;
  1371. },
  1372. toArray: function ( array, offset ) {
  1373. if ( array === undefined ) array = [];
  1374. if ( offset === undefined ) offset = 0;
  1375. array[ offset ] = this.x;
  1376. array[ offset + 1 ] = this.y;
  1377. array[ offset + 2 ] = this.z;
  1378. return array;
  1379. },
  1380. fromBufferAttribute: function ( attribute, index, offset ) {
  1381. if ( offset !== undefined ) {
  1382. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1383. }
  1384. this.x = attribute.getX( index );
  1385. this.y = attribute.getY( index );
  1386. this.z = attribute.getZ( index );
  1387. return this;
  1388. }
  1389. } );
  1390. /**
  1391. * @author alteredq / http://alteredqualia.com/
  1392. * @author WestLangley / http://github.com/WestLangley
  1393. * @author bhouston / http://clara.io
  1394. * @author tschw
  1395. */
  1396. var _vector$1;
  1397. function Matrix3() {
  1398. this.elements = [
  1399. 1, 0, 0,
  1400. 0, 1, 0,
  1401. 0, 0, 1
  1402. ];
  1403. if ( arguments.length > 0 ) {
  1404. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1405. }
  1406. }
  1407. Object.assign( Matrix3.prototype, {
  1408. isMatrix3: true,
  1409. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1410. var te = this.elements;
  1411. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1412. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1413. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1414. return this;
  1415. },
  1416. identity: function () {
  1417. this.set(
  1418. 1, 0, 0,
  1419. 0, 1, 0,
  1420. 0, 0, 1
  1421. );
  1422. return this;
  1423. },
  1424. clone: function () {
  1425. return new this.constructor().fromArray( this.elements );
  1426. },
  1427. copy: function ( m ) {
  1428. var te = this.elements;
  1429. var me = m.elements;
  1430. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1431. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1432. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1433. return this;
  1434. },
  1435. setFromMatrix4: function ( m ) {
  1436. var me = m.elements;
  1437. this.set(
  1438. me[ 0 ], me[ 4 ], me[ 8 ],
  1439. me[ 1 ], me[ 5 ], me[ 9 ],
  1440. me[ 2 ], me[ 6 ], me[ 10 ]
  1441. );
  1442. return this;
  1443. },
  1444. applyToBufferAttribute: function ( attribute ) {
  1445. if ( _vector$1 === undefined ) _vector$1 = new Vector3();
  1446. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1447. _vector$1.x = attribute.getX( i );
  1448. _vector$1.y = attribute.getY( i );
  1449. _vector$1.z = attribute.getZ( i );
  1450. _vector$1.applyMatrix3( this );
  1451. attribute.setXYZ( i, _vector$1.x, _vector$1.y, _vector$1.z );
  1452. }
  1453. return attribute;
  1454. },
  1455. multiply: function ( m ) {
  1456. return this.multiplyMatrices( this, m );
  1457. },
  1458. premultiply: function ( m ) {
  1459. return this.multiplyMatrices( m, this );
  1460. },
  1461. multiplyMatrices: function ( a, b ) {
  1462. var ae = a.elements;
  1463. var be = b.elements;
  1464. var te = this.elements;
  1465. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1466. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1467. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1468. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1469. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1470. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1471. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1472. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1473. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1474. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1475. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1476. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1477. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1478. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1479. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1480. return this;
  1481. },
  1482. multiplyScalar: function ( s ) {
  1483. var te = this.elements;
  1484. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1485. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1486. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1487. return this;
  1488. },
  1489. determinant: function () {
  1490. var te = this.elements;
  1491. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1492. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1493. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1494. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1495. },
  1496. getInverse: function ( matrix, throwOnDegenerate ) {
  1497. if ( matrix && matrix.isMatrix4 ) {
  1498. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1499. }
  1500. var me = matrix.elements,
  1501. te = this.elements,
  1502. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1503. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1504. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1505. t11 = n33 * n22 - n32 * n23,
  1506. t12 = n32 * n13 - n33 * n12,
  1507. t13 = n23 * n12 - n22 * n13,
  1508. det = n11 * t11 + n21 * t12 + n31 * t13;
  1509. if ( det === 0 ) {
  1510. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1511. if ( throwOnDegenerate === true ) {
  1512. throw new Error( msg );
  1513. } else {
  1514. console.warn( msg );
  1515. }
  1516. return this.identity();
  1517. }
  1518. var detInv = 1 / det;
  1519. te[ 0 ] = t11 * detInv;
  1520. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1521. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1522. te[ 3 ] = t12 * detInv;
  1523. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1524. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1525. te[ 6 ] = t13 * detInv;
  1526. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1527. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1528. return this;
  1529. },
  1530. transpose: function () {
  1531. var tmp, m = this.elements;
  1532. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1533. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1534. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1535. return this;
  1536. },
  1537. getNormalMatrix: function ( matrix4 ) {
  1538. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1539. },
  1540. transposeIntoArray: function ( r ) {
  1541. var m = this.elements;
  1542. r[ 0 ] = m[ 0 ];
  1543. r[ 1 ] = m[ 3 ];
  1544. r[ 2 ] = m[ 6 ];
  1545. r[ 3 ] = m[ 1 ];
  1546. r[ 4 ] = m[ 4 ];
  1547. r[ 5 ] = m[ 7 ];
  1548. r[ 6 ] = m[ 2 ];
  1549. r[ 7 ] = m[ 5 ];
  1550. r[ 8 ] = m[ 8 ];
  1551. return this;
  1552. },
  1553. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1554. var c = Math.cos( rotation );
  1555. var s = Math.sin( rotation );
  1556. this.set(
  1557. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1558. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1559. 0, 0, 1
  1560. );
  1561. },
  1562. scale: function ( sx, sy ) {
  1563. var te = this.elements;
  1564. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1565. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1566. return this;
  1567. },
  1568. rotate: function ( theta ) {
  1569. var c = Math.cos( theta );
  1570. var s = Math.sin( theta );
  1571. var te = this.elements;
  1572. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1573. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1574. te[ 0 ] = c * a11 + s * a21;
  1575. te[ 3 ] = c * a12 + s * a22;
  1576. te[ 6 ] = c * a13 + s * a23;
  1577. te[ 1 ] = - s * a11 + c * a21;
  1578. te[ 4 ] = - s * a12 + c * a22;
  1579. te[ 7 ] = - s * a13 + c * a23;
  1580. return this;
  1581. },
  1582. translate: function ( tx, ty ) {
  1583. var te = this.elements;
  1584. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1585. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1586. return this;
  1587. },
  1588. equals: function ( matrix ) {
  1589. var te = this.elements;
  1590. var me = matrix.elements;
  1591. for ( var i = 0; i < 9; i ++ ) {
  1592. if ( te[ i ] !== me[ i ] ) return false;
  1593. }
  1594. return true;
  1595. },
  1596. fromArray: function ( array, offset ) {
  1597. if ( offset === undefined ) offset = 0;
  1598. for ( var i = 0; i < 9; i ++ ) {
  1599. this.elements[ i ] = array[ i + offset ];
  1600. }
  1601. return this;
  1602. },
  1603. toArray: function ( array, offset ) {
  1604. if ( array === undefined ) array = [];
  1605. if ( offset === undefined ) offset = 0;
  1606. var te = this.elements;
  1607. array[ offset ] = te[ 0 ];
  1608. array[ offset + 1 ] = te[ 1 ];
  1609. array[ offset + 2 ] = te[ 2 ];
  1610. array[ offset + 3 ] = te[ 3 ];
  1611. array[ offset + 4 ] = te[ 4 ];
  1612. array[ offset + 5 ] = te[ 5 ];
  1613. array[ offset + 6 ] = te[ 6 ];
  1614. array[ offset + 7 ] = te[ 7 ];
  1615. array[ offset + 8 ] = te[ 8 ];
  1616. return array;
  1617. }
  1618. } );
  1619. /**
  1620. * @author mrdoob / http://mrdoob.com/
  1621. * @author alteredq / http://alteredqualia.com/
  1622. * @author szimek / https://github.com/szimek/
  1623. */
  1624. var _canvas;
  1625. var ImageUtils = {
  1626. getDataURL: function ( image ) {
  1627. var canvas;
  1628. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1629. return image.src;
  1630. } else if ( image instanceof HTMLCanvasElement ) {
  1631. canvas = image;
  1632. } else {
  1633. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1634. _canvas.width = image.width;
  1635. _canvas.height = image.height;
  1636. var context = _canvas.getContext( '2d' );
  1637. if ( image instanceof ImageData ) {
  1638. context.putImageData( image, 0, 0 );
  1639. } else {
  1640. context.drawImage( image, 0, 0, image.width, image.height );
  1641. }
  1642. canvas = _canvas;
  1643. }
  1644. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1645. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1646. } else {
  1647. return canvas.toDataURL( 'image/png' );
  1648. }
  1649. }
  1650. };
  1651. /**
  1652. * @author mrdoob / http://mrdoob.com/
  1653. * @author alteredq / http://alteredqualia.com/
  1654. * @author szimek / https://github.com/szimek/
  1655. */
  1656. var textureId = 0;
  1657. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1658. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1659. this.uuid = _Math.generateUUID();
  1660. this.name = '';
  1661. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1662. this.mipmaps = [];
  1663. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1664. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1665. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1666. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1667. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1668. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1669. this.format = format !== undefined ? format : RGBAFormat;
  1670. this.type = type !== undefined ? type : UnsignedByteType;
  1671. this.offset = new Vector2( 0, 0 );
  1672. this.repeat = new Vector2( 1, 1 );
  1673. this.center = new Vector2( 0, 0 );
  1674. this.rotation = 0;
  1675. this.matrixAutoUpdate = true;
  1676. this.matrix = new Matrix3();
  1677. this.generateMipmaps = true;
  1678. this.premultiplyAlpha = false;
  1679. this.flipY = true;
  1680. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1681. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1682. //
  1683. // Also changing the encoding after already used by a Material will not automatically make the Material
  1684. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1685. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1686. this.version = 0;
  1687. this.onUpdate = null;
  1688. }
  1689. Texture.DEFAULT_IMAGE = undefined;
  1690. Texture.DEFAULT_MAPPING = UVMapping;
  1691. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1692. constructor: Texture,
  1693. isTexture: true,
  1694. updateMatrix: function () {
  1695. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1696. },
  1697. clone: function () {
  1698. return new this.constructor().copy( this );
  1699. },
  1700. copy: function ( source ) {
  1701. this.name = source.name;
  1702. this.image = source.image;
  1703. this.mipmaps = source.mipmaps.slice( 0 );
  1704. this.mapping = source.mapping;
  1705. this.wrapS = source.wrapS;
  1706. this.wrapT = source.wrapT;
  1707. this.magFilter = source.magFilter;
  1708. this.minFilter = source.minFilter;
  1709. this.anisotropy = source.anisotropy;
  1710. this.format = source.format;
  1711. this.type = source.type;
  1712. this.offset.copy( source.offset );
  1713. this.repeat.copy( source.repeat );
  1714. this.center.copy( source.center );
  1715. this.rotation = source.rotation;
  1716. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1717. this.matrix.copy( source.matrix );
  1718. this.generateMipmaps = source.generateMipmaps;
  1719. this.premultiplyAlpha = source.premultiplyAlpha;
  1720. this.flipY = source.flipY;
  1721. this.unpackAlignment = source.unpackAlignment;
  1722. this.encoding = source.encoding;
  1723. return this;
  1724. },
  1725. toJSON: function ( meta ) {
  1726. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1727. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1728. return meta.textures[ this.uuid ];
  1729. }
  1730. var output = {
  1731. metadata: {
  1732. version: 4.5,
  1733. type: 'Texture',
  1734. generator: 'Texture.toJSON'
  1735. },
  1736. uuid: this.uuid,
  1737. name: this.name,
  1738. mapping: this.mapping,
  1739. repeat: [ this.repeat.x, this.repeat.y ],
  1740. offset: [ this.offset.x, this.offset.y ],
  1741. center: [ this.center.x, this.center.y ],
  1742. rotation: this.rotation,
  1743. wrap: [ this.wrapS, this.wrapT ],
  1744. format: this.format,
  1745. type: this.type,
  1746. encoding: this.encoding,
  1747. minFilter: this.minFilter,
  1748. magFilter: this.magFilter,
  1749. anisotropy: this.anisotropy,
  1750. flipY: this.flipY,
  1751. premultiplyAlpha: this.premultiplyAlpha,
  1752. unpackAlignment: this.unpackAlignment
  1753. };
  1754. if ( this.image !== undefined ) {
  1755. // TODO: Move to THREE.Image
  1756. var image = this.image;
  1757. if ( image.uuid === undefined ) {
  1758. image.uuid = _Math.generateUUID(); // UGH
  1759. }
  1760. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1761. var url;
  1762. if ( Array.isArray( image ) ) {
  1763. // process array of images e.g. CubeTexture
  1764. url = [];
  1765. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1766. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1767. }
  1768. } else {
  1769. // process single image
  1770. url = ImageUtils.getDataURL( image );
  1771. }
  1772. meta.images[ image.uuid ] = {
  1773. uuid: image.uuid,
  1774. url: url
  1775. };
  1776. }
  1777. output.image = image.uuid;
  1778. }
  1779. if ( ! isRootObject ) {
  1780. meta.textures[ this.uuid ] = output;
  1781. }
  1782. return output;
  1783. },
  1784. dispose: function () {
  1785. this.dispatchEvent( { type: 'dispose' } );
  1786. },
  1787. transformUv: function ( uv ) {
  1788. if ( this.mapping !== UVMapping ) return uv;
  1789. uv.applyMatrix3( this.matrix );
  1790. if ( uv.x < 0 || uv.x > 1 ) {
  1791. switch ( this.wrapS ) {
  1792. case RepeatWrapping:
  1793. uv.x = uv.x - Math.floor( uv.x );
  1794. break;
  1795. case ClampToEdgeWrapping:
  1796. uv.x = uv.x < 0 ? 0 : 1;
  1797. break;
  1798. case MirroredRepeatWrapping:
  1799. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1800. uv.x = Math.ceil( uv.x ) - uv.x;
  1801. } else {
  1802. uv.x = uv.x - Math.floor( uv.x );
  1803. }
  1804. break;
  1805. }
  1806. }
  1807. if ( uv.y < 0 || uv.y > 1 ) {
  1808. switch ( this.wrapT ) {
  1809. case RepeatWrapping:
  1810. uv.y = uv.y - Math.floor( uv.y );
  1811. break;
  1812. case ClampToEdgeWrapping:
  1813. uv.y = uv.y < 0 ? 0 : 1;
  1814. break;
  1815. case MirroredRepeatWrapping:
  1816. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1817. uv.y = Math.ceil( uv.y ) - uv.y;
  1818. } else {
  1819. uv.y = uv.y - Math.floor( uv.y );
  1820. }
  1821. break;
  1822. }
  1823. }
  1824. if ( this.flipY ) {
  1825. uv.y = 1 - uv.y;
  1826. }
  1827. return uv;
  1828. }
  1829. } );
  1830. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1831. set: function ( value ) {
  1832. if ( value === true ) this.version ++;
  1833. }
  1834. } );
  1835. /**
  1836. * @author supereggbert / http://www.paulbrunt.co.uk/
  1837. * @author philogb / http://blog.thejit.org/
  1838. * @author mikael emtinger / http://gomo.se/
  1839. * @author egraether / http://egraether.com/
  1840. * @author WestLangley / http://github.com/WestLangley
  1841. */
  1842. function Vector4( x, y, z, w ) {
  1843. this.x = x || 0;
  1844. this.y = y || 0;
  1845. this.z = z || 0;
  1846. this.w = ( w !== undefined ) ? w : 1;
  1847. }
  1848. Object.defineProperties( Vector4.prototype, {
  1849. "width": {
  1850. get: function () {
  1851. return this.z;
  1852. },
  1853. set: function ( value ) {
  1854. this.z = value;
  1855. }
  1856. },
  1857. "height": {
  1858. get: function () {
  1859. return this.w;
  1860. },
  1861. set: function ( value ) {
  1862. this.w = value;
  1863. }
  1864. }
  1865. } );
  1866. Object.assign( Vector4.prototype, {
  1867. isVector4: true,
  1868. set: function ( x, y, z, w ) {
  1869. this.x = x;
  1870. this.y = y;
  1871. this.z = z;
  1872. this.w = w;
  1873. return this;
  1874. },
  1875. setScalar: function ( scalar ) {
  1876. this.x = scalar;
  1877. this.y = scalar;
  1878. this.z = scalar;
  1879. this.w = scalar;
  1880. return this;
  1881. },
  1882. setX: function ( x ) {
  1883. this.x = x;
  1884. return this;
  1885. },
  1886. setY: function ( y ) {
  1887. this.y = y;
  1888. return this;
  1889. },
  1890. setZ: function ( z ) {
  1891. this.z = z;
  1892. return this;
  1893. },
  1894. setW: function ( w ) {
  1895. this.w = w;
  1896. return this;
  1897. },
  1898. setComponent: function ( index, value ) {
  1899. switch ( index ) {
  1900. case 0: this.x = value; break;
  1901. case 1: this.y = value; break;
  1902. case 2: this.z = value; break;
  1903. case 3: this.w = value; break;
  1904. default: throw new Error( 'index is out of range: ' + index );
  1905. }
  1906. return this;
  1907. },
  1908. getComponent: function ( index ) {
  1909. switch ( index ) {
  1910. case 0: return this.x;
  1911. case 1: return this.y;
  1912. case 2: return this.z;
  1913. case 3: return this.w;
  1914. default: throw new Error( 'index is out of range: ' + index );
  1915. }
  1916. },
  1917. clone: function () {
  1918. return new this.constructor( this.x, this.y, this.z, this.w );
  1919. },
  1920. copy: function ( v ) {
  1921. this.x = v.x;
  1922. this.y = v.y;
  1923. this.z = v.z;
  1924. this.w = ( v.w !== undefined ) ? v.w : 1;
  1925. return this;
  1926. },
  1927. add: function ( v, w ) {
  1928. if ( w !== undefined ) {
  1929. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1930. return this.addVectors( v, w );
  1931. }
  1932. this.x += v.x;
  1933. this.y += v.y;
  1934. this.z += v.z;
  1935. this.w += v.w;
  1936. return this;
  1937. },
  1938. addScalar: function ( s ) {
  1939. this.x += s;
  1940. this.y += s;
  1941. this.z += s;
  1942. this.w += s;
  1943. return this;
  1944. },
  1945. addVectors: function ( a, b ) {
  1946. this.x = a.x + b.x;
  1947. this.y = a.y + b.y;
  1948. this.z = a.z + b.z;
  1949. this.w = a.w + b.w;
  1950. return this;
  1951. },
  1952. addScaledVector: function ( v, s ) {
  1953. this.x += v.x * s;
  1954. this.y += v.y * s;
  1955. this.z += v.z * s;
  1956. this.w += v.w * s;
  1957. return this;
  1958. },
  1959. sub: function ( v, w ) {
  1960. if ( w !== undefined ) {
  1961. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1962. return this.subVectors( v, w );
  1963. }
  1964. this.x -= v.x;
  1965. this.y -= v.y;
  1966. this.z -= v.z;
  1967. this.w -= v.w;
  1968. return this;
  1969. },
  1970. subScalar: function ( s ) {
  1971. this.x -= s;
  1972. this.y -= s;
  1973. this.z -= s;
  1974. this.w -= s;
  1975. return this;
  1976. },
  1977. subVectors: function ( a, b ) {
  1978. this.x = a.x - b.x;
  1979. this.y = a.y - b.y;
  1980. this.z = a.z - b.z;
  1981. this.w = a.w - b.w;
  1982. return this;
  1983. },
  1984. multiplyScalar: function ( scalar ) {
  1985. this.x *= scalar;
  1986. this.y *= scalar;
  1987. this.z *= scalar;
  1988. this.w *= scalar;
  1989. return this;
  1990. },
  1991. applyMatrix4: function ( m ) {
  1992. var x = this.x, y = this.y, z = this.z, w = this.w;
  1993. var e = m.elements;
  1994. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1995. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1996. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1997. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1998. return this;
  1999. },
  2000. divideScalar: function ( scalar ) {
  2001. return this.multiplyScalar( 1 / scalar );
  2002. },
  2003. setAxisAngleFromQuaternion: function ( q ) {
  2004. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2005. // q is assumed to be normalized
  2006. this.w = 2 * Math.acos( q.w );
  2007. var s = Math.sqrt( 1 - q.w * q.w );
  2008. if ( s < 0.0001 ) {
  2009. this.x = 1;
  2010. this.y = 0;
  2011. this.z = 0;
  2012. } else {
  2013. this.x = q.x / s;
  2014. this.y = q.y / s;
  2015. this.z = q.z / s;
  2016. }
  2017. return this;
  2018. },
  2019. setAxisAngleFromRotationMatrix: function ( m ) {
  2020. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2021. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2022. var angle, x, y, z, // variables for result
  2023. epsilon = 0.01, // margin to allow for rounding errors
  2024. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2025. te = m.elements,
  2026. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2027. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2028. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2029. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2030. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2031. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2032. // singularity found
  2033. // first check for identity matrix which must have +1 for all terms
  2034. // in leading diagonal and zero in other terms
  2035. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2036. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2037. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2038. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2039. // this singularity is identity matrix so angle = 0
  2040. this.set( 1, 0, 0, 0 );
  2041. return this; // zero angle, arbitrary axis
  2042. }
  2043. // otherwise this singularity is angle = 180
  2044. angle = Math.PI;
  2045. var xx = ( m11 + 1 ) / 2;
  2046. var yy = ( m22 + 1 ) / 2;
  2047. var zz = ( m33 + 1 ) / 2;
  2048. var xy = ( m12 + m21 ) / 4;
  2049. var xz = ( m13 + m31 ) / 4;
  2050. var yz = ( m23 + m32 ) / 4;
  2051. if ( ( xx > yy ) && ( xx > zz ) ) {
  2052. // m11 is the largest diagonal term
  2053. if ( xx < epsilon ) {
  2054. x = 0;
  2055. y = 0.707106781;
  2056. z = 0.707106781;
  2057. } else {
  2058. x = Math.sqrt( xx );
  2059. y = xy / x;
  2060. z = xz / x;
  2061. }
  2062. } else if ( yy > zz ) {
  2063. // m22 is the largest diagonal term
  2064. if ( yy < epsilon ) {
  2065. x = 0.707106781;
  2066. y = 0;
  2067. z = 0.707106781;
  2068. } else {
  2069. y = Math.sqrt( yy );
  2070. x = xy / y;
  2071. z = yz / y;
  2072. }
  2073. } else {
  2074. // m33 is the largest diagonal term so base result on this
  2075. if ( zz < epsilon ) {
  2076. x = 0.707106781;
  2077. y = 0.707106781;
  2078. z = 0;
  2079. } else {
  2080. z = Math.sqrt( zz );
  2081. x = xz / z;
  2082. y = yz / z;
  2083. }
  2084. }
  2085. this.set( x, y, z, angle );
  2086. return this; // return 180 deg rotation
  2087. }
  2088. // as we have reached here there are no singularities so we can handle normally
  2089. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2090. ( m13 - m31 ) * ( m13 - m31 ) +
  2091. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2092. if ( Math.abs( s ) < 0.001 ) s = 1;
  2093. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2094. // caught by singularity test above, but I've left it in just in case
  2095. this.x = ( m32 - m23 ) / s;
  2096. this.y = ( m13 - m31 ) / s;
  2097. this.z = ( m21 - m12 ) / s;
  2098. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2099. return this;
  2100. },
  2101. min: function ( v ) {
  2102. this.x = Math.min( this.x, v.x );
  2103. this.y = Math.min( this.y, v.y );
  2104. this.z = Math.min( this.z, v.z );
  2105. this.w = Math.min( this.w, v.w );
  2106. return this;
  2107. },
  2108. max: function ( v ) {
  2109. this.x = Math.max( this.x, v.x );
  2110. this.y = Math.max( this.y, v.y );
  2111. this.z = Math.max( this.z, v.z );
  2112. this.w = Math.max( this.w, v.w );
  2113. return this;
  2114. },
  2115. clamp: function ( min, max ) {
  2116. // assumes min < max, componentwise
  2117. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2118. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2119. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2120. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2121. return this;
  2122. },
  2123. clampScalar: function ( minVal, maxVal ) {
  2124. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2125. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2126. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2127. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  2128. return this;
  2129. },
  2130. clampLength: function ( min, max ) {
  2131. var length = this.length();
  2132. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2133. },
  2134. floor: function () {
  2135. this.x = Math.floor( this.x );
  2136. this.y = Math.floor( this.y );
  2137. this.z = Math.floor( this.z );
  2138. this.w = Math.floor( this.w );
  2139. return this;
  2140. },
  2141. ceil: function () {
  2142. this.x = Math.ceil( this.x );
  2143. this.y = Math.ceil( this.y );
  2144. this.z = Math.ceil( this.z );
  2145. this.w = Math.ceil( this.w );
  2146. return this;
  2147. },
  2148. round: function () {
  2149. this.x = Math.round( this.x );
  2150. this.y = Math.round( this.y );
  2151. this.z = Math.round( this.z );
  2152. this.w = Math.round( this.w );
  2153. return this;
  2154. },
  2155. roundToZero: function () {
  2156. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2157. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2158. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2159. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2160. return this;
  2161. },
  2162. negate: function () {
  2163. this.x = - this.x;
  2164. this.y = - this.y;
  2165. this.z = - this.z;
  2166. this.w = - this.w;
  2167. return this;
  2168. },
  2169. dot: function ( v ) {
  2170. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2171. },
  2172. lengthSq: function () {
  2173. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2174. },
  2175. length: function () {
  2176. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2177. },
  2178. manhattanLength: function () {
  2179. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2180. },
  2181. normalize: function () {
  2182. return this.divideScalar( this.length() || 1 );
  2183. },
  2184. setLength: function ( length ) {
  2185. return this.normalize().multiplyScalar( length );
  2186. },
  2187. lerp: function ( v, alpha ) {
  2188. this.x += ( v.x - this.x ) * alpha;
  2189. this.y += ( v.y - this.y ) * alpha;
  2190. this.z += ( v.z - this.z ) * alpha;
  2191. this.w += ( v.w - this.w ) * alpha;
  2192. return this;
  2193. },
  2194. lerpVectors: function ( v1, v2, alpha ) {
  2195. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2196. },
  2197. equals: function ( v ) {
  2198. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2199. },
  2200. fromArray: function ( array, offset ) {
  2201. if ( offset === undefined ) offset = 0;
  2202. this.x = array[ offset ];
  2203. this.y = array[ offset + 1 ];
  2204. this.z = array[ offset + 2 ];
  2205. this.w = array[ offset + 3 ];
  2206. return this;
  2207. },
  2208. toArray: function ( array, offset ) {
  2209. if ( array === undefined ) array = [];
  2210. if ( offset === undefined ) offset = 0;
  2211. array[ offset ] = this.x;
  2212. array[ offset + 1 ] = this.y;
  2213. array[ offset + 2 ] = this.z;
  2214. array[ offset + 3 ] = this.w;
  2215. return array;
  2216. },
  2217. fromBufferAttribute: function ( attribute, index, offset ) {
  2218. if ( offset !== undefined ) {
  2219. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2220. }
  2221. this.x = attribute.getX( index );
  2222. this.y = attribute.getY( index );
  2223. this.z = attribute.getZ( index );
  2224. this.w = attribute.getW( index );
  2225. return this;
  2226. }
  2227. } );
  2228. /**
  2229. * @author szimek / https://github.com/szimek/
  2230. * @author alteredq / http://alteredqualia.com/
  2231. * @author Marius Kintel / https://github.com/kintel
  2232. */
  2233. /*
  2234. In options, we can specify:
  2235. * Texture parameters for an auto-generated target texture
  2236. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2237. */
  2238. function WebGLRenderTarget( width, height, options ) {
  2239. this.width = width;
  2240. this.height = height;
  2241. this.scissor = new Vector4( 0, 0, width, height );
  2242. this.scissorTest = false;
  2243. this.viewport = new Vector4( 0, 0, width, height );
  2244. options = options || {};
  2245. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2246. this.texture.image = {};
  2247. this.texture.image.width = width;
  2248. this.texture.image.height = height;
  2249. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2250. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2251. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2252. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2253. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2254. }
  2255. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2256. constructor: WebGLRenderTarget,
  2257. isWebGLRenderTarget: true,
  2258. setSize: function ( width, height ) {
  2259. if ( this.width !== width || this.height !== height ) {
  2260. this.width = width;
  2261. this.height = height;
  2262. this.texture.image.width = width;
  2263. this.texture.image.height = height;
  2264. this.dispose();
  2265. }
  2266. this.viewport.set( 0, 0, width, height );
  2267. this.scissor.set( 0, 0, width, height );
  2268. },
  2269. clone: function () {
  2270. return new this.constructor().copy( this );
  2271. },
  2272. copy: function ( source ) {
  2273. this.width = source.width;
  2274. this.height = source.height;
  2275. this.viewport.copy( source.viewport );
  2276. this.texture = source.texture.clone();
  2277. this.depthBuffer = source.depthBuffer;
  2278. this.stencilBuffer = source.stencilBuffer;
  2279. this.depthTexture = source.depthTexture;
  2280. return this;
  2281. },
  2282. dispose: function () {
  2283. this.dispatchEvent( { type: 'dispose' } );
  2284. }
  2285. } );
  2286. /**
  2287. * @author Mugen87 / https://github.com/Mugen87
  2288. * @author Matt DesLauriers / @mattdesl
  2289. */
  2290. function WebGLMultisampleRenderTarget( width, height, options ) {
  2291. WebGLRenderTarget.call( this, width, height, options );
  2292. this.samples = 4;
  2293. }
  2294. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2295. constructor: WebGLMultisampleRenderTarget,
  2296. isWebGLMultisampleRenderTarget: true,
  2297. copy: function ( source ) {
  2298. WebGLRenderTarget.prototype.copy.call( this, source );
  2299. this.samples = source.samples;
  2300. return this;
  2301. }
  2302. } );
  2303. /**
  2304. * @author mrdoob / http://mrdoob.com/
  2305. * @author supereggbert / http://www.paulbrunt.co.uk/
  2306. * @author philogb / http://blog.thejit.org/
  2307. * @author jordi_ros / http://plattsoft.com
  2308. * @author D1plo1d / http://github.com/D1plo1d
  2309. * @author alteredq / http://alteredqualia.com/
  2310. * @author mikael emtinger / http://gomo.se/
  2311. * @author timknip / http://www.floorplanner.com/
  2312. * @author bhouston / http://clara.io
  2313. * @author WestLangley / http://github.com/WestLangley
  2314. */
  2315. var _v1, _m1;
  2316. var _zero, _one;
  2317. var _x, _y, _z;
  2318. function Matrix4() {
  2319. this.elements = [
  2320. 1, 0, 0, 0,
  2321. 0, 1, 0, 0,
  2322. 0, 0, 1, 0,
  2323. 0, 0, 0, 1
  2324. ];
  2325. if ( arguments.length > 0 ) {
  2326. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2327. }
  2328. }
  2329. Object.assign( Matrix4.prototype, {
  2330. isMatrix4: true,
  2331. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2332. var te = this.elements;
  2333. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2334. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2335. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2336. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2337. return this;
  2338. },
  2339. identity: function () {
  2340. this.set(
  2341. 1, 0, 0, 0,
  2342. 0, 1, 0, 0,
  2343. 0, 0, 1, 0,
  2344. 0, 0, 0, 1
  2345. );
  2346. return this;
  2347. },
  2348. clone: function () {
  2349. return new Matrix4().fromArray( this.elements );
  2350. },
  2351. copy: function ( m ) {
  2352. var te = this.elements;
  2353. var me = m.elements;
  2354. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2355. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2356. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2357. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2358. return this;
  2359. },
  2360. copyPosition: function ( m ) {
  2361. var te = this.elements, me = m.elements;
  2362. te[ 12 ] = me[ 12 ];
  2363. te[ 13 ] = me[ 13 ];
  2364. te[ 14 ] = me[ 14 ];
  2365. return this;
  2366. },
  2367. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2368. xAxis.setFromMatrixColumn( this, 0 );
  2369. yAxis.setFromMatrixColumn( this, 1 );
  2370. zAxis.setFromMatrixColumn( this, 2 );
  2371. return this;
  2372. },
  2373. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2374. this.set(
  2375. xAxis.x, yAxis.x, zAxis.x, 0,
  2376. xAxis.y, yAxis.y, zAxis.y, 0,
  2377. xAxis.z, yAxis.z, zAxis.z, 0,
  2378. 0, 0, 0, 1
  2379. );
  2380. return this;
  2381. },
  2382. extractRotation: function ( m ) {
  2383. if ( _v1 === undefined ) _v1 = new Vector3();
  2384. // this method does not support reflection matrices
  2385. var te = this.elements;
  2386. var me = m.elements;
  2387. var scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length();
  2388. var scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length();
  2389. var scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length();
  2390. te[ 0 ] = me[ 0 ] * scaleX;
  2391. te[ 1 ] = me[ 1 ] * scaleX;
  2392. te[ 2 ] = me[ 2 ] * scaleX;
  2393. te[ 3 ] = 0;
  2394. te[ 4 ] = me[ 4 ] * scaleY;
  2395. te[ 5 ] = me[ 5 ] * scaleY;
  2396. te[ 6 ] = me[ 6 ] * scaleY;
  2397. te[ 7 ] = 0;
  2398. te[ 8 ] = me[ 8 ] * scaleZ;
  2399. te[ 9 ] = me[ 9 ] * scaleZ;
  2400. te[ 10 ] = me[ 10 ] * scaleZ;
  2401. te[ 11 ] = 0;
  2402. te[ 12 ] = 0;
  2403. te[ 13 ] = 0;
  2404. te[ 14 ] = 0;
  2405. te[ 15 ] = 1;
  2406. return this;
  2407. },
  2408. makeRotationFromEuler: function ( euler ) {
  2409. if ( ! ( euler && euler.isEuler ) ) {
  2410. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2411. }
  2412. var te = this.elements;
  2413. var x = euler.x, y = euler.y, z = euler.z;
  2414. var a = Math.cos( x ), b = Math.sin( x );
  2415. var c = Math.cos( y ), d = Math.sin( y );
  2416. var e = Math.cos( z ), f = Math.sin( z );
  2417. if ( euler.order === 'XYZ' ) {
  2418. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2419. te[ 0 ] = c * e;
  2420. te[ 4 ] = - c * f;
  2421. te[ 8 ] = d;
  2422. te[ 1 ] = af + be * d;
  2423. te[ 5 ] = ae - bf * d;
  2424. te[ 9 ] = - b * c;
  2425. te[ 2 ] = bf - ae * d;
  2426. te[ 6 ] = be + af * d;
  2427. te[ 10 ] = a * c;
  2428. } else if ( euler.order === 'YXZ' ) {
  2429. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2430. te[ 0 ] = ce + df * b;
  2431. te[ 4 ] = de * b - cf;
  2432. te[ 8 ] = a * d;
  2433. te[ 1 ] = a * f;
  2434. te[ 5 ] = a * e;
  2435. te[ 9 ] = - b;
  2436. te[ 2 ] = cf * b - de;
  2437. te[ 6 ] = df + ce * b;
  2438. te[ 10 ] = a * c;
  2439. } else if ( euler.order === 'ZXY' ) {
  2440. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2441. te[ 0 ] = ce - df * b;
  2442. te[ 4 ] = - a * f;
  2443. te[ 8 ] = de + cf * b;
  2444. te[ 1 ] = cf + de * b;
  2445. te[ 5 ] = a * e;
  2446. te[ 9 ] = df - ce * b;
  2447. te[ 2 ] = - a * d;
  2448. te[ 6 ] = b;
  2449. te[ 10 ] = a * c;
  2450. } else if ( euler.order === 'ZYX' ) {
  2451. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2452. te[ 0 ] = c * e;
  2453. te[ 4 ] = be * d - af;
  2454. te[ 8 ] = ae * d + bf;
  2455. te[ 1 ] = c * f;
  2456. te[ 5 ] = bf * d + ae;
  2457. te[ 9 ] = af * d - be;
  2458. te[ 2 ] = - d;
  2459. te[ 6 ] = b * c;
  2460. te[ 10 ] = a * c;
  2461. } else if ( euler.order === 'YZX' ) {
  2462. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2463. te[ 0 ] = c * e;
  2464. te[ 4 ] = bd - ac * f;
  2465. te[ 8 ] = bc * f + ad;
  2466. te[ 1 ] = f;
  2467. te[ 5 ] = a * e;
  2468. te[ 9 ] = - b * e;
  2469. te[ 2 ] = - d * e;
  2470. te[ 6 ] = ad * f + bc;
  2471. te[ 10 ] = ac - bd * f;
  2472. } else if ( euler.order === 'XZY' ) {
  2473. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2474. te[ 0 ] = c * e;
  2475. te[ 4 ] = - f;
  2476. te[ 8 ] = d * e;
  2477. te[ 1 ] = ac * f + bd;
  2478. te[ 5 ] = a * e;
  2479. te[ 9 ] = ad * f - bc;
  2480. te[ 2 ] = bc * f - ad;
  2481. te[ 6 ] = b * e;
  2482. te[ 10 ] = bd * f + ac;
  2483. }
  2484. // bottom row
  2485. te[ 3 ] = 0;
  2486. te[ 7 ] = 0;
  2487. te[ 11 ] = 0;
  2488. // last column
  2489. te[ 12 ] = 0;
  2490. te[ 13 ] = 0;
  2491. te[ 14 ] = 0;
  2492. te[ 15 ] = 1;
  2493. return this;
  2494. },
  2495. makeRotationFromQuaternion: function ( q ) {
  2496. if ( _zero === undefined ) {
  2497. _zero = new Vector3( 0, 0, 0 );
  2498. _one = new Vector3( 1, 1, 1 );
  2499. }
  2500. return this.compose( _zero, q, _one );
  2501. },
  2502. lookAt: function ( eye, target, up ) {
  2503. if ( _x === undefined ) {
  2504. _x = new Vector3();
  2505. _y = new Vector3();
  2506. _z = new Vector3();
  2507. }
  2508. var te = this.elements;
  2509. _z.subVectors( eye, target );
  2510. if ( _z.lengthSq() === 0 ) {
  2511. // eye and target are in the same position
  2512. _z.z = 1;
  2513. }
  2514. _z.normalize();
  2515. _x.crossVectors( up, _z );
  2516. if ( _x.lengthSq() === 0 ) {
  2517. // up and z are parallel
  2518. if ( Math.abs( up.z ) === 1 ) {
  2519. _z.x += 0.0001;
  2520. } else {
  2521. _z.z += 0.0001;
  2522. }
  2523. _z.normalize();
  2524. _x.crossVectors( up, _z );
  2525. }
  2526. _x.normalize();
  2527. _y.crossVectors( _z, _x );
  2528. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  2529. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  2530. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  2531. return this;
  2532. },
  2533. multiply: function ( m, n ) {
  2534. if ( n !== undefined ) {
  2535. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2536. return this.multiplyMatrices( m, n );
  2537. }
  2538. return this.multiplyMatrices( this, m );
  2539. },
  2540. premultiply: function ( m ) {
  2541. return this.multiplyMatrices( m, this );
  2542. },
  2543. multiplyMatrices: function ( a, b ) {
  2544. var ae = a.elements;
  2545. var be = b.elements;
  2546. var te = this.elements;
  2547. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2548. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2549. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2550. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2551. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2552. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2553. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2554. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2555. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2556. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2557. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2558. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2559. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2560. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2561. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2562. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2563. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2564. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2565. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2566. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2567. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2568. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2569. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2570. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2571. return this;
  2572. },
  2573. multiplyScalar: function ( s ) {
  2574. var te = this.elements;
  2575. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2576. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2577. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2578. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2579. return this;
  2580. },
  2581. applyToBufferAttribute: function ( attribute ) {
  2582. if ( _v1 === undefined ) _v1 = new Vector3();
  2583. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2584. _v1.x = attribute.getX( i );
  2585. _v1.y = attribute.getY( i );
  2586. _v1.z = attribute.getZ( i );
  2587. _v1.applyMatrix4( this );
  2588. attribute.setXYZ( i, _v1.x, _v1.y, _v1.z );
  2589. }
  2590. return attribute;
  2591. },
  2592. determinant: function () {
  2593. var te = this.elements;
  2594. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2595. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2596. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2597. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2598. //TODO: make this more efficient
  2599. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2600. return (
  2601. n41 * (
  2602. + n14 * n23 * n32
  2603. - n13 * n24 * n32
  2604. - n14 * n22 * n33
  2605. + n12 * n24 * n33
  2606. + n13 * n22 * n34
  2607. - n12 * n23 * n34
  2608. ) +
  2609. n42 * (
  2610. + n11 * n23 * n34
  2611. - n11 * n24 * n33
  2612. + n14 * n21 * n33
  2613. - n13 * n21 * n34
  2614. + n13 * n24 * n31
  2615. - n14 * n23 * n31
  2616. ) +
  2617. n43 * (
  2618. + n11 * n24 * n32
  2619. - n11 * n22 * n34
  2620. - n14 * n21 * n32
  2621. + n12 * n21 * n34
  2622. + n14 * n22 * n31
  2623. - n12 * n24 * n31
  2624. ) +
  2625. n44 * (
  2626. - n13 * n22 * n31
  2627. - n11 * n23 * n32
  2628. + n11 * n22 * n33
  2629. + n13 * n21 * n32
  2630. - n12 * n21 * n33
  2631. + n12 * n23 * n31
  2632. )
  2633. );
  2634. },
  2635. transpose: function () {
  2636. var te = this.elements;
  2637. var tmp;
  2638. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2639. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2640. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2641. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2642. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2643. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2644. return this;
  2645. },
  2646. setPosition: function ( x, y, z ) {
  2647. var te = this.elements;
  2648. if ( x.isVector3 ) {
  2649. te[ 12 ] = x.x;
  2650. te[ 13 ] = x.y;
  2651. te[ 14 ] = x.z;
  2652. } else {
  2653. te[ 12 ] = x;
  2654. te[ 13 ] = y;
  2655. te[ 14 ] = z;
  2656. }
  2657. return this;
  2658. },
  2659. getInverse: function ( m, throwOnDegenerate ) {
  2660. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2661. var te = this.elements,
  2662. me = m.elements,
  2663. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2664. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2665. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2666. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2667. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2668. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2669. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2670. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2671. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2672. if ( det === 0 ) {
  2673. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  2674. if ( throwOnDegenerate === true ) {
  2675. throw new Error( msg );
  2676. } else {
  2677. console.warn( msg );
  2678. }
  2679. return this.identity();
  2680. }
  2681. var detInv = 1 / det;
  2682. te[ 0 ] = t11 * detInv;
  2683. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2684. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2685. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2686. te[ 4 ] = t12 * detInv;
  2687. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2688. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2689. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2690. te[ 8 ] = t13 * detInv;
  2691. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2692. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2693. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2694. te[ 12 ] = t14 * detInv;
  2695. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2696. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2697. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2698. return this;
  2699. },
  2700. scale: function ( v ) {
  2701. var te = this.elements;
  2702. var x = v.x, y = v.y, z = v.z;
  2703. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2704. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2705. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2706. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2707. return this;
  2708. },
  2709. getMaxScaleOnAxis: function () {
  2710. var te = this.elements;
  2711. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2712. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2713. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2714. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2715. },
  2716. makeTranslation: function ( x, y, z ) {
  2717. this.set(
  2718. 1, 0, 0, x,
  2719. 0, 1, 0, y,
  2720. 0, 0, 1, z,
  2721. 0, 0, 0, 1
  2722. );
  2723. return this;
  2724. },
  2725. makeRotationX: function ( theta ) {
  2726. var c = Math.cos( theta ), s = Math.sin( theta );
  2727. this.set(
  2728. 1, 0, 0, 0,
  2729. 0, c, - s, 0,
  2730. 0, s, c, 0,
  2731. 0, 0, 0, 1
  2732. );
  2733. return this;
  2734. },
  2735. makeRotationY: function ( theta ) {
  2736. var c = Math.cos( theta ), s = Math.sin( theta );
  2737. this.set(
  2738. c, 0, s, 0,
  2739. 0, 1, 0, 0,
  2740. - s, 0, c, 0,
  2741. 0, 0, 0, 1
  2742. );
  2743. return this;
  2744. },
  2745. makeRotationZ: function ( theta ) {
  2746. var c = Math.cos( theta ), s = Math.sin( theta );
  2747. this.set(
  2748. c, - s, 0, 0,
  2749. s, c, 0, 0,
  2750. 0, 0, 1, 0,
  2751. 0, 0, 0, 1
  2752. );
  2753. return this;
  2754. },
  2755. makeRotationAxis: function ( axis, angle ) {
  2756. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2757. var c = Math.cos( angle );
  2758. var s = Math.sin( angle );
  2759. var t = 1 - c;
  2760. var x = axis.x, y = axis.y, z = axis.z;
  2761. var tx = t * x, ty = t * y;
  2762. this.set(
  2763. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2764. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2765. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2766. 0, 0, 0, 1
  2767. );
  2768. return this;
  2769. },
  2770. makeScale: function ( x, y, z ) {
  2771. this.set(
  2772. x, 0, 0, 0,
  2773. 0, y, 0, 0,
  2774. 0, 0, z, 0,
  2775. 0, 0, 0, 1
  2776. );
  2777. return this;
  2778. },
  2779. makeShear: function ( x, y, z ) {
  2780. this.set(
  2781. 1, y, z, 0,
  2782. x, 1, z, 0,
  2783. x, y, 1, 0,
  2784. 0, 0, 0, 1
  2785. );
  2786. return this;
  2787. },
  2788. compose: function ( position, quaternion, scale ) {
  2789. var te = this.elements;
  2790. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2791. var x2 = x + x, y2 = y + y, z2 = z + z;
  2792. var xx = x * x2, xy = x * y2, xz = x * z2;
  2793. var yy = y * y2, yz = y * z2, zz = z * z2;
  2794. var wx = w * x2, wy = w * y2, wz = w * z2;
  2795. var sx = scale.x, sy = scale.y, sz = scale.z;
  2796. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2797. te[ 1 ] = ( xy + wz ) * sx;
  2798. te[ 2 ] = ( xz - wy ) * sx;
  2799. te[ 3 ] = 0;
  2800. te[ 4 ] = ( xy - wz ) * sy;
  2801. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2802. te[ 6 ] = ( yz + wx ) * sy;
  2803. te[ 7 ] = 0;
  2804. te[ 8 ] = ( xz + wy ) * sz;
  2805. te[ 9 ] = ( yz - wx ) * sz;
  2806. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2807. te[ 11 ] = 0;
  2808. te[ 12 ] = position.x;
  2809. te[ 13 ] = position.y;
  2810. te[ 14 ] = position.z;
  2811. te[ 15 ] = 1;
  2812. return this;
  2813. },
  2814. decompose: function ( position, quaternion, scale ) {
  2815. if ( _m1 === undefined ) {
  2816. _m1 = new Matrix4();
  2817. _v1 = new Vector3();
  2818. }
  2819. var te = this.elements;
  2820. var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2821. var sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2822. var sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2823. // if determine is negative, we need to invert one scale
  2824. var det = this.determinant();
  2825. if ( det < 0 ) sx = - sx;
  2826. position.x = te[ 12 ];
  2827. position.y = te[ 13 ];
  2828. position.z = te[ 14 ];
  2829. // scale the rotation part
  2830. _m1.copy( this );
  2831. var invSX = 1 / sx;
  2832. var invSY = 1 / sy;
  2833. var invSZ = 1 / sz;
  2834. _m1.elements[ 0 ] *= invSX;
  2835. _m1.elements[ 1 ] *= invSX;
  2836. _m1.elements[ 2 ] *= invSX;
  2837. _m1.elements[ 4 ] *= invSY;
  2838. _m1.elements[ 5 ] *= invSY;
  2839. _m1.elements[ 6 ] *= invSY;
  2840. _m1.elements[ 8 ] *= invSZ;
  2841. _m1.elements[ 9 ] *= invSZ;
  2842. _m1.elements[ 10 ] *= invSZ;
  2843. quaternion.setFromRotationMatrix( _m1 );
  2844. scale.x = sx;
  2845. scale.y = sy;
  2846. scale.z = sz;
  2847. return this;
  2848. },
  2849. makePerspective: function ( left, right, top, bottom, near, far ) {
  2850. if ( far === undefined ) {
  2851. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2852. }
  2853. var te = this.elements;
  2854. var x = 2 * near / ( right - left );
  2855. var y = 2 * near / ( top - bottom );
  2856. var a = ( right + left ) / ( right - left );
  2857. var b = ( top + bottom ) / ( top - bottom );
  2858. var c = - ( far + near ) / ( far - near );
  2859. var d = - 2 * far * near / ( far - near );
  2860. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2861. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2862. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2863. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2864. return this;
  2865. },
  2866. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2867. var te = this.elements;
  2868. var w = 1.0 / ( right - left );
  2869. var h = 1.0 / ( top - bottom );
  2870. var p = 1.0 / ( far - near );
  2871. var x = ( right + left ) * w;
  2872. var y = ( top + bottom ) * h;
  2873. var z = ( far + near ) * p;
  2874. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2875. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2876. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2877. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2878. return this;
  2879. },
  2880. equals: function ( matrix ) {
  2881. var te = this.elements;
  2882. var me = matrix.elements;
  2883. for ( var i = 0; i < 16; i ++ ) {
  2884. if ( te[ i ] !== me[ i ] ) return false;
  2885. }
  2886. return true;
  2887. },
  2888. fromArray: function ( array, offset ) {
  2889. if ( offset === undefined ) offset = 0;
  2890. for ( var i = 0; i < 16; i ++ ) {
  2891. this.elements[ i ] = array[ i + offset ];
  2892. }
  2893. return this;
  2894. },
  2895. toArray: function ( array, offset ) {
  2896. if ( array === undefined ) array = [];
  2897. if ( offset === undefined ) offset = 0;
  2898. var te = this.elements;
  2899. array[ offset ] = te[ 0 ];
  2900. array[ offset + 1 ] = te[ 1 ];
  2901. array[ offset + 2 ] = te[ 2 ];
  2902. array[ offset + 3 ] = te[ 3 ];
  2903. array[ offset + 4 ] = te[ 4 ];
  2904. array[ offset + 5 ] = te[ 5 ];
  2905. array[ offset + 6 ] = te[ 6 ];
  2906. array[ offset + 7 ] = te[ 7 ];
  2907. array[ offset + 8 ] = te[ 8 ];
  2908. array[ offset + 9 ] = te[ 9 ];
  2909. array[ offset + 10 ] = te[ 10 ];
  2910. array[ offset + 11 ] = te[ 11 ];
  2911. array[ offset + 12 ] = te[ 12 ];
  2912. array[ offset + 13 ] = te[ 13 ];
  2913. array[ offset + 14 ] = te[ 14 ];
  2914. array[ offset + 15 ] = te[ 15 ];
  2915. return array;
  2916. }
  2917. } );
  2918. /**
  2919. * @author mrdoob / http://mrdoob.com/
  2920. * @author WestLangley / http://github.com/WestLangley
  2921. * @author bhouston / http://clara.io
  2922. */
  2923. var _matrix, _quaternion$1;
  2924. function Euler( x, y, z, order ) {
  2925. this._x = x || 0;
  2926. this._y = y || 0;
  2927. this._z = z || 0;
  2928. this._order = order || Euler.DefaultOrder;
  2929. }
  2930. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2931. Euler.DefaultOrder = 'XYZ';
  2932. Object.defineProperties( Euler.prototype, {
  2933. x: {
  2934. get: function () {
  2935. return this._x;
  2936. },
  2937. set: function ( value ) {
  2938. this._x = value;
  2939. this._onChangeCallback();
  2940. }
  2941. },
  2942. y: {
  2943. get: function () {
  2944. return this._y;
  2945. },
  2946. set: function ( value ) {
  2947. this._y = value;
  2948. this._onChangeCallback();
  2949. }
  2950. },
  2951. z: {
  2952. get: function () {
  2953. return this._z;
  2954. },
  2955. set: function ( value ) {
  2956. this._z = value;
  2957. this._onChangeCallback();
  2958. }
  2959. },
  2960. order: {
  2961. get: function () {
  2962. return this._order;
  2963. },
  2964. set: function ( value ) {
  2965. this._order = value;
  2966. this._onChangeCallback();
  2967. }
  2968. }
  2969. } );
  2970. Object.assign( Euler.prototype, {
  2971. isEuler: true,
  2972. set: function ( x, y, z, order ) {
  2973. this._x = x;
  2974. this._y = y;
  2975. this._z = z;
  2976. this._order = order || this._order;
  2977. this._onChangeCallback();
  2978. return this;
  2979. },
  2980. clone: function () {
  2981. return new this.constructor( this._x, this._y, this._z, this._order );
  2982. },
  2983. copy: function ( euler ) {
  2984. this._x = euler._x;
  2985. this._y = euler._y;
  2986. this._z = euler._z;
  2987. this._order = euler._order;
  2988. this._onChangeCallback();
  2989. return this;
  2990. },
  2991. setFromRotationMatrix: function ( m, order, update ) {
  2992. var clamp = _Math.clamp;
  2993. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2994. var te = m.elements;
  2995. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2996. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2997. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2998. order = order || this._order;
  2999. if ( order === 'XYZ' ) {
  3000. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3001. if ( Math.abs( m13 ) < 0.9999999 ) {
  3002. this._x = Math.atan2( - m23, m33 );
  3003. this._z = Math.atan2( - m12, m11 );
  3004. } else {
  3005. this._x = Math.atan2( m32, m22 );
  3006. this._z = 0;
  3007. }
  3008. } else if ( order === 'YXZ' ) {
  3009. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3010. if ( Math.abs( m23 ) < 0.9999999 ) {
  3011. this._y = Math.atan2( m13, m33 );
  3012. this._z = Math.atan2( m21, m22 );
  3013. } else {
  3014. this._y = Math.atan2( - m31, m11 );
  3015. this._z = 0;
  3016. }
  3017. } else if ( order === 'ZXY' ) {
  3018. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3019. if ( Math.abs( m32 ) < 0.9999999 ) {
  3020. this._y = Math.atan2( - m31, m33 );
  3021. this._z = Math.atan2( - m12, m22 );
  3022. } else {
  3023. this._y = 0;
  3024. this._z = Math.atan2( m21, m11 );
  3025. }
  3026. } else if ( order === 'ZYX' ) {
  3027. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3028. if ( Math.abs( m31 ) < 0.9999999 ) {
  3029. this._x = Math.atan2( m32, m33 );
  3030. this._z = Math.atan2( m21, m11 );
  3031. } else {
  3032. this._x = 0;
  3033. this._z = Math.atan2( - m12, m22 );
  3034. }
  3035. } else if ( order === 'YZX' ) {
  3036. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3037. if ( Math.abs( m21 ) < 0.9999999 ) {
  3038. this._x = Math.atan2( - m23, m22 );
  3039. this._y = Math.atan2( - m31, m11 );
  3040. } else {
  3041. this._x = 0;
  3042. this._y = Math.atan2( m13, m33 );
  3043. }
  3044. } else if ( order === 'XZY' ) {
  3045. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3046. if ( Math.abs( m12 ) < 0.9999999 ) {
  3047. this._x = Math.atan2( m32, m22 );
  3048. this._y = Math.atan2( m13, m11 );
  3049. } else {
  3050. this._x = Math.atan2( - m23, m33 );
  3051. this._y = 0;
  3052. }
  3053. } else {
  3054. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  3055. }
  3056. this._order = order;
  3057. if ( update !== false ) this._onChangeCallback();
  3058. return this;
  3059. },
  3060. setFromQuaternion: function ( q, order, update ) {
  3061. if ( _matrix === undefined ) _matrix = new Matrix4();
  3062. _matrix.makeRotationFromQuaternion( q );
  3063. return this.setFromRotationMatrix( _matrix, order, update );
  3064. },
  3065. setFromVector3: function ( v, order ) {
  3066. return this.set( v.x, v.y, v.z, order || this._order );
  3067. },
  3068. reorder: function ( newOrder ) {
  3069. // WARNING: this discards revolution information -bhouston
  3070. if ( _quaternion$1 === undefined ) _quaternion$1 = new Quaternion();
  3071. _quaternion$1.setFromEuler( this );
  3072. return this.setFromQuaternion( _quaternion$1, newOrder );
  3073. },
  3074. equals: function ( euler ) {
  3075. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3076. },
  3077. fromArray: function ( array ) {
  3078. this._x = array[ 0 ];
  3079. this._y = array[ 1 ];
  3080. this._z = array[ 2 ];
  3081. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3082. this._onChangeCallback();
  3083. return this;
  3084. },
  3085. toArray: function ( array, offset ) {
  3086. if ( array === undefined ) array = [];
  3087. if ( offset === undefined ) offset = 0;
  3088. array[ offset ] = this._x;
  3089. array[ offset + 1 ] = this._y;
  3090. array[ offset + 2 ] = this._z;
  3091. array[ offset + 3 ] = this._order;
  3092. return array;
  3093. },
  3094. toVector3: function ( optionalResult ) {
  3095. if ( optionalResult ) {
  3096. return optionalResult.set( this._x, this._y, this._z );
  3097. } else {
  3098. return new Vector3( this._x, this._y, this._z );
  3099. }
  3100. },
  3101. _onChange: function ( callback ) {
  3102. this._onChangeCallback = callback;
  3103. return this;
  3104. },
  3105. _onChangeCallback: function () {}
  3106. } );
  3107. /**
  3108. * @author mrdoob / http://mrdoob.com/
  3109. */
  3110. function Layers() {
  3111. this.mask = 1 | 0;
  3112. }
  3113. Object.assign( Layers.prototype, {
  3114. set: function ( channel ) {
  3115. this.mask = 1 << channel | 0;
  3116. },
  3117. enable: function ( channel ) {
  3118. this.mask |= 1 << channel | 0;
  3119. },
  3120. toggle: function ( channel ) {
  3121. this.mask ^= 1 << channel | 0;
  3122. },
  3123. disable: function ( channel ) {
  3124. this.mask &= ~ ( 1 << channel | 0 );
  3125. },
  3126. test: function ( layers ) {
  3127. return ( this.mask & layers.mask ) !== 0;
  3128. }
  3129. } );
  3130. /**
  3131. * @author mrdoob / http://mrdoob.com/
  3132. * @author mikael emtinger / http://gomo.se/
  3133. * @author alteredq / http://alteredqualia.com/
  3134. * @author WestLangley / http://github.com/WestLangley
  3135. * @author elephantatwork / www.elephantatwork.ch
  3136. */
  3137. var object3DId = 0;
  3138. function Object3D() {
  3139. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  3140. this.uuid = _Math.generateUUID();
  3141. this.name = '';
  3142. this.type = 'Object3D';
  3143. this.parent = null;
  3144. this.children = [];
  3145. this.up = Object3D.DefaultUp.clone();
  3146. var position = new Vector3();
  3147. var rotation = new Euler();
  3148. var quaternion = new Quaternion();
  3149. var scale = new Vector3( 1, 1, 1 );
  3150. function onRotationChange() {
  3151. quaternion.setFromEuler( rotation, false );
  3152. }
  3153. function onQuaternionChange() {
  3154. rotation.setFromQuaternion( quaternion, undefined, false );
  3155. }
  3156. rotation._onChange( onRotationChange );
  3157. quaternion._onChange( onQuaternionChange );
  3158. Object.defineProperties( this, {
  3159. position: {
  3160. configurable: true,
  3161. enumerable: true,
  3162. value: position
  3163. },
  3164. rotation: {
  3165. configurable: true,
  3166. enumerable: true,
  3167. value: rotation
  3168. },
  3169. quaternion: {
  3170. configurable: true,
  3171. enumerable: true,
  3172. value: quaternion
  3173. },
  3174. scale: {
  3175. configurable: true,
  3176. enumerable: true,
  3177. value: scale
  3178. },
  3179. modelViewMatrix: {
  3180. value: new Matrix4()
  3181. },
  3182. normalMatrix: {
  3183. value: new Matrix3()
  3184. }
  3185. } );
  3186. this.matrix = new Matrix4();
  3187. this.matrixWorld = new Matrix4();
  3188. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3189. this.matrixWorldNeedsUpdate = false;
  3190. this.layers = new Layers();
  3191. this.visible = true;
  3192. this.castShadow = false;
  3193. this.receiveShadow = false;
  3194. this.frustumCulled = true;
  3195. this.renderOrder = 0;
  3196. this.userData = {};
  3197. }
  3198. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3199. Object3D.DefaultMatrixAutoUpdate = true;
  3200. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3201. constructor: Object3D,
  3202. isObject3D: true,
  3203. onBeforeRender: function () {},
  3204. onAfterRender: function () {},
  3205. applyMatrix: function ( matrix ) {
  3206. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3207. this.matrix.premultiply( matrix );
  3208. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3209. },
  3210. applyQuaternion: function ( q ) {
  3211. this.quaternion.premultiply( q );
  3212. return this;
  3213. },
  3214. setRotationFromAxisAngle: function ( axis, angle ) {
  3215. // assumes axis is normalized
  3216. this.quaternion.setFromAxisAngle( axis, angle );
  3217. },
  3218. setRotationFromEuler: function ( euler ) {
  3219. this.quaternion.setFromEuler( euler, true );
  3220. },
  3221. setRotationFromMatrix: function ( m ) {
  3222. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3223. this.quaternion.setFromRotationMatrix( m );
  3224. },
  3225. setRotationFromQuaternion: function ( q ) {
  3226. // assumes q is normalized
  3227. this.quaternion.copy( q );
  3228. },
  3229. rotateOnAxis: function () {
  3230. // rotate object on axis in object space
  3231. // axis is assumed to be normalized
  3232. var q1 = new Quaternion();
  3233. return function rotateOnAxis( axis, angle ) {
  3234. q1.setFromAxisAngle( axis, angle );
  3235. this.quaternion.multiply( q1 );
  3236. return this;
  3237. };
  3238. }(),
  3239. rotateOnWorldAxis: function () {
  3240. // rotate object on axis in world space
  3241. // axis is assumed to be normalized
  3242. // method assumes no rotated parent
  3243. var q1 = new Quaternion();
  3244. return function rotateOnWorldAxis( axis, angle ) {
  3245. q1.setFromAxisAngle( axis, angle );
  3246. this.quaternion.premultiply( q1 );
  3247. return this;
  3248. };
  3249. }(),
  3250. rotateX: function () {
  3251. var v1 = new Vector3( 1, 0, 0 );
  3252. return function rotateX( angle ) {
  3253. return this.rotateOnAxis( v1, angle );
  3254. };
  3255. }(),
  3256. rotateY: function () {
  3257. var v1 = new Vector3( 0, 1, 0 );
  3258. return function rotateY( angle ) {
  3259. return this.rotateOnAxis( v1, angle );
  3260. };
  3261. }(),
  3262. rotateZ: function () {
  3263. var v1 = new Vector3( 0, 0, 1 );
  3264. return function rotateZ( angle ) {
  3265. return this.rotateOnAxis( v1, angle );
  3266. };
  3267. }(),
  3268. translateOnAxis: function () {
  3269. // translate object by distance along axis in object space
  3270. // axis is assumed to be normalized
  3271. var v1 = new Vector3();
  3272. return function translateOnAxis( axis, distance ) {
  3273. v1.copy( axis ).applyQuaternion( this.quaternion );
  3274. this.position.add( v1.multiplyScalar( distance ) );
  3275. return this;
  3276. };
  3277. }(),
  3278. translateX: function () {
  3279. var v1 = new Vector3( 1, 0, 0 );
  3280. return function translateX( distance ) {
  3281. return this.translateOnAxis( v1, distance );
  3282. };
  3283. }(),
  3284. translateY: function () {
  3285. var v1 = new Vector3( 0, 1, 0 );
  3286. return function translateY( distance ) {
  3287. return this.translateOnAxis( v1, distance );
  3288. };
  3289. }(),
  3290. translateZ: function () {
  3291. var v1 = new Vector3( 0, 0, 1 );
  3292. return function translateZ( distance ) {
  3293. return this.translateOnAxis( v1, distance );
  3294. };
  3295. }(),
  3296. localToWorld: function ( vector ) {
  3297. return vector.applyMatrix4( this.matrixWorld );
  3298. },
  3299. worldToLocal: function () {
  3300. var m1 = new Matrix4();
  3301. return function worldToLocal( vector ) {
  3302. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  3303. };
  3304. }(),
  3305. lookAt: function () {
  3306. // This method does not support objects having non-uniformly-scaled parent(s)
  3307. var q1 = new Quaternion();
  3308. var m1 = new Matrix4();
  3309. var target = new Vector3();
  3310. var position = new Vector3();
  3311. return function lookAt( x, y, z ) {
  3312. if ( x.isVector3 ) {
  3313. target.copy( x );
  3314. } else {
  3315. target.set( x, y, z );
  3316. }
  3317. var parent = this.parent;
  3318. this.updateWorldMatrix( true, false );
  3319. position.setFromMatrixPosition( this.matrixWorld );
  3320. if ( this.isCamera || this.isLight ) {
  3321. m1.lookAt( position, target, this.up );
  3322. } else {
  3323. m1.lookAt( target, position, this.up );
  3324. }
  3325. this.quaternion.setFromRotationMatrix( m1 );
  3326. if ( parent ) {
  3327. m1.extractRotation( parent.matrixWorld );
  3328. q1.setFromRotationMatrix( m1 );
  3329. this.quaternion.premultiply( q1.inverse() );
  3330. }
  3331. };
  3332. }(),
  3333. add: function ( object ) {
  3334. if ( arguments.length > 1 ) {
  3335. for ( var i = 0; i < arguments.length; i ++ ) {
  3336. this.add( arguments[ i ] );
  3337. }
  3338. return this;
  3339. }
  3340. if ( object === this ) {
  3341. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3342. return this;
  3343. }
  3344. if ( ( object && object.isObject3D ) ) {
  3345. if ( object.parent !== null ) {
  3346. object.parent.remove( object );
  3347. }
  3348. object.parent = this;
  3349. this.children.push( object );
  3350. object.dispatchEvent( { type: 'added' } );
  3351. } else {
  3352. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3353. }
  3354. return this;
  3355. },
  3356. remove: function ( object ) {
  3357. if ( arguments.length > 1 ) {
  3358. for ( var i = 0; i < arguments.length; i ++ ) {
  3359. this.remove( arguments[ i ] );
  3360. }
  3361. return this;
  3362. }
  3363. var index = this.children.indexOf( object );
  3364. if ( index !== - 1 ) {
  3365. object.parent = null;
  3366. this.children.splice( index, 1 );
  3367. object.dispatchEvent( { type: 'removed' } );
  3368. }
  3369. return this;
  3370. },
  3371. attach: function () {
  3372. // adds object as a child of this, while maintaining the object's world transform
  3373. var m = new Matrix4();
  3374. return function attach( object ) {
  3375. this.updateWorldMatrix( true, false );
  3376. m.getInverse( this.matrixWorld );
  3377. if ( object.parent !== null ) {
  3378. object.parent.updateWorldMatrix( true, false );
  3379. m.multiply( object.parent.matrixWorld );
  3380. }
  3381. object.applyMatrix( m );
  3382. object.updateWorldMatrix( false, false );
  3383. this.add( object );
  3384. return this;
  3385. };
  3386. }(),
  3387. getObjectById: function ( id ) {
  3388. return this.getObjectByProperty( 'id', id );
  3389. },
  3390. getObjectByName: function ( name ) {
  3391. return this.getObjectByProperty( 'name', name );
  3392. },
  3393. getObjectByProperty: function ( name, value ) {
  3394. if ( this[ name ] === value ) return this;
  3395. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3396. var child = this.children[ i ];
  3397. var object = child.getObjectByProperty( name, value );
  3398. if ( object !== undefined ) {
  3399. return object;
  3400. }
  3401. }
  3402. return undefined;
  3403. },
  3404. getWorldPosition: function ( target ) {
  3405. if ( target === undefined ) {
  3406. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3407. target = new Vector3();
  3408. }
  3409. this.updateMatrixWorld( true );
  3410. return target.setFromMatrixPosition( this.matrixWorld );
  3411. },
  3412. getWorldQuaternion: function () {
  3413. var position = new Vector3();
  3414. var scale = new Vector3();
  3415. return function getWorldQuaternion( target ) {
  3416. if ( target === undefined ) {
  3417. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3418. target = new Quaternion();
  3419. }
  3420. this.updateMatrixWorld( true );
  3421. this.matrixWorld.decompose( position, target, scale );
  3422. return target;
  3423. };
  3424. }(),
  3425. getWorldScale: function () {
  3426. var position = new Vector3();
  3427. var quaternion = new Quaternion();
  3428. return function getWorldScale( target ) {
  3429. if ( target === undefined ) {
  3430. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3431. target = new Vector3();
  3432. }
  3433. this.updateMatrixWorld( true );
  3434. this.matrixWorld.decompose( position, quaternion, target );
  3435. return target;
  3436. };
  3437. }(),
  3438. getWorldDirection: function ( target ) {
  3439. if ( target === undefined ) {
  3440. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3441. target = new Vector3();
  3442. }
  3443. this.updateMatrixWorld( true );
  3444. var e = this.matrixWorld.elements;
  3445. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3446. },
  3447. raycast: function () {},
  3448. traverse: function ( callback ) {
  3449. callback( this );
  3450. var children = this.children;
  3451. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3452. children[ i ].traverse( callback );
  3453. }
  3454. },
  3455. traverseVisible: function ( callback ) {
  3456. if ( this.visible === false ) return;
  3457. callback( this );
  3458. var children = this.children;
  3459. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3460. children[ i ].traverseVisible( callback );
  3461. }
  3462. },
  3463. traverseAncestors: function ( callback ) {
  3464. var parent = this.parent;
  3465. if ( parent !== null ) {
  3466. callback( parent );
  3467. parent.traverseAncestors( callback );
  3468. }
  3469. },
  3470. updateMatrix: function () {
  3471. this.matrix.compose( this.position, this.quaternion, this.scale );
  3472. this.matrixWorldNeedsUpdate = true;
  3473. },
  3474. updateMatrixWorld: function ( force ) {
  3475. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3476. if ( this.matrixWorldNeedsUpdate || force ) {
  3477. if ( this.parent === null ) {
  3478. this.matrixWorld.copy( this.matrix );
  3479. } else {
  3480. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3481. }
  3482. this.matrixWorldNeedsUpdate = false;
  3483. force = true;
  3484. }
  3485. // update children
  3486. var children = this.children;
  3487. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3488. children[ i ].updateMatrixWorld( force );
  3489. }
  3490. },
  3491. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3492. var parent = this.parent;
  3493. if ( updateParents === true && parent !== null ) {
  3494. parent.updateWorldMatrix( true, false );
  3495. }
  3496. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3497. if ( this.parent === null ) {
  3498. this.matrixWorld.copy( this.matrix );
  3499. } else {
  3500. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3501. }
  3502. // update children
  3503. if ( updateChildren === true ) {
  3504. var children = this.children;
  3505. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3506. children[ i ].updateWorldMatrix( false, true );
  3507. }
  3508. }
  3509. },
  3510. toJSON: function ( meta ) {
  3511. // meta is a string when called from JSON.stringify
  3512. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3513. var output = {};
  3514. // meta is a hash used to collect geometries, materials.
  3515. // not providing it implies that this is the root object
  3516. // being serialized.
  3517. if ( isRootObject ) {
  3518. // initialize meta obj
  3519. meta = {
  3520. geometries: {},
  3521. materials: {},
  3522. textures: {},
  3523. images: {},
  3524. shapes: {}
  3525. };
  3526. output.metadata = {
  3527. version: 4.5,
  3528. type: 'Object',
  3529. generator: 'Object3D.toJSON'
  3530. };
  3531. }
  3532. // standard Object3D serialization
  3533. var object = {};
  3534. object.uuid = this.uuid;
  3535. object.type = this.type;
  3536. if ( this.name !== '' ) object.name = this.name;
  3537. if ( this.castShadow === true ) object.castShadow = true;
  3538. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3539. if ( this.visible === false ) object.visible = false;
  3540. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3541. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3542. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3543. object.layers = this.layers.mask;
  3544. object.matrix = this.matrix.toArray();
  3545. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3546. // object specific properties
  3547. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  3548. //
  3549. function serialize( library, element ) {
  3550. if ( library[ element.uuid ] === undefined ) {
  3551. library[ element.uuid ] = element.toJSON( meta );
  3552. }
  3553. return element.uuid;
  3554. }
  3555. if ( this.isMesh || this.isLine || this.isPoints ) {
  3556. object.geometry = serialize( meta.geometries, this.geometry );
  3557. var parameters = this.geometry.parameters;
  3558. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3559. var shapes = parameters.shapes;
  3560. if ( Array.isArray( shapes ) ) {
  3561. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3562. var shape = shapes[ i ];
  3563. serialize( meta.shapes, shape );
  3564. }
  3565. } else {
  3566. serialize( meta.shapes, shapes );
  3567. }
  3568. }
  3569. }
  3570. if ( this.material !== undefined ) {
  3571. if ( Array.isArray( this.material ) ) {
  3572. var uuids = [];
  3573. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  3574. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3575. }
  3576. object.material = uuids;
  3577. } else {
  3578. object.material = serialize( meta.materials, this.material );
  3579. }
  3580. }
  3581. //
  3582. if ( this.children.length > 0 ) {
  3583. object.children = [];
  3584. for ( var i = 0; i < this.children.length; i ++ ) {
  3585. object.children.push( this.children[ i ].toJSON( meta ).object );
  3586. }
  3587. }
  3588. if ( isRootObject ) {
  3589. var geometries = extractFromCache( meta.geometries );
  3590. var materials = extractFromCache( meta.materials );
  3591. var textures = extractFromCache( meta.textures );
  3592. var images = extractFromCache( meta.images );
  3593. var shapes = extractFromCache( meta.shapes );
  3594. if ( geometries.length > 0 ) output.geometries = geometries;
  3595. if ( materials.length > 0 ) output.materials = materials;
  3596. if ( textures.length > 0 ) output.textures = textures;
  3597. if ( images.length > 0 ) output.images = images;
  3598. if ( shapes.length > 0 ) output.shapes = shapes;
  3599. }
  3600. output.object = object;
  3601. return output;
  3602. // extract data from the cache hash
  3603. // remove metadata on each item
  3604. // and return as array
  3605. function extractFromCache( cache ) {
  3606. var values = [];
  3607. for ( var key in cache ) {
  3608. var data = cache[ key ];
  3609. delete data.metadata;
  3610. values.push( data );
  3611. }
  3612. return values;
  3613. }
  3614. },
  3615. clone: function ( recursive ) {
  3616. return new this.constructor().copy( this, recursive );
  3617. },
  3618. copy: function ( source, recursive ) {
  3619. if ( recursive === undefined ) recursive = true;
  3620. this.name = source.name;
  3621. this.up.copy( source.up );
  3622. this.position.copy( source.position );
  3623. this.quaternion.copy( source.quaternion );
  3624. this.scale.copy( source.scale );
  3625. this.matrix.copy( source.matrix );
  3626. this.matrixWorld.copy( source.matrixWorld );
  3627. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3628. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3629. this.layers.mask = source.layers.mask;
  3630. this.visible = source.visible;
  3631. this.castShadow = source.castShadow;
  3632. this.receiveShadow = source.receiveShadow;
  3633. this.frustumCulled = source.frustumCulled;
  3634. this.renderOrder = source.renderOrder;
  3635. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3636. if ( recursive === true ) {
  3637. for ( var i = 0; i < source.children.length; i ++ ) {
  3638. var child = source.children[ i ];
  3639. this.add( child.clone() );
  3640. }
  3641. }
  3642. return this;
  3643. }
  3644. } );
  3645. /**
  3646. * @author mrdoob / http://mrdoob.com/
  3647. */
  3648. function Scene() {
  3649. Object3D.call( this );
  3650. this.type = 'Scene';
  3651. this.background = null;
  3652. this.fog = null;
  3653. this.overrideMaterial = null;
  3654. this.autoUpdate = true; // checked by the renderer
  3655. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3656. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3657. }
  3658. }
  3659. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3660. constructor: Scene,
  3661. isScene: true,
  3662. copy: function ( source, recursive ) {
  3663. Object3D.prototype.copy.call( this, source, recursive );
  3664. if ( source.background !== null ) this.background = source.background.clone();
  3665. if ( source.fog !== null ) this.fog = source.fog.clone();
  3666. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3667. this.autoUpdate = source.autoUpdate;
  3668. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3669. return this;
  3670. },
  3671. toJSON: function ( meta ) {
  3672. var data = Object3D.prototype.toJSON.call( this, meta );
  3673. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3674. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3675. return data;
  3676. },
  3677. dispose: function () {
  3678. this.dispatchEvent( { type: 'dispose' } );
  3679. }
  3680. } );
  3681. /**
  3682. * @author bhouston / http://clara.io
  3683. * @author WestLangley / http://github.com/WestLangley
  3684. */
  3685. var _points;
  3686. var _vector$2;
  3687. var _v0, _v1$1, _v2;
  3688. var _f0, _f1, _f2;
  3689. var _center;
  3690. var _extents;
  3691. var _triangleNormal;
  3692. function Box3( min, max ) {
  3693. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3694. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3695. }
  3696. Object.assign( Box3.prototype, {
  3697. isBox3: true,
  3698. set: function ( min, max ) {
  3699. this.min.copy( min );
  3700. this.max.copy( max );
  3701. return this;
  3702. },
  3703. setFromArray: function ( array ) {
  3704. var minX = + Infinity;
  3705. var minY = + Infinity;
  3706. var minZ = + Infinity;
  3707. var maxX = - Infinity;
  3708. var maxY = - Infinity;
  3709. var maxZ = - Infinity;
  3710. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3711. var x = array[ i ];
  3712. var y = array[ i + 1 ];
  3713. var z = array[ i + 2 ];
  3714. if ( x < minX ) minX = x;
  3715. if ( y < minY ) minY = y;
  3716. if ( z < minZ ) minZ = z;
  3717. if ( x > maxX ) maxX = x;
  3718. if ( y > maxY ) maxY = y;
  3719. if ( z > maxZ ) maxZ = z;
  3720. }
  3721. this.min.set( minX, minY, minZ );
  3722. this.max.set( maxX, maxY, maxZ );
  3723. return this;
  3724. },
  3725. setFromBufferAttribute: function ( attribute ) {
  3726. var minX = + Infinity;
  3727. var minY = + Infinity;
  3728. var minZ = + Infinity;
  3729. var maxX = - Infinity;
  3730. var maxY = - Infinity;
  3731. var maxZ = - Infinity;
  3732. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3733. var x = attribute.getX( i );
  3734. var y = attribute.getY( i );
  3735. var z = attribute.getZ( i );
  3736. if ( x < minX ) minX = x;
  3737. if ( y < minY ) minY = y;
  3738. if ( z < minZ ) minZ = z;
  3739. if ( x > maxX ) maxX = x;
  3740. if ( y > maxY ) maxY = y;
  3741. if ( z > maxZ ) maxZ = z;
  3742. }
  3743. this.min.set( minX, minY, minZ );
  3744. this.max.set( maxX, maxY, maxZ );
  3745. return this;
  3746. },
  3747. setFromPoints: function ( points ) {
  3748. this.makeEmpty();
  3749. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3750. this.expandByPoint( points[ i ] );
  3751. }
  3752. return this;
  3753. },
  3754. setFromCenterAndSize: function ( center, size ) {
  3755. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3756. var halfSize = _vector$2.copy( size ).multiplyScalar( 0.5 );
  3757. this.min.copy( center ).sub( halfSize );
  3758. this.max.copy( center ).add( halfSize );
  3759. return this;
  3760. },
  3761. setFromObject: function ( object ) {
  3762. this.makeEmpty();
  3763. return this.expandByObject( object );
  3764. },
  3765. clone: function () {
  3766. return new this.constructor().copy( this );
  3767. },
  3768. copy: function ( box ) {
  3769. this.min.copy( box.min );
  3770. this.max.copy( box.max );
  3771. return this;
  3772. },
  3773. makeEmpty: function () {
  3774. this.min.x = this.min.y = this.min.z = + Infinity;
  3775. this.max.x = this.max.y = this.max.z = - Infinity;
  3776. return this;
  3777. },
  3778. isEmpty: function () {
  3779. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3780. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3781. },
  3782. getCenter: function ( target ) {
  3783. if ( target === undefined ) {
  3784. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3785. target = new Vector3();
  3786. }
  3787. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3788. },
  3789. getSize: function ( target ) {
  3790. if ( target === undefined ) {
  3791. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3792. target = new Vector3();
  3793. }
  3794. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3795. },
  3796. expandByPoint: function ( point ) {
  3797. this.min.min( point );
  3798. this.max.max( point );
  3799. return this;
  3800. },
  3801. expandByVector: function ( vector ) {
  3802. this.min.sub( vector );
  3803. this.max.add( vector );
  3804. return this;
  3805. },
  3806. expandByScalar: function ( scalar ) {
  3807. this.min.addScalar( - scalar );
  3808. this.max.addScalar( scalar );
  3809. return this;
  3810. },
  3811. expandByObject: function ( object ) {
  3812. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3813. var i, l;
  3814. // Computes the world-axis-aligned bounding box of an object (including its children),
  3815. // accounting for both the object's, and children's, world transforms
  3816. object.updateWorldMatrix( false, false );
  3817. var geometry = object.geometry;
  3818. if ( geometry !== undefined ) {
  3819. if ( geometry.isGeometry ) {
  3820. var vertices = geometry.vertices;
  3821. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3822. _vector$2.copy( vertices[ i ] );
  3823. _vector$2.applyMatrix4( object.matrixWorld );
  3824. this.expandByPoint( _vector$2 );
  3825. }
  3826. } else if ( geometry.isBufferGeometry ) {
  3827. var attribute = geometry.attributes.position;
  3828. if ( attribute !== undefined ) {
  3829. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3830. _vector$2.fromBufferAttribute( attribute, i ).applyMatrix4( object.matrixWorld );
  3831. this.expandByPoint( _vector$2 );
  3832. }
  3833. }
  3834. }
  3835. }
  3836. //
  3837. var children = object.children;
  3838. for ( i = 0, l = children.length; i < l; i ++ ) {
  3839. this.expandByObject( children[ i ] );
  3840. }
  3841. return this;
  3842. },
  3843. containsPoint: function ( point ) {
  3844. return point.x < this.min.x || point.x > this.max.x ||
  3845. point.y < this.min.y || point.y > this.max.y ||
  3846. point.z < this.min.z || point.z > this.max.z ? false : true;
  3847. },
  3848. containsBox: function ( box ) {
  3849. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3850. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3851. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3852. },
  3853. getParameter: function ( point, target ) {
  3854. // This can potentially have a divide by zero if the box
  3855. // has a size dimension of 0.
  3856. if ( target === undefined ) {
  3857. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3858. target = new Vector3();
  3859. }
  3860. return target.set(
  3861. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3862. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3863. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3864. );
  3865. },
  3866. intersectsBox: function ( box ) {
  3867. // using 6 splitting planes to rule out intersections.
  3868. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3869. box.max.y < this.min.y || box.min.y > this.max.y ||
  3870. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3871. },
  3872. intersectsSphere: function ( sphere ) {
  3873. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3874. // Find the point on the AABB closest to the sphere center.
  3875. this.clampPoint( sphere.center, _vector$2 );
  3876. // If that point is inside the sphere, the AABB and sphere intersect.
  3877. return _vector$2.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3878. },
  3879. intersectsPlane: function ( plane ) {
  3880. // We compute the minimum and maximum dot product values. If those values
  3881. // are on the same side (back or front) of the plane, then there is no intersection.
  3882. var min, max;
  3883. if ( plane.normal.x > 0 ) {
  3884. min = plane.normal.x * this.min.x;
  3885. max = plane.normal.x * this.max.x;
  3886. } else {
  3887. min = plane.normal.x * this.max.x;
  3888. max = plane.normal.x * this.min.x;
  3889. }
  3890. if ( plane.normal.y > 0 ) {
  3891. min += plane.normal.y * this.min.y;
  3892. max += plane.normal.y * this.max.y;
  3893. } else {
  3894. min += plane.normal.y * this.max.y;
  3895. max += plane.normal.y * this.min.y;
  3896. }
  3897. if ( plane.normal.z > 0 ) {
  3898. min += plane.normal.z * this.min.z;
  3899. max += plane.normal.z * this.max.z;
  3900. } else {
  3901. min += plane.normal.z * this.max.z;
  3902. max += plane.normal.z * this.min.z;
  3903. }
  3904. return ( min <= - plane.constant && max >= - plane.constant );
  3905. },
  3906. intersectsTriangle: function ( triangle ) {
  3907. if ( _v0 === undefined ) {
  3908. // triangle centered vertices
  3909. _v0 = new Vector3();
  3910. _v1$1 = new Vector3();
  3911. _v2 = new Vector3();
  3912. // triangle edge vectors
  3913. _f0 = new Vector3();
  3914. _f1 = new Vector3();
  3915. _f2 = new Vector3();
  3916. _center = new Vector3();
  3917. _extents = new Vector3();
  3918. _triangleNormal = new Vector3();
  3919. }
  3920. if ( this.isEmpty() ) {
  3921. return false;
  3922. }
  3923. // compute box center and extents
  3924. this.getCenter( _center );
  3925. _extents.subVectors( this.max, _center );
  3926. // translate triangle to aabb origin
  3927. _v0.subVectors( triangle.a, _center );
  3928. _v1$1.subVectors( triangle.b, _center );
  3929. _v2.subVectors( triangle.c, _center );
  3930. // compute edge vectors for triangle
  3931. _f0.subVectors( _v1$1, _v0 );
  3932. _f1.subVectors( _v2, _v1$1 );
  3933. _f2.subVectors( _v0, _v2 );
  3934. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3935. // 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
  3936. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3937. var axes = [
  3938. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  3939. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  3940. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  3941. ];
  3942. if ( ! satForAxes( axes, _v0, _v1$1, _v2, _extents ) ) {
  3943. return false;
  3944. }
  3945. // test 3 face normals from the aabb
  3946. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3947. if ( ! satForAxes( axes, _v0, _v1$1, _v2, _extents ) ) {
  3948. return false;
  3949. }
  3950. // finally testing the face normal of the triangle
  3951. // use already existing triangle edge vectors here
  3952. _triangleNormal.crossVectors( _f0, _f1 );
  3953. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  3954. return satForAxes( axes, _v0, _v1$1, _v2, _extents );
  3955. },
  3956. clampPoint: function ( point, target ) {
  3957. if ( target === undefined ) {
  3958. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3959. target = new Vector3();
  3960. }
  3961. return target.copy( point ).clamp( this.min, this.max );
  3962. },
  3963. distanceToPoint: function ( point ) {
  3964. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3965. var clampedPoint = _vector$2.copy( point ).clamp( this.min, this.max );
  3966. return clampedPoint.sub( point ).length();
  3967. },
  3968. getBoundingSphere: function ( target ) {
  3969. if ( _vector$2 === undefined ) _vector$2 = new Vector3();
  3970. if ( target === undefined ) {
  3971. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3972. //target = new Sphere(); // removed to avoid cyclic dependency
  3973. }
  3974. this.getCenter( target.center );
  3975. target.radius = this.getSize( _vector$2 ).length() * 0.5;
  3976. return target;
  3977. },
  3978. intersect: function ( box ) {
  3979. this.min.max( box.min );
  3980. this.max.min( box.max );
  3981. // 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.
  3982. if ( this.isEmpty() ) this.makeEmpty();
  3983. return this;
  3984. },
  3985. union: function ( box ) {
  3986. this.min.min( box.min );
  3987. this.max.max( box.max );
  3988. return this;
  3989. },
  3990. applyMatrix4: function ( matrix ) {
  3991. if ( _points === undefined ) {
  3992. _points = [
  3993. new Vector3(),
  3994. new Vector3(),
  3995. new Vector3(),
  3996. new Vector3(),
  3997. new Vector3(),
  3998. new Vector3(),
  3999. new Vector3(),
  4000. new Vector3()
  4001. ];
  4002. }
  4003. // transform of empty box is an empty box.
  4004. if ( this.isEmpty() ) return this;
  4005. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4006. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4007. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4008. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4009. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4010. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4011. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4012. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4013. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4014. this.setFromPoints( _points );
  4015. return this;
  4016. },
  4017. translate: function ( offset ) {
  4018. this.min.add( offset );
  4019. this.max.add( offset );
  4020. return this;
  4021. },
  4022. equals: function ( box ) {
  4023. return box.min.equals( this.min ) && box.max.equals( this.max );
  4024. }
  4025. } );
  4026. var _testAxis;
  4027. function satForAxes( axes, v0, v1, v2, extents ) {
  4028. if ( _testAxis === undefined ) _testAxis = new Vector3();
  4029. var i, j;
  4030. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  4031. _testAxis.fromArray( axes, i );
  4032. // project the aabb onto the seperating axis
  4033. var r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  4034. // project all 3 vertices of the triangle onto the seperating axis
  4035. var p0 = v0.dot( _testAxis );
  4036. var p1 = v1.dot( _testAxis );
  4037. var p2 = v2.dot( _testAxis );
  4038. // actual test, basically see if either of the most extreme of the triangle points intersects r
  4039. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  4040. // points of the projected triangle are outside the projected half-length of the aabb
  4041. // the axis is seperating and we can exit
  4042. return false;
  4043. }
  4044. }
  4045. return true;
  4046. }
  4047. /**
  4048. * @author bhouston / http://clara.io
  4049. * @author mrdoob / http://mrdoob.com/
  4050. */
  4051. var _box;
  4052. function Sphere( center, radius ) {
  4053. this.center = ( center !== undefined ) ? center : new Vector3();
  4054. this.radius = ( radius !== undefined ) ? radius : 0;
  4055. }
  4056. Object.assign( Sphere.prototype, {
  4057. set: function ( center, radius ) {
  4058. this.center.copy( center );
  4059. this.radius = radius;
  4060. return this;
  4061. },
  4062. setFromPoints: function ( points, optionalCenter ) {
  4063. if ( _box === undefined ) _box = new Box3();
  4064. var center = this.center;
  4065. if ( optionalCenter !== undefined ) {
  4066. center.copy( optionalCenter );
  4067. } else {
  4068. _box.setFromPoints( points ).getCenter( center );
  4069. }
  4070. var maxRadiusSq = 0;
  4071. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4072. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4073. }
  4074. this.radius = Math.sqrt( maxRadiusSq );
  4075. return this;
  4076. },
  4077. clone: function () {
  4078. return new this.constructor().copy( this );
  4079. },
  4080. copy: function ( sphere ) {
  4081. this.center.copy( sphere.center );
  4082. this.radius = sphere.radius;
  4083. return this;
  4084. },
  4085. empty: function () {
  4086. return ( this.radius <= 0 );
  4087. },
  4088. containsPoint: function ( point ) {
  4089. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4090. },
  4091. distanceToPoint: function ( point ) {
  4092. return ( point.distanceTo( this.center ) - this.radius );
  4093. },
  4094. intersectsSphere: function ( sphere ) {
  4095. var radiusSum = this.radius + sphere.radius;
  4096. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4097. },
  4098. intersectsBox: function ( box ) {
  4099. return box.intersectsSphere( this );
  4100. },
  4101. intersectsPlane: function ( plane ) {
  4102. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4103. },
  4104. clampPoint: function ( point, target ) {
  4105. var deltaLengthSq = this.center.distanceToSquared( point );
  4106. if ( target === undefined ) {
  4107. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4108. target = new Vector3();
  4109. }
  4110. target.copy( point );
  4111. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4112. target.sub( this.center ).normalize();
  4113. target.multiplyScalar( this.radius ).add( this.center );
  4114. }
  4115. return target;
  4116. },
  4117. getBoundingBox: function ( target ) {
  4118. if ( target === undefined ) {
  4119. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4120. target = new Box3();
  4121. }
  4122. target.set( this.center, this.center );
  4123. target.expandByScalar( this.radius );
  4124. return target;
  4125. },
  4126. applyMatrix4: function ( matrix ) {
  4127. this.center.applyMatrix4( matrix );
  4128. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4129. return this;
  4130. },
  4131. translate: function ( offset ) {
  4132. this.center.add( offset );
  4133. return this;
  4134. },
  4135. equals: function ( sphere ) {
  4136. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4137. }
  4138. } );
  4139. /**
  4140. * @author bhouston / http://clara.io
  4141. */
  4142. var _vector$3;
  4143. var _segCenter, _segDir, _diff;
  4144. var _diff, _edge1, _edge2, _normal;
  4145. function Ray( origin, direction ) {
  4146. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4147. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  4148. }
  4149. Object.assign( Ray.prototype, {
  4150. set: function ( origin, direction ) {
  4151. this.origin.copy( origin );
  4152. this.direction.copy( direction );
  4153. return this;
  4154. },
  4155. clone: function () {
  4156. return new this.constructor().copy( this );
  4157. },
  4158. copy: function ( ray ) {
  4159. this.origin.copy( ray.origin );
  4160. this.direction.copy( ray.direction );
  4161. return this;
  4162. },
  4163. at: function ( t, target ) {
  4164. if ( target === undefined ) {
  4165. console.warn( 'THREE.Ray: .at() target is now required' );
  4166. target = new Vector3();
  4167. }
  4168. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4169. },
  4170. lookAt: function ( v ) {
  4171. this.direction.copy( v ).sub( this.origin ).normalize();
  4172. return this;
  4173. },
  4174. recast: function ( t ) {
  4175. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4176. this.origin.copy( this.at( t, _vector$3 ) );
  4177. return this;
  4178. },
  4179. closestPointToPoint: function ( point, target ) {
  4180. if ( target === undefined ) {
  4181. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4182. target = new Vector3();
  4183. }
  4184. target.subVectors( point, this.origin );
  4185. var directionDistance = target.dot( this.direction );
  4186. if ( directionDistance < 0 ) {
  4187. return target.copy( this.origin );
  4188. }
  4189. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4190. },
  4191. distanceToPoint: function ( point ) {
  4192. return Math.sqrt( this.distanceSqToPoint( point ) );
  4193. },
  4194. distanceSqToPoint: function ( point ) {
  4195. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4196. var directionDistance = _vector$3.subVectors( point, this.origin ).dot( this.direction );
  4197. // point behind the ray
  4198. if ( directionDistance < 0 ) {
  4199. return this.origin.distanceToSquared( point );
  4200. }
  4201. _vector$3.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4202. return _vector$3.distanceToSquared( point );
  4203. },
  4204. distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4205. if ( _segCenter === undefined ) {
  4206. _segCenter = new Vector3();
  4207. _segDir = new Vector3();
  4208. _diff = new Vector3();
  4209. }
  4210. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4211. // It returns the min distance between the ray and the segment
  4212. // defined by v0 and v1
  4213. // It can also set two optional targets :
  4214. // - The closest point on the ray
  4215. // - The closest point on the segment
  4216. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4217. _segDir.copy( v1 ).sub( v0 ).normalize();
  4218. _diff.copy( this.origin ).sub( _segCenter );
  4219. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4220. var a01 = - this.direction.dot( _segDir );
  4221. var b0 = _diff.dot( this.direction );
  4222. var b1 = - _diff.dot( _segDir );
  4223. var c = _diff.lengthSq();
  4224. var det = Math.abs( 1 - a01 * a01 );
  4225. var s0, s1, sqrDist, extDet;
  4226. if ( det > 0 ) {
  4227. // The ray and segment are not parallel.
  4228. s0 = a01 * b1 - b0;
  4229. s1 = a01 * b0 - b1;
  4230. extDet = segExtent * det;
  4231. if ( s0 >= 0 ) {
  4232. if ( s1 >= - extDet ) {
  4233. if ( s1 <= extDet ) {
  4234. // region 0
  4235. // Minimum at interior points of ray and segment.
  4236. var invDet = 1 / det;
  4237. s0 *= invDet;
  4238. s1 *= invDet;
  4239. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4240. } else {
  4241. // region 1
  4242. s1 = segExtent;
  4243. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4244. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4245. }
  4246. } else {
  4247. // region 5
  4248. s1 = - segExtent;
  4249. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4250. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4251. }
  4252. } else {
  4253. if ( s1 <= - extDet ) {
  4254. // region 4
  4255. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4256. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4257. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4258. } else if ( s1 <= extDet ) {
  4259. // region 3
  4260. s0 = 0;
  4261. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4262. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4263. } else {
  4264. // region 2
  4265. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4266. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4267. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4268. }
  4269. }
  4270. } else {
  4271. // Ray and segment are parallel.
  4272. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4273. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4274. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4275. }
  4276. if ( optionalPointOnRay ) {
  4277. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4278. }
  4279. if ( optionalPointOnSegment ) {
  4280. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  4281. }
  4282. return sqrDist;
  4283. },
  4284. intersectSphere: function ( sphere, target ) {
  4285. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4286. _vector$3.subVectors( sphere.center, this.origin );
  4287. var tca = _vector$3.dot( this.direction );
  4288. var d2 = _vector$3.dot( _vector$3 ) - tca * tca;
  4289. var radius2 = sphere.radius * sphere.radius;
  4290. if ( d2 > radius2 ) return null;
  4291. var thc = Math.sqrt( radius2 - d2 );
  4292. // t0 = first intersect point - entrance on front of sphere
  4293. var t0 = tca - thc;
  4294. // t1 = second intersect point - exit point on back of sphere
  4295. var t1 = tca + thc;
  4296. // test to see if both t0 and t1 are behind the ray - if so, return null
  4297. if ( t0 < 0 && t1 < 0 ) return null;
  4298. // test to see if t0 is behind the ray:
  4299. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4300. // in order to always return an intersect point that is in front of the ray.
  4301. if ( t0 < 0 ) return this.at( t1, target );
  4302. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4303. return this.at( t0, target );
  4304. },
  4305. intersectsSphere: function ( sphere ) {
  4306. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4307. },
  4308. distanceToPlane: function ( plane ) {
  4309. var denominator = plane.normal.dot( this.direction );
  4310. if ( denominator === 0 ) {
  4311. // line is coplanar, return origin
  4312. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4313. return 0;
  4314. }
  4315. // Null is preferable to undefined since undefined means.... it is undefined
  4316. return null;
  4317. }
  4318. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4319. // Return if the ray never intersects the plane
  4320. return t >= 0 ? t : null;
  4321. },
  4322. intersectPlane: function ( plane, target ) {
  4323. var t = this.distanceToPlane( plane );
  4324. if ( t === null ) {
  4325. return null;
  4326. }
  4327. return this.at( t, target );
  4328. },
  4329. intersectsPlane: function ( plane ) {
  4330. // check if the ray lies on the plane first
  4331. var distToPoint = plane.distanceToPoint( this.origin );
  4332. if ( distToPoint === 0 ) {
  4333. return true;
  4334. }
  4335. var denominator = plane.normal.dot( this.direction );
  4336. if ( denominator * distToPoint < 0 ) {
  4337. return true;
  4338. }
  4339. // ray origin is behind the plane (and is pointing behind it)
  4340. return false;
  4341. },
  4342. intersectBox: function ( box, target ) {
  4343. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4344. var invdirx = 1 / this.direction.x,
  4345. invdiry = 1 / this.direction.y,
  4346. invdirz = 1 / this.direction.z;
  4347. var origin = this.origin;
  4348. if ( invdirx >= 0 ) {
  4349. tmin = ( box.min.x - origin.x ) * invdirx;
  4350. tmax = ( box.max.x - origin.x ) * invdirx;
  4351. } else {
  4352. tmin = ( box.max.x - origin.x ) * invdirx;
  4353. tmax = ( box.min.x - origin.x ) * invdirx;
  4354. }
  4355. if ( invdiry >= 0 ) {
  4356. tymin = ( box.min.y - origin.y ) * invdiry;
  4357. tymax = ( box.max.y - origin.y ) * invdiry;
  4358. } else {
  4359. tymin = ( box.max.y - origin.y ) * invdiry;
  4360. tymax = ( box.min.y - origin.y ) * invdiry;
  4361. }
  4362. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4363. // These lines also handle the case where tmin or tmax is NaN
  4364. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4365. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4366. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4367. if ( invdirz >= 0 ) {
  4368. tzmin = ( box.min.z - origin.z ) * invdirz;
  4369. tzmax = ( box.max.z - origin.z ) * invdirz;
  4370. } else {
  4371. tzmin = ( box.max.z - origin.z ) * invdirz;
  4372. tzmax = ( box.min.z - origin.z ) * invdirz;
  4373. }
  4374. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4375. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4376. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4377. //return point closest to the ray (positive side)
  4378. if ( tmax < 0 ) return null;
  4379. return this.at( tmin >= 0 ? tmin : tmax, target );
  4380. },
  4381. intersectsBox: function ( box ) {
  4382. if ( _vector$3 === undefined ) _vector$3 = new Vector3();
  4383. return this.intersectBox( box, _vector$3 ) !== null;
  4384. },
  4385. intersectTriangle: function ( a, b, c, backfaceCulling, target ) {
  4386. // Compute the offset origin, edges, and normal.
  4387. if ( _diff === undefined ) {
  4388. _diff = new Vector3();
  4389. _edge1 = new Vector3();
  4390. _edge2 = new Vector3();
  4391. _normal = new Vector3();
  4392. }
  4393. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4394. _edge1.subVectors( b, a );
  4395. _edge2.subVectors( c, a );
  4396. _normal.crossVectors( _edge1, _edge2 );
  4397. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4398. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4399. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4400. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4401. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4402. var DdN = this.direction.dot( _normal );
  4403. var sign;
  4404. if ( DdN > 0 ) {
  4405. if ( backfaceCulling ) return null;
  4406. sign = 1;
  4407. } else if ( DdN < 0 ) {
  4408. sign = - 1;
  4409. DdN = - DdN;
  4410. } else {
  4411. return null;
  4412. }
  4413. _diff.subVectors( this.origin, a );
  4414. var DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  4415. // b1 < 0, no intersection
  4416. if ( DdQxE2 < 0 ) {
  4417. return null;
  4418. }
  4419. var DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  4420. // b2 < 0, no intersection
  4421. if ( DdE1xQ < 0 ) {
  4422. return null;
  4423. }
  4424. // b1+b2 > 1, no intersection
  4425. if ( DdQxE2 + DdE1xQ > DdN ) {
  4426. return null;
  4427. }
  4428. // Line intersects triangle, check if ray does.
  4429. var QdN = - sign * _diff.dot( _normal );
  4430. // t < 0, no intersection
  4431. if ( QdN < 0 ) {
  4432. return null;
  4433. }
  4434. // Ray intersects triangle.
  4435. return this.at( QdN / DdN, target );
  4436. },
  4437. applyMatrix4: function ( matrix4 ) {
  4438. this.origin.applyMatrix4( matrix4 );
  4439. this.direction.transformDirection( matrix4 );
  4440. return this;
  4441. },
  4442. equals: function ( ray ) {
  4443. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4444. }
  4445. } );
  4446. /**
  4447. * @author bhouston / http://clara.io
  4448. * @author mrdoob / http://mrdoob.com/
  4449. */
  4450. var _v0$1, _v1$2, _v2$1, _v3;
  4451. var _vab, _vac, _vbc, _vap, _vbp, _vcp;
  4452. function Triangle( a, b, c ) {
  4453. this.a = ( a !== undefined ) ? a : new Vector3();
  4454. this.b = ( b !== undefined ) ? b : new Vector3();
  4455. this.c = ( c !== undefined ) ? c : new Vector3();
  4456. }
  4457. Object.assign( Triangle, {
  4458. getNormal: function ( a, b, c, target ) {
  4459. if ( _v0$1 === undefined ) _v0$1 = new Vector3();
  4460. if ( target === undefined ) {
  4461. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4462. target = new Vector3();
  4463. }
  4464. target.subVectors( c, b );
  4465. _v0$1.subVectors( a, b );
  4466. target.cross( _v0$1 );
  4467. var targetLengthSq = target.lengthSq();
  4468. if ( targetLengthSq > 0 ) {
  4469. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4470. }
  4471. return target.set( 0, 0, 0 );
  4472. },
  4473. // static/instance method to calculate barycentric coordinates
  4474. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4475. getBarycoord: function ( point, a, b, c, target ) {
  4476. if ( _v2$1 === undefined ) {
  4477. _v0$1 = new Vector3();
  4478. _v1$2 = new Vector3();
  4479. _v2$1 = new Vector3();
  4480. }
  4481. _v0$1.subVectors( c, a );
  4482. _v1$2.subVectors( b, a );
  4483. _v2$1.subVectors( point, a );
  4484. var dot00 = _v0$1.dot( _v0$1 );
  4485. var dot01 = _v0$1.dot( _v1$2 );
  4486. var dot02 = _v0$1.dot( _v2$1 );
  4487. var dot11 = _v1$2.dot( _v1$2 );
  4488. var dot12 = _v1$2.dot( _v2$1 );
  4489. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4490. if ( target === undefined ) {
  4491. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4492. target = new Vector3();
  4493. }
  4494. // collinear or singular triangle
  4495. if ( denom === 0 ) {
  4496. // arbitrary location outside of triangle?
  4497. // not sure if this is the best idea, maybe should be returning undefined
  4498. return target.set( - 2, - 1, - 1 );
  4499. }
  4500. var invDenom = 1 / denom;
  4501. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4502. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4503. // barycentric coordinates must always sum to 1
  4504. return target.set( 1 - u - v, v, u );
  4505. },
  4506. containsPoint: function ( point, a, b, c ) {
  4507. if ( _v3 === undefined ) _v3 = new Vector3();
  4508. Triangle.getBarycoord( point, a, b, c, _v3 );
  4509. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4510. },
  4511. getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4512. if ( _v3 === undefined ) _v3 = new Vector3();
  4513. this.getBarycoord( point, p1, p2, p3, _v3 );
  4514. target.set( 0, 0 );
  4515. target.addScaledVector( uv1, _v3.x );
  4516. target.addScaledVector( uv2, _v3.y );
  4517. target.addScaledVector( uv3, _v3.z );
  4518. return target;
  4519. },
  4520. isFrontFacing: function ( a, b, c, direction ) {
  4521. if ( _v1$2 === undefined ) {
  4522. _v0$1 = new Vector3();
  4523. _v1$2 = new Vector3();
  4524. }
  4525. _v0$1.subVectors( c, b );
  4526. _v1$2.subVectors( a, b );
  4527. // strictly front facing
  4528. return ( _v0$1.cross( _v1$2 ).dot( direction ) < 0 ) ? true : false;
  4529. }
  4530. } );
  4531. Object.assign( Triangle.prototype, {
  4532. set: function ( a, b, c ) {
  4533. this.a.copy( a );
  4534. this.b.copy( b );
  4535. this.c.copy( c );
  4536. return this;
  4537. },
  4538. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4539. this.a.copy( points[ i0 ] );
  4540. this.b.copy( points[ i1 ] );
  4541. this.c.copy( points[ i2 ] );
  4542. return this;
  4543. },
  4544. clone: function () {
  4545. return new this.constructor().copy( this );
  4546. },
  4547. copy: function ( triangle ) {
  4548. this.a.copy( triangle.a );
  4549. this.b.copy( triangle.b );
  4550. this.c.copy( triangle.c );
  4551. return this;
  4552. },
  4553. getArea: function () {
  4554. if ( _v1$2 === undefined ) {
  4555. _v0$1 = new Vector3();
  4556. _v1$2 = new Vector3();
  4557. }
  4558. _v0$1.subVectors( this.c, this.b );
  4559. _v1$2.subVectors( this.a, this.b );
  4560. return _v0$1.cross( _v1$2 ).length() * 0.5;
  4561. },
  4562. getMidpoint: function ( target ) {
  4563. if ( target === undefined ) {
  4564. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4565. target = new Vector3();
  4566. }
  4567. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4568. },
  4569. getNormal: function ( target ) {
  4570. return Triangle.getNormal( this.a, this.b, this.c, target );
  4571. },
  4572. getPlane: function ( target ) {
  4573. if ( target === undefined ) {
  4574. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4575. target = new Vector3();
  4576. }
  4577. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4578. },
  4579. getBarycoord: function ( point, target ) {
  4580. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4581. },
  4582. getUV: function ( point, uv1, uv2, uv3, target ) {
  4583. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4584. },
  4585. containsPoint: function ( point ) {
  4586. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4587. },
  4588. isFrontFacing: function ( direction ) {
  4589. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4590. },
  4591. intersectsBox: function ( box ) {
  4592. return box.intersectsTriangle( this );
  4593. },
  4594. closestPointToPoint: function ( p, target ) {
  4595. if ( _vab === undefined ) {
  4596. _vab = new Vector3();
  4597. _vac = new Vector3();
  4598. _vbc = new Vector3();
  4599. _vap = new Vector3();
  4600. _vbp = new Vector3();
  4601. _vcp = new Vector3();
  4602. }
  4603. if ( target === undefined ) {
  4604. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4605. target = new Vector3();
  4606. }
  4607. var a = this.a, b = this.b, c = this.c;
  4608. var v, w;
  4609. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4610. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4611. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4612. // basically, we're distinguishing which of the voronoi regions of the triangle
  4613. // the point lies in with the minimum amount of redundant computation.
  4614. _vab.subVectors( b, a );
  4615. _vac.subVectors( c, a );
  4616. _vap.subVectors( p, a );
  4617. var d1 = _vab.dot( _vap );
  4618. var d2 = _vac.dot( _vap );
  4619. if ( d1 <= 0 && d2 <= 0 ) {
  4620. // vertex region of A; barycentric coords (1, 0, 0)
  4621. return target.copy( a );
  4622. }
  4623. _vbp.subVectors( p, b );
  4624. var d3 = _vab.dot( _vbp );
  4625. var d4 = _vac.dot( _vbp );
  4626. if ( d3 >= 0 && d4 <= d3 ) {
  4627. // vertex region of B; barycentric coords (0, 1, 0)
  4628. return target.copy( b );
  4629. }
  4630. var vc = d1 * d4 - d3 * d2;
  4631. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4632. v = d1 / ( d1 - d3 );
  4633. // edge region of AB; barycentric coords (1-v, v, 0)
  4634. return target.copy( a ).addScaledVector( _vab, v );
  4635. }
  4636. _vcp.subVectors( p, c );
  4637. var d5 = _vab.dot( _vcp );
  4638. var d6 = _vac.dot( _vcp );
  4639. if ( d6 >= 0 && d5 <= d6 ) {
  4640. // vertex region of C; barycentric coords (0, 0, 1)
  4641. return target.copy( c );
  4642. }
  4643. var vb = d5 * d2 - d1 * d6;
  4644. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4645. w = d2 / ( d2 - d6 );
  4646. // edge region of AC; barycentric coords (1-w, 0, w)
  4647. return target.copy( a ).addScaledVector( _vac, w );
  4648. }
  4649. var va = d3 * d6 - d5 * d4;
  4650. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4651. _vbc.subVectors( c, b );
  4652. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4653. // edge region of BC; barycentric coords (0, 1-w, w)
  4654. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4655. }
  4656. // face region
  4657. var denom = 1 / ( va + vb + vc );
  4658. // u = va * denom
  4659. v = vb * denom;
  4660. w = vc * denom;
  4661. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4662. },
  4663. equals: function ( triangle ) {
  4664. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4665. }
  4666. } );
  4667. /**
  4668. * @author mrdoob / http://mrdoob.com/
  4669. */
  4670. var _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4671. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4672. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4673. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4674. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4675. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4676. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4677. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4678. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4679. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4680. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4681. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4682. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4683. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4684. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4685. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4686. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4687. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4688. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4689. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4690. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4691. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4692. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4693. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4694. var _hslA = { h: 0, s: 0, l: 0 };
  4695. var _hslB = { h: 0, s: 0, l: 0 };
  4696. function Color( r, g, b ) {
  4697. if ( g === undefined && b === undefined ) {
  4698. // r is THREE.Color, hex or string
  4699. return this.set( r );
  4700. }
  4701. return this.setRGB( r, g, b );
  4702. }
  4703. function hue2rgb( p, q, t ) {
  4704. if ( t < 0 ) t += 1;
  4705. if ( t > 1 ) t -= 1;
  4706. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4707. if ( t < 1 / 2 ) return q;
  4708. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4709. return p;
  4710. }
  4711. function SRGBToLinear( c ) {
  4712. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4713. }
  4714. function LinearToSRGB( c ) {
  4715. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4716. }
  4717. Object.assign( Color.prototype, {
  4718. isColor: true,
  4719. r: 1, g: 1, b: 1,
  4720. set: function ( value ) {
  4721. if ( value && value.isColor ) {
  4722. this.copy( value );
  4723. } else if ( typeof value === 'number' ) {
  4724. this.setHex( value );
  4725. } else if ( typeof value === 'string' ) {
  4726. this.setStyle( value );
  4727. }
  4728. return this;
  4729. },
  4730. setScalar: function ( scalar ) {
  4731. this.r = scalar;
  4732. this.g = scalar;
  4733. this.b = scalar;
  4734. return this;
  4735. },
  4736. setHex: function ( hex ) {
  4737. hex = Math.floor( hex );
  4738. this.r = ( hex >> 16 & 255 ) / 255;
  4739. this.g = ( hex >> 8 & 255 ) / 255;
  4740. this.b = ( hex & 255 ) / 255;
  4741. return this;
  4742. },
  4743. setRGB: function ( r, g, b ) {
  4744. this.r = r;
  4745. this.g = g;
  4746. this.b = b;
  4747. return this;
  4748. },
  4749. setHSL: function ( h, s, l ) {
  4750. // h,s,l ranges are in 0.0 - 1.0
  4751. h = _Math.euclideanModulo( h, 1 );
  4752. s = _Math.clamp( s, 0, 1 );
  4753. l = _Math.clamp( l, 0, 1 );
  4754. if ( s === 0 ) {
  4755. this.r = this.g = this.b = l;
  4756. } else {
  4757. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4758. var q = ( 2 * l ) - p;
  4759. this.r = hue2rgb( q, p, h + 1 / 3 );
  4760. this.g = hue2rgb( q, p, h );
  4761. this.b = hue2rgb( q, p, h - 1 / 3 );
  4762. }
  4763. return this;
  4764. },
  4765. setStyle: function ( style ) {
  4766. function handleAlpha( string ) {
  4767. if ( string === undefined ) return;
  4768. if ( parseFloat( string ) < 1 ) {
  4769. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4770. }
  4771. }
  4772. var m;
  4773. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4774. // rgb / hsl
  4775. var color;
  4776. var name = m[ 1 ];
  4777. var components = m[ 2 ];
  4778. switch ( name ) {
  4779. case 'rgb':
  4780. case 'rgba':
  4781. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4782. // rgb(255,0,0) rgba(255,0,0,0.5)
  4783. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4784. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4785. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4786. handleAlpha( color[ 5 ] );
  4787. return this;
  4788. }
  4789. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4790. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4791. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4792. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4793. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4794. handleAlpha( color[ 5 ] );
  4795. return this;
  4796. }
  4797. break;
  4798. case 'hsl':
  4799. case 'hsla':
  4800. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4801. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4802. var h = parseFloat( color[ 1 ] ) / 360;
  4803. var s = parseInt( color[ 2 ], 10 ) / 100;
  4804. var l = parseInt( color[ 3 ], 10 ) / 100;
  4805. handleAlpha( color[ 5 ] );
  4806. return this.setHSL( h, s, l );
  4807. }
  4808. break;
  4809. }
  4810. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4811. // hex color
  4812. var hex = m[ 1 ];
  4813. var size = hex.length;
  4814. if ( size === 3 ) {
  4815. // #ff0
  4816. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4817. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4818. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4819. return this;
  4820. } else if ( size === 6 ) {
  4821. // #ff0000
  4822. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4823. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4824. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4825. return this;
  4826. }
  4827. }
  4828. if ( style && style.length > 0 ) {
  4829. // color keywords
  4830. var hex = _colorKeywords[ style ];
  4831. if ( hex !== undefined ) {
  4832. // red
  4833. this.setHex( hex );
  4834. } else {
  4835. // unknown color
  4836. console.warn( 'THREE.Color: Unknown color ' + style );
  4837. }
  4838. }
  4839. return this;
  4840. },
  4841. clone: function () {
  4842. return new this.constructor( this.r, this.g, this.b );
  4843. },
  4844. copy: function ( color ) {
  4845. this.r = color.r;
  4846. this.g = color.g;
  4847. this.b = color.b;
  4848. return this;
  4849. },
  4850. copyGammaToLinear: function ( color, gammaFactor ) {
  4851. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4852. this.r = Math.pow( color.r, gammaFactor );
  4853. this.g = Math.pow( color.g, gammaFactor );
  4854. this.b = Math.pow( color.b, gammaFactor );
  4855. return this;
  4856. },
  4857. copyLinearToGamma: function ( color, gammaFactor ) {
  4858. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4859. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4860. this.r = Math.pow( color.r, safeInverse );
  4861. this.g = Math.pow( color.g, safeInverse );
  4862. this.b = Math.pow( color.b, safeInverse );
  4863. return this;
  4864. },
  4865. convertGammaToLinear: function ( gammaFactor ) {
  4866. this.copyGammaToLinear( this, gammaFactor );
  4867. return this;
  4868. },
  4869. convertLinearToGamma: function ( gammaFactor ) {
  4870. this.copyLinearToGamma( this, gammaFactor );
  4871. return this;
  4872. },
  4873. copySRGBToLinear: function ( color ) {
  4874. this.r = SRGBToLinear( color.r );
  4875. this.g = SRGBToLinear( color.g );
  4876. this.b = SRGBToLinear( color.b );
  4877. return this;
  4878. },
  4879. copyLinearToSRGB: function ( color ) {
  4880. this.r = LinearToSRGB( color.r );
  4881. this.g = LinearToSRGB( color.g );
  4882. this.b = LinearToSRGB( color.b );
  4883. return this;
  4884. },
  4885. convertSRGBToLinear: function () {
  4886. this.copySRGBToLinear( this );
  4887. return this;
  4888. },
  4889. convertLinearToSRGB: function () {
  4890. this.copyLinearToSRGB( this );
  4891. return this;
  4892. },
  4893. getHex: function () {
  4894. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4895. },
  4896. getHexString: function () {
  4897. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4898. },
  4899. getHSL: function ( target ) {
  4900. // h,s,l ranges are in 0.0 - 1.0
  4901. if ( target === undefined ) {
  4902. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4903. target = { h: 0, s: 0, l: 0 };
  4904. }
  4905. var r = this.r, g = this.g, b = this.b;
  4906. var max = Math.max( r, g, b );
  4907. var min = Math.min( r, g, b );
  4908. var hue, saturation;
  4909. var lightness = ( min + max ) / 2.0;
  4910. if ( min === max ) {
  4911. hue = 0;
  4912. saturation = 0;
  4913. } else {
  4914. var delta = max - min;
  4915. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4916. switch ( max ) {
  4917. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4918. case g: hue = ( b - r ) / delta + 2; break;
  4919. case b: hue = ( r - g ) / delta + 4; break;
  4920. }
  4921. hue /= 6;
  4922. }
  4923. target.h = hue;
  4924. target.s = saturation;
  4925. target.l = lightness;
  4926. return target;
  4927. },
  4928. getStyle: function () {
  4929. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4930. },
  4931. offsetHSL: function ( h, s, l ) {
  4932. this.getHSL( _hslA );
  4933. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  4934. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  4935. return this;
  4936. },
  4937. add: function ( color ) {
  4938. this.r += color.r;
  4939. this.g += color.g;
  4940. this.b += color.b;
  4941. return this;
  4942. },
  4943. addColors: function ( color1, color2 ) {
  4944. this.r = color1.r + color2.r;
  4945. this.g = color1.g + color2.g;
  4946. this.b = color1.b + color2.b;
  4947. return this;
  4948. },
  4949. addScalar: function ( s ) {
  4950. this.r += s;
  4951. this.g += s;
  4952. this.b += s;
  4953. return this;
  4954. },
  4955. sub: function ( color ) {
  4956. this.r = Math.max( 0, this.r - color.r );
  4957. this.g = Math.max( 0, this.g - color.g );
  4958. this.b = Math.max( 0, this.b - color.b );
  4959. return this;
  4960. },
  4961. multiply: function ( color ) {
  4962. this.r *= color.r;
  4963. this.g *= color.g;
  4964. this.b *= color.b;
  4965. return this;
  4966. },
  4967. multiplyScalar: function ( s ) {
  4968. this.r *= s;
  4969. this.g *= s;
  4970. this.b *= s;
  4971. return this;
  4972. },
  4973. lerp: function ( color, alpha ) {
  4974. this.r += ( color.r - this.r ) * alpha;
  4975. this.g += ( color.g - this.g ) * alpha;
  4976. this.b += ( color.b - this.b ) * alpha;
  4977. return this;
  4978. },
  4979. lerpHSL: function ( color, alpha ) {
  4980. this.getHSL( _hslA );
  4981. color.getHSL( _hslB );
  4982. var h = _Math.lerp( _hslA.h, _hslB.h, alpha );
  4983. var s = _Math.lerp( _hslA.s, _hslB.s, alpha );
  4984. var l = _Math.lerp( _hslA.l, _hslB.l, alpha );
  4985. this.setHSL( h, s, l );
  4986. return this;
  4987. },
  4988. equals: function ( c ) {
  4989. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4990. },
  4991. fromArray: function ( array, offset ) {
  4992. if ( offset === undefined ) offset = 0;
  4993. this.r = array[ offset ];
  4994. this.g = array[ offset + 1 ];
  4995. this.b = array[ offset + 2 ];
  4996. return this;
  4997. },
  4998. toArray: function ( array, offset ) {
  4999. if ( array === undefined ) array = [];
  5000. if ( offset === undefined ) offset = 0;
  5001. array[ offset ] = this.r;
  5002. array[ offset + 1 ] = this.g;
  5003. array[ offset + 2 ] = this.b;
  5004. return array;
  5005. },
  5006. toJSON: function () {
  5007. return this.getHex();
  5008. }
  5009. } );
  5010. /**
  5011. * @author mrdoob / http://mrdoob.com/
  5012. * @author alteredq / http://alteredqualia.com/
  5013. */
  5014. function Face3( a, b, c, normal, color, materialIndex ) {
  5015. this.a = a;
  5016. this.b = b;
  5017. this.c = c;
  5018. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5019. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5020. this.color = ( color && color.isColor ) ? color : new Color();
  5021. this.vertexColors = Array.isArray( color ) ? color : [];
  5022. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5023. }
  5024. Object.assign( Face3.prototype, {
  5025. clone: function () {
  5026. return new this.constructor().copy( this );
  5027. },
  5028. copy: function ( source ) {
  5029. this.a = source.a;
  5030. this.b = source.b;
  5031. this.c = source.c;
  5032. this.normal.copy( source.normal );
  5033. this.color.copy( source.color );
  5034. this.materialIndex = source.materialIndex;
  5035. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5036. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5037. }
  5038. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5039. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5040. }
  5041. return this;
  5042. }
  5043. } );
  5044. /**
  5045. * @author mrdoob / http://mrdoob.com/
  5046. * @author alteredq / http://alteredqualia.com/
  5047. */
  5048. var materialId = 0;
  5049. function Material() {
  5050. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5051. this.uuid = _Math.generateUUID();
  5052. this.name = '';
  5053. this.type = 'Material';
  5054. this.fog = true;
  5055. this.lights = true;
  5056. this.blending = NormalBlending;
  5057. this.side = FrontSide;
  5058. this.flatShading = false;
  5059. this.vertexTangents = false;
  5060. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  5061. this.opacity = 1;
  5062. this.transparent = false;
  5063. this.blendSrc = SrcAlphaFactor;
  5064. this.blendDst = OneMinusSrcAlphaFactor;
  5065. this.blendEquation = AddEquation;
  5066. this.blendSrcAlpha = null;
  5067. this.blendDstAlpha = null;
  5068. this.blendEquationAlpha = null;
  5069. this.depthFunc = LessEqualDepth;
  5070. this.depthTest = true;
  5071. this.depthWrite = true;
  5072. this.stencilFunc = AlwaysStencilFunc;
  5073. this.stencilRef = 0;
  5074. this.stencilMask = 0xff;
  5075. this.stencilFail = KeepStencilOp;
  5076. this.stencilZFail = KeepStencilOp;
  5077. this.stencilZPass = KeepStencilOp;
  5078. this.stencilWrite = false;
  5079. this.clippingPlanes = null;
  5080. this.clipIntersection = false;
  5081. this.clipShadows = false;
  5082. this.shadowSide = null;
  5083. this.colorWrite = true;
  5084. this.precision = null; // override the renderer's default precision for this material
  5085. this.polygonOffset = false;
  5086. this.polygonOffsetFactor = 0;
  5087. this.polygonOffsetUnits = 0;
  5088. this.dithering = false;
  5089. this.alphaTest = 0;
  5090. this.premultipliedAlpha = false;
  5091. this.visible = true;
  5092. this.userData = {};
  5093. this.needsUpdate = true;
  5094. }
  5095. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5096. constructor: Material,
  5097. isMaterial: true,
  5098. onBeforeCompile: function () {},
  5099. setValues: function ( values ) {
  5100. if ( values === undefined ) return;
  5101. for ( var key in values ) {
  5102. var newValue = values[ key ];
  5103. if ( newValue === undefined ) {
  5104. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5105. continue;
  5106. }
  5107. // for backward compatability if shading is set in the constructor
  5108. if ( key === 'shading' ) {
  5109. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5110. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5111. continue;
  5112. }
  5113. var currentValue = this[ key ];
  5114. if ( currentValue === undefined ) {
  5115. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5116. continue;
  5117. }
  5118. if ( currentValue && currentValue.isColor ) {
  5119. currentValue.set( newValue );
  5120. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5121. currentValue.copy( newValue );
  5122. } else {
  5123. this[ key ] = newValue;
  5124. }
  5125. }
  5126. },
  5127. toJSON: function ( meta ) {
  5128. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5129. if ( isRoot ) {
  5130. meta = {
  5131. textures: {},
  5132. images: {}
  5133. };
  5134. }
  5135. var data = {
  5136. metadata: {
  5137. version: 4.5,
  5138. type: 'Material',
  5139. generator: 'Material.toJSON'
  5140. }
  5141. };
  5142. // standard Material serialization
  5143. data.uuid = this.uuid;
  5144. data.type = this.type;
  5145. if ( this.name !== '' ) data.name = this.name;
  5146. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5147. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5148. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5149. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5150. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5151. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5152. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5153. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  5154. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  5155. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5156. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5157. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5158. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5159. if ( this.aoMap && this.aoMap.isTexture ) {
  5160. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5161. data.aoMapIntensity = this.aoMapIntensity;
  5162. }
  5163. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5164. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5165. data.bumpScale = this.bumpScale;
  5166. }
  5167. if ( this.normalMap && this.normalMap.isTexture ) {
  5168. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5169. data.normalMapType = this.normalMapType;
  5170. data.normalScale = this.normalScale.toArray();
  5171. }
  5172. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5173. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5174. data.displacementScale = this.displacementScale;
  5175. data.displacementBias = this.displacementBias;
  5176. }
  5177. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5178. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5179. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5180. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5181. if ( this.envMap && this.envMap.isTexture ) {
  5182. data.envMap = this.envMap.toJSON( meta ).uuid;
  5183. data.reflectivity = this.reflectivity; // Scale behind envMap
  5184. data.refractionRatio = this.refractionRatio;
  5185. if ( this.combine !== undefined ) data.combine = this.combine;
  5186. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5187. }
  5188. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5189. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5190. }
  5191. if ( this.size !== undefined ) data.size = this.size;
  5192. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5193. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5194. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5195. if ( this.side !== FrontSide ) data.side = this.side;
  5196. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  5197. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5198. if ( this.transparent === true ) data.transparent = this.transparent;
  5199. data.depthFunc = this.depthFunc;
  5200. data.depthTest = this.depthTest;
  5201. data.depthWrite = this.depthWrite;
  5202. data.stencilWrite = this.stencilWrite;
  5203. data.stencilFunc = this.stencilFunc;
  5204. data.stencilRef = this.stencilRef;
  5205. data.stencilMask = this.stencilMask;
  5206. data.stencilFail = this.stencilFail;
  5207. data.stencilZFail = this.stencilZFail;
  5208. data.stencilZPass = this.stencilZPass;
  5209. // rotation (SpriteMaterial)
  5210. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5211. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5212. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5213. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5214. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5215. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5216. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5217. if ( this.scale !== undefined ) data.scale = this.scale;
  5218. if ( this.dithering === true ) data.dithering = true;
  5219. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5220. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5221. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5222. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5223. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5224. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5225. if ( this.morphTargets === true ) data.morphTargets = true;
  5226. if ( this.morphNormals === true ) data.morphNormals = true;
  5227. if ( this.skinning === true ) data.skinning = true;
  5228. if ( this.visible === false ) data.visible = false;
  5229. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5230. // TODO: Copied from Object3D.toJSON
  5231. function extractFromCache( cache ) {
  5232. var values = [];
  5233. for ( var key in cache ) {
  5234. var data = cache[ key ];
  5235. delete data.metadata;
  5236. values.push( data );
  5237. }
  5238. return values;
  5239. }
  5240. if ( isRoot ) {
  5241. var textures = extractFromCache( meta.textures );
  5242. var images = extractFromCache( meta.images );
  5243. if ( textures.length > 0 ) data.textures = textures;
  5244. if ( images.length > 0 ) data.images = images;
  5245. }
  5246. return data;
  5247. },
  5248. clone: function () {
  5249. return new this.constructor().copy( this );
  5250. },
  5251. copy: function ( source ) {
  5252. this.name = source.name;
  5253. this.fog = source.fog;
  5254. this.lights = source.lights;
  5255. this.blending = source.blending;
  5256. this.side = source.side;
  5257. this.flatShading = source.flatShading;
  5258. this.vertexColors = source.vertexColors;
  5259. this.opacity = source.opacity;
  5260. this.transparent = source.transparent;
  5261. this.blendSrc = source.blendSrc;
  5262. this.blendDst = source.blendDst;
  5263. this.blendEquation = source.blendEquation;
  5264. this.blendSrcAlpha = source.blendSrcAlpha;
  5265. this.blendDstAlpha = source.blendDstAlpha;
  5266. this.blendEquationAlpha = source.blendEquationAlpha;
  5267. this.depthFunc = source.depthFunc;
  5268. this.depthTest = source.depthTest;
  5269. this.depthWrite = source.depthWrite;
  5270. this.stencilWrite = source.stencilWrite;
  5271. this.stencilFunc = source.stencilFunc;
  5272. this.stencilRef = source.stencilRef;
  5273. this.stencilMask = source.stencilMask;
  5274. this.stencilFail = source.stencilFail;
  5275. this.stencilZFail = source.stencilZFail;
  5276. this.stencilZPass = source.stencilZPass;
  5277. this.colorWrite = source.colorWrite;
  5278. this.precision = source.precision;
  5279. this.polygonOffset = source.polygonOffset;
  5280. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5281. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5282. this.dithering = source.dithering;
  5283. this.alphaTest = source.alphaTest;
  5284. this.premultipliedAlpha = source.premultipliedAlpha;
  5285. this.visible = source.visible;
  5286. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5287. this.clipShadows = source.clipShadows;
  5288. this.clipIntersection = source.clipIntersection;
  5289. var srcPlanes = source.clippingPlanes,
  5290. dstPlanes = null;
  5291. if ( srcPlanes !== null ) {
  5292. var n = srcPlanes.length;
  5293. dstPlanes = new Array( n );
  5294. for ( var i = 0; i !== n; ++ i )
  5295. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5296. }
  5297. this.clippingPlanes = dstPlanes;
  5298. this.shadowSide = source.shadowSide;
  5299. return this;
  5300. },
  5301. dispose: function () {
  5302. this.dispatchEvent( { type: 'dispose' } );
  5303. }
  5304. } );
  5305. /**
  5306. * @author mrdoob / http://mrdoob.com/
  5307. * @author alteredq / http://alteredqualia.com/
  5308. *
  5309. * parameters = {
  5310. * color: <hex>,
  5311. * opacity: <float>,
  5312. * map: new THREE.Texture( <Image> ),
  5313. *
  5314. * lightMap: new THREE.Texture( <Image> ),
  5315. * lightMapIntensity: <float>
  5316. *
  5317. * aoMap: new THREE.Texture( <Image> ),
  5318. * aoMapIntensity: <float>
  5319. *
  5320. * specularMap: new THREE.Texture( <Image> ),
  5321. *
  5322. * alphaMap: new THREE.Texture( <Image> ),
  5323. *
  5324. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5325. * combine: THREE.Multiply,
  5326. * reflectivity: <float>,
  5327. * refractionRatio: <float>,
  5328. *
  5329. * depthTest: <bool>,
  5330. * depthWrite: <bool>,
  5331. *
  5332. * wireframe: <boolean>,
  5333. * wireframeLinewidth: <float>,
  5334. *
  5335. * skinning: <bool>,
  5336. * morphTargets: <bool>
  5337. * }
  5338. */
  5339. function MeshBasicMaterial( parameters ) {
  5340. Material.call( this );
  5341. this.type = 'MeshBasicMaterial';
  5342. this.color = new Color( 0xffffff ); // emissive
  5343. this.map = null;
  5344. this.lightMap = null;
  5345. this.lightMapIntensity = 1.0;
  5346. this.aoMap = null;
  5347. this.aoMapIntensity = 1.0;
  5348. this.specularMap = null;
  5349. this.alphaMap = null;
  5350. this.envMap = null;
  5351. this.combine = MultiplyOperation;
  5352. this.reflectivity = 1;
  5353. this.refractionRatio = 0.98;
  5354. this.wireframe = false;
  5355. this.wireframeLinewidth = 1;
  5356. this.wireframeLinecap = 'round';
  5357. this.wireframeLinejoin = 'round';
  5358. this.skinning = false;
  5359. this.morphTargets = false;
  5360. this.lights = false;
  5361. this.setValues( parameters );
  5362. }
  5363. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5364. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5365. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5366. MeshBasicMaterial.prototype.copy = function ( source ) {
  5367. Material.prototype.copy.call( this, source );
  5368. this.color.copy( source.color );
  5369. this.map = source.map;
  5370. this.lightMap = source.lightMap;
  5371. this.lightMapIntensity = source.lightMapIntensity;
  5372. this.aoMap = source.aoMap;
  5373. this.aoMapIntensity = source.aoMapIntensity;
  5374. this.specularMap = source.specularMap;
  5375. this.alphaMap = source.alphaMap;
  5376. this.envMap = source.envMap;
  5377. this.combine = source.combine;
  5378. this.reflectivity = source.reflectivity;
  5379. this.refractionRatio = source.refractionRatio;
  5380. this.wireframe = source.wireframe;
  5381. this.wireframeLinewidth = source.wireframeLinewidth;
  5382. this.wireframeLinecap = source.wireframeLinecap;
  5383. this.wireframeLinejoin = source.wireframeLinejoin;
  5384. this.skinning = source.skinning;
  5385. this.morphTargets = source.morphTargets;
  5386. return this;
  5387. };
  5388. /**
  5389. * @author mrdoob / http://mrdoob.com/
  5390. */
  5391. function BufferAttribute( array, itemSize, normalized ) {
  5392. if ( Array.isArray( array ) ) {
  5393. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5394. }
  5395. this.name = '';
  5396. this.array = array;
  5397. this.itemSize = itemSize;
  5398. this.count = array !== undefined ? array.length / itemSize : 0;
  5399. this.normalized = normalized === true;
  5400. this.dynamic = false;
  5401. this.updateRange = { offset: 0, count: - 1 };
  5402. this.version = 0;
  5403. }
  5404. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5405. set: function ( value ) {
  5406. if ( value === true ) this.version ++;
  5407. }
  5408. } );
  5409. Object.assign( BufferAttribute.prototype, {
  5410. isBufferAttribute: true,
  5411. onUploadCallback: function () {},
  5412. setArray: function ( array ) {
  5413. if ( Array.isArray( array ) ) {
  5414. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5415. }
  5416. this.count = array !== undefined ? array.length / this.itemSize : 0;
  5417. this.array = array;
  5418. return this;
  5419. },
  5420. setDynamic: function ( value ) {
  5421. this.dynamic = value;
  5422. return this;
  5423. },
  5424. copy: function ( source ) {
  5425. this.name = source.name;
  5426. this.array = new source.array.constructor( source.array );
  5427. this.itemSize = source.itemSize;
  5428. this.count = source.count;
  5429. this.normalized = source.normalized;
  5430. this.dynamic = source.dynamic;
  5431. return this;
  5432. },
  5433. copyAt: function ( index1, attribute, index2 ) {
  5434. index1 *= this.itemSize;
  5435. index2 *= attribute.itemSize;
  5436. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5437. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5438. }
  5439. return this;
  5440. },
  5441. copyArray: function ( array ) {
  5442. this.array.set( array );
  5443. return this;
  5444. },
  5445. copyColorsArray: function ( colors ) {
  5446. var array = this.array, offset = 0;
  5447. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5448. var color = colors[ i ];
  5449. if ( color === undefined ) {
  5450. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5451. color = new Color();
  5452. }
  5453. array[ offset ++ ] = color.r;
  5454. array[ offset ++ ] = color.g;
  5455. array[ offset ++ ] = color.b;
  5456. }
  5457. return this;
  5458. },
  5459. copyVector2sArray: function ( vectors ) {
  5460. var array = this.array, offset = 0;
  5461. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5462. var vector = vectors[ i ];
  5463. if ( vector === undefined ) {
  5464. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5465. vector = new Vector2();
  5466. }
  5467. array[ offset ++ ] = vector.x;
  5468. array[ offset ++ ] = vector.y;
  5469. }
  5470. return this;
  5471. },
  5472. copyVector3sArray: function ( vectors ) {
  5473. var array = this.array, offset = 0;
  5474. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5475. var vector = vectors[ i ];
  5476. if ( vector === undefined ) {
  5477. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5478. vector = new Vector3();
  5479. }
  5480. array[ offset ++ ] = vector.x;
  5481. array[ offset ++ ] = vector.y;
  5482. array[ offset ++ ] = vector.z;
  5483. }
  5484. return this;
  5485. },
  5486. copyVector4sArray: function ( vectors ) {
  5487. var array = this.array, offset = 0;
  5488. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5489. var vector = vectors[ i ];
  5490. if ( vector === undefined ) {
  5491. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5492. vector = new Vector4();
  5493. }
  5494. array[ offset ++ ] = vector.x;
  5495. array[ offset ++ ] = vector.y;
  5496. array[ offset ++ ] = vector.z;
  5497. array[ offset ++ ] = vector.w;
  5498. }
  5499. return this;
  5500. },
  5501. set: function ( value, offset ) {
  5502. if ( offset === undefined ) offset = 0;
  5503. this.array.set( value, offset );
  5504. return this;
  5505. },
  5506. getX: function ( index ) {
  5507. return this.array[ index * this.itemSize ];
  5508. },
  5509. setX: function ( index, x ) {
  5510. this.array[ index * this.itemSize ] = x;
  5511. return this;
  5512. },
  5513. getY: function ( index ) {
  5514. return this.array[ index * this.itemSize + 1 ];
  5515. },
  5516. setY: function ( index, y ) {
  5517. this.array[ index * this.itemSize + 1 ] = y;
  5518. return this;
  5519. },
  5520. getZ: function ( index ) {
  5521. return this.array[ index * this.itemSize + 2 ];
  5522. },
  5523. setZ: function ( index, z ) {
  5524. this.array[ index * this.itemSize + 2 ] = z;
  5525. return this;
  5526. },
  5527. getW: function ( index ) {
  5528. return this.array[ index * this.itemSize + 3 ];
  5529. },
  5530. setW: function ( index, w ) {
  5531. this.array[ index * this.itemSize + 3 ] = w;
  5532. return this;
  5533. },
  5534. setXY: function ( index, x, y ) {
  5535. index *= this.itemSize;
  5536. this.array[ index + 0 ] = x;
  5537. this.array[ index + 1 ] = y;
  5538. return this;
  5539. },
  5540. setXYZ: function ( index, x, y, z ) {
  5541. index *= this.itemSize;
  5542. this.array[ index + 0 ] = x;
  5543. this.array[ index + 1 ] = y;
  5544. this.array[ index + 2 ] = z;
  5545. return this;
  5546. },
  5547. setXYZW: function ( index, x, y, z, w ) {
  5548. index *= this.itemSize;
  5549. this.array[ index + 0 ] = x;
  5550. this.array[ index + 1 ] = y;
  5551. this.array[ index + 2 ] = z;
  5552. this.array[ index + 3 ] = w;
  5553. return this;
  5554. },
  5555. onUpload: function ( callback ) {
  5556. this.onUploadCallback = callback;
  5557. return this;
  5558. },
  5559. clone: function () {
  5560. return new this.constructor( this.array, this.itemSize ).copy( this );
  5561. },
  5562. toJSON: function () {
  5563. return {
  5564. itemSize: this.itemSize,
  5565. type: this.array.constructor.name,
  5566. array: Array.prototype.slice.call( this.array ),
  5567. normalized: this.normalized
  5568. };
  5569. }
  5570. } );
  5571. //
  5572. function Int8BufferAttribute( array, itemSize, normalized ) {
  5573. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5574. }
  5575. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5576. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5577. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5578. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5579. }
  5580. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5581. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5582. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5583. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5584. }
  5585. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5586. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5587. function Int16BufferAttribute( array, itemSize, normalized ) {
  5588. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5589. }
  5590. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5591. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5592. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5593. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5594. }
  5595. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5596. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5597. function Int32BufferAttribute( array, itemSize, normalized ) {
  5598. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5599. }
  5600. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5601. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5602. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5603. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5604. }
  5605. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5606. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5607. function Float32BufferAttribute( array, itemSize, normalized ) {
  5608. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5609. }
  5610. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5611. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5612. function Float64BufferAttribute( array, itemSize, normalized ) {
  5613. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5614. }
  5615. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5616. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5617. /**
  5618. * @author mrdoob / http://mrdoob.com/
  5619. */
  5620. function DirectGeometry() {
  5621. this.vertices = [];
  5622. this.normals = [];
  5623. this.colors = [];
  5624. this.uvs = [];
  5625. this.uvs2 = [];
  5626. this.groups = [];
  5627. this.morphTargets = {};
  5628. this.skinWeights = [];
  5629. this.skinIndices = [];
  5630. // this.lineDistances = [];
  5631. this.boundingBox = null;
  5632. this.boundingSphere = null;
  5633. // update flags
  5634. this.verticesNeedUpdate = false;
  5635. this.normalsNeedUpdate = false;
  5636. this.colorsNeedUpdate = false;
  5637. this.uvsNeedUpdate = false;
  5638. this.groupsNeedUpdate = false;
  5639. }
  5640. Object.assign( DirectGeometry.prototype, {
  5641. computeGroups: function ( geometry ) {
  5642. var group;
  5643. var groups = [];
  5644. var materialIndex = undefined;
  5645. var faces = geometry.faces;
  5646. for ( var i = 0; i < faces.length; i ++ ) {
  5647. var face = faces[ i ];
  5648. // materials
  5649. if ( face.materialIndex !== materialIndex ) {
  5650. materialIndex = face.materialIndex;
  5651. if ( group !== undefined ) {
  5652. group.count = ( i * 3 ) - group.start;
  5653. groups.push( group );
  5654. }
  5655. group = {
  5656. start: i * 3,
  5657. materialIndex: materialIndex
  5658. };
  5659. }
  5660. }
  5661. if ( group !== undefined ) {
  5662. group.count = ( i * 3 ) - group.start;
  5663. groups.push( group );
  5664. }
  5665. this.groups = groups;
  5666. },
  5667. fromGeometry: function ( geometry ) {
  5668. var faces = geometry.faces;
  5669. var vertices = geometry.vertices;
  5670. var faceVertexUvs = geometry.faceVertexUvs;
  5671. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5672. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5673. // morphs
  5674. var morphTargets = geometry.morphTargets;
  5675. var morphTargetsLength = morphTargets.length;
  5676. var morphTargetsPosition;
  5677. if ( morphTargetsLength > 0 ) {
  5678. morphTargetsPosition = [];
  5679. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5680. morphTargetsPosition[ i ] = {
  5681. name: morphTargets[ i ].name,
  5682. data: []
  5683. };
  5684. }
  5685. this.morphTargets.position = morphTargetsPosition;
  5686. }
  5687. var morphNormals = geometry.morphNormals;
  5688. var morphNormalsLength = morphNormals.length;
  5689. var morphTargetsNormal;
  5690. if ( morphNormalsLength > 0 ) {
  5691. morphTargetsNormal = [];
  5692. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5693. morphTargetsNormal[ i ] = {
  5694. name: morphNormals[ i ].name,
  5695. data: []
  5696. };
  5697. }
  5698. this.morphTargets.normal = morphTargetsNormal;
  5699. }
  5700. // skins
  5701. var skinIndices = geometry.skinIndices;
  5702. var skinWeights = geometry.skinWeights;
  5703. var hasSkinIndices = skinIndices.length === vertices.length;
  5704. var hasSkinWeights = skinWeights.length === vertices.length;
  5705. //
  5706. if ( vertices.length > 0 && faces.length === 0 ) {
  5707. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5708. }
  5709. for ( var i = 0; i < faces.length; i ++ ) {
  5710. var face = faces[ i ];
  5711. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5712. var vertexNormals = face.vertexNormals;
  5713. if ( vertexNormals.length === 3 ) {
  5714. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5715. } else {
  5716. var normal = face.normal;
  5717. this.normals.push( normal, normal, normal );
  5718. }
  5719. var vertexColors = face.vertexColors;
  5720. if ( vertexColors.length === 3 ) {
  5721. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5722. } else {
  5723. var color = face.color;
  5724. this.colors.push( color, color, color );
  5725. }
  5726. if ( hasFaceVertexUv === true ) {
  5727. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5728. if ( vertexUvs !== undefined ) {
  5729. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5730. } else {
  5731. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5732. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5733. }
  5734. }
  5735. if ( hasFaceVertexUv2 === true ) {
  5736. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5737. if ( vertexUvs !== undefined ) {
  5738. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5739. } else {
  5740. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5741. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5742. }
  5743. }
  5744. // morphs
  5745. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5746. var morphTarget = morphTargets[ j ].vertices;
  5747. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5748. }
  5749. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5750. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5751. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5752. }
  5753. // skins
  5754. if ( hasSkinIndices ) {
  5755. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5756. }
  5757. if ( hasSkinWeights ) {
  5758. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5759. }
  5760. }
  5761. this.computeGroups( geometry );
  5762. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5763. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5764. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5765. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5766. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5767. if ( geometry.boundingSphere !== null ) {
  5768. this.boundingSphere = geometry.boundingSphere.clone();
  5769. }
  5770. if ( geometry.boundingBox !== null ) {
  5771. this.boundingBox = geometry.boundingBox.clone();
  5772. }
  5773. return this;
  5774. }
  5775. } );
  5776. /**
  5777. * @author mrdoob / http://mrdoob.com/
  5778. */
  5779. function arrayMax( array ) {
  5780. if ( array.length === 0 ) return - Infinity;
  5781. var max = array[ 0 ];
  5782. for ( var i = 1, l = array.length; i < l; ++ i ) {
  5783. if ( array[ i ] > max ) max = array[ i ];
  5784. }
  5785. return max;
  5786. }
  5787. /**
  5788. * @author alteredq / http://alteredqualia.com/
  5789. * @author mrdoob / http://mrdoob.com/
  5790. */
  5791. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5792. function BufferGeometry() {
  5793. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  5794. this.uuid = _Math.generateUUID();
  5795. this.name = '';
  5796. this.type = 'BufferGeometry';
  5797. this.index = null;
  5798. this.attributes = {};
  5799. this.morphAttributes = {};
  5800. this.groups = [];
  5801. this.boundingBox = null;
  5802. this.boundingSphere = null;
  5803. this.drawRange = { start: 0, count: Infinity };
  5804. this.userData = {};
  5805. }
  5806. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5807. constructor: BufferGeometry,
  5808. isBufferGeometry: true,
  5809. getIndex: function () {
  5810. return this.index;
  5811. },
  5812. setIndex: function ( index ) {
  5813. if ( Array.isArray( index ) ) {
  5814. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5815. } else {
  5816. this.index = index;
  5817. }
  5818. },
  5819. addAttribute: function ( name, attribute ) {
  5820. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  5821. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  5822. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  5823. }
  5824. if ( name === 'index' ) {
  5825. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  5826. this.setIndex( attribute );
  5827. return this;
  5828. }
  5829. this.attributes[ name ] = attribute;
  5830. return this;
  5831. },
  5832. getAttribute: function ( name ) {
  5833. return this.attributes[ name ];
  5834. },
  5835. removeAttribute: function ( name ) {
  5836. delete this.attributes[ name ];
  5837. return this;
  5838. },
  5839. addGroup: function ( start, count, materialIndex ) {
  5840. this.groups.push( {
  5841. start: start,
  5842. count: count,
  5843. materialIndex: materialIndex !== undefined ? materialIndex : 0
  5844. } );
  5845. },
  5846. clearGroups: function () {
  5847. this.groups = [];
  5848. },
  5849. setDrawRange: function ( start, count ) {
  5850. this.drawRange.start = start;
  5851. this.drawRange.count = count;
  5852. },
  5853. applyMatrix: function ( matrix ) {
  5854. var position = this.attributes.position;
  5855. if ( position !== undefined ) {
  5856. matrix.applyToBufferAttribute( position );
  5857. position.needsUpdate = true;
  5858. }
  5859. var normal = this.attributes.normal;
  5860. if ( normal !== undefined ) {
  5861. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5862. normalMatrix.applyToBufferAttribute( normal );
  5863. normal.needsUpdate = true;
  5864. }
  5865. var tangent = this.attributes.tangent;
  5866. if ( tangent !== undefined ) {
  5867. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5868. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  5869. normalMatrix.applyToBufferAttribute( tangent );
  5870. tangent.needsUpdate = true;
  5871. }
  5872. if ( this.boundingBox !== null ) {
  5873. this.computeBoundingBox();
  5874. }
  5875. if ( this.boundingSphere !== null ) {
  5876. this.computeBoundingSphere();
  5877. }
  5878. return this;
  5879. },
  5880. rotateX: function () {
  5881. // rotate geometry around world x-axis
  5882. var m1 = new Matrix4();
  5883. return function rotateX( angle ) {
  5884. m1.makeRotationX( angle );
  5885. this.applyMatrix( m1 );
  5886. return this;
  5887. };
  5888. }(),
  5889. rotateY: function () {
  5890. // rotate geometry around world y-axis
  5891. var m1 = new Matrix4();
  5892. return function rotateY( angle ) {
  5893. m1.makeRotationY( angle );
  5894. this.applyMatrix( m1 );
  5895. return this;
  5896. };
  5897. }(),
  5898. rotateZ: function () {
  5899. // rotate geometry around world z-axis
  5900. var m1 = new Matrix4();
  5901. return function rotateZ( angle ) {
  5902. m1.makeRotationZ( angle );
  5903. this.applyMatrix( m1 );
  5904. return this;
  5905. };
  5906. }(),
  5907. translate: function () {
  5908. // translate geometry
  5909. var m1 = new Matrix4();
  5910. return function translate( x, y, z ) {
  5911. m1.makeTranslation( x, y, z );
  5912. this.applyMatrix( m1 );
  5913. return this;
  5914. };
  5915. }(),
  5916. scale: function () {
  5917. // scale geometry
  5918. var m1 = new Matrix4();
  5919. return function scale( x, y, z ) {
  5920. m1.makeScale( x, y, z );
  5921. this.applyMatrix( m1 );
  5922. return this;
  5923. };
  5924. }(),
  5925. lookAt: function () {
  5926. var obj = new Object3D();
  5927. return function lookAt( vector ) {
  5928. obj.lookAt( vector );
  5929. obj.updateMatrix();
  5930. this.applyMatrix( obj.matrix );
  5931. };
  5932. }(),
  5933. center: function () {
  5934. var offset = new Vector3();
  5935. return function center() {
  5936. this.computeBoundingBox();
  5937. this.boundingBox.getCenter( offset ).negate();
  5938. this.translate( offset.x, offset.y, offset.z );
  5939. return this;
  5940. };
  5941. }(),
  5942. setFromObject: function ( object ) {
  5943. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5944. var geometry = object.geometry;
  5945. if ( object.isPoints || object.isLine ) {
  5946. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5947. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  5948. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5949. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5950. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  5951. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  5952. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  5953. }
  5954. if ( geometry.boundingSphere !== null ) {
  5955. this.boundingSphere = geometry.boundingSphere.clone();
  5956. }
  5957. if ( geometry.boundingBox !== null ) {
  5958. this.boundingBox = geometry.boundingBox.clone();
  5959. }
  5960. } else if ( object.isMesh ) {
  5961. if ( geometry && geometry.isGeometry ) {
  5962. this.fromGeometry( geometry );
  5963. }
  5964. }
  5965. return this;
  5966. },
  5967. setFromPoints: function ( points ) {
  5968. var position = [];
  5969. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5970. var point = points[ i ];
  5971. position.push( point.x, point.y, point.z || 0 );
  5972. }
  5973. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  5974. return this;
  5975. },
  5976. updateFromObject: function ( object ) {
  5977. var geometry = object.geometry;
  5978. if ( object.isMesh ) {
  5979. var direct = geometry.__directGeometry;
  5980. if ( geometry.elementsNeedUpdate === true ) {
  5981. direct = undefined;
  5982. geometry.elementsNeedUpdate = false;
  5983. }
  5984. if ( direct === undefined ) {
  5985. return this.fromGeometry( geometry );
  5986. }
  5987. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5988. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5989. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5990. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5991. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5992. geometry.verticesNeedUpdate = false;
  5993. geometry.normalsNeedUpdate = false;
  5994. geometry.colorsNeedUpdate = false;
  5995. geometry.uvsNeedUpdate = false;
  5996. geometry.groupsNeedUpdate = false;
  5997. geometry = direct;
  5998. }
  5999. var attribute;
  6000. if ( geometry.verticesNeedUpdate === true ) {
  6001. attribute = this.attributes.position;
  6002. if ( attribute !== undefined ) {
  6003. attribute.copyVector3sArray( geometry.vertices );
  6004. attribute.needsUpdate = true;
  6005. }
  6006. geometry.verticesNeedUpdate = false;
  6007. }
  6008. if ( geometry.normalsNeedUpdate === true ) {
  6009. attribute = this.attributes.normal;
  6010. if ( attribute !== undefined ) {
  6011. attribute.copyVector3sArray( geometry.normals );
  6012. attribute.needsUpdate = true;
  6013. }
  6014. geometry.normalsNeedUpdate = false;
  6015. }
  6016. if ( geometry.colorsNeedUpdate === true ) {
  6017. attribute = this.attributes.color;
  6018. if ( attribute !== undefined ) {
  6019. attribute.copyColorsArray( geometry.colors );
  6020. attribute.needsUpdate = true;
  6021. }
  6022. geometry.colorsNeedUpdate = false;
  6023. }
  6024. if ( geometry.uvsNeedUpdate ) {
  6025. attribute = this.attributes.uv;
  6026. if ( attribute !== undefined ) {
  6027. attribute.copyVector2sArray( geometry.uvs );
  6028. attribute.needsUpdate = true;
  6029. }
  6030. geometry.uvsNeedUpdate = false;
  6031. }
  6032. if ( geometry.lineDistancesNeedUpdate ) {
  6033. attribute = this.attributes.lineDistance;
  6034. if ( attribute !== undefined ) {
  6035. attribute.copyArray( geometry.lineDistances );
  6036. attribute.needsUpdate = true;
  6037. }
  6038. geometry.lineDistancesNeedUpdate = false;
  6039. }
  6040. if ( geometry.groupsNeedUpdate ) {
  6041. geometry.computeGroups( object.geometry );
  6042. this.groups = geometry.groups;
  6043. geometry.groupsNeedUpdate = false;
  6044. }
  6045. return this;
  6046. },
  6047. fromGeometry: function ( geometry ) {
  6048. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6049. return this.fromDirectGeometry( geometry.__directGeometry );
  6050. },
  6051. fromDirectGeometry: function ( geometry ) {
  6052. var positions = new Float32Array( geometry.vertices.length * 3 );
  6053. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6054. if ( geometry.normals.length > 0 ) {
  6055. var normals = new Float32Array( geometry.normals.length * 3 );
  6056. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6057. }
  6058. if ( geometry.colors.length > 0 ) {
  6059. var colors = new Float32Array( geometry.colors.length * 3 );
  6060. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6061. }
  6062. if ( geometry.uvs.length > 0 ) {
  6063. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6064. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6065. }
  6066. if ( geometry.uvs2.length > 0 ) {
  6067. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6068. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6069. }
  6070. // groups
  6071. this.groups = geometry.groups;
  6072. // morphs
  6073. for ( var name in geometry.morphTargets ) {
  6074. var array = [];
  6075. var morphTargets = geometry.morphTargets[ name ];
  6076. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6077. var morphTarget = morphTargets[ i ];
  6078. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6079. attribute.name = morphTarget.name;
  6080. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6081. }
  6082. this.morphAttributes[ name ] = array;
  6083. }
  6084. // skinning
  6085. if ( geometry.skinIndices.length > 0 ) {
  6086. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6087. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6088. }
  6089. if ( geometry.skinWeights.length > 0 ) {
  6090. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6091. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6092. }
  6093. //
  6094. if ( geometry.boundingSphere !== null ) {
  6095. this.boundingSphere = geometry.boundingSphere.clone();
  6096. }
  6097. if ( geometry.boundingBox !== null ) {
  6098. this.boundingBox = geometry.boundingBox.clone();
  6099. }
  6100. return this;
  6101. },
  6102. computeBoundingBox: function () {
  6103. var box = new Box3();
  6104. return function computeBoundingBox() {
  6105. if ( this.boundingBox === null ) {
  6106. this.boundingBox = new Box3();
  6107. }
  6108. var position = this.attributes.position;
  6109. var morphAttributesPosition = this.morphAttributes.position;
  6110. if ( position !== undefined ) {
  6111. this.boundingBox.setFromBufferAttribute( position );
  6112. // process morph attributes if present
  6113. if ( morphAttributesPosition ) {
  6114. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6115. var morphAttribute = morphAttributesPosition[ i ];
  6116. box.setFromBufferAttribute( morphAttribute );
  6117. this.boundingBox.expandByPoint( box.min );
  6118. this.boundingBox.expandByPoint( box.max );
  6119. }
  6120. }
  6121. } else {
  6122. this.boundingBox.makeEmpty();
  6123. }
  6124. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6125. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6126. }
  6127. };
  6128. }(),
  6129. computeBoundingSphere: function () {
  6130. var box = new Box3();
  6131. var boxMorphTargets = new Box3();
  6132. var vector = new Vector3();
  6133. return function computeBoundingSphere() {
  6134. if ( this.boundingSphere === null ) {
  6135. this.boundingSphere = new Sphere();
  6136. }
  6137. var position = this.attributes.position;
  6138. var morphAttributesPosition = this.morphAttributes.position;
  6139. if ( position ) {
  6140. // first, find the center of the bounding sphere
  6141. var center = this.boundingSphere.center;
  6142. box.setFromBufferAttribute( position );
  6143. // process morph attributes if present
  6144. if ( morphAttributesPosition ) {
  6145. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6146. var morphAttribute = morphAttributesPosition[ i ];
  6147. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6148. box.expandByPoint( boxMorphTargets.min );
  6149. box.expandByPoint( boxMorphTargets.max );
  6150. }
  6151. }
  6152. box.getCenter( center );
  6153. // second, try to find a boundingSphere with a radius smaller than the
  6154. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6155. var maxRadiusSq = 0;
  6156. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6157. vector.fromBufferAttribute( position, i );
  6158. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6159. }
  6160. // process morph attributes if present
  6161. if ( morphAttributesPosition ) {
  6162. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6163. var morphAttribute = morphAttributesPosition[ i ];
  6164. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6165. vector.fromBufferAttribute( morphAttribute, j );
  6166. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6167. }
  6168. }
  6169. }
  6170. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6171. if ( isNaN( this.boundingSphere.radius ) ) {
  6172. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6173. }
  6174. }
  6175. };
  6176. }(),
  6177. computeFaceNormals: function () {
  6178. // backwards compatibility
  6179. },
  6180. computeVertexNormals: function () {
  6181. var index = this.index;
  6182. var attributes = this.attributes;
  6183. if ( attributes.position ) {
  6184. var positions = attributes.position.array;
  6185. if ( attributes.normal === undefined ) {
  6186. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6187. } else {
  6188. // reset existing normals to zero
  6189. var array = attributes.normal.array;
  6190. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6191. array[ i ] = 0;
  6192. }
  6193. }
  6194. var normals = attributes.normal.array;
  6195. var vA, vB, vC;
  6196. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6197. var cb = new Vector3(), ab = new Vector3();
  6198. // indexed elements
  6199. if ( index ) {
  6200. var indices = index.array;
  6201. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  6202. vA = indices[ i + 0 ] * 3;
  6203. vB = indices[ i + 1 ] * 3;
  6204. vC = indices[ i + 2 ] * 3;
  6205. pA.fromArray( positions, vA );
  6206. pB.fromArray( positions, vB );
  6207. pC.fromArray( positions, vC );
  6208. cb.subVectors( pC, pB );
  6209. ab.subVectors( pA, pB );
  6210. cb.cross( ab );
  6211. normals[ vA ] += cb.x;
  6212. normals[ vA + 1 ] += cb.y;
  6213. normals[ vA + 2 ] += cb.z;
  6214. normals[ vB ] += cb.x;
  6215. normals[ vB + 1 ] += cb.y;
  6216. normals[ vB + 2 ] += cb.z;
  6217. normals[ vC ] += cb.x;
  6218. normals[ vC + 1 ] += cb.y;
  6219. normals[ vC + 2 ] += cb.z;
  6220. }
  6221. } else {
  6222. // non-indexed elements (unconnected triangle soup)
  6223. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6224. pA.fromArray( positions, i );
  6225. pB.fromArray( positions, i + 3 );
  6226. pC.fromArray( positions, i + 6 );
  6227. cb.subVectors( pC, pB );
  6228. ab.subVectors( pA, pB );
  6229. cb.cross( ab );
  6230. normals[ i ] = cb.x;
  6231. normals[ i + 1 ] = cb.y;
  6232. normals[ i + 2 ] = cb.z;
  6233. normals[ i + 3 ] = cb.x;
  6234. normals[ i + 4 ] = cb.y;
  6235. normals[ i + 5 ] = cb.z;
  6236. normals[ i + 6 ] = cb.x;
  6237. normals[ i + 7 ] = cb.y;
  6238. normals[ i + 8 ] = cb.z;
  6239. }
  6240. }
  6241. this.normalizeNormals();
  6242. attributes.normal.needsUpdate = true;
  6243. }
  6244. },
  6245. merge: function ( geometry, offset ) {
  6246. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6247. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6248. return;
  6249. }
  6250. if ( offset === undefined ) {
  6251. offset = 0;
  6252. console.warn(
  6253. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6254. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6255. );
  6256. }
  6257. var attributes = this.attributes;
  6258. for ( var key in attributes ) {
  6259. if ( geometry.attributes[ key ] === undefined ) continue;
  6260. var attribute1 = attributes[ key ];
  6261. var attributeArray1 = attribute1.array;
  6262. var attribute2 = geometry.attributes[ key ];
  6263. var attributeArray2 = attribute2.array;
  6264. var attributeOffset = attribute2.itemSize * offset;
  6265. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6266. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6267. attributeArray1[ j ] = attributeArray2[ i ];
  6268. }
  6269. }
  6270. return this;
  6271. },
  6272. normalizeNormals: function () {
  6273. var vector = new Vector3();
  6274. return function normalizeNormals() {
  6275. var normals = this.attributes.normal;
  6276. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6277. vector.x = normals.getX( i );
  6278. vector.y = normals.getY( i );
  6279. vector.z = normals.getZ( i );
  6280. vector.normalize();
  6281. normals.setXYZ( i, vector.x, vector.y, vector.z );
  6282. }
  6283. };
  6284. }(),
  6285. toNonIndexed: function () {
  6286. function convertBufferAttribute( attribute, indices ) {
  6287. var array = attribute.array;
  6288. var itemSize = attribute.itemSize;
  6289. var array2 = new array.constructor( indices.length * itemSize );
  6290. var index = 0, index2 = 0;
  6291. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6292. index = indices[ i ] * itemSize;
  6293. for ( var j = 0; j < itemSize; j ++ ) {
  6294. array2[ index2 ++ ] = array[ index ++ ];
  6295. }
  6296. }
  6297. return new BufferAttribute( array2, itemSize );
  6298. }
  6299. //
  6300. if ( this.index === null ) {
  6301. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6302. return this;
  6303. }
  6304. var geometry2 = new BufferGeometry();
  6305. var indices = this.index.array;
  6306. var attributes = this.attributes;
  6307. // attributes
  6308. for ( var name in attributes ) {
  6309. var attribute = attributes[ name ];
  6310. var newAttribute = convertBufferAttribute( attribute, indices );
  6311. geometry2.addAttribute( name, newAttribute );
  6312. }
  6313. // morph attributes
  6314. var morphAttributes = this.morphAttributes;
  6315. for ( name in morphAttributes ) {
  6316. var morphArray = [];
  6317. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6318. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6319. var attribute = morphAttribute[ i ];
  6320. var newAttribute = convertBufferAttribute( attribute, indices );
  6321. morphArray.push( newAttribute );
  6322. }
  6323. geometry2.morphAttributes[ name ] = morphArray;
  6324. }
  6325. // groups
  6326. var groups = this.groups;
  6327. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6328. var group = groups[ i ];
  6329. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6330. }
  6331. return geometry2;
  6332. },
  6333. toJSON: function () {
  6334. var data = {
  6335. metadata: {
  6336. version: 4.5,
  6337. type: 'BufferGeometry',
  6338. generator: 'BufferGeometry.toJSON'
  6339. }
  6340. };
  6341. // standard BufferGeometry serialization
  6342. data.uuid = this.uuid;
  6343. data.type = this.type;
  6344. if ( this.name !== '' ) data.name = this.name;
  6345. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6346. if ( this.parameters !== undefined ) {
  6347. var parameters = this.parameters;
  6348. for ( var key in parameters ) {
  6349. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6350. }
  6351. return data;
  6352. }
  6353. data.data = { attributes: {} };
  6354. var index = this.index;
  6355. if ( index !== null ) {
  6356. data.data.index = {
  6357. type: index.array.constructor.name,
  6358. array: Array.prototype.slice.call( index.array )
  6359. };
  6360. }
  6361. var attributes = this.attributes;
  6362. for ( var key in attributes ) {
  6363. var attribute = attributes[ key ];
  6364. var attributeData = attribute.toJSON();
  6365. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6366. data.data.attributes[ key ] = attributeData;
  6367. }
  6368. var morphAttributes = {};
  6369. var hasMorphAttributes = false;
  6370. for ( var key in this.morphAttributes ) {
  6371. var attributeArray = this.morphAttributes[ key ];
  6372. var array = [];
  6373. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6374. var attribute = attributeArray[ i ];
  6375. var attributeData = attribute.toJSON();
  6376. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6377. array.push( attributeData );
  6378. }
  6379. if ( array.length > 0 ) {
  6380. morphAttributes[ key ] = array;
  6381. hasMorphAttributes = true;
  6382. }
  6383. }
  6384. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  6385. var groups = this.groups;
  6386. if ( groups.length > 0 ) {
  6387. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6388. }
  6389. var boundingSphere = this.boundingSphere;
  6390. if ( boundingSphere !== null ) {
  6391. data.data.boundingSphere = {
  6392. center: boundingSphere.center.toArray(),
  6393. radius: boundingSphere.radius
  6394. };
  6395. }
  6396. return data;
  6397. },
  6398. clone: function () {
  6399. /*
  6400. // Handle primitives
  6401. var parameters = this.parameters;
  6402. if ( parameters !== undefined ) {
  6403. var values = [];
  6404. for ( var key in parameters ) {
  6405. values.push( parameters[ key ] );
  6406. }
  6407. var geometry = Object.create( this.constructor.prototype );
  6408. this.constructor.apply( geometry, values );
  6409. return geometry;
  6410. }
  6411. return new this.constructor().copy( this );
  6412. */
  6413. return new BufferGeometry().copy( this );
  6414. },
  6415. copy: function ( source ) {
  6416. var name, i, l;
  6417. // reset
  6418. this.index = null;
  6419. this.attributes = {};
  6420. this.morphAttributes = {};
  6421. this.groups = [];
  6422. this.boundingBox = null;
  6423. this.boundingSphere = null;
  6424. // name
  6425. this.name = source.name;
  6426. // index
  6427. var index = source.index;
  6428. if ( index !== null ) {
  6429. this.setIndex( index.clone() );
  6430. }
  6431. // attributes
  6432. var attributes = source.attributes;
  6433. for ( name in attributes ) {
  6434. var attribute = attributes[ name ];
  6435. this.addAttribute( name, attribute.clone() );
  6436. }
  6437. // morph attributes
  6438. var morphAttributes = source.morphAttributes;
  6439. for ( name in morphAttributes ) {
  6440. var array = [];
  6441. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6442. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6443. array.push( morphAttribute[ i ].clone() );
  6444. }
  6445. this.morphAttributes[ name ] = array;
  6446. }
  6447. // groups
  6448. var groups = source.groups;
  6449. for ( i = 0, l = groups.length; i < l; i ++ ) {
  6450. var group = groups[ i ];
  6451. this.addGroup( group.start, group.count, group.materialIndex );
  6452. }
  6453. // bounding box
  6454. var boundingBox = source.boundingBox;
  6455. if ( boundingBox !== null ) {
  6456. this.boundingBox = boundingBox.clone();
  6457. }
  6458. // bounding sphere
  6459. var boundingSphere = source.boundingSphere;
  6460. if ( boundingSphere !== null ) {
  6461. this.boundingSphere = boundingSphere.clone();
  6462. }
  6463. // draw range
  6464. this.drawRange.start = source.drawRange.start;
  6465. this.drawRange.count = source.drawRange.count;
  6466. // user data
  6467. this.userData = source.userData;
  6468. return this;
  6469. },
  6470. dispose: function () {
  6471. this.dispatchEvent( { type: 'dispose' } );
  6472. }
  6473. } );
  6474. /**
  6475. * @author mrdoob / http://mrdoob.com/
  6476. * @author alteredq / http://alteredqualia.com/
  6477. * @author mikael emtinger / http://gomo.se/
  6478. * @author jonobr1 / http://jonobr1.com/
  6479. */
  6480. function Mesh( geometry, material ) {
  6481. Object3D.call( this );
  6482. this.type = 'Mesh';
  6483. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6484. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  6485. this.drawMode = TrianglesDrawMode;
  6486. this.updateMorphTargets();
  6487. }
  6488. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6489. constructor: Mesh,
  6490. isMesh: true,
  6491. setDrawMode: function ( value ) {
  6492. this.drawMode = value;
  6493. },
  6494. copy: function ( source ) {
  6495. Object3D.prototype.copy.call( this, source );
  6496. this.drawMode = source.drawMode;
  6497. if ( source.morphTargetInfluences !== undefined ) {
  6498. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6499. }
  6500. if ( source.morphTargetDictionary !== undefined ) {
  6501. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6502. }
  6503. return this;
  6504. },
  6505. updateMorphTargets: function () {
  6506. var geometry = this.geometry;
  6507. var m, ml, name;
  6508. if ( geometry.isBufferGeometry ) {
  6509. var morphAttributes = geometry.morphAttributes;
  6510. var keys = Object.keys( morphAttributes );
  6511. if ( keys.length > 0 ) {
  6512. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6513. if ( morphAttribute !== undefined ) {
  6514. this.morphTargetInfluences = [];
  6515. this.morphTargetDictionary = {};
  6516. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6517. name = morphAttribute[ m ].name || String( m );
  6518. this.morphTargetInfluences.push( 0 );
  6519. this.morphTargetDictionary[ name ] = m;
  6520. }
  6521. }
  6522. }
  6523. } else {
  6524. var morphTargets = geometry.morphTargets;
  6525. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6526. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6527. }
  6528. }
  6529. },
  6530. raycast: ( function () {
  6531. var inverseMatrix = new Matrix4();
  6532. var ray = new Ray();
  6533. var sphere = new Sphere();
  6534. var vA = new Vector3();
  6535. var vB = new Vector3();
  6536. var vC = new Vector3();
  6537. var tempA = new Vector3();
  6538. var tempB = new Vector3();
  6539. var tempC = new Vector3();
  6540. var morphA = new Vector3();
  6541. var morphB = new Vector3();
  6542. var morphC = new Vector3();
  6543. var uvA = new Vector2();
  6544. var uvB = new Vector2();
  6545. var uvC = new Vector2();
  6546. var intersectionPoint = new Vector3();
  6547. var intersectionPointWorld = new Vector3();
  6548. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6549. var intersect;
  6550. if ( material.side === BackSide ) {
  6551. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6552. } else {
  6553. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6554. }
  6555. if ( intersect === null ) return null;
  6556. intersectionPointWorld.copy( point );
  6557. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6558. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  6559. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6560. return {
  6561. distance: distance,
  6562. point: intersectionPointWorld.clone(),
  6563. object: object
  6564. };
  6565. }
  6566. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c ) {
  6567. vA.fromBufferAttribute( position, a );
  6568. vB.fromBufferAttribute( position, b );
  6569. vC.fromBufferAttribute( position, c );
  6570. var morphInfluences = object.morphTargetInfluences;
  6571. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6572. morphA.set( 0, 0, 0 );
  6573. morphB.set( 0, 0, 0 );
  6574. morphC.set( 0, 0, 0 );
  6575. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6576. var influence = morphInfluences[ i ];
  6577. var morphAttribute = morphPosition[ i ];
  6578. if ( influence === 0 ) continue;
  6579. tempA.fromBufferAttribute( morphAttribute, a );
  6580. tempB.fromBufferAttribute( morphAttribute, b );
  6581. tempC.fromBufferAttribute( morphAttribute, c );
  6582. morphA.addScaledVector( tempA.sub( vA ), influence );
  6583. morphB.addScaledVector( tempB.sub( vB ), influence );
  6584. morphC.addScaledVector( tempC.sub( vC ), influence );
  6585. }
  6586. vA.add( morphA );
  6587. vB.add( morphB );
  6588. vC.add( morphC );
  6589. }
  6590. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  6591. if ( intersection ) {
  6592. if ( uv ) {
  6593. uvA.fromBufferAttribute( uv, a );
  6594. uvB.fromBufferAttribute( uv, b );
  6595. uvC.fromBufferAttribute( uv, c );
  6596. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  6597. }
  6598. if ( uv2 ) {
  6599. uvA.fromBufferAttribute( uv2, a );
  6600. uvB.fromBufferAttribute( uv2, b );
  6601. uvC.fromBufferAttribute( uv2, c );
  6602. intersection.uv2 = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  6603. }
  6604. var face = new Face3( a, b, c );
  6605. Triangle.getNormal( vA, vB, vC, face.normal );
  6606. intersection.face = face;
  6607. }
  6608. return intersection;
  6609. }
  6610. return function raycast( raycaster, intersects ) {
  6611. var geometry = this.geometry;
  6612. var material = this.material;
  6613. var matrixWorld = this.matrixWorld;
  6614. if ( material === undefined ) return;
  6615. // Checking boundingSphere distance to ray
  6616. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6617. sphere.copy( geometry.boundingSphere );
  6618. sphere.applyMatrix4( matrixWorld );
  6619. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  6620. //
  6621. inverseMatrix.getInverse( matrixWorld );
  6622. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  6623. // Check boundingBox before continuing
  6624. if ( geometry.boundingBox !== null ) {
  6625. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6626. }
  6627. var intersection;
  6628. if ( geometry.isBufferGeometry ) {
  6629. var a, b, c;
  6630. var index = geometry.index;
  6631. var position = geometry.attributes.position;
  6632. var morphPosition = geometry.morphAttributes.position;
  6633. var uv = geometry.attributes.uv;
  6634. var uv2 = geometry.attributes.uv2;
  6635. var groups = geometry.groups;
  6636. var drawRange = geometry.drawRange;
  6637. var i, j, il, jl;
  6638. var group, groupMaterial;
  6639. var start, end;
  6640. if ( index !== null ) {
  6641. // indexed buffer geometry
  6642. if ( Array.isArray( material ) ) {
  6643. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6644. group = groups[ i ];
  6645. groupMaterial = material[ group.materialIndex ];
  6646. start = Math.max( group.start, drawRange.start );
  6647. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6648. for ( j = start, jl = end; j < jl; j += 3 ) {
  6649. a = index.getX( j );
  6650. b = index.getX( j + 1 );
  6651. c = index.getX( j + 2 );
  6652. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6653. if ( intersection ) {
  6654. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6655. intersection.face.materialIndex = group.materialIndex;
  6656. intersects.push( intersection );
  6657. }
  6658. }
  6659. }
  6660. } else {
  6661. start = Math.max( 0, drawRange.start );
  6662. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6663. for ( i = start, il = end; i < il; i += 3 ) {
  6664. a = index.getX( i );
  6665. b = index.getX( i + 1 );
  6666. c = index.getX( i + 2 );
  6667. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6668. if ( intersection ) {
  6669. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6670. intersects.push( intersection );
  6671. }
  6672. }
  6673. }
  6674. } else if ( position !== undefined ) {
  6675. // non-indexed buffer geometry
  6676. if ( Array.isArray( material ) ) {
  6677. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6678. group = groups[ i ];
  6679. groupMaterial = material[ group.materialIndex ];
  6680. start = Math.max( group.start, drawRange.start );
  6681. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6682. for ( j = start, jl = end; j < jl; j += 3 ) {
  6683. a = j;
  6684. b = j + 1;
  6685. c = j + 2;
  6686. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6687. if ( intersection ) {
  6688. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6689. intersection.face.materialIndex = group.materialIndex;
  6690. intersects.push( intersection );
  6691. }
  6692. }
  6693. }
  6694. } else {
  6695. start = Math.max( 0, drawRange.start );
  6696. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6697. for ( i = start, il = end; i < il; i += 3 ) {
  6698. a = i;
  6699. b = i + 1;
  6700. c = i + 2;
  6701. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c );
  6702. if ( intersection ) {
  6703. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6704. intersects.push( intersection );
  6705. }
  6706. }
  6707. }
  6708. }
  6709. } else if ( geometry.isGeometry ) {
  6710. var fvA, fvB, fvC;
  6711. var isMultiMaterial = Array.isArray( material );
  6712. var vertices = geometry.vertices;
  6713. var faces = geometry.faces;
  6714. var uvs;
  6715. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6716. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6717. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6718. var face = faces[ f ];
  6719. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6720. if ( faceMaterial === undefined ) continue;
  6721. fvA = vertices[ face.a ];
  6722. fvB = vertices[ face.b ];
  6723. fvC = vertices[ face.c ];
  6724. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  6725. if ( intersection ) {
  6726. if ( uvs && uvs[ f ] ) {
  6727. var uvs_f = uvs[ f ];
  6728. uvA.copy( uvs_f[ 0 ] );
  6729. uvB.copy( uvs_f[ 1 ] );
  6730. uvC.copy( uvs_f[ 2 ] );
  6731. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  6732. }
  6733. intersection.face = face;
  6734. intersection.faceIndex = f;
  6735. intersects.push( intersection );
  6736. }
  6737. }
  6738. }
  6739. };
  6740. }() ),
  6741. clone: function () {
  6742. return new this.constructor( this.geometry, this.material ).copy( this );
  6743. }
  6744. } );
  6745. /**
  6746. * @author mrdoob / http://mrdoob.com/
  6747. * @author kile / http://kile.stravaganza.org/
  6748. * @author alteredq / http://alteredqualia.com/
  6749. * @author mikael emtinger / http://gomo.se/
  6750. * @author zz85 / http://www.lab4games.net/zz85/blog
  6751. * @author bhouston / http://clara.io
  6752. */
  6753. var geometryId = 0; // Geometry uses even numbers as Id
  6754. function Geometry() {
  6755. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6756. this.uuid = _Math.generateUUID();
  6757. this.name = '';
  6758. this.type = 'Geometry';
  6759. this.vertices = [];
  6760. this.colors = [];
  6761. this.faces = [];
  6762. this.faceVertexUvs = [[]];
  6763. this.morphTargets = [];
  6764. this.morphNormals = [];
  6765. this.skinWeights = [];
  6766. this.skinIndices = [];
  6767. this.lineDistances = [];
  6768. this.boundingBox = null;
  6769. this.boundingSphere = null;
  6770. // update flags
  6771. this.elementsNeedUpdate = false;
  6772. this.verticesNeedUpdate = false;
  6773. this.uvsNeedUpdate = false;
  6774. this.normalsNeedUpdate = false;
  6775. this.colorsNeedUpdate = false;
  6776. this.lineDistancesNeedUpdate = false;
  6777. this.groupsNeedUpdate = false;
  6778. }
  6779. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6780. constructor: Geometry,
  6781. isGeometry: true,
  6782. applyMatrix: function ( matrix ) {
  6783. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6784. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6785. var vertex = this.vertices[ i ];
  6786. vertex.applyMatrix4( matrix );
  6787. }
  6788. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6789. var face = this.faces[ i ];
  6790. face.normal.applyMatrix3( normalMatrix ).normalize();
  6791. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6792. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6793. }
  6794. }
  6795. if ( this.boundingBox !== null ) {
  6796. this.computeBoundingBox();
  6797. }
  6798. if ( this.boundingSphere !== null ) {
  6799. this.computeBoundingSphere();
  6800. }
  6801. this.verticesNeedUpdate = true;
  6802. this.normalsNeedUpdate = true;
  6803. return this;
  6804. },
  6805. rotateX: function () {
  6806. // rotate geometry around world x-axis
  6807. var m1 = new Matrix4();
  6808. return function rotateX( angle ) {
  6809. m1.makeRotationX( angle );
  6810. this.applyMatrix( m1 );
  6811. return this;
  6812. };
  6813. }(),
  6814. rotateY: function () {
  6815. // rotate geometry around world y-axis
  6816. var m1 = new Matrix4();
  6817. return function rotateY( angle ) {
  6818. m1.makeRotationY( angle );
  6819. this.applyMatrix( m1 );
  6820. return this;
  6821. };
  6822. }(),
  6823. rotateZ: function () {
  6824. // rotate geometry around world z-axis
  6825. var m1 = new Matrix4();
  6826. return function rotateZ( angle ) {
  6827. m1.makeRotationZ( angle );
  6828. this.applyMatrix( m1 );
  6829. return this;
  6830. };
  6831. }(),
  6832. translate: function () {
  6833. // translate geometry
  6834. var m1 = new Matrix4();
  6835. return function translate( x, y, z ) {
  6836. m1.makeTranslation( x, y, z );
  6837. this.applyMatrix( m1 );
  6838. return this;
  6839. };
  6840. }(),
  6841. scale: function () {
  6842. // scale geometry
  6843. var m1 = new Matrix4();
  6844. return function scale( x, y, z ) {
  6845. m1.makeScale( x, y, z );
  6846. this.applyMatrix( m1 );
  6847. return this;
  6848. };
  6849. }(),
  6850. lookAt: function () {
  6851. var obj = new Object3D();
  6852. return function lookAt( vector ) {
  6853. obj.lookAt( vector );
  6854. obj.updateMatrix();
  6855. this.applyMatrix( obj.matrix );
  6856. };
  6857. }(),
  6858. fromBufferGeometry: function ( geometry ) {
  6859. var scope = this;
  6860. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6861. var attributes = geometry.attributes;
  6862. var positions = attributes.position.array;
  6863. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6864. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6865. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6866. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6867. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6868. for ( var i = 0; i < positions.length; i += 3 ) {
  6869. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  6870. if ( colors !== undefined ) {
  6871. scope.colors.push( new Color().fromArray( colors, i ) );
  6872. }
  6873. }
  6874. function addFace( a, b, c, materialIndex ) {
  6875. var vertexColors = ( colors === undefined ) ? [] : [
  6876. scope.colors[ a ].clone(),
  6877. scope.colors[ b ].clone(),
  6878. scope.colors[ c ].clone() ];
  6879. var vertexNormals = ( normals === undefined ) ? [] : [
  6880. new Vector3().fromArray( normals, a * 3 ),
  6881. new Vector3().fromArray( normals, b * 3 ),
  6882. new Vector3().fromArray( normals, c * 3 )
  6883. ];
  6884. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6885. scope.faces.push( face );
  6886. if ( uvs !== undefined ) {
  6887. scope.faceVertexUvs[ 0 ].push( [
  6888. new Vector2().fromArray( uvs, a * 2 ),
  6889. new Vector2().fromArray( uvs, b * 2 ),
  6890. new Vector2().fromArray( uvs, c * 2 )
  6891. ] );
  6892. }
  6893. if ( uvs2 !== undefined ) {
  6894. scope.faceVertexUvs[ 1 ].push( [
  6895. new Vector2().fromArray( uvs2, a * 2 ),
  6896. new Vector2().fromArray( uvs2, b * 2 ),
  6897. new Vector2().fromArray( uvs2, c * 2 )
  6898. ] );
  6899. }
  6900. }
  6901. var groups = geometry.groups;
  6902. if ( groups.length > 0 ) {
  6903. for ( var i = 0; i < groups.length; i ++ ) {
  6904. var group = groups[ i ];
  6905. var start = group.start;
  6906. var count = group.count;
  6907. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6908. if ( indices !== undefined ) {
  6909. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6910. } else {
  6911. addFace( j, j + 1, j + 2, group.materialIndex );
  6912. }
  6913. }
  6914. }
  6915. } else {
  6916. if ( indices !== undefined ) {
  6917. for ( var i = 0; i < indices.length; i += 3 ) {
  6918. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6919. }
  6920. } else {
  6921. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6922. addFace( i, i + 1, i + 2 );
  6923. }
  6924. }
  6925. }
  6926. this.computeFaceNormals();
  6927. if ( geometry.boundingBox !== null ) {
  6928. this.boundingBox = geometry.boundingBox.clone();
  6929. }
  6930. if ( geometry.boundingSphere !== null ) {
  6931. this.boundingSphere = geometry.boundingSphere.clone();
  6932. }
  6933. return this;
  6934. },
  6935. center: function () {
  6936. var offset = new Vector3();
  6937. return function center() {
  6938. this.computeBoundingBox();
  6939. this.boundingBox.getCenter( offset ).negate();
  6940. this.translate( offset.x, offset.y, offset.z );
  6941. return this;
  6942. };
  6943. }(),
  6944. normalize: function () {
  6945. this.computeBoundingSphere();
  6946. var center = this.boundingSphere.center;
  6947. var radius = this.boundingSphere.radius;
  6948. var s = radius === 0 ? 1 : 1.0 / radius;
  6949. var matrix = new Matrix4();
  6950. matrix.set(
  6951. s, 0, 0, - s * center.x,
  6952. 0, s, 0, - s * center.y,
  6953. 0, 0, s, - s * center.z,
  6954. 0, 0, 0, 1
  6955. );
  6956. this.applyMatrix( matrix );
  6957. return this;
  6958. },
  6959. computeFaceNormals: function () {
  6960. var cb = new Vector3(), ab = new Vector3();
  6961. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6962. var face = this.faces[ f ];
  6963. var vA = this.vertices[ face.a ];
  6964. var vB = this.vertices[ face.b ];
  6965. var vC = this.vertices[ face.c ];
  6966. cb.subVectors( vC, vB );
  6967. ab.subVectors( vA, vB );
  6968. cb.cross( ab );
  6969. cb.normalize();
  6970. face.normal.copy( cb );
  6971. }
  6972. },
  6973. computeVertexNormals: function ( areaWeighted ) {
  6974. if ( areaWeighted === undefined ) areaWeighted = true;
  6975. var v, vl, f, fl, face, vertices;
  6976. vertices = new Array( this.vertices.length );
  6977. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6978. vertices[ v ] = new Vector3();
  6979. }
  6980. if ( areaWeighted ) {
  6981. // vertex normals weighted by triangle areas
  6982. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6983. var vA, vB, vC;
  6984. var cb = new Vector3(), ab = new Vector3();
  6985. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6986. face = this.faces[ f ];
  6987. vA = this.vertices[ face.a ];
  6988. vB = this.vertices[ face.b ];
  6989. vC = this.vertices[ face.c ];
  6990. cb.subVectors( vC, vB );
  6991. ab.subVectors( vA, vB );
  6992. cb.cross( ab );
  6993. vertices[ face.a ].add( cb );
  6994. vertices[ face.b ].add( cb );
  6995. vertices[ face.c ].add( cb );
  6996. }
  6997. } else {
  6998. this.computeFaceNormals();
  6999. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7000. face = this.faces[ f ];
  7001. vertices[ face.a ].add( face.normal );
  7002. vertices[ face.b ].add( face.normal );
  7003. vertices[ face.c ].add( face.normal );
  7004. }
  7005. }
  7006. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7007. vertices[ v ].normalize();
  7008. }
  7009. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7010. face = this.faces[ f ];
  7011. var vertexNormals = face.vertexNormals;
  7012. if ( vertexNormals.length === 3 ) {
  7013. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7014. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7015. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7016. } else {
  7017. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7018. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7019. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7020. }
  7021. }
  7022. if ( this.faces.length > 0 ) {
  7023. this.normalsNeedUpdate = true;
  7024. }
  7025. },
  7026. computeFlatVertexNormals: function () {
  7027. var f, fl, face;
  7028. this.computeFaceNormals();
  7029. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7030. face = this.faces[ f ];
  7031. var vertexNormals = face.vertexNormals;
  7032. if ( vertexNormals.length === 3 ) {
  7033. vertexNormals[ 0 ].copy( face.normal );
  7034. vertexNormals[ 1 ].copy( face.normal );
  7035. vertexNormals[ 2 ].copy( face.normal );
  7036. } else {
  7037. vertexNormals[ 0 ] = face.normal.clone();
  7038. vertexNormals[ 1 ] = face.normal.clone();
  7039. vertexNormals[ 2 ] = face.normal.clone();
  7040. }
  7041. }
  7042. if ( this.faces.length > 0 ) {
  7043. this.normalsNeedUpdate = true;
  7044. }
  7045. },
  7046. computeMorphNormals: function () {
  7047. var i, il, f, fl, face;
  7048. // save original normals
  7049. // - create temp variables on first access
  7050. // otherwise just copy (for faster repeated calls)
  7051. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7052. face = this.faces[ f ];
  7053. if ( ! face.__originalFaceNormal ) {
  7054. face.__originalFaceNormal = face.normal.clone();
  7055. } else {
  7056. face.__originalFaceNormal.copy( face.normal );
  7057. }
  7058. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7059. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7060. if ( ! face.__originalVertexNormals[ i ] ) {
  7061. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7062. } else {
  7063. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7064. }
  7065. }
  7066. }
  7067. // use temp geometry to compute face and vertex normals for each morph
  7068. var tmpGeo = new Geometry();
  7069. tmpGeo.faces = this.faces;
  7070. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7071. // create on first access
  7072. if ( ! this.morphNormals[ i ] ) {
  7073. this.morphNormals[ i ] = {};
  7074. this.morphNormals[ i ].faceNormals = [];
  7075. this.morphNormals[ i ].vertexNormals = [];
  7076. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7077. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7078. var faceNormal, vertexNormals;
  7079. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7080. faceNormal = new Vector3();
  7081. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7082. dstNormalsFace.push( faceNormal );
  7083. dstNormalsVertex.push( vertexNormals );
  7084. }
  7085. }
  7086. var morphNormals = this.morphNormals[ i ];
  7087. // set vertices to morph target
  7088. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7089. // compute morph normals
  7090. tmpGeo.computeFaceNormals();
  7091. tmpGeo.computeVertexNormals();
  7092. // store morph normals
  7093. var faceNormal, vertexNormals;
  7094. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7095. face = this.faces[ f ];
  7096. faceNormal = morphNormals.faceNormals[ f ];
  7097. vertexNormals = morphNormals.vertexNormals[ f ];
  7098. faceNormal.copy( face.normal );
  7099. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7100. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7101. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7102. }
  7103. }
  7104. // restore original normals
  7105. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7106. face = this.faces[ f ];
  7107. face.normal = face.__originalFaceNormal;
  7108. face.vertexNormals = face.__originalVertexNormals;
  7109. }
  7110. },
  7111. computeBoundingBox: function () {
  7112. if ( this.boundingBox === null ) {
  7113. this.boundingBox = new Box3();
  7114. }
  7115. this.boundingBox.setFromPoints( this.vertices );
  7116. },
  7117. computeBoundingSphere: function () {
  7118. if ( this.boundingSphere === null ) {
  7119. this.boundingSphere = new Sphere();
  7120. }
  7121. this.boundingSphere.setFromPoints( this.vertices );
  7122. },
  7123. merge: function ( geometry, matrix, materialIndexOffset ) {
  7124. if ( ! ( geometry && geometry.isGeometry ) ) {
  7125. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7126. return;
  7127. }
  7128. var normalMatrix,
  7129. vertexOffset = this.vertices.length,
  7130. vertices1 = this.vertices,
  7131. vertices2 = geometry.vertices,
  7132. faces1 = this.faces,
  7133. faces2 = geometry.faces,
  7134. colors1 = this.colors,
  7135. colors2 = geometry.colors;
  7136. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7137. if ( matrix !== undefined ) {
  7138. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7139. }
  7140. // vertices
  7141. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7142. var vertex = vertices2[ i ];
  7143. var vertexCopy = vertex.clone();
  7144. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7145. vertices1.push( vertexCopy );
  7146. }
  7147. // colors
  7148. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7149. colors1.push( colors2[ i ].clone() );
  7150. }
  7151. // faces
  7152. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7153. var face = faces2[ i ], faceCopy, normal, color,
  7154. faceVertexNormals = face.vertexNormals,
  7155. faceVertexColors = face.vertexColors;
  7156. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7157. faceCopy.normal.copy( face.normal );
  7158. if ( normalMatrix !== undefined ) {
  7159. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7160. }
  7161. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7162. normal = faceVertexNormals[ j ].clone();
  7163. if ( normalMatrix !== undefined ) {
  7164. normal.applyMatrix3( normalMatrix ).normalize();
  7165. }
  7166. faceCopy.vertexNormals.push( normal );
  7167. }
  7168. faceCopy.color.copy( face.color );
  7169. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7170. color = faceVertexColors[ j ];
  7171. faceCopy.vertexColors.push( color.clone() );
  7172. }
  7173. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7174. faces1.push( faceCopy );
  7175. }
  7176. // uvs
  7177. for ( var i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7178. var faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7179. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7180. for ( var j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7181. var uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7182. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7183. uvsCopy.push( uvs2[ k ].clone() );
  7184. }
  7185. this.faceVertexUvs[ i ].push( uvsCopy );
  7186. }
  7187. }
  7188. },
  7189. mergeMesh: function ( mesh ) {
  7190. if ( ! ( mesh && mesh.isMesh ) ) {
  7191. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7192. return;
  7193. }
  7194. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7195. this.merge( mesh.geometry, mesh.matrix );
  7196. },
  7197. /*
  7198. * Checks for duplicate vertices with hashmap.
  7199. * Duplicated vertices are removed
  7200. * and faces' vertices are updated.
  7201. */
  7202. mergeVertices: function () {
  7203. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7204. var unique = [], changes = [];
  7205. var v, key;
  7206. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7207. var precision = Math.pow( 10, precisionPoints );
  7208. var i, il, face;
  7209. var indices, j, jl;
  7210. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7211. v = this.vertices[ i ];
  7212. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7213. if ( verticesMap[ key ] === undefined ) {
  7214. verticesMap[ key ] = i;
  7215. unique.push( this.vertices[ i ] );
  7216. changes[ i ] = unique.length - 1;
  7217. } else {
  7218. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7219. changes[ i ] = changes[ verticesMap[ key ] ];
  7220. }
  7221. }
  7222. // if faces are completely degenerate after merging vertices, we
  7223. // have to remove them from the geometry.
  7224. var faceIndicesToRemove = [];
  7225. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7226. face = this.faces[ i ];
  7227. face.a = changes[ face.a ];
  7228. face.b = changes[ face.b ];
  7229. face.c = changes[ face.c ];
  7230. indices = [ face.a, face.b, face.c ];
  7231. // if any duplicate vertices are found in a Face3
  7232. // we have to remove the face as nothing can be saved
  7233. for ( var n = 0; n < 3; n ++ ) {
  7234. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7235. faceIndicesToRemove.push( i );
  7236. break;
  7237. }
  7238. }
  7239. }
  7240. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7241. var idx = faceIndicesToRemove[ i ];
  7242. this.faces.splice( idx, 1 );
  7243. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7244. this.faceVertexUvs[ j ].splice( idx, 1 );
  7245. }
  7246. }
  7247. // Use unique set of vertices
  7248. var diff = this.vertices.length - unique.length;
  7249. this.vertices = unique;
  7250. return diff;
  7251. },
  7252. setFromPoints: function ( points ) {
  7253. this.vertices = [];
  7254. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7255. var point = points[ i ];
  7256. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7257. }
  7258. return this;
  7259. },
  7260. sortFacesByMaterialIndex: function () {
  7261. var faces = this.faces;
  7262. var length = faces.length;
  7263. // tag faces
  7264. for ( var i = 0; i < length; i ++ ) {
  7265. faces[ i ]._id = i;
  7266. }
  7267. // sort faces
  7268. function materialIndexSort( a, b ) {
  7269. return a.materialIndex - b.materialIndex;
  7270. }
  7271. faces.sort( materialIndexSort );
  7272. // sort uvs
  7273. var uvs1 = this.faceVertexUvs[ 0 ];
  7274. var uvs2 = this.faceVertexUvs[ 1 ];
  7275. var newUvs1, newUvs2;
  7276. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7277. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7278. for ( var i = 0; i < length; i ++ ) {
  7279. var id = faces[ i ]._id;
  7280. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7281. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7282. }
  7283. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7284. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7285. },
  7286. toJSON: function () {
  7287. var data = {
  7288. metadata: {
  7289. version: 4.5,
  7290. type: 'Geometry',
  7291. generator: 'Geometry.toJSON'
  7292. }
  7293. };
  7294. // standard Geometry serialization
  7295. data.uuid = this.uuid;
  7296. data.type = this.type;
  7297. if ( this.name !== '' ) data.name = this.name;
  7298. if ( this.parameters !== undefined ) {
  7299. var parameters = this.parameters;
  7300. for ( var key in parameters ) {
  7301. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7302. }
  7303. return data;
  7304. }
  7305. var vertices = [];
  7306. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7307. var vertex = this.vertices[ i ];
  7308. vertices.push( vertex.x, vertex.y, vertex.z );
  7309. }
  7310. var faces = [];
  7311. var normals = [];
  7312. var normalsHash = {};
  7313. var colors = [];
  7314. var colorsHash = {};
  7315. var uvs = [];
  7316. var uvsHash = {};
  7317. for ( var i = 0; i < this.faces.length; i ++ ) {
  7318. var face = this.faces[ i ];
  7319. var hasMaterial = true;
  7320. var hasFaceUv = false; // deprecated
  7321. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7322. var hasFaceNormal = face.normal.length() > 0;
  7323. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7324. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7325. var hasFaceVertexColor = face.vertexColors.length > 0;
  7326. var faceType = 0;
  7327. faceType = setBit( faceType, 0, 0 ); // isQuad
  7328. faceType = setBit( faceType, 1, hasMaterial );
  7329. faceType = setBit( faceType, 2, hasFaceUv );
  7330. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7331. faceType = setBit( faceType, 4, hasFaceNormal );
  7332. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7333. faceType = setBit( faceType, 6, hasFaceColor );
  7334. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7335. faces.push( faceType );
  7336. faces.push( face.a, face.b, face.c );
  7337. faces.push( face.materialIndex );
  7338. if ( hasFaceVertexUv ) {
  7339. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7340. faces.push(
  7341. getUvIndex( faceVertexUvs[ 0 ] ),
  7342. getUvIndex( faceVertexUvs[ 1 ] ),
  7343. getUvIndex( faceVertexUvs[ 2 ] )
  7344. );
  7345. }
  7346. if ( hasFaceNormal ) {
  7347. faces.push( getNormalIndex( face.normal ) );
  7348. }
  7349. if ( hasFaceVertexNormal ) {
  7350. var vertexNormals = face.vertexNormals;
  7351. faces.push(
  7352. getNormalIndex( vertexNormals[ 0 ] ),
  7353. getNormalIndex( vertexNormals[ 1 ] ),
  7354. getNormalIndex( vertexNormals[ 2 ] )
  7355. );
  7356. }
  7357. if ( hasFaceColor ) {
  7358. faces.push( getColorIndex( face.color ) );
  7359. }
  7360. if ( hasFaceVertexColor ) {
  7361. var vertexColors = face.vertexColors;
  7362. faces.push(
  7363. getColorIndex( vertexColors[ 0 ] ),
  7364. getColorIndex( vertexColors[ 1 ] ),
  7365. getColorIndex( vertexColors[ 2 ] )
  7366. );
  7367. }
  7368. }
  7369. function setBit( value, position, enabled ) {
  7370. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7371. }
  7372. function getNormalIndex( normal ) {
  7373. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7374. if ( normalsHash[ hash ] !== undefined ) {
  7375. return normalsHash[ hash ];
  7376. }
  7377. normalsHash[ hash ] = normals.length / 3;
  7378. normals.push( normal.x, normal.y, normal.z );
  7379. return normalsHash[ hash ];
  7380. }
  7381. function getColorIndex( color ) {
  7382. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7383. if ( colorsHash[ hash ] !== undefined ) {
  7384. return colorsHash[ hash ];
  7385. }
  7386. colorsHash[ hash ] = colors.length;
  7387. colors.push( color.getHex() );
  7388. return colorsHash[ hash ];
  7389. }
  7390. function getUvIndex( uv ) {
  7391. var hash = uv.x.toString() + uv.y.toString();
  7392. if ( uvsHash[ hash ] !== undefined ) {
  7393. return uvsHash[ hash ];
  7394. }
  7395. uvsHash[ hash ] = uvs.length / 2;
  7396. uvs.push( uv.x, uv.y );
  7397. return uvsHash[ hash ];
  7398. }
  7399. data.data = {};
  7400. data.data.vertices = vertices;
  7401. data.data.normals = normals;
  7402. if ( colors.length > 0 ) data.data.colors = colors;
  7403. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7404. data.data.faces = faces;
  7405. return data;
  7406. },
  7407. clone: function () {
  7408. /*
  7409. // Handle primitives
  7410. var parameters = this.parameters;
  7411. if ( parameters !== undefined ) {
  7412. var values = [];
  7413. for ( var key in parameters ) {
  7414. values.push( parameters[ key ] );
  7415. }
  7416. var geometry = Object.create( this.constructor.prototype );
  7417. this.constructor.apply( geometry, values );
  7418. return geometry;
  7419. }
  7420. return new this.constructor().copy( this );
  7421. */
  7422. return new Geometry().copy( this );
  7423. },
  7424. copy: function ( source ) {
  7425. var i, il, j, jl, k, kl;
  7426. // reset
  7427. this.vertices = [];
  7428. this.colors = [];
  7429. this.faces = [];
  7430. this.faceVertexUvs = [[]];
  7431. this.morphTargets = [];
  7432. this.morphNormals = [];
  7433. this.skinWeights = [];
  7434. this.skinIndices = [];
  7435. this.lineDistances = [];
  7436. this.boundingBox = null;
  7437. this.boundingSphere = null;
  7438. // name
  7439. this.name = source.name;
  7440. // vertices
  7441. var vertices = source.vertices;
  7442. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7443. this.vertices.push( vertices[ i ].clone() );
  7444. }
  7445. // colors
  7446. var colors = source.colors;
  7447. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7448. this.colors.push( colors[ i ].clone() );
  7449. }
  7450. // faces
  7451. var faces = source.faces;
  7452. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7453. this.faces.push( faces[ i ].clone() );
  7454. }
  7455. // face vertex uvs
  7456. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7457. var faceVertexUvs = source.faceVertexUvs[ i ];
  7458. if ( this.faceVertexUvs[ i ] === undefined ) {
  7459. this.faceVertexUvs[ i ] = [];
  7460. }
  7461. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7462. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7463. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7464. var uv = uvs[ k ];
  7465. uvsCopy.push( uv.clone() );
  7466. }
  7467. this.faceVertexUvs[ i ].push( uvsCopy );
  7468. }
  7469. }
  7470. // morph targets
  7471. var morphTargets = source.morphTargets;
  7472. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7473. var morphTarget = {};
  7474. morphTarget.name = morphTargets[ i ].name;
  7475. // vertices
  7476. if ( morphTargets[ i ].vertices !== undefined ) {
  7477. morphTarget.vertices = [];
  7478. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7479. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7480. }
  7481. }
  7482. // normals
  7483. if ( morphTargets[ i ].normals !== undefined ) {
  7484. morphTarget.normals = [];
  7485. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7486. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7487. }
  7488. }
  7489. this.morphTargets.push( morphTarget );
  7490. }
  7491. // morph normals
  7492. var morphNormals = source.morphNormals;
  7493. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7494. var morphNormal = {};
  7495. // vertex normals
  7496. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7497. morphNormal.vertexNormals = [];
  7498. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7499. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7500. var destVertexNormal = {};
  7501. destVertexNormal.a = srcVertexNormal.a.clone();
  7502. destVertexNormal.b = srcVertexNormal.b.clone();
  7503. destVertexNormal.c = srcVertexNormal.c.clone();
  7504. morphNormal.vertexNormals.push( destVertexNormal );
  7505. }
  7506. }
  7507. // face normals
  7508. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7509. morphNormal.faceNormals = [];
  7510. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7511. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7512. }
  7513. }
  7514. this.morphNormals.push( morphNormal );
  7515. }
  7516. // skin weights
  7517. var skinWeights = source.skinWeights;
  7518. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7519. this.skinWeights.push( skinWeights[ i ].clone() );
  7520. }
  7521. // skin indices
  7522. var skinIndices = source.skinIndices;
  7523. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7524. this.skinIndices.push( skinIndices[ i ].clone() );
  7525. }
  7526. // line distances
  7527. var lineDistances = source.lineDistances;
  7528. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7529. this.lineDistances.push( lineDistances[ i ] );
  7530. }
  7531. // bounding box
  7532. var boundingBox = source.boundingBox;
  7533. if ( boundingBox !== null ) {
  7534. this.boundingBox = boundingBox.clone();
  7535. }
  7536. // bounding sphere
  7537. var boundingSphere = source.boundingSphere;
  7538. if ( boundingSphere !== null ) {
  7539. this.boundingSphere = boundingSphere.clone();
  7540. }
  7541. // update flags
  7542. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7543. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7544. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7545. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7546. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7547. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7548. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7549. return this;
  7550. },
  7551. dispose: function () {
  7552. this.dispatchEvent( { type: 'dispose' } );
  7553. }
  7554. } );
  7555. /**
  7556. * @author mrdoob / http://mrdoob.com/
  7557. * @author Mugen87 / https://github.com/Mugen87
  7558. */
  7559. // BoxGeometry
  7560. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7561. Geometry.call( this );
  7562. this.type = 'BoxGeometry';
  7563. this.parameters = {
  7564. width: width,
  7565. height: height,
  7566. depth: depth,
  7567. widthSegments: widthSegments,
  7568. heightSegments: heightSegments,
  7569. depthSegments: depthSegments
  7570. };
  7571. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7572. this.mergeVertices();
  7573. }
  7574. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7575. BoxGeometry.prototype.constructor = BoxGeometry;
  7576. // BoxBufferGeometry
  7577. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7578. BufferGeometry.call( this );
  7579. this.type = 'BoxBufferGeometry';
  7580. this.parameters = {
  7581. width: width,
  7582. height: height,
  7583. depth: depth,
  7584. widthSegments: widthSegments,
  7585. heightSegments: heightSegments,
  7586. depthSegments: depthSegments
  7587. };
  7588. var scope = this;
  7589. width = width || 1;
  7590. height = height || 1;
  7591. depth = depth || 1;
  7592. // segments
  7593. widthSegments = Math.floor( widthSegments ) || 1;
  7594. heightSegments = Math.floor( heightSegments ) || 1;
  7595. depthSegments = Math.floor( depthSegments ) || 1;
  7596. // buffers
  7597. var indices = [];
  7598. var vertices = [];
  7599. var normals = [];
  7600. var uvs = [];
  7601. // helper variables
  7602. var numberOfVertices = 0;
  7603. var groupStart = 0;
  7604. // build each side of the box geometry
  7605. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7606. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7607. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7608. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7609. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7610. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7611. // build geometry
  7612. this.setIndex( indices );
  7613. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7614. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7615. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7616. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7617. var segmentWidth = width / gridX;
  7618. var segmentHeight = height / gridY;
  7619. var widthHalf = width / 2;
  7620. var heightHalf = height / 2;
  7621. var depthHalf = depth / 2;
  7622. var gridX1 = gridX + 1;
  7623. var gridY1 = gridY + 1;
  7624. var vertexCounter = 0;
  7625. var groupCount = 0;
  7626. var ix, iy;
  7627. var vector = new Vector3();
  7628. // generate vertices, normals and uvs
  7629. for ( iy = 0; iy < gridY1; iy ++ ) {
  7630. var y = iy * segmentHeight - heightHalf;
  7631. for ( ix = 0; ix < gridX1; ix ++ ) {
  7632. var x = ix * segmentWidth - widthHalf;
  7633. // set values to correct vector component
  7634. vector[ u ] = x * udir;
  7635. vector[ v ] = y * vdir;
  7636. vector[ w ] = depthHalf;
  7637. // now apply vector to vertex buffer
  7638. vertices.push( vector.x, vector.y, vector.z );
  7639. // set values to correct vector component
  7640. vector[ u ] = 0;
  7641. vector[ v ] = 0;
  7642. vector[ w ] = depth > 0 ? 1 : - 1;
  7643. // now apply vector to normal buffer
  7644. normals.push( vector.x, vector.y, vector.z );
  7645. // uvs
  7646. uvs.push( ix / gridX );
  7647. uvs.push( 1 - ( iy / gridY ) );
  7648. // counters
  7649. vertexCounter += 1;
  7650. }
  7651. }
  7652. // indices
  7653. // 1. you need three indices to draw a single face
  7654. // 2. a single segment consists of two faces
  7655. // 3. so we need to generate six (2*3) indices per segment
  7656. for ( iy = 0; iy < gridY; iy ++ ) {
  7657. for ( ix = 0; ix < gridX; ix ++ ) {
  7658. var a = numberOfVertices + ix + gridX1 * iy;
  7659. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7660. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7661. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7662. // faces
  7663. indices.push( a, b, d );
  7664. indices.push( b, c, d );
  7665. // increase counter
  7666. groupCount += 6;
  7667. }
  7668. }
  7669. // add a group to the geometry. this will ensure multi material support
  7670. scope.addGroup( groupStart, groupCount, materialIndex );
  7671. // calculate new start value for groups
  7672. groupStart += groupCount;
  7673. // update total number of vertices
  7674. numberOfVertices += vertexCounter;
  7675. }
  7676. }
  7677. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7678. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7679. /**
  7680. * Uniform Utilities
  7681. */
  7682. function cloneUniforms( src ) {
  7683. var dst = {};
  7684. for ( var u in src ) {
  7685. dst[ u ] = {};
  7686. for ( var p in src[ u ] ) {
  7687. var property = src[ u ][ p ];
  7688. if ( property && ( property.isColor ||
  7689. property.isMatrix3 || property.isMatrix4 ||
  7690. property.isVector2 || property.isVector3 || property.isVector4 ||
  7691. property.isTexture ) ) {
  7692. dst[ u ][ p ] = property.clone();
  7693. } else if ( Array.isArray( property ) ) {
  7694. dst[ u ][ p ] = property.slice();
  7695. } else {
  7696. dst[ u ][ p ] = property;
  7697. }
  7698. }
  7699. }
  7700. return dst;
  7701. }
  7702. function mergeUniforms( uniforms ) {
  7703. var merged = {};
  7704. for ( var u = 0; u < uniforms.length; u ++ ) {
  7705. var tmp = cloneUniforms( uniforms[ u ] );
  7706. for ( var p in tmp ) {
  7707. merged[ p ] = tmp[ p ];
  7708. }
  7709. }
  7710. return merged;
  7711. }
  7712. // Legacy
  7713. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7714. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7715. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7716. /**
  7717. * @author alteredq / http://alteredqualia.com/
  7718. *
  7719. * parameters = {
  7720. * defines: { "label" : "value" },
  7721. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7722. *
  7723. * fragmentShader: <string>,
  7724. * vertexShader: <string>,
  7725. *
  7726. * wireframe: <boolean>,
  7727. * wireframeLinewidth: <float>,
  7728. *
  7729. * lights: <bool>,
  7730. *
  7731. * skinning: <bool>,
  7732. * morphTargets: <bool>,
  7733. * morphNormals: <bool>
  7734. * }
  7735. */
  7736. function ShaderMaterial( parameters ) {
  7737. Material.call( this );
  7738. this.type = 'ShaderMaterial';
  7739. this.defines = {};
  7740. this.uniforms = {};
  7741. this.vertexShader = default_vertex;
  7742. this.fragmentShader = default_fragment;
  7743. this.linewidth = 1;
  7744. this.wireframe = false;
  7745. this.wireframeLinewidth = 1;
  7746. this.fog = false; // set to use scene fog
  7747. this.lights = false; // set to use scene lights
  7748. this.clipping = false; // set to use user-defined clipping planes
  7749. this.skinning = false; // set to use skinning attribute streams
  7750. this.morphTargets = false; // set to use morph targets
  7751. this.morphNormals = false; // set to use morph normals
  7752. this.extensions = {
  7753. derivatives: false, // set to use derivatives
  7754. fragDepth: false, // set to use fragment depth values
  7755. drawBuffers: false, // set to use draw buffers
  7756. shaderTextureLOD: false // set to use shader texture LOD
  7757. };
  7758. // When rendered geometry doesn't include these attributes but the material does,
  7759. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7760. this.defaultAttributeValues = {
  7761. 'color': [ 1, 1, 1 ],
  7762. 'uv': [ 0, 0 ],
  7763. 'uv2': [ 0, 0 ]
  7764. };
  7765. this.index0AttributeName = undefined;
  7766. this.uniformsNeedUpdate = false;
  7767. if ( parameters !== undefined ) {
  7768. if ( parameters.attributes !== undefined ) {
  7769. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7770. }
  7771. this.setValues( parameters );
  7772. }
  7773. }
  7774. ShaderMaterial.prototype = Object.create( Material.prototype );
  7775. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7776. ShaderMaterial.prototype.isShaderMaterial = true;
  7777. ShaderMaterial.prototype.copy = function ( source ) {
  7778. Material.prototype.copy.call( this, source );
  7779. this.fragmentShader = source.fragmentShader;
  7780. this.vertexShader = source.vertexShader;
  7781. this.uniforms = cloneUniforms( source.uniforms );
  7782. this.defines = Object.assign( {}, source.defines );
  7783. this.wireframe = source.wireframe;
  7784. this.wireframeLinewidth = source.wireframeLinewidth;
  7785. this.lights = source.lights;
  7786. this.clipping = source.clipping;
  7787. this.skinning = source.skinning;
  7788. this.morphTargets = source.morphTargets;
  7789. this.morphNormals = source.morphNormals;
  7790. this.extensions = source.extensions;
  7791. return this;
  7792. };
  7793. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7794. var data = Material.prototype.toJSON.call( this, meta );
  7795. data.uniforms = {};
  7796. for ( var name in this.uniforms ) {
  7797. var uniform = this.uniforms[ name ];
  7798. var value = uniform.value;
  7799. if ( value && value.isTexture ) {
  7800. data.uniforms[ name ] = {
  7801. type: 't',
  7802. value: value.toJSON( meta ).uuid
  7803. };
  7804. } else if ( value && value.isColor ) {
  7805. data.uniforms[ name ] = {
  7806. type: 'c',
  7807. value: value.getHex()
  7808. };
  7809. } else if ( value && value.isVector2 ) {
  7810. data.uniforms[ name ] = {
  7811. type: 'v2',
  7812. value: value.toArray()
  7813. };
  7814. } else if ( value && value.isVector3 ) {
  7815. data.uniforms[ name ] = {
  7816. type: 'v3',
  7817. value: value.toArray()
  7818. };
  7819. } else if ( value && value.isVector4 ) {
  7820. data.uniforms[ name ] = {
  7821. type: 'v4',
  7822. value: value.toArray()
  7823. };
  7824. } else if ( value && value.isMatrix3 ) {
  7825. data.uniforms[ name ] = {
  7826. type: 'm3',
  7827. value: value.toArray()
  7828. };
  7829. } else if ( value && value.isMatrix4 ) {
  7830. data.uniforms[ name ] = {
  7831. type: 'm4',
  7832. value: value.toArray()
  7833. };
  7834. } else {
  7835. data.uniforms[ name ] = {
  7836. value: value
  7837. };
  7838. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7839. }
  7840. }
  7841. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7842. data.vertexShader = this.vertexShader;
  7843. data.fragmentShader = this.fragmentShader;
  7844. var extensions = {};
  7845. for ( var key in this.extensions ) {
  7846. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7847. }
  7848. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7849. return data;
  7850. };
  7851. /**
  7852. * @author mrdoob / http://mrdoob.com/
  7853. * @author mikael emtinger / http://gomo.se/
  7854. * @author WestLangley / http://github.com/WestLangley
  7855. */
  7856. function Camera() {
  7857. Object3D.call( this );
  7858. this.type = 'Camera';
  7859. this.matrixWorldInverse = new Matrix4();
  7860. this.projectionMatrix = new Matrix4();
  7861. this.projectionMatrixInverse = new Matrix4();
  7862. }
  7863. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7864. constructor: Camera,
  7865. isCamera: true,
  7866. copy: function ( source, recursive ) {
  7867. Object3D.prototype.copy.call( this, source, recursive );
  7868. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7869. this.projectionMatrix.copy( source.projectionMatrix );
  7870. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7871. return this;
  7872. },
  7873. getWorldDirection: function ( target ) {
  7874. if ( target === undefined ) {
  7875. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7876. target = new Vector3();
  7877. }
  7878. this.updateMatrixWorld( true );
  7879. var e = this.matrixWorld.elements;
  7880. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7881. },
  7882. updateMatrixWorld: function ( force ) {
  7883. Object3D.prototype.updateMatrixWorld.call( this, force );
  7884. this.matrixWorldInverse.getInverse( this.matrixWorld );
  7885. },
  7886. clone: function () {
  7887. return new this.constructor().copy( this );
  7888. }
  7889. } );
  7890. /**
  7891. * @author mrdoob / http://mrdoob.com/
  7892. * @author greggman / http://games.greggman.com/
  7893. * @author zz85 / http://www.lab4games.net/zz85/blog
  7894. * @author tschw
  7895. */
  7896. function PerspectiveCamera( fov, aspect, near, far ) {
  7897. Camera.call( this );
  7898. this.type = 'PerspectiveCamera';
  7899. this.fov = fov !== undefined ? fov : 50;
  7900. this.zoom = 1;
  7901. this.near = near !== undefined ? near : 0.1;
  7902. this.far = far !== undefined ? far : 2000;
  7903. this.focus = 10;
  7904. this.aspect = aspect !== undefined ? aspect : 1;
  7905. this.view = null;
  7906. this.filmGauge = 35; // width of the film (default in millimeters)
  7907. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7908. this.updateProjectionMatrix();
  7909. }
  7910. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7911. constructor: PerspectiveCamera,
  7912. isPerspectiveCamera: true,
  7913. copy: function ( source, recursive ) {
  7914. Camera.prototype.copy.call( this, source, recursive );
  7915. this.fov = source.fov;
  7916. this.zoom = source.zoom;
  7917. this.near = source.near;
  7918. this.far = source.far;
  7919. this.focus = source.focus;
  7920. this.aspect = source.aspect;
  7921. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7922. this.filmGauge = source.filmGauge;
  7923. this.filmOffset = source.filmOffset;
  7924. return this;
  7925. },
  7926. /**
  7927. * Sets the FOV by focal length in respect to the current .filmGauge.
  7928. *
  7929. * The default film gauge is 35, so that the focal length can be specified for
  7930. * a 35mm (full frame) camera.
  7931. *
  7932. * Values for focal length and film gauge must have the same unit.
  7933. */
  7934. setFocalLength: function ( focalLength ) {
  7935. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7936. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7937. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7938. this.updateProjectionMatrix();
  7939. },
  7940. /**
  7941. * Calculates the focal length from the current .fov and .filmGauge.
  7942. */
  7943. getFocalLength: function () {
  7944. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  7945. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7946. },
  7947. getEffectiveFOV: function () {
  7948. return _Math.RAD2DEG * 2 * Math.atan(
  7949. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7950. },
  7951. getFilmWidth: function () {
  7952. // film not completely covered in portrait format (aspect < 1)
  7953. return this.filmGauge * Math.min( this.aspect, 1 );
  7954. },
  7955. getFilmHeight: function () {
  7956. // film not completely covered in landscape format (aspect > 1)
  7957. return this.filmGauge / Math.max( this.aspect, 1 );
  7958. },
  7959. /**
  7960. * Sets an offset in a larger frustum. This is useful for multi-window or
  7961. * multi-monitor/multi-machine setups.
  7962. *
  7963. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7964. * the monitors are in grid like this
  7965. *
  7966. * +---+---+---+
  7967. * | A | B | C |
  7968. * +---+---+---+
  7969. * | D | E | F |
  7970. * +---+---+---+
  7971. *
  7972. * then for each monitor you would call it like this
  7973. *
  7974. * var w = 1920;
  7975. * var h = 1080;
  7976. * var fullWidth = w * 3;
  7977. * var fullHeight = h * 2;
  7978. *
  7979. * --A--
  7980. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7981. * --B--
  7982. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7983. * --C--
  7984. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7985. * --D--
  7986. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7987. * --E--
  7988. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7989. * --F--
  7990. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7991. *
  7992. * Note there is no reason monitors have to be the same size or in a grid.
  7993. */
  7994. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  7995. this.aspect = fullWidth / fullHeight;
  7996. if ( this.view === null ) {
  7997. this.view = {
  7998. enabled: true,
  7999. fullWidth: 1,
  8000. fullHeight: 1,
  8001. offsetX: 0,
  8002. offsetY: 0,
  8003. width: 1,
  8004. height: 1
  8005. };
  8006. }
  8007. this.view.enabled = true;
  8008. this.view.fullWidth = fullWidth;
  8009. this.view.fullHeight = fullHeight;
  8010. this.view.offsetX = x;
  8011. this.view.offsetY = y;
  8012. this.view.width = width;
  8013. this.view.height = height;
  8014. this.updateProjectionMatrix();
  8015. },
  8016. clearViewOffset: function () {
  8017. if ( this.view !== null ) {
  8018. this.view.enabled = false;
  8019. }
  8020. this.updateProjectionMatrix();
  8021. },
  8022. updateProjectionMatrix: function () {
  8023. var near = this.near,
  8024. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8025. height = 2 * top,
  8026. width = this.aspect * height,
  8027. left = - 0.5 * width,
  8028. view = this.view;
  8029. if ( this.view !== null && this.view.enabled ) {
  8030. var fullWidth = view.fullWidth,
  8031. fullHeight = view.fullHeight;
  8032. left += view.offsetX * width / fullWidth;
  8033. top -= view.offsetY * height / fullHeight;
  8034. width *= view.width / fullWidth;
  8035. height *= view.height / fullHeight;
  8036. }
  8037. var skew = this.filmOffset;
  8038. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8039. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8040. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8041. },
  8042. toJSON: function ( meta ) {
  8043. var data = Object3D.prototype.toJSON.call( this, meta );
  8044. data.object.fov = this.fov;
  8045. data.object.zoom = this.zoom;
  8046. data.object.near = this.near;
  8047. data.object.far = this.far;
  8048. data.object.focus = this.focus;
  8049. data.object.aspect = this.aspect;
  8050. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8051. data.object.filmGauge = this.filmGauge;
  8052. data.object.filmOffset = this.filmOffset;
  8053. return data;
  8054. }
  8055. } );
  8056. /**
  8057. * Camera for rendering cube maps
  8058. * - renders scene into axis-aligned cube
  8059. *
  8060. * @author alteredq / http://alteredqualia.com/
  8061. */
  8062. var fov = 90, aspect = 1;
  8063. function CubeCamera( near, far, cubeResolution, options ) {
  8064. Object3D.call( this );
  8065. this.type = 'CubeCamera';
  8066. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8067. cameraPX.up.set( 0, - 1, 0 );
  8068. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8069. this.add( cameraPX );
  8070. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8071. cameraNX.up.set( 0, - 1, 0 );
  8072. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8073. this.add( cameraNX );
  8074. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8075. cameraPY.up.set( 0, 0, 1 );
  8076. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8077. this.add( cameraPY );
  8078. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8079. cameraNY.up.set( 0, 0, - 1 );
  8080. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8081. this.add( cameraNY );
  8082. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8083. cameraPZ.up.set( 0, - 1, 0 );
  8084. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8085. this.add( cameraPZ );
  8086. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8087. cameraNZ.up.set( 0, - 1, 0 );
  8088. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8089. this.add( cameraNZ );
  8090. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  8091. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  8092. this.renderTarget.texture.name = "CubeCamera";
  8093. this.update = function ( renderer, scene ) {
  8094. if ( this.parent === null ) this.updateMatrixWorld();
  8095. var currentRenderTarget = renderer.getRenderTarget();
  8096. var renderTarget = this.renderTarget;
  8097. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8098. renderTarget.texture.generateMipmaps = false;
  8099. renderer.setRenderTarget( renderTarget, 0 );
  8100. renderer.render( scene, cameraPX );
  8101. renderer.setRenderTarget( renderTarget, 1 );
  8102. renderer.render( scene, cameraNX );
  8103. renderer.setRenderTarget( renderTarget, 2 );
  8104. renderer.render( scene, cameraPY );
  8105. renderer.setRenderTarget( renderTarget, 3 );
  8106. renderer.render( scene, cameraNY );
  8107. renderer.setRenderTarget( renderTarget, 4 );
  8108. renderer.render( scene, cameraPZ );
  8109. renderTarget.texture.generateMipmaps = generateMipmaps;
  8110. renderer.setRenderTarget( renderTarget, 5 );
  8111. renderer.render( scene, cameraNZ );
  8112. renderer.setRenderTarget( currentRenderTarget );
  8113. };
  8114. this.clear = function ( renderer, color, depth, stencil ) {
  8115. var currentRenderTarget = renderer.getRenderTarget();
  8116. var renderTarget = this.renderTarget;
  8117. for ( var i = 0; i < 6; i ++ ) {
  8118. renderer.setRenderTarget( renderTarget, i );
  8119. renderer.clear( color, depth, stencil );
  8120. }
  8121. renderer.setRenderTarget( currentRenderTarget );
  8122. };
  8123. }
  8124. CubeCamera.prototype = Object.create( Object3D.prototype );
  8125. CubeCamera.prototype.constructor = CubeCamera;
  8126. /**
  8127. * @author alteredq / http://alteredqualia.com
  8128. * @author WestLangley / http://github.com/WestLangley
  8129. */
  8130. function WebGLRenderTargetCube( width, height, options ) {
  8131. WebGLRenderTarget.call( this, width, height, options );
  8132. }
  8133. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  8134. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  8135. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  8136. WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8137. this.texture.type = texture.type;
  8138. this.texture.format = texture.format;
  8139. this.texture.encoding = texture.encoding;
  8140. var scene = new Scene();
  8141. var shader = {
  8142. uniforms: {
  8143. tEquirect: { value: null },
  8144. },
  8145. vertexShader: [
  8146. "varying vec3 vWorldDirection;",
  8147. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8148. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8149. "}",
  8150. "void main() {",
  8151. " vWorldDirection = transformDirection( position, modelMatrix );",
  8152. " #include <begin_vertex>",
  8153. " #include <project_vertex>",
  8154. "}"
  8155. ].join( '\n' ),
  8156. fragmentShader: [
  8157. "uniform sampler2D tEquirect;",
  8158. "varying vec3 vWorldDirection;",
  8159. "#define RECIPROCAL_PI 0.31830988618",
  8160. "#define RECIPROCAL_PI2 0.15915494",
  8161. "void main() {",
  8162. " vec3 direction = normalize( vWorldDirection );",
  8163. " vec2 sampleUV;",
  8164. " sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
  8165. " sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  8166. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8167. "}"
  8168. ].join( '\n' ),
  8169. };
  8170. var material = new ShaderMaterial( {
  8171. type: 'CubemapFromEquirect',
  8172. uniforms: cloneUniforms( shader.uniforms ),
  8173. vertexShader: shader.vertexShader,
  8174. fragmentShader: shader.fragmentShader,
  8175. side: BackSide,
  8176. blending: NoBlending
  8177. } );
  8178. material.uniforms.tEquirect.value = texture;
  8179. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8180. scene.add( mesh );
  8181. var camera = new CubeCamera( 1, 10, 1 );
  8182. camera.renderTarget = this;
  8183. camera.renderTarget.texture.name = 'CubeCameraTexture';
  8184. camera.update( renderer, scene );
  8185. mesh.geometry.dispose();
  8186. mesh.material.dispose();
  8187. return this;
  8188. };
  8189. /**
  8190. * @author alteredq / http://alteredqualia.com/
  8191. */
  8192. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8193. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8194. this.image = { data: data, width: width, height: height };
  8195. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8196. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8197. this.generateMipmaps = false;
  8198. this.flipY = false;
  8199. this.unpackAlignment = 1;
  8200. }
  8201. DataTexture.prototype = Object.create( Texture.prototype );
  8202. DataTexture.prototype.constructor = DataTexture;
  8203. DataTexture.prototype.isDataTexture = true;
  8204. /**
  8205. * @author bhouston / http://clara.io
  8206. */
  8207. var _vector1, _vector2, _normalMatrix;
  8208. function Plane( normal, constant ) {
  8209. // normal is assumed to be normalized
  8210. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  8211. this.constant = ( constant !== undefined ) ? constant : 0;
  8212. }
  8213. Object.assign( Plane.prototype, {
  8214. isPlane: true,
  8215. set: function ( normal, constant ) {
  8216. this.normal.copy( normal );
  8217. this.constant = constant;
  8218. return this;
  8219. },
  8220. setComponents: function ( x, y, z, w ) {
  8221. this.normal.set( x, y, z );
  8222. this.constant = w;
  8223. return this;
  8224. },
  8225. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  8226. this.normal.copy( normal );
  8227. this.constant = - point.dot( this.normal );
  8228. return this;
  8229. },
  8230. setFromCoplanarPoints: function ( a, b, c ) {
  8231. if ( _vector1 === undefined ) {
  8232. _vector1 = new Vector3();
  8233. _vector2 = new Vector3();
  8234. }
  8235. var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  8236. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8237. this.setFromNormalAndCoplanarPoint( normal, a );
  8238. return this;
  8239. },
  8240. clone: function () {
  8241. return new this.constructor().copy( this );
  8242. },
  8243. copy: function ( plane ) {
  8244. this.normal.copy( plane.normal );
  8245. this.constant = plane.constant;
  8246. return this;
  8247. },
  8248. normalize: function () {
  8249. // Note: will lead to a divide by zero if the plane is invalid.
  8250. var inverseNormalLength = 1.0 / this.normal.length();
  8251. this.normal.multiplyScalar( inverseNormalLength );
  8252. this.constant *= inverseNormalLength;
  8253. return this;
  8254. },
  8255. negate: function () {
  8256. this.constant *= - 1;
  8257. this.normal.negate();
  8258. return this;
  8259. },
  8260. distanceToPoint: function ( point ) {
  8261. return this.normal.dot( point ) + this.constant;
  8262. },
  8263. distanceToSphere: function ( sphere ) {
  8264. return this.distanceToPoint( sphere.center ) - sphere.radius;
  8265. },
  8266. projectPoint: function ( point, target ) {
  8267. if ( target === undefined ) {
  8268. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  8269. target = new Vector3();
  8270. }
  8271. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  8272. },
  8273. intersectLine: function ( line, target ) {
  8274. if ( _vector1 === undefined ) _vector1 = new Vector3();
  8275. if ( target === undefined ) {
  8276. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  8277. target = new Vector3();
  8278. }
  8279. var direction = line.delta( _vector1 );
  8280. var denominator = this.normal.dot( direction );
  8281. if ( denominator === 0 ) {
  8282. // line is coplanar, return origin
  8283. if ( this.distanceToPoint( line.start ) === 0 ) {
  8284. return target.copy( line.start );
  8285. }
  8286. // Unsure if this is the correct method to handle this case.
  8287. return undefined;
  8288. }
  8289. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  8290. if ( t < 0 || t > 1 ) {
  8291. return undefined;
  8292. }
  8293. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  8294. },
  8295. intersectsLine: function ( line ) {
  8296. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  8297. var startSign = this.distanceToPoint( line.start );
  8298. var endSign = this.distanceToPoint( line.end );
  8299. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  8300. },
  8301. intersectsBox: function ( box ) {
  8302. return box.intersectsPlane( this );
  8303. },
  8304. intersectsSphere: function ( sphere ) {
  8305. return sphere.intersectsPlane( this );
  8306. },
  8307. coplanarPoint: function ( target ) {
  8308. if ( target === undefined ) {
  8309. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  8310. target = new Vector3();
  8311. }
  8312. return target.copy( this.normal ).multiplyScalar( - this.constant );
  8313. },
  8314. applyMatrix4: function ( matrix, optionalNormalMatrix ) {
  8315. if ( _normalMatrix === undefined ) {
  8316. _normalMatrix = new Matrix3();
  8317. _vector1 = new Vector3();
  8318. }
  8319. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  8320. var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  8321. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  8322. this.constant = - referencePoint.dot( normal );
  8323. return this;
  8324. },
  8325. translate: function ( offset ) {
  8326. this.constant -= offset.dot( this.normal );
  8327. return this;
  8328. },
  8329. equals: function ( plane ) {
  8330. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  8331. }
  8332. } );
  8333. /**
  8334. * @author mrdoob / http://mrdoob.com/
  8335. * @author alteredq / http://alteredqualia.com/
  8336. * @author bhouston / http://clara.io
  8337. */
  8338. var _sphere;
  8339. var _vector$4;
  8340. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8341. this.planes = [
  8342. ( p0 !== undefined ) ? p0 : new Plane(),
  8343. ( p1 !== undefined ) ? p1 : new Plane(),
  8344. ( p2 !== undefined ) ? p2 : new Plane(),
  8345. ( p3 !== undefined ) ? p3 : new Plane(),
  8346. ( p4 !== undefined ) ? p4 : new Plane(),
  8347. ( p5 !== undefined ) ? p5 : new Plane()
  8348. ];
  8349. }
  8350. Object.assign( Frustum.prototype, {
  8351. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8352. var planes = this.planes;
  8353. planes[ 0 ].copy( p0 );
  8354. planes[ 1 ].copy( p1 );
  8355. planes[ 2 ].copy( p2 );
  8356. planes[ 3 ].copy( p3 );
  8357. planes[ 4 ].copy( p4 );
  8358. planes[ 5 ].copy( p5 );
  8359. return this;
  8360. },
  8361. clone: function () {
  8362. return new this.constructor().copy( this );
  8363. },
  8364. copy: function ( frustum ) {
  8365. var planes = this.planes;
  8366. for ( var i = 0; i < 6; i ++ ) {
  8367. planes[ i ].copy( frustum.planes[ i ] );
  8368. }
  8369. return this;
  8370. },
  8371. setFromMatrix: function ( m ) {
  8372. var planes = this.planes;
  8373. var me = m.elements;
  8374. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8375. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8376. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8377. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8378. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8379. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8380. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8381. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8382. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8383. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8384. return this;
  8385. },
  8386. intersectsObject: function ( object ) {
  8387. if ( _sphere === undefined ) _sphere = new Sphere();
  8388. var geometry = object.geometry;
  8389. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8390. _sphere.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  8391. return this.intersectsSphere( _sphere );
  8392. },
  8393. intersectsSprite: function ( sprite ) {
  8394. if ( _sphere === undefined ) _sphere = new Sphere();
  8395. _sphere.center.set( 0, 0, 0 );
  8396. _sphere.radius = 0.7071067811865476;
  8397. _sphere.applyMatrix4( sprite.matrixWorld );
  8398. return this.intersectsSphere( _sphere );
  8399. },
  8400. intersectsSphere: function ( sphere ) {
  8401. var planes = this.planes;
  8402. var center = sphere.center;
  8403. var negRadius = - sphere.radius;
  8404. for ( var i = 0; i < 6; i ++ ) {
  8405. var distance = planes[ i ].distanceToPoint( center );
  8406. if ( distance < negRadius ) {
  8407. return false;
  8408. }
  8409. }
  8410. return true;
  8411. },
  8412. intersectsBox: function ( box ) {
  8413. if ( _vector$4 === undefined ) _vector$4 = new Vector3();
  8414. var planes = this.planes;
  8415. for ( var i = 0; i < 6; i ++ ) {
  8416. var plane = planes[ i ];
  8417. // corner at max distance
  8418. _vector$4.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8419. _vector$4.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8420. _vector$4.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8421. if ( plane.distanceToPoint( _vector$4 ) < 0 ) {
  8422. return false;
  8423. }
  8424. }
  8425. return true;
  8426. },
  8427. containsPoint: function ( point ) {
  8428. var planes = this.planes;
  8429. for ( var i = 0; i < 6; i ++ ) {
  8430. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8431. return false;
  8432. }
  8433. }
  8434. return true;
  8435. }
  8436. } );
  8437. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8438. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8439. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8440. 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";
  8441. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8442. var begin_vertex = "vec3 transformed = vec3( position );";
  8443. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8444. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}";
  8445. 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";
  8446. 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";
  8447. 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";
  8448. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  8449. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  8450. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8451. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8452. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8453. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8454. 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\tvec3 clearCoatNormal;\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}";
  8455. 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";
  8456. 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";
  8457. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8458. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  8459. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8460. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8461. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8462. 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}";
  8463. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8464. 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( USE_CLEARCOAT_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( USE_CLEARCOAT_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  8465. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8466. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8467. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8468. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8469. 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";
  8470. 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";
  8471. 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";
  8472. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  8473. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8474. 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";
  8475. 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";
  8476. 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 vec3 viewDir, const in vec3 normal, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t vec3 reflectVec = reflect( -viewDir, normal );\n\t\t#else\n\t\t vec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( 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";
  8477. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8478. 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)";
  8479. 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";
  8480. 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 ccDotNL = saturate( dot( geometry.clearCoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n}\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 ccDotNV = saturate( dot( geometry.clearCoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearCoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\tfloat clearCoatInv = 1.0 - clearCoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;\n\treflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness );\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}";
  8481. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tgeometry.clearCoatNormal = clearCoatNormal;\n#else\n\tgeometry.clearCoatNormal = geometryNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tdirectLight.color *= all( 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#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\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#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\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";
  8482. 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 radiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, Material_BlinnShininessExponent( material ), maxMipLevel );\n\t#ifndef STANDARD\n\t\t#ifdef USE_CLEARCOAT_NORMALMAP\n\t\t\tclearCoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearCoatNormal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );\n\t\t#else\n\t\t\tclearCoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );\n\t\t#endif\n\t#endif\n#endif";
  8483. 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";
  8484. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  8485. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  8486. 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";
  8487. 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";
  8488. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8489. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8490. 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";
  8491. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  8492. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8493. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8494. 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";
  8495. 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";
  8496. 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";
  8497. 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\nvec3 geometryNormal = normal;";
  8498. 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, normalScale, normalMap );\n\t\t#endif\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  8499. 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#endif\n#endif\n#if ( defined ( USE_NORMALMAP ) && !defined ( OBJECTSPACE_NORMALMAP )) || defined ( USE_CLEARCOAT_NORMALMAP )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec2 normalScale, in sampler2D normalMap ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy *= normalScale;\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8500. var clearcoat_normal_fragment_begin = "#ifdef USE_CLEARCOAT_NORMALMAP\n vec3 clearCoatNormal = geometryNormal;\n#endif";
  8501. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 vTBN = mat3( tangent, bitangent, clearCoatNormal );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy = clearCoatNormalScale * mapN.xy;\n\t\tclearCoatNormal = normalize( vTBN * mapN );\n\t#else\n\t\tclearCoatNormal = perturbNormal2Arb( - vViewPosition, clearCoatNormal, clearCoatNormalScale, clearCoatNormalMap );\n\t#endif\n#endif";
  8502. var clearcoat_normalmap_pars_fragment = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearCoatNormalMap;\n\tuniform vec2 clearCoatNormalScale;\n#endif";
  8503. 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}";
  8504. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8505. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  8506. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8507. 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";
  8508. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8509. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8510. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\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\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#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";
  8511. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
  8512. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif";
  8513. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= 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_LIGHT_SHADOWS > 0\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= 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_LIGHT_SHADOWS > 0\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= 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}";
  8514. 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";
  8515. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  8516. 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";
  8517. 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";
  8518. 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";
  8519. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8520. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8521. 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}";
  8522. var uv_pars_fragment = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n\tvarying vec2 vUv;\n#endif";
  8523. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8524. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_CLEARCOAT_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";
  8525. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8526. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  8527. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  8528. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  8529. 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}";
  8530. 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}";
  8531. 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}";
  8532. 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}";
  8533. 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}";
  8534. 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}";
  8535. 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}";
  8536. 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}";
  8537. 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}";
  8538. 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}";
  8539. 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}";
  8540. 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}";
  8541. 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}";
  8542. 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}";
  8543. 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}";
  8544. 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}";
  8545. 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}";
  8546. 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}";
  8547. 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}";
  8548. 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}";
  8549. 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 <clearcoat_normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\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}";
  8550. 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}";
  8551. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  8552. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_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>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) ) || defined( USE_CLEARCOAT_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  8553. 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}";
  8554. 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}";
  8555. 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}";
  8556. 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}";
  8557. 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}";
  8558. 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}";
  8559. var ShaderChunk = {
  8560. alphamap_fragment: alphamap_fragment,
  8561. alphamap_pars_fragment: alphamap_pars_fragment,
  8562. alphatest_fragment: alphatest_fragment,
  8563. aomap_fragment: aomap_fragment,
  8564. aomap_pars_fragment: aomap_pars_fragment,
  8565. begin_vertex: begin_vertex,
  8566. beginnormal_vertex: beginnormal_vertex,
  8567. bsdfs: bsdfs,
  8568. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8569. clipping_planes_fragment: clipping_planes_fragment,
  8570. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8571. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8572. clipping_planes_vertex: clipping_planes_vertex,
  8573. color_fragment: color_fragment,
  8574. color_pars_fragment: color_pars_fragment,
  8575. color_pars_vertex: color_pars_vertex,
  8576. color_vertex: color_vertex,
  8577. common: common,
  8578. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8579. defaultnormal_vertex: defaultnormal_vertex,
  8580. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8581. displacementmap_vertex: displacementmap_vertex,
  8582. emissivemap_fragment: emissivemap_fragment,
  8583. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8584. encodings_fragment: encodings_fragment,
  8585. encodings_pars_fragment: encodings_pars_fragment,
  8586. envmap_fragment: envmap_fragment,
  8587. envmap_pars_fragment: envmap_pars_fragment,
  8588. envmap_pars_vertex: envmap_pars_vertex,
  8589. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8590. envmap_vertex: envmap_vertex,
  8591. fog_vertex: fog_vertex,
  8592. fog_pars_vertex: fog_pars_vertex,
  8593. fog_fragment: fog_fragment,
  8594. fog_pars_fragment: fog_pars_fragment,
  8595. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8596. lightmap_fragment: lightmap_fragment,
  8597. lightmap_pars_fragment: lightmap_pars_fragment,
  8598. lights_lambert_vertex: lights_lambert_vertex,
  8599. lights_pars_begin: lights_pars_begin,
  8600. lights_phong_fragment: lights_phong_fragment,
  8601. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8602. lights_physical_fragment: lights_physical_fragment,
  8603. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8604. lights_fragment_begin: lights_fragment_begin,
  8605. lights_fragment_maps: lights_fragment_maps,
  8606. lights_fragment_end: lights_fragment_end,
  8607. logdepthbuf_fragment: logdepthbuf_fragment,
  8608. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8609. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8610. logdepthbuf_vertex: logdepthbuf_vertex,
  8611. map_fragment: map_fragment,
  8612. map_pars_fragment: map_pars_fragment,
  8613. map_particle_fragment: map_particle_fragment,
  8614. map_particle_pars_fragment: map_particle_pars_fragment,
  8615. metalnessmap_fragment: metalnessmap_fragment,
  8616. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8617. morphnormal_vertex: morphnormal_vertex,
  8618. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8619. morphtarget_vertex: morphtarget_vertex,
  8620. normal_fragment_begin: normal_fragment_begin,
  8621. normal_fragment_maps: normal_fragment_maps,
  8622. normalmap_pars_fragment: normalmap_pars_fragment,
  8623. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  8624. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  8625. clearcoat_normalmap_pars_fragment: clearcoat_normalmap_pars_fragment,
  8626. packing: packing,
  8627. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8628. project_vertex: project_vertex,
  8629. dithering_fragment: dithering_fragment,
  8630. dithering_pars_fragment: dithering_pars_fragment,
  8631. roughnessmap_fragment: roughnessmap_fragment,
  8632. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8633. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8634. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8635. shadowmap_vertex: shadowmap_vertex,
  8636. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8637. skinbase_vertex: skinbase_vertex,
  8638. skinning_pars_vertex: skinning_pars_vertex,
  8639. skinning_vertex: skinning_vertex,
  8640. skinnormal_vertex: skinnormal_vertex,
  8641. specularmap_fragment: specularmap_fragment,
  8642. specularmap_pars_fragment: specularmap_pars_fragment,
  8643. tonemapping_fragment: tonemapping_fragment,
  8644. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8645. uv_pars_fragment: uv_pars_fragment,
  8646. uv_pars_vertex: uv_pars_vertex,
  8647. uv_vertex: uv_vertex,
  8648. uv2_pars_fragment: uv2_pars_fragment,
  8649. uv2_pars_vertex: uv2_pars_vertex,
  8650. uv2_vertex: uv2_vertex,
  8651. worldpos_vertex: worldpos_vertex,
  8652. background_frag: background_frag,
  8653. background_vert: background_vert,
  8654. cube_frag: cube_frag,
  8655. cube_vert: cube_vert,
  8656. depth_frag: depth_frag,
  8657. depth_vert: depth_vert,
  8658. distanceRGBA_frag: distanceRGBA_frag,
  8659. distanceRGBA_vert: distanceRGBA_vert,
  8660. equirect_frag: equirect_frag,
  8661. equirect_vert: equirect_vert,
  8662. linedashed_frag: linedashed_frag,
  8663. linedashed_vert: linedashed_vert,
  8664. meshbasic_frag: meshbasic_frag,
  8665. meshbasic_vert: meshbasic_vert,
  8666. meshlambert_frag: meshlambert_frag,
  8667. meshlambert_vert: meshlambert_vert,
  8668. meshmatcap_frag: meshmatcap_frag,
  8669. meshmatcap_vert: meshmatcap_vert,
  8670. meshphong_frag: meshphong_frag,
  8671. meshphong_vert: meshphong_vert,
  8672. meshphysical_frag: meshphysical_frag,
  8673. meshphysical_vert: meshphysical_vert,
  8674. normal_frag: normal_frag,
  8675. normal_vert: normal_vert,
  8676. points_frag: points_frag,
  8677. points_vert: points_vert,
  8678. shadow_frag: shadow_frag,
  8679. shadow_vert: shadow_vert,
  8680. sprite_frag: sprite_frag,
  8681. sprite_vert: sprite_vert
  8682. };
  8683. /**
  8684. * Uniforms library for shared webgl shaders
  8685. */
  8686. var UniformsLib = {
  8687. common: {
  8688. diffuse: { value: new Color( 0xeeeeee ) },
  8689. opacity: { value: 1.0 },
  8690. map: { value: null },
  8691. uvTransform: { value: new Matrix3() },
  8692. alphaMap: { value: null },
  8693. },
  8694. specularmap: {
  8695. specularMap: { value: null },
  8696. },
  8697. envmap: {
  8698. envMap: { value: null },
  8699. flipEnvMap: { value: - 1 },
  8700. reflectivity: { value: 1.0 },
  8701. refractionRatio: { value: 0.98 },
  8702. maxMipLevel: { value: 0 }
  8703. },
  8704. aomap: {
  8705. aoMap: { value: null },
  8706. aoMapIntensity: { value: 1 }
  8707. },
  8708. lightmap: {
  8709. lightMap: { value: null },
  8710. lightMapIntensity: { value: 1 }
  8711. },
  8712. emissivemap: {
  8713. emissiveMap: { value: null }
  8714. },
  8715. bumpmap: {
  8716. bumpMap: { value: null },
  8717. bumpScale: { value: 1 }
  8718. },
  8719. normalmap: {
  8720. normalMap: { value: null },
  8721. normalScale: { value: new Vector2( 1, 1 ) }
  8722. },
  8723. displacementmap: {
  8724. displacementMap: { value: null },
  8725. displacementScale: { value: 1 },
  8726. displacementBias: { value: 0 }
  8727. },
  8728. roughnessmap: {
  8729. roughnessMap: { value: null }
  8730. },
  8731. metalnessmap: {
  8732. metalnessMap: { value: null }
  8733. },
  8734. gradientmap: {
  8735. gradientMap: { value: null }
  8736. },
  8737. fog: {
  8738. fogDensity: { value: 0.00025 },
  8739. fogNear: { value: 1 },
  8740. fogFar: { value: 2000 },
  8741. fogColor: { value: new Color( 0xffffff ) }
  8742. },
  8743. lights: {
  8744. ambientLightColor: { value: [] },
  8745. lightProbe: { value: [] },
  8746. directionalLights: { value: [], properties: {
  8747. direction: {},
  8748. color: {},
  8749. shadow: {},
  8750. shadowBias: {},
  8751. shadowRadius: {},
  8752. shadowMapSize: {}
  8753. } },
  8754. directionalShadowMap: { value: [] },
  8755. directionalShadowMatrix: { value: [] },
  8756. spotLights: { value: [], properties: {
  8757. color: {},
  8758. position: {},
  8759. direction: {},
  8760. distance: {},
  8761. coneCos: {},
  8762. penumbraCos: {},
  8763. decay: {},
  8764. shadow: {},
  8765. shadowBias: {},
  8766. shadowRadius: {},
  8767. shadowMapSize: {}
  8768. } },
  8769. spotShadowMap: { value: [] },
  8770. spotShadowMatrix: { value: [] },
  8771. pointLights: { value: [], properties: {
  8772. color: {},
  8773. position: {},
  8774. decay: {},
  8775. distance: {},
  8776. shadow: {},
  8777. shadowBias: {},
  8778. shadowRadius: {},
  8779. shadowMapSize: {},
  8780. shadowCameraNear: {},
  8781. shadowCameraFar: {}
  8782. } },
  8783. pointShadowMap: { value: [] },
  8784. pointShadowMatrix: { value: [] },
  8785. hemisphereLights: { value: [], properties: {
  8786. direction: {},
  8787. skyColor: {},
  8788. groundColor: {}
  8789. } },
  8790. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8791. rectAreaLights: { value: [], properties: {
  8792. color: {},
  8793. position: {},
  8794. width: {},
  8795. height: {}
  8796. } }
  8797. },
  8798. points: {
  8799. diffuse: { value: new Color( 0xeeeeee ) },
  8800. opacity: { value: 1.0 },
  8801. size: { value: 1.0 },
  8802. scale: { value: 1.0 },
  8803. map: { value: null },
  8804. uvTransform: { value: new Matrix3() }
  8805. },
  8806. sprite: {
  8807. diffuse: { value: new Color( 0xeeeeee ) },
  8808. opacity: { value: 1.0 },
  8809. center: { value: new Vector2( 0.5, 0.5 ) },
  8810. rotation: { value: 0.0 },
  8811. map: { value: null },
  8812. uvTransform: { value: new Matrix3() }
  8813. }
  8814. };
  8815. /**
  8816. * @author alteredq / http://alteredqualia.com/
  8817. * @author mrdoob / http://mrdoob.com/
  8818. * @author mikael emtinger / http://gomo.se/
  8819. */
  8820. var ShaderLib = {
  8821. basic: {
  8822. uniforms: mergeUniforms( [
  8823. UniformsLib.common,
  8824. UniformsLib.specularmap,
  8825. UniformsLib.envmap,
  8826. UniformsLib.aomap,
  8827. UniformsLib.lightmap,
  8828. UniformsLib.fog
  8829. ] ),
  8830. vertexShader: ShaderChunk.meshbasic_vert,
  8831. fragmentShader: ShaderChunk.meshbasic_frag
  8832. },
  8833. lambert: {
  8834. uniforms: mergeUniforms( [
  8835. UniformsLib.common,
  8836. UniformsLib.specularmap,
  8837. UniformsLib.envmap,
  8838. UniformsLib.aomap,
  8839. UniformsLib.lightmap,
  8840. UniformsLib.emissivemap,
  8841. UniformsLib.fog,
  8842. UniformsLib.lights,
  8843. {
  8844. emissive: { value: new Color( 0x000000 ) }
  8845. }
  8846. ] ),
  8847. vertexShader: ShaderChunk.meshlambert_vert,
  8848. fragmentShader: ShaderChunk.meshlambert_frag
  8849. },
  8850. phong: {
  8851. uniforms: mergeUniforms( [
  8852. UniformsLib.common,
  8853. UniformsLib.specularmap,
  8854. UniformsLib.envmap,
  8855. UniformsLib.aomap,
  8856. UniformsLib.lightmap,
  8857. UniformsLib.emissivemap,
  8858. UniformsLib.bumpmap,
  8859. UniformsLib.normalmap,
  8860. UniformsLib.displacementmap,
  8861. UniformsLib.gradientmap,
  8862. UniformsLib.fog,
  8863. UniformsLib.lights,
  8864. {
  8865. emissive: { value: new Color( 0x000000 ) },
  8866. specular: { value: new Color( 0x111111 ) },
  8867. shininess: { value: 30 }
  8868. }
  8869. ] ),
  8870. vertexShader: ShaderChunk.meshphong_vert,
  8871. fragmentShader: ShaderChunk.meshphong_frag
  8872. },
  8873. standard: {
  8874. uniforms: mergeUniforms( [
  8875. UniformsLib.common,
  8876. UniformsLib.envmap,
  8877. UniformsLib.aomap,
  8878. UniformsLib.lightmap,
  8879. UniformsLib.emissivemap,
  8880. UniformsLib.bumpmap,
  8881. UniformsLib.normalmap,
  8882. UniformsLib.displacementmap,
  8883. UniformsLib.roughnessmap,
  8884. UniformsLib.metalnessmap,
  8885. UniformsLib.fog,
  8886. UniformsLib.lights,
  8887. {
  8888. emissive: { value: new Color( 0x000000 ) },
  8889. roughness: { value: 0.5 },
  8890. metalness: { value: 0.5 },
  8891. envMapIntensity: { value: 1 } // temporary
  8892. }
  8893. ] ),
  8894. vertexShader: ShaderChunk.meshphysical_vert,
  8895. fragmentShader: ShaderChunk.meshphysical_frag
  8896. },
  8897. matcap: {
  8898. uniforms: mergeUniforms( [
  8899. UniformsLib.common,
  8900. UniformsLib.bumpmap,
  8901. UniformsLib.normalmap,
  8902. UniformsLib.displacementmap,
  8903. UniformsLib.fog,
  8904. {
  8905. matcap: { value: null }
  8906. }
  8907. ] ),
  8908. vertexShader: ShaderChunk.meshmatcap_vert,
  8909. fragmentShader: ShaderChunk.meshmatcap_frag
  8910. },
  8911. points: {
  8912. uniforms: mergeUniforms( [
  8913. UniformsLib.points,
  8914. UniformsLib.fog
  8915. ] ),
  8916. vertexShader: ShaderChunk.points_vert,
  8917. fragmentShader: ShaderChunk.points_frag
  8918. },
  8919. dashed: {
  8920. uniforms: mergeUniforms( [
  8921. UniformsLib.common,
  8922. UniformsLib.fog,
  8923. {
  8924. scale: { value: 1 },
  8925. dashSize: { value: 1 },
  8926. totalSize: { value: 2 }
  8927. }
  8928. ] ),
  8929. vertexShader: ShaderChunk.linedashed_vert,
  8930. fragmentShader: ShaderChunk.linedashed_frag
  8931. },
  8932. depth: {
  8933. uniforms: mergeUniforms( [
  8934. UniformsLib.common,
  8935. UniformsLib.displacementmap
  8936. ] ),
  8937. vertexShader: ShaderChunk.depth_vert,
  8938. fragmentShader: ShaderChunk.depth_frag
  8939. },
  8940. normal: {
  8941. uniforms: mergeUniforms( [
  8942. UniformsLib.common,
  8943. UniformsLib.bumpmap,
  8944. UniformsLib.normalmap,
  8945. UniformsLib.displacementmap,
  8946. {
  8947. opacity: { value: 1.0 }
  8948. }
  8949. ] ),
  8950. vertexShader: ShaderChunk.normal_vert,
  8951. fragmentShader: ShaderChunk.normal_frag
  8952. },
  8953. sprite: {
  8954. uniforms: mergeUniforms( [
  8955. UniformsLib.sprite,
  8956. UniformsLib.fog
  8957. ] ),
  8958. vertexShader: ShaderChunk.sprite_vert,
  8959. fragmentShader: ShaderChunk.sprite_frag
  8960. },
  8961. background: {
  8962. uniforms: {
  8963. uvTransform: { value: new Matrix3() },
  8964. t2D: { value: null },
  8965. },
  8966. vertexShader: ShaderChunk.background_vert,
  8967. fragmentShader: ShaderChunk.background_frag
  8968. },
  8969. /* -------------------------------------------------------------------------
  8970. // Cube map shader
  8971. ------------------------------------------------------------------------- */
  8972. cube: {
  8973. uniforms: {
  8974. tCube: { value: null },
  8975. tFlip: { value: - 1 },
  8976. opacity: { value: 1.0 }
  8977. },
  8978. vertexShader: ShaderChunk.cube_vert,
  8979. fragmentShader: ShaderChunk.cube_frag
  8980. },
  8981. equirect: {
  8982. uniforms: {
  8983. tEquirect: { value: null },
  8984. },
  8985. vertexShader: ShaderChunk.equirect_vert,
  8986. fragmentShader: ShaderChunk.equirect_frag
  8987. },
  8988. distanceRGBA: {
  8989. uniforms: mergeUniforms( [
  8990. UniformsLib.common,
  8991. UniformsLib.displacementmap,
  8992. {
  8993. referencePosition: { value: new Vector3() },
  8994. nearDistance: { value: 1 },
  8995. farDistance: { value: 1000 }
  8996. }
  8997. ] ),
  8998. vertexShader: ShaderChunk.distanceRGBA_vert,
  8999. fragmentShader: ShaderChunk.distanceRGBA_frag
  9000. },
  9001. shadow: {
  9002. uniforms: mergeUniforms( [
  9003. UniformsLib.lights,
  9004. UniformsLib.fog,
  9005. {
  9006. color: { value: new Color( 0x00000 ) },
  9007. opacity: { value: 1.0 }
  9008. },
  9009. ] ),
  9010. vertexShader: ShaderChunk.shadow_vert,
  9011. fragmentShader: ShaderChunk.shadow_frag
  9012. }
  9013. };
  9014. ShaderLib.physical = {
  9015. uniforms: mergeUniforms( [
  9016. ShaderLib.standard.uniforms,
  9017. {
  9018. clearCoat: { value: 0 },
  9019. clearCoatRoughness: { value: 0 },
  9020. clearCoatNormalScale: { value: new Vector2( 1, 1 ) },
  9021. clearCoatNormalMap: { value: null },
  9022. }
  9023. ] ),
  9024. vertexShader: ShaderChunk.meshphysical_vert,
  9025. fragmentShader: ShaderChunk.meshphysical_frag
  9026. };
  9027. /**
  9028. * @author mrdoob / http://mrdoob.com/
  9029. */
  9030. function WebGLAnimation() {
  9031. var context = null;
  9032. var isAnimating = false;
  9033. var animationLoop = null;
  9034. function onAnimationFrame( time, frame ) {
  9035. if ( isAnimating === false ) return;
  9036. animationLoop( time, frame );
  9037. context.requestAnimationFrame( onAnimationFrame );
  9038. }
  9039. return {
  9040. start: function () {
  9041. if ( isAnimating === true ) return;
  9042. if ( animationLoop === null ) return;
  9043. context.requestAnimationFrame( onAnimationFrame );
  9044. isAnimating = true;
  9045. },
  9046. stop: function () {
  9047. isAnimating = false;
  9048. },
  9049. setAnimationLoop: function ( callback ) {
  9050. animationLoop = callback;
  9051. },
  9052. setContext: function ( value ) {
  9053. context = value;
  9054. }
  9055. };
  9056. }
  9057. /**
  9058. * @author mrdoob / http://mrdoob.com/
  9059. */
  9060. function WebGLAttributes( gl ) {
  9061. var buffers = new WeakMap();
  9062. function createBuffer( attribute, bufferType ) {
  9063. var array = attribute.array;
  9064. var usage = attribute.dynamic ? 35048 : 35044;
  9065. var buffer = gl.createBuffer();
  9066. gl.bindBuffer( bufferType, buffer );
  9067. gl.bufferData( bufferType, array, usage );
  9068. attribute.onUploadCallback();
  9069. var type = 5126;
  9070. if ( array instanceof Float32Array ) {
  9071. type = 5126;
  9072. } else if ( array instanceof Float64Array ) {
  9073. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  9074. } else if ( array instanceof Uint16Array ) {
  9075. type = 5123;
  9076. } else if ( array instanceof Int16Array ) {
  9077. type = 5122;
  9078. } else if ( array instanceof Uint32Array ) {
  9079. type = 5125;
  9080. } else if ( array instanceof Int32Array ) {
  9081. type = 5124;
  9082. } else if ( array instanceof Int8Array ) {
  9083. type = 5120;
  9084. } else if ( array instanceof Uint8Array ) {
  9085. type = 5121;
  9086. }
  9087. return {
  9088. buffer: buffer,
  9089. type: type,
  9090. bytesPerElement: array.BYTES_PER_ELEMENT,
  9091. version: attribute.version
  9092. };
  9093. }
  9094. function updateBuffer( buffer, attribute, bufferType ) {
  9095. var array = attribute.array;
  9096. var updateRange = attribute.updateRange;
  9097. gl.bindBuffer( bufferType, buffer );
  9098. if ( attribute.dynamic === false ) {
  9099. gl.bufferData( bufferType, array, 35044 );
  9100. } else if ( updateRange.count === - 1 ) {
  9101. // Not using update ranges
  9102. gl.bufferSubData( bufferType, 0, array );
  9103. } else if ( updateRange.count === 0 ) {
  9104. 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.' );
  9105. } else {
  9106. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9107. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9108. updateRange.count = - 1; // reset range
  9109. }
  9110. }
  9111. //
  9112. function get( attribute ) {
  9113. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9114. return buffers.get( attribute );
  9115. }
  9116. function remove( attribute ) {
  9117. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9118. var data = buffers.get( attribute );
  9119. if ( data ) {
  9120. gl.deleteBuffer( data.buffer );
  9121. buffers.delete( attribute );
  9122. }
  9123. }
  9124. function update( attribute, bufferType ) {
  9125. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9126. var data = buffers.get( attribute );
  9127. if ( data === undefined ) {
  9128. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  9129. } else if ( data.version < attribute.version ) {
  9130. updateBuffer( data.buffer, attribute, bufferType );
  9131. data.version = attribute.version;
  9132. }
  9133. }
  9134. return {
  9135. get: get,
  9136. remove: remove,
  9137. update: update
  9138. };
  9139. }
  9140. /**
  9141. * @author mrdoob / http://mrdoob.com/
  9142. * @author Mugen87 / https://github.com/Mugen87
  9143. */
  9144. // PlaneGeometry
  9145. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  9146. Geometry.call( this );
  9147. this.type = 'PlaneGeometry';
  9148. this.parameters = {
  9149. width: width,
  9150. height: height,
  9151. widthSegments: widthSegments,
  9152. heightSegments: heightSegments
  9153. };
  9154. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  9155. this.mergeVertices();
  9156. }
  9157. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  9158. PlaneGeometry.prototype.constructor = PlaneGeometry;
  9159. // PlaneBufferGeometry
  9160. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  9161. BufferGeometry.call( this );
  9162. this.type = 'PlaneBufferGeometry';
  9163. this.parameters = {
  9164. width: width,
  9165. height: height,
  9166. widthSegments: widthSegments,
  9167. heightSegments: heightSegments
  9168. };
  9169. width = width || 1;
  9170. height = height || 1;
  9171. var width_half = width / 2;
  9172. var height_half = height / 2;
  9173. var gridX = Math.floor( widthSegments ) || 1;
  9174. var gridY = Math.floor( heightSegments ) || 1;
  9175. var gridX1 = gridX + 1;
  9176. var gridY1 = gridY + 1;
  9177. var segment_width = width / gridX;
  9178. var segment_height = height / gridY;
  9179. var ix, iy;
  9180. // buffers
  9181. var indices = [];
  9182. var vertices = [];
  9183. var normals = [];
  9184. var uvs = [];
  9185. // generate vertices, normals and uvs
  9186. for ( iy = 0; iy < gridY1; iy ++ ) {
  9187. var y = iy * segment_height - height_half;
  9188. for ( ix = 0; ix < gridX1; ix ++ ) {
  9189. var x = ix * segment_width - width_half;
  9190. vertices.push( x, - y, 0 );
  9191. normals.push( 0, 0, 1 );
  9192. uvs.push( ix / gridX );
  9193. uvs.push( 1 - ( iy / gridY ) );
  9194. }
  9195. }
  9196. // indices
  9197. for ( iy = 0; iy < gridY; iy ++ ) {
  9198. for ( ix = 0; ix < gridX; ix ++ ) {
  9199. var a = ix + gridX1 * iy;
  9200. var b = ix + gridX1 * ( iy + 1 );
  9201. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  9202. var d = ( ix + 1 ) + gridX1 * iy;
  9203. // faces
  9204. indices.push( a, b, d );
  9205. indices.push( b, c, d );
  9206. }
  9207. }
  9208. // build geometry
  9209. this.setIndex( indices );
  9210. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9211. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9212. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9213. }
  9214. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9215. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  9216. /**
  9217. * @author mrdoob / http://mrdoob.com/
  9218. */
  9219. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9220. var clearColor = new Color( 0x000000 );
  9221. var clearAlpha = 0;
  9222. var planeMesh;
  9223. var boxMesh;
  9224. // Store the current background texture and its `version`
  9225. // so we can recompile the material accordingly.
  9226. var currentBackground = null;
  9227. var currentBackgroundVersion = 0;
  9228. function render( renderList, scene, camera, forceClear ) {
  9229. var background = scene.background;
  9230. // Ignore background in AR
  9231. // TODO: Reconsider this.
  9232. var vr = renderer.vr;
  9233. var session = vr.getSession && vr.getSession();
  9234. if ( session && session.environmentBlendMode === 'additive' ) {
  9235. background = null;
  9236. }
  9237. if ( background === null ) {
  9238. setClear( clearColor, clearAlpha );
  9239. currentBackground = null;
  9240. currentBackgroundVersion = 0;
  9241. } else if ( background && background.isColor ) {
  9242. setClear( background, 1 );
  9243. forceClear = true;
  9244. currentBackground = null;
  9245. currentBackgroundVersion = 0;
  9246. }
  9247. if ( renderer.autoClear || forceClear ) {
  9248. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9249. }
  9250. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  9251. if ( boxMesh === undefined ) {
  9252. boxMesh = new Mesh(
  9253. new BoxBufferGeometry( 1, 1, 1 ),
  9254. new ShaderMaterial( {
  9255. type: 'BackgroundCubeMaterial',
  9256. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9257. vertexShader: ShaderLib.cube.vertexShader,
  9258. fragmentShader: ShaderLib.cube.fragmentShader,
  9259. side: BackSide,
  9260. depthTest: false,
  9261. depthWrite: false,
  9262. fog: false
  9263. } )
  9264. );
  9265. boxMesh.geometry.removeAttribute( 'normal' );
  9266. boxMesh.geometry.removeAttribute( 'uv' );
  9267. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9268. this.matrixWorld.copyPosition( camera.matrixWorld );
  9269. };
  9270. // enable code injection for non-built-in material
  9271. Object.defineProperty( boxMesh.material, 'map', {
  9272. get: function () {
  9273. return this.uniforms.tCube.value;
  9274. }
  9275. } );
  9276. objects.update( boxMesh );
  9277. }
  9278. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  9279. boxMesh.material.uniforms.tCube.value = texture;
  9280. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  9281. if ( currentBackground !== background ||
  9282. currentBackgroundVersion !== texture.version ) {
  9283. boxMesh.material.needsUpdate = true;
  9284. currentBackground = background;
  9285. currentBackgroundVersion = texture.version;
  9286. }
  9287. // push to the pre-sorted opaque render list
  9288. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9289. } else if ( background && background.isTexture ) {
  9290. if ( planeMesh === undefined ) {
  9291. planeMesh = new Mesh(
  9292. new PlaneBufferGeometry( 2, 2 ),
  9293. new ShaderMaterial( {
  9294. type: 'BackgroundMaterial',
  9295. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9296. vertexShader: ShaderLib.background.vertexShader,
  9297. fragmentShader: ShaderLib.background.fragmentShader,
  9298. side: FrontSide,
  9299. depthTest: false,
  9300. depthWrite: false,
  9301. fog: false
  9302. } )
  9303. );
  9304. planeMesh.geometry.removeAttribute( 'normal' );
  9305. // enable code injection for non-built-in material
  9306. Object.defineProperty( planeMesh.material, 'map', {
  9307. get: function () {
  9308. return this.uniforms.t2D.value;
  9309. }
  9310. } );
  9311. objects.update( planeMesh );
  9312. }
  9313. planeMesh.material.uniforms.t2D.value = background;
  9314. if ( background.matrixAutoUpdate === true ) {
  9315. background.updateMatrix();
  9316. }
  9317. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9318. if ( currentBackground !== background ||
  9319. currentBackgroundVersion !== background.version ) {
  9320. planeMesh.material.needsUpdate = true;
  9321. currentBackground = background;
  9322. currentBackgroundVersion = background.version;
  9323. }
  9324. // push to the pre-sorted opaque render list
  9325. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9326. }
  9327. }
  9328. function setClear( color, alpha ) {
  9329. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9330. }
  9331. return {
  9332. getClearColor: function () {
  9333. return clearColor;
  9334. },
  9335. setClearColor: function ( color, alpha ) {
  9336. clearColor.set( color );
  9337. clearAlpha = alpha !== undefined ? alpha : 1;
  9338. setClear( clearColor, clearAlpha );
  9339. },
  9340. getClearAlpha: function () {
  9341. return clearAlpha;
  9342. },
  9343. setClearAlpha: function ( alpha ) {
  9344. clearAlpha = alpha;
  9345. setClear( clearColor, clearAlpha );
  9346. },
  9347. render: render
  9348. };
  9349. }
  9350. /**
  9351. * @author mrdoob / http://mrdoob.com/
  9352. */
  9353. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9354. var mode;
  9355. function setMode( value ) {
  9356. mode = value;
  9357. }
  9358. function render( start, count ) {
  9359. gl.drawArrays( mode, start, count );
  9360. info.update( count, mode );
  9361. }
  9362. function renderInstances( geometry, start, count ) {
  9363. var extension;
  9364. if ( capabilities.isWebGL2 ) {
  9365. extension = gl;
  9366. } else {
  9367. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9368. if ( extension === null ) {
  9369. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9370. return;
  9371. }
  9372. }
  9373. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  9374. info.update( count, mode, geometry.maxInstancedCount );
  9375. }
  9376. //
  9377. this.setMode = setMode;
  9378. this.render = render;
  9379. this.renderInstances = renderInstances;
  9380. }
  9381. /**
  9382. * @author mrdoob / http://mrdoob.com/
  9383. */
  9384. function WebGLCapabilities( gl, extensions, parameters ) {
  9385. var maxAnisotropy;
  9386. function getMaxAnisotropy() {
  9387. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  9388. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9389. if ( extension !== null ) {
  9390. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9391. } else {
  9392. maxAnisotropy = 0;
  9393. }
  9394. return maxAnisotropy;
  9395. }
  9396. function getMaxPrecision( precision ) {
  9397. if ( precision === 'highp' ) {
  9398. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9399. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9400. return 'highp';
  9401. }
  9402. precision = 'mediump';
  9403. }
  9404. if ( precision === 'mediump' ) {
  9405. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9406. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9407. return 'mediump';
  9408. }
  9409. }
  9410. return 'lowp';
  9411. }
  9412. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  9413. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9414. var maxPrecision = getMaxPrecision( precision );
  9415. if ( maxPrecision !== precision ) {
  9416. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9417. precision = maxPrecision;
  9418. }
  9419. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9420. var maxTextures = gl.getParameter( 34930 );
  9421. var maxVertexTextures = gl.getParameter( 35660 );
  9422. var maxTextureSize = gl.getParameter( 3379 );
  9423. var maxCubemapSize = gl.getParameter( 34076 );
  9424. var maxAttributes = gl.getParameter( 34921 );
  9425. var maxVertexUniforms = gl.getParameter( 36347 );
  9426. var maxVaryings = gl.getParameter( 36348 );
  9427. var maxFragmentUniforms = gl.getParameter( 36349 );
  9428. var vertexTextures = maxVertexTextures > 0;
  9429. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9430. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9431. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9432. return {
  9433. isWebGL2: isWebGL2,
  9434. getMaxAnisotropy: getMaxAnisotropy,
  9435. getMaxPrecision: getMaxPrecision,
  9436. precision: precision,
  9437. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9438. maxTextures: maxTextures,
  9439. maxVertexTextures: maxVertexTextures,
  9440. maxTextureSize: maxTextureSize,
  9441. maxCubemapSize: maxCubemapSize,
  9442. maxAttributes: maxAttributes,
  9443. maxVertexUniforms: maxVertexUniforms,
  9444. maxVaryings: maxVaryings,
  9445. maxFragmentUniforms: maxFragmentUniforms,
  9446. vertexTextures: vertexTextures,
  9447. floatFragmentTextures: floatFragmentTextures,
  9448. floatVertexTextures: floatVertexTextures,
  9449. maxSamples: maxSamples
  9450. };
  9451. }
  9452. /**
  9453. * @author tschw
  9454. */
  9455. function WebGLClipping() {
  9456. var scope = this,
  9457. globalState = null,
  9458. numGlobalPlanes = 0,
  9459. localClippingEnabled = false,
  9460. renderingShadows = false,
  9461. plane = new Plane(),
  9462. viewNormalMatrix = new Matrix3(),
  9463. uniform = { value: null, needsUpdate: false };
  9464. this.uniform = uniform;
  9465. this.numPlanes = 0;
  9466. this.numIntersection = 0;
  9467. this.init = function ( planes, enableLocalClipping, camera ) {
  9468. var enabled =
  9469. planes.length !== 0 ||
  9470. enableLocalClipping ||
  9471. // enable state of previous frame - the clipping code has to
  9472. // run another frame in order to reset the state:
  9473. numGlobalPlanes !== 0 ||
  9474. localClippingEnabled;
  9475. localClippingEnabled = enableLocalClipping;
  9476. globalState = projectPlanes( planes, camera, 0 );
  9477. numGlobalPlanes = planes.length;
  9478. return enabled;
  9479. };
  9480. this.beginShadows = function () {
  9481. renderingShadows = true;
  9482. projectPlanes( null );
  9483. };
  9484. this.endShadows = function () {
  9485. renderingShadows = false;
  9486. resetGlobalState();
  9487. };
  9488. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9489. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9490. // there's no local clipping
  9491. if ( renderingShadows ) {
  9492. // there's no global clipping
  9493. projectPlanes( null );
  9494. } else {
  9495. resetGlobalState();
  9496. }
  9497. } else {
  9498. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9499. lGlobal = nGlobal * 4,
  9500. dstArray = cache.clippingState || null;
  9501. uniform.value = dstArray; // ensure unique state
  9502. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9503. for ( var i = 0; i !== lGlobal; ++ i ) {
  9504. dstArray[ i ] = globalState[ i ];
  9505. }
  9506. cache.clippingState = dstArray;
  9507. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9508. this.numPlanes += nGlobal;
  9509. }
  9510. };
  9511. function resetGlobalState() {
  9512. if ( uniform.value !== globalState ) {
  9513. uniform.value = globalState;
  9514. uniform.needsUpdate = numGlobalPlanes > 0;
  9515. }
  9516. scope.numPlanes = numGlobalPlanes;
  9517. scope.numIntersection = 0;
  9518. }
  9519. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9520. var nPlanes = planes !== null ? planes.length : 0,
  9521. dstArray = null;
  9522. if ( nPlanes !== 0 ) {
  9523. dstArray = uniform.value;
  9524. if ( skipTransform !== true || dstArray === null ) {
  9525. var flatSize = dstOffset + nPlanes * 4,
  9526. viewMatrix = camera.matrixWorldInverse;
  9527. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9528. if ( dstArray === null || dstArray.length < flatSize ) {
  9529. dstArray = new Float32Array( flatSize );
  9530. }
  9531. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9532. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9533. plane.normal.toArray( dstArray, i4 );
  9534. dstArray[ i4 + 3 ] = plane.constant;
  9535. }
  9536. }
  9537. uniform.value = dstArray;
  9538. uniform.needsUpdate = true;
  9539. }
  9540. scope.numPlanes = nPlanes;
  9541. return dstArray;
  9542. }
  9543. }
  9544. /**
  9545. * @author mrdoob / http://mrdoob.com/
  9546. */
  9547. function WebGLExtensions( gl ) {
  9548. var extensions = {};
  9549. return {
  9550. get: function ( name ) {
  9551. if ( extensions[ name ] !== undefined ) {
  9552. return extensions[ name ];
  9553. }
  9554. var extension;
  9555. switch ( name ) {
  9556. case 'WEBGL_depth_texture':
  9557. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9558. break;
  9559. case 'EXT_texture_filter_anisotropic':
  9560. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9561. break;
  9562. case 'WEBGL_compressed_texture_s3tc':
  9563. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9564. break;
  9565. case 'WEBGL_compressed_texture_pvrtc':
  9566. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9567. break;
  9568. default:
  9569. extension = gl.getExtension( name );
  9570. }
  9571. if ( extension === null ) {
  9572. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9573. }
  9574. extensions[ name ] = extension;
  9575. return extension;
  9576. }
  9577. };
  9578. }
  9579. /**
  9580. * @author mrdoob / http://mrdoob.com/
  9581. */
  9582. function WebGLGeometries( gl, attributes, info ) {
  9583. var geometries = {};
  9584. var wireframeAttributes = {};
  9585. function onGeometryDispose( event ) {
  9586. var geometry = event.target;
  9587. var buffergeometry = geometries[ geometry.id ];
  9588. if ( buffergeometry.index !== null ) {
  9589. attributes.remove( buffergeometry.index );
  9590. }
  9591. for ( var name in buffergeometry.attributes ) {
  9592. attributes.remove( buffergeometry.attributes[ name ] );
  9593. }
  9594. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9595. delete geometries[ geometry.id ];
  9596. var attribute = wireframeAttributes[ buffergeometry.id ];
  9597. if ( attribute ) {
  9598. attributes.remove( attribute );
  9599. delete wireframeAttributes[ buffergeometry.id ];
  9600. }
  9601. //
  9602. info.memory.geometries --;
  9603. }
  9604. function get( object, geometry ) {
  9605. var buffergeometry = geometries[ geometry.id ];
  9606. if ( buffergeometry ) return buffergeometry;
  9607. geometry.addEventListener( 'dispose', onGeometryDispose );
  9608. if ( geometry.isBufferGeometry ) {
  9609. buffergeometry = geometry;
  9610. } else if ( geometry.isGeometry ) {
  9611. if ( geometry._bufferGeometry === undefined ) {
  9612. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9613. }
  9614. buffergeometry = geometry._bufferGeometry;
  9615. }
  9616. geometries[ geometry.id ] = buffergeometry;
  9617. info.memory.geometries ++;
  9618. return buffergeometry;
  9619. }
  9620. function update( geometry ) {
  9621. var index = geometry.index;
  9622. var geometryAttributes = geometry.attributes;
  9623. if ( index !== null ) {
  9624. attributes.update( index, 34963 );
  9625. }
  9626. for ( var name in geometryAttributes ) {
  9627. attributes.update( geometryAttributes[ name ], 34962 );
  9628. }
  9629. // morph targets
  9630. var morphAttributes = geometry.morphAttributes;
  9631. for ( var name in morphAttributes ) {
  9632. var array = morphAttributes[ name ];
  9633. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9634. attributes.update( array[ i ], 34962 );
  9635. }
  9636. }
  9637. }
  9638. function updateWireframeAttribute( geometry ) {
  9639. var indices = [];
  9640. var geometryIndex = geometry.index;
  9641. var geometryPosition = geometry.attributes.position;
  9642. var version = 0;
  9643. if ( geometryIndex !== null ) {
  9644. var array = geometryIndex.array;
  9645. version = geometryIndex.version;
  9646. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9647. var a = array[ i + 0 ];
  9648. var b = array[ i + 1 ];
  9649. var c = array[ i + 2 ];
  9650. indices.push( a, b, b, c, c, a );
  9651. }
  9652. } else {
  9653. var array = geometryPosition.array;
  9654. version = geometryPosition.version;
  9655. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9656. var a = i + 0;
  9657. var b = i + 1;
  9658. var c = i + 2;
  9659. indices.push( a, b, b, c, c, a );
  9660. }
  9661. }
  9662. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9663. attribute.version = version;
  9664. attributes.update( attribute, 34963 );
  9665. //
  9666. var previousAttribute = wireframeAttributes[ geometry.id ];
  9667. if ( previousAttribute ) attributes.remove( previousAttribute );
  9668. //
  9669. wireframeAttributes[ geometry.id ] = attribute;
  9670. }
  9671. function getWireframeAttribute( geometry ) {
  9672. var currentAttribute = wireframeAttributes[ geometry.id ];
  9673. if ( currentAttribute ) {
  9674. var geometryIndex = geometry.index;
  9675. if ( geometryIndex !== null ) {
  9676. // if the attribute is obsolete, create a new one
  9677. if ( currentAttribute.version < geometryIndex.version ) {
  9678. updateWireframeAttribute( geometry );
  9679. }
  9680. }
  9681. } else {
  9682. updateWireframeAttribute( geometry );
  9683. }
  9684. return wireframeAttributes[ geometry.id ];
  9685. }
  9686. return {
  9687. get: get,
  9688. update: update,
  9689. getWireframeAttribute: getWireframeAttribute
  9690. };
  9691. }
  9692. /**
  9693. * @author mrdoob / http://mrdoob.com/
  9694. */
  9695. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9696. var mode;
  9697. function setMode( value ) {
  9698. mode = value;
  9699. }
  9700. var type, bytesPerElement;
  9701. function setIndex( value ) {
  9702. type = value.type;
  9703. bytesPerElement = value.bytesPerElement;
  9704. }
  9705. function render( start, count ) {
  9706. gl.drawElements( mode, count, type, start * bytesPerElement );
  9707. info.update( count, mode );
  9708. }
  9709. function renderInstances( geometry, start, count ) {
  9710. var extension;
  9711. if ( capabilities.isWebGL2 ) {
  9712. extension = gl;
  9713. } else {
  9714. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9715. if ( extension === null ) {
  9716. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9717. return;
  9718. }
  9719. }
  9720. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9721. info.update( count, mode, geometry.maxInstancedCount );
  9722. }
  9723. //
  9724. this.setMode = setMode;
  9725. this.setIndex = setIndex;
  9726. this.render = render;
  9727. this.renderInstances = renderInstances;
  9728. }
  9729. /**
  9730. * @author Mugen87 / https://github.com/Mugen87
  9731. */
  9732. function WebGLInfo( gl ) {
  9733. var memory = {
  9734. geometries: 0,
  9735. textures: 0
  9736. };
  9737. var render = {
  9738. frame: 0,
  9739. calls: 0,
  9740. triangles: 0,
  9741. points: 0,
  9742. lines: 0
  9743. };
  9744. function update( count, mode, instanceCount ) {
  9745. instanceCount = instanceCount || 1;
  9746. render.calls ++;
  9747. switch ( mode ) {
  9748. case 4:
  9749. render.triangles += instanceCount * ( count / 3 );
  9750. break;
  9751. case 5:
  9752. case 6:
  9753. render.triangles += instanceCount * ( count - 2 );
  9754. break;
  9755. case 1:
  9756. render.lines += instanceCount * ( count / 2 );
  9757. break;
  9758. case 3:
  9759. render.lines += instanceCount * ( count - 1 );
  9760. break;
  9761. case 2:
  9762. render.lines += instanceCount * count;
  9763. break;
  9764. case 0:
  9765. render.points += instanceCount * count;
  9766. break;
  9767. default:
  9768. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9769. break;
  9770. }
  9771. }
  9772. function reset() {
  9773. render.frame ++;
  9774. render.calls = 0;
  9775. render.triangles = 0;
  9776. render.points = 0;
  9777. render.lines = 0;
  9778. }
  9779. return {
  9780. memory: memory,
  9781. render: render,
  9782. programs: null,
  9783. autoReset: true,
  9784. reset: reset,
  9785. update: update
  9786. };
  9787. }
  9788. /**
  9789. * @author mrdoob / http://mrdoob.com/
  9790. */
  9791. function absNumericalSort( a, b ) {
  9792. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9793. }
  9794. function WebGLMorphtargets( gl ) {
  9795. var influencesList = {};
  9796. var morphInfluences = new Float32Array( 8 );
  9797. function update( object, geometry, material, program ) {
  9798. var objectInfluences = object.morphTargetInfluences;
  9799. var length = objectInfluences.length;
  9800. var influences = influencesList[ geometry.id ];
  9801. if ( influences === undefined ) {
  9802. // initialise list
  9803. influences = [];
  9804. for ( var i = 0; i < length; i ++ ) {
  9805. influences[ i ] = [ i, 0 ];
  9806. }
  9807. influencesList[ geometry.id ] = influences;
  9808. }
  9809. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9810. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9811. // Remove current morphAttributes
  9812. for ( var i = 0; i < length; i ++ ) {
  9813. var influence = influences[ i ];
  9814. if ( influence[ 1 ] !== 0 ) {
  9815. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9816. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9817. }
  9818. }
  9819. // Collect influences
  9820. for ( var i = 0; i < length; i ++ ) {
  9821. var influence = influences[ i ];
  9822. influence[ 0 ] = i;
  9823. influence[ 1 ] = objectInfluences[ i ];
  9824. }
  9825. influences.sort( absNumericalSort );
  9826. // Add morphAttributes
  9827. for ( var i = 0; i < 8; i ++ ) {
  9828. var influence = influences[ i ];
  9829. if ( influence ) {
  9830. var index = influence[ 0 ];
  9831. var value = influence[ 1 ];
  9832. if ( value ) {
  9833. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9834. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9835. morphInfluences[ i ] = value;
  9836. continue;
  9837. }
  9838. }
  9839. morphInfluences[ i ] = 0;
  9840. }
  9841. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9842. }
  9843. return {
  9844. update: update
  9845. };
  9846. }
  9847. /**
  9848. * @author mrdoob / http://mrdoob.com/
  9849. */
  9850. function WebGLObjects( geometries, info ) {
  9851. var updateList = {};
  9852. function update( object ) {
  9853. var frame = info.render.frame;
  9854. var geometry = object.geometry;
  9855. var buffergeometry = geometries.get( object, geometry );
  9856. // Update once per frame
  9857. if ( updateList[ buffergeometry.id ] !== frame ) {
  9858. if ( geometry.isGeometry ) {
  9859. buffergeometry.updateFromObject( object );
  9860. }
  9861. geometries.update( buffergeometry );
  9862. updateList[ buffergeometry.id ] = frame;
  9863. }
  9864. return buffergeometry;
  9865. }
  9866. function dispose() {
  9867. updateList = {};
  9868. }
  9869. return {
  9870. update: update,
  9871. dispose: dispose
  9872. };
  9873. }
  9874. /**
  9875. * @author mrdoob / http://mrdoob.com/
  9876. */
  9877. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9878. images = images !== undefined ? images : [];
  9879. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9880. format = format !== undefined ? format : RGBFormat;
  9881. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9882. this.flipY = false;
  9883. }
  9884. CubeTexture.prototype = Object.create( Texture.prototype );
  9885. CubeTexture.prototype.constructor = CubeTexture;
  9886. CubeTexture.prototype.isCubeTexture = true;
  9887. Object.defineProperty( CubeTexture.prototype, 'images', {
  9888. get: function () {
  9889. return this.image;
  9890. },
  9891. set: function ( value ) {
  9892. this.image = value;
  9893. }
  9894. } );
  9895. /**
  9896. * @author Takahiro https://github.com/takahirox
  9897. */
  9898. function DataTexture2DArray( data, width, height, depth ) {
  9899. Texture.call( this, null );
  9900. this.image = { data: data, width: width, height: height, depth: depth };
  9901. this.magFilter = NearestFilter;
  9902. this.minFilter = NearestFilter;
  9903. this.wrapR = ClampToEdgeWrapping;
  9904. this.generateMipmaps = false;
  9905. this.flipY = false;
  9906. }
  9907. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9908. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9909. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9910. /**
  9911. * @author Artur Trzesiok
  9912. */
  9913. function DataTexture3D( data, width, height, depth ) {
  9914. // We're going to add .setXXX() methods for setting properties later.
  9915. // Users can still set in DataTexture3D directly.
  9916. //
  9917. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9918. // texture.anisotropy = 16;
  9919. //
  9920. // See #14839
  9921. Texture.call( this, null );
  9922. this.image = { data: data, width: width, height: height, depth: depth };
  9923. this.magFilter = NearestFilter;
  9924. this.minFilter = NearestFilter;
  9925. this.wrapR = ClampToEdgeWrapping;
  9926. this.generateMipmaps = false;
  9927. this.flipY = false;
  9928. }
  9929. DataTexture3D.prototype = Object.create( Texture.prototype );
  9930. DataTexture3D.prototype.constructor = DataTexture3D;
  9931. DataTexture3D.prototype.isDataTexture3D = true;
  9932. /**
  9933. * @author tschw
  9934. * @author Mugen87 / https://github.com/Mugen87
  9935. * @author mrdoob / http://mrdoob.com/
  9936. *
  9937. * Uniforms of a program.
  9938. * Those form a tree structure with a special top-level container for the root,
  9939. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9940. *
  9941. *
  9942. * Properties of inner nodes including the top-level container:
  9943. *
  9944. * .seq - array of nested uniforms
  9945. * .map - nested uniforms by name
  9946. *
  9947. *
  9948. * Methods of all nodes except the top-level container:
  9949. *
  9950. * .setValue( gl, value, [textures] )
  9951. *
  9952. * uploads a uniform value(s)
  9953. * the 'textures' parameter is needed for sampler uniforms
  9954. *
  9955. *
  9956. * Static methods of the top-level container (textures factorizations):
  9957. *
  9958. * .upload( gl, seq, values, textures )
  9959. *
  9960. * sets uniforms in 'seq' to 'values[id].value'
  9961. *
  9962. * .seqWithValue( seq, values ) : filteredSeq
  9963. *
  9964. * filters 'seq' entries with corresponding entry in values
  9965. *
  9966. *
  9967. * Methods of the top-level container (textures factorizations):
  9968. *
  9969. * .setValue( gl, name, value, textures )
  9970. *
  9971. * sets uniform with name 'name' to 'value'
  9972. *
  9973. * .setOptional( gl, obj, prop )
  9974. *
  9975. * like .set for an optional property of the object
  9976. *
  9977. */
  9978. var emptyTexture = new Texture();
  9979. var emptyTexture2dArray = new DataTexture2DArray();
  9980. var emptyTexture3d = new DataTexture3D();
  9981. var emptyCubeTexture = new CubeTexture();
  9982. // --- Utilities ---
  9983. // Array Caches (provide typed arrays for temporary by size)
  9984. var arrayCacheF32 = [];
  9985. var arrayCacheI32 = [];
  9986. // Float32Array caches used for uploading Matrix uniforms
  9987. var mat4array = new Float32Array( 16 );
  9988. var mat3array = new Float32Array( 9 );
  9989. var mat2array = new Float32Array( 4 );
  9990. // Flattening for arrays of vectors and matrices
  9991. function flatten( array, nBlocks, blockSize ) {
  9992. var firstElem = array[ 0 ];
  9993. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9994. // unoptimized: ! isNaN( firstElem )
  9995. // see http://jacksondunstan.com/articles/983
  9996. var n = nBlocks * blockSize,
  9997. r = arrayCacheF32[ n ];
  9998. if ( r === undefined ) {
  9999. r = new Float32Array( n );
  10000. arrayCacheF32[ n ] = r;
  10001. }
  10002. if ( nBlocks !== 0 ) {
  10003. firstElem.toArray( r, 0 );
  10004. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10005. offset += blockSize;
  10006. array[ i ].toArray( r, offset );
  10007. }
  10008. }
  10009. return r;
  10010. }
  10011. function arraysEqual( a, b ) {
  10012. if ( a.length !== b.length ) return false;
  10013. for ( var i = 0, l = a.length; i < l; i ++ ) {
  10014. if ( a[ i ] !== b[ i ] ) return false;
  10015. }
  10016. return true;
  10017. }
  10018. function copyArray( a, b ) {
  10019. for ( var i = 0, l = b.length; i < l; i ++ ) {
  10020. a[ i ] = b[ i ];
  10021. }
  10022. }
  10023. // Texture unit allocation
  10024. function allocTexUnits( textures, n ) {
  10025. var r = arrayCacheI32[ n ];
  10026. if ( r === undefined ) {
  10027. r = new Int32Array( n );
  10028. arrayCacheI32[ n ] = r;
  10029. }
  10030. for ( var i = 0; i !== n; ++ i )
  10031. r[ i ] = textures.allocateTextureUnit();
  10032. return r;
  10033. }
  10034. // --- Setters ---
  10035. // Note: Defining these methods externally, because they come in a bunch
  10036. // and this way their names minify.
  10037. // Single scalar
  10038. function setValueV1f( gl, v ) {
  10039. var cache = this.cache;
  10040. if ( cache[ 0 ] === v ) return;
  10041. gl.uniform1f( this.addr, v );
  10042. cache[ 0 ] = v;
  10043. }
  10044. // Single float vector (from flat array or THREE.VectorN)
  10045. function setValueV2f( gl, v ) {
  10046. var cache = this.cache;
  10047. if ( v.x !== undefined ) {
  10048. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10049. gl.uniform2f( this.addr, v.x, v.y );
  10050. cache[ 0 ] = v.x;
  10051. cache[ 1 ] = v.y;
  10052. }
  10053. } else {
  10054. if ( arraysEqual( cache, v ) ) return;
  10055. gl.uniform2fv( this.addr, v );
  10056. copyArray( cache, v );
  10057. }
  10058. }
  10059. function setValueV3f( gl, v ) {
  10060. var cache = this.cache;
  10061. if ( v.x !== undefined ) {
  10062. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10063. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10064. cache[ 0 ] = v.x;
  10065. cache[ 1 ] = v.y;
  10066. cache[ 2 ] = v.z;
  10067. }
  10068. } else if ( v.r !== undefined ) {
  10069. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10070. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10071. cache[ 0 ] = v.r;
  10072. cache[ 1 ] = v.g;
  10073. cache[ 2 ] = v.b;
  10074. }
  10075. } else {
  10076. if ( arraysEqual( cache, v ) ) return;
  10077. gl.uniform3fv( this.addr, v );
  10078. copyArray( cache, v );
  10079. }
  10080. }
  10081. function setValueV4f( gl, v ) {
  10082. var cache = this.cache;
  10083. if ( v.x !== undefined ) {
  10084. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10085. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10086. cache[ 0 ] = v.x;
  10087. cache[ 1 ] = v.y;
  10088. cache[ 2 ] = v.z;
  10089. cache[ 3 ] = v.w;
  10090. }
  10091. } else {
  10092. if ( arraysEqual( cache, v ) ) return;
  10093. gl.uniform4fv( this.addr, v );
  10094. copyArray( cache, v );
  10095. }
  10096. }
  10097. // Single matrix (from flat array or MatrixN)
  10098. function setValueM2( gl, v ) {
  10099. var cache = this.cache;
  10100. var elements = v.elements;
  10101. if ( elements === undefined ) {
  10102. if ( arraysEqual( cache, v ) ) return;
  10103. gl.uniformMatrix2fv( this.addr, false, v );
  10104. copyArray( cache, v );
  10105. } else {
  10106. if ( arraysEqual( cache, elements ) ) return;
  10107. mat2array.set( elements );
  10108. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10109. copyArray( cache, elements );
  10110. }
  10111. }
  10112. function setValueM3( gl, v ) {
  10113. var cache = this.cache;
  10114. var elements = v.elements;
  10115. if ( elements === undefined ) {
  10116. if ( arraysEqual( cache, v ) ) return;
  10117. gl.uniformMatrix3fv( this.addr, false, v );
  10118. copyArray( cache, v );
  10119. } else {
  10120. if ( arraysEqual( cache, elements ) ) return;
  10121. mat3array.set( elements );
  10122. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10123. copyArray( cache, elements );
  10124. }
  10125. }
  10126. function setValueM4( gl, v ) {
  10127. var cache = this.cache;
  10128. var elements = v.elements;
  10129. if ( elements === undefined ) {
  10130. if ( arraysEqual( cache, v ) ) return;
  10131. gl.uniformMatrix4fv( this.addr, false, v );
  10132. copyArray( cache, v );
  10133. } else {
  10134. if ( arraysEqual( cache, elements ) ) return;
  10135. mat4array.set( elements );
  10136. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10137. copyArray( cache, elements );
  10138. }
  10139. }
  10140. // Single texture (2D / Cube)
  10141. function setValueT1( gl, v, textures ) {
  10142. var cache = this.cache;
  10143. var unit = textures.allocateTextureUnit();
  10144. if ( cache[ 0 ] !== unit ) {
  10145. gl.uniform1i( this.addr, unit );
  10146. cache[ 0 ] = unit;
  10147. }
  10148. textures.safeSetTexture2D( v || emptyTexture, unit );
  10149. }
  10150. function setValueT2DArray1( gl, v, textures ) {
  10151. var cache = this.cache;
  10152. var unit = textures.allocateTextureUnit();
  10153. if ( cache[ 0 ] !== unit ) {
  10154. gl.uniform1i( this.addr, unit );
  10155. cache[ 0 ] = unit;
  10156. }
  10157. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10158. }
  10159. function setValueT3D1( gl, v, textures ) {
  10160. var cache = this.cache;
  10161. var unit = textures.allocateTextureUnit();
  10162. if ( cache[ 0 ] !== unit ) {
  10163. gl.uniform1i( this.addr, unit );
  10164. cache[ 0 ] = unit;
  10165. }
  10166. textures.setTexture3D( v || emptyTexture3d, unit );
  10167. }
  10168. function setValueT6( gl, v, textures ) {
  10169. var cache = this.cache;
  10170. var unit = textures.allocateTextureUnit();
  10171. if ( cache[ 0 ] !== unit ) {
  10172. gl.uniform1i( this.addr, unit );
  10173. cache[ 0 ] = unit;
  10174. }
  10175. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10176. }
  10177. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10178. function setValueV1i( gl, v ) {
  10179. var cache = this.cache;
  10180. if ( cache[ 0 ] === v ) return;
  10181. gl.uniform1i( this.addr, v );
  10182. cache[ 0 ] = v;
  10183. }
  10184. function setValueV2i( gl, v ) {
  10185. var cache = this.cache;
  10186. if ( arraysEqual( cache, v ) ) return;
  10187. gl.uniform2iv( this.addr, v );
  10188. copyArray( cache, v );
  10189. }
  10190. function setValueV3i( gl, v ) {
  10191. var cache = this.cache;
  10192. if ( arraysEqual( cache, v ) ) return;
  10193. gl.uniform3iv( this.addr, v );
  10194. copyArray( cache, v );
  10195. }
  10196. function setValueV4i( gl, v ) {
  10197. var cache = this.cache;
  10198. if ( arraysEqual( cache, v ) ) return;
  10199. gl.uniform4iv( this.addr, v );
  10200. copyArray( cache, v );
  10201. }
  10202. // Helper to pick the right setter for the singular case
  10203. function getSingularSetter( type ) {
  10204. switch ( type ) {
  10205. case 0x1406: return setValueV1f; // FLOAT
  10206. case 0x8b50: return setValueV2f; // _VEC2
  10207. case 0x8b51: return setValueV3f; // _VEC3
  10208. case 0x8b52: return setValueV4f; // _VEC4
  10209. case 0x8b5a: return setValueM2; // _MAT2
  10210. case 0x8b5b: return setValueM3; // _MAT3
  10211. case 0x8b5c: return setValueM4; // _MAT4
  10212. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  10213. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  10214. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  10215. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  10216. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10217. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10218. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10219. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10220. }
  10221. }
  10222. // Array of scalars
  10223. function setValueV1fArray( gl, v ) {
  10224. gl.uniform1fv( this.addr, v );
  10225. }
  10226. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10227. function setValueV1iArray( gl, v ) {
  10228. gl.uniform1iv( this.addr, v );
  10229. }
  10230. function setValueV2iArray( gl, v ) {
  10231. gl.uniform2iv( this.addr, v );
  10232. }
  10233. function setValueV3iArray( gl, v ) {
  10234. gl.uniform3iv( this.addr, v );
  10235. }
  10236. function setValueV4iArray( gl, v ) {
  10237. gl.uniform4iv( this.addr, v );
  10238. }
  10239. // Array of vectors (flat or from THREE classes)
  10240. function setValueV2fArray( gl, v ) {
  10241. var data = flatten( v, this.size, 2 );
  10242. gl.uniform2fv( this.addr, data );
  10243. }
  10244. function setValueV3fArray( gl, v ) {
  10245. var data = flatten( v, this.size, 3 );
  10246. gl.uniform3fv( this.addr, data );
  10247. }
  10248. function setValueV4fArray( gl, v ) {
  10249. var data = flatten( v, this.size, 4 );
  10250. gl.uniform4fv( this.addr, data );
  10251. }
  10252. // Array of matrices (flat or from THREE clases)
  10253. function setValueM2Array( gl, v ) {
  10254. var data = flatten( v, this.size, 4 );
  10255. gl.uniformMatrix2fv( this.addr, false, data );
  10256. }
  10257. function setValueM3Array( gl, v ) {
  10258. var data = flatten( v, this.size, 9 );
  10259. gl.uniformMatrix3fv( this.addr, false, data );
  10260. }
  10261. function setValueM4Array( gl, v ) {
  10262. var data = flatten( v, this.size, 16 );
  10263. gl.uniformMatrix4fv( this.addr, false, data );
  10264. }
  10265. // Array of textures (2D / Cube)
  10266. function setValueT1Array( gl, v, textures ) {
  10267. var n = v.length;
  10268. var units = allocTexUnits( textures, n );
  10269. gl.uniform1iv( this.addr, units );
  10270. for ( var i = 0; i !== n; ++ i ) {
  10271. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10272. }
  10273. }
  10274. function setValueT6Array( gl, v, textures ) {
  10275. var n = v.length;
  10276. var units = allocTexUnits( textures, n );
  10277. gl.uniform1iv( this.addr, units );
  10278. for ( var i = 0; i !== n; ++ i ) {
  10279. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10280. }
  10281. }
  10282. // Helper to pick the right setter for a pure (bottom-level) array
  10283. function getPureArraySetter( type ) {
  10284. switch ( type ) {
  10285. case 0x1406: return setValueV1fArray; // FLOAT
  10286. case 0x8b50: return setValueV2fArray; // _VEC2
  10287. case 0x8b51: return setValueV3fArray; // _VEC3
  10288. case 0x8b52: return setValueV4fArray; // _VEC4
  10289. case 0x8b5a: return setValueM2Array; // _MAT2
  10290. case 0x8b5b: return setValueM3Array; // _MAT3
  10291. case 0x8b5c: return setValueM4Array; // _MAT4
  10292. case 0x8b5e: return setValueT1Array; // SAMPLER_2D
  10293. case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
  10294. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10295. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10296. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10297. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10298. }
  10299. }
  10300. // --- Uniform Classes ---
  10301. function SingleUniform( id, activeInfo, addr ) {
  10302. this.id = id;
  10303. this.addr = addr;
  10304. this.cache = [];
  10305. this.setValue = getSingularSetter( activeInfo.type );
  10306. // this.path = activeInfo.name; // DEBUG
  10307. }
  10308. function PureArrayUniform( id, activeInfo, addr ) {
  10309. this.id = id;
  10310. this.addr = addr;
  10311. this.cache = [];
  10312. this.size = activeInfo.size;
  10313. this.setValue = getPureArraySetter( activeInfo.type );
  10314. // this.path = activeInfo.name; // DEBUG
  10315. }
  10316. PureArrayUniform.prototype.updateCache = function ( data ) {
  10317. var cache = this.cache;
  10318. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10319. this.cache = new Float32Array( data.length );
  10320. }
  10321. copyArray( cache, data );
  10322. };
  10323. function StructuredUniform( id ) {
  10324. this.id = id;
  10325. this.seq = [];
  10326. this.map = {};
  10327. }
  10328. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10329. var seq = this.seq;
  10330. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10331. var u = seq[ i ];
  10332. u.setValue( gl, value[ u.id ], textures );
  10333. }
  10334. };
  10335. // --- Top-level ---
  10336. // Parser - builds up the property tree from the path strings
  10337. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10338. // extracts
  10339. // - the identifier (member name or array index)
  10340. // - followed by an optional right bracket (found when array index)
  10341. // - followed by an optional left bracket or dot (type of subscript)
  10342. //
  10343. // Note: These portions can be read in a non-overlapping fashion and
  10344. // allow straightforward parsing of the hierarchy that WebGL encodes
  10345. // in the uniform names.
  10346. function addUniform( container, uniformObject ) {
  10347. container.seq.push( uniformObject );
  10348. container.map[ uniformObject.id ] = uniformObject;
  10349. }
  10350. function parseUniform( activeInfo, addr, container ) {
  10351. var path = activeInfo.name,
  10352. pathLength = path.length;
  10353. // reset RegExp object, because of the early exit of a previous run
  10354. RePathPart.lastIndex = 0;
  10355. while ( true ) {
  10356. var match = RePathPart.exec( path ),
  10357. matchEnd = RePathPart.lastIndex,
  10358. id = match[ 1 ],
  10359. idIsIndex = match[ 2 ] === ']',
  10360. subscript = match[ 3 ];
  10361. if ( idIsIndex ) id = id | 0; // convert to integer
  10362. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10363. // bare name or "pure" bottom-level array "[0]" suffix
  10364. addUniform( container, subscript === undefined ?
  10365. new SingleUniform( id, activeInfo, addr ) :
  10366. new PureArrayUniform( id, activeInfo, addr ) );
  10367. break;
  10368. } else {
  10369. // step into inner node / create it in case it doesn't exist
  10370. var map = container.map, next = map[ id ];
  10371. if ( next === undefined ) {
  10372. next = new StructuredUniform( id );
  10373. addUniform( container, next );
  10374. }
  10375. container = next;
  10376. }
  10377. }
  10378. }
  10379. // Root Container
  10380. function WebGLUniforms( gl, program ) {
  10381. this.seq = [];
  10382. this.map = {};
  10383. var n = gl.getProgramParameter( program, 35718 );
  10384. for ( var i = 0; i < n; ++ i ) {
  10385. var info = gl.getActiveUniform( program, i ),
  10386. addr = gl.getUniformLocation( program, info.name );
  10387. parseUniform( info, addr, this );
  10388. }
  10389. }
  10390. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10391. var u = this.map[ name ];
  10392. if ( u !== undefined ) u.setValue( gl, value, textures );
  10393. };
  10394. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10395. var v = object[ name ];
  10396. if ( v !== undefined ) this.setValue( gl, name, v );
  10397. };
  10398. // Static interface
  10399. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10400. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10401. var u = seq[ i ],
  10402. v = values[ u.id ];
  10403. if ( v.needsUpdate !== false ) {
  10404. // note: always updating when .needsUpdate is undefined
  10405. u.setValue( gl, v.value, textures );
  10406. }
  10407. }
  10408. };
  10409. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10410. var r = [];
  10411. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10412. var u = seq[ i ];
  10413. if ( u.id in values ) r.push( u );
  10414. }
  10415. return r;
  10416. };
  10417. /**
  10418. * @author mrdoob / http://mrdoob.com/
  10419. */
  10420. function WebGLShader( gl, type, string ) {
  10421. var shader = gl.createShader( type );
  10422. gl.shaderSource( shader, string );
  10423. gl.compileShader( shader );
  10424. return shader;
  10425. }
  10426. /**
  10427. * @author mrdoob / http://mrdoob.com/
  10428. */
  10429. var programIdCount = 0;
  10430. function addLineNumbers( string ) {
  10431. var lines = string.split( '\n' );
  10432. for ( var i = 0; i < lines.length; i ++ ) {
  10433. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10434. }
  10435. return lines.join( '\n' );
  10436. }
  10437. function getEncodingComponents( encoding ) {
  10438. switch ( encoding ) {
  10439. case LinearEncoding:
  10440. return [ 'Linear', '( value )' ];
  10441. case sRGBEncoding:
  10442. return [ 'sRGB', '( value )' ];
  10443. case RGBEEncoding:
  10444. return [ 'RGBE', '( value )' ];
  10445. case RGBM7Encoding:
  10446. return [ 'RGBM', '( value, 7.0 )' ];
  10447. case RGBM16Encoding:
  10448. return [ 'RGBM', '( value, 16.0 )' ];
  10449. case RGBDEncoding:
  10450. return [ 'RGBD', '( value, 256.0 )' ];
  10451. case GammaEncoding:
  10452. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10453. case LogLuvEncoding:
  10454. return [ 'LogLuv', '( value )' ];
  10455. default:
  10456. throw new Error( 'unsupported encoding: ' + encoding );
  10457. }
  10458. }
  10459. function getShaderErrors( gl, shader, type ) {
  10460. var status = gl.getShaderParameter( shader, 35713 );
  10461. var log = gl.getShaderInfoLog( shader ).trim();
  10462. if ( status && log === '' ) return '';
  10463. // --enable-privileged-webgl-extension
  10464. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10465. var source = gl.getShaderSource( shader );
  10466. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10467. }
  10468. function getTexelDecodingFunction( functionName, encoding ) {
  10469. var components = getEncodingComponents( encoding );
  10470. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10471. }
  10472. function getTexelEncodingFunction( functionName, encoding ) {
  10473. var components = getEncodingComponents( encoding );
  10474. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10475. }
  10476. function getToneMappingFunction( functionName, toneMapping ) {
  10477. var toneMappingName;
  10478. switch ( toneMapping ) {
  10479. case LinearToneMapping:
  10480. toneMappingName = 'Linear';
  10481. break;
  10482. case ReinhardToneMapping:
  10483. toneMappingName = 'Reinhard';
  10484. break;
  10485. case Uncharted2ToneMapping:
  10486. toneMappingName = 'Uncharted2';
  10487. break;
  10488. case CineonToneMapping:
  10489. toneMappingName = 'OptimizedCineon';
  10490. break;
  10491. case ACESFilmicToneMapping:
  10492. toneMappingName = 'ACESFilmic';
  10493. break;
  10494. default:
  10495. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10496. }
  10497. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10498. }
  10499. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10500. extensions = extensions || {};
  10501. var chunks = [
  10502. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.clearCoatNormalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10503. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10504. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10505. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10506. ];
  10507. return chunks.filter( filterEmptyLine ).join( '\n' );
  10508. }
  10509. function generateDefines( defines ) {
  10510. var chunks = [];
  10511. for ( var name in defines ) {
  10512. var value = defines[ name ];
  10513. if ( value === false ) continue;
  10514. chunks.push( '#define ' + name + ' ' + value );
  10515. }
  10516. return chunks.join( '\n' );
  10517. }
  10518. function fetchAttributeLocations( gl, program ) {
  10519. var attributes = {};
  10520. var n = gl.getProgramParameter( program, 35721 );
  10521. for ( var i = 0; i < n; i ++ ) {
  10522. var info = gl.getActiveAttrib( program, i );
  10523. var name = info.name;
  10524. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10525. attributes[ name ] = gl.getAttribLocation( program, name );
  10526. }
  10527. return attributes;
  10528. }
  10529. function filterEmptyLine( string ) {
  10530. return string !== '';
  10531. }
  10532. function replaceLightNums( string, parameters ) {
  10533. return string
  10534. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10535. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10536. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10537. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10538. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  10539. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  10540. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  10541. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  10542. }
  10543. function replaceClippingPlaneNums( string, parameters ) {
  10544. return string
  10545. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10546. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10547. }
  10548. function parseIncludes( string ) {
  10549. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10550. function replace( match, include ) {
  10551. var replace = ShaderChunk[ include ];
  10552. if ( replace === undefined ) {
  10553. throw new Error( 'Can not resolve #include <' + include + '>' );
  10554. }
  10555. return parseIncludes( replace );
  10556. }
  10557. return string.replace( pattern, replace );
  10558. }
  10559. function unrollLoops( string ) {
  10560. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10561. function replace( match, start, end, snippet ) {
  10562. var unroll = '';
  10563. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10564. unroll += snippet
  10565. .replace( /\[ i \]/g, '[ ' + i + ' ]' )
  10566. .replace( /UNROLLED_LOOP_INDEX/g, i );
  10567. }
  10568. return unroll;
  10569. }
  10570. return string.replace( pattern, replace );
  10571. }
  10572. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  10573. var gl = renderer.getContext();
  10574. var defines = material.defines;
  10575. var vertexShader = shader.vertexShader;
  10576. var fragmentShader = shader.fragmentShader;
  10577. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10578. if ( parameters.shadowMapType === PCFShadowMap ) {
  10579. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10580. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10581. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10582. }
  10583. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10584. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10585. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10586. if ( parameters.envMap ) {
  10587. switch ( material.envMap.mapping ) {
  10588. case CubeReflectionMapping:
  10589. case CubeRefractionMapping:
  10590. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10591. break;
  10592. case CubeUVReflectionMapping:
  10593. case CubeUVRefractionMapping:
  10594. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10595. break;
  10596. case EquirectangularReflectionMapping:
  10597. case EquirectangularRefractionMapping:
  10598. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10599. break;
  10600. case SphericalReflectionMapping:
  10601. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10602. break;
  10603. }
  10604. switch ( material.envMap.mapping ) {
  10605. case CubeRefractionMapping:
  10606. case EquirectangularRefractionMapping:
  10607. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10608. break;
  10609. }
  10610. switch ( material.combine ) {
  10611. case MultiplyOperation:
  10612. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10613. break;
  10614. case MixOperation:
  10615. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10616. break;
  10617. case AddOperation:
  10618. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10619. break;
  10620. }
  10621. }
  10622. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10623. // console.log( 'building new program ' );
  10624. //
  10625. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10626. var customDefines = generateDefines( defines );
  10627. //
  10628. var program = gl.createProgram();
  10629. var prefixVertex, prefixFragment;
  10630. if ( material.isRawShaderMaterial ) {
  10631. prefixVertex = [
  10632. customDefines
  10633. ].filter( filterEmptyLine ).join( '\n' );
  10634. if ( prefixVertex.length > 0 ) {
  10635. prefixVertex += '\n';
  10636. }
  10637. prefixFragment = [
  10638. customExtensions,
  10639. customDefines
  10640. ].filter( filterEmptyLine ).join( '\n' );
  10641. if ( prefixFragment.length > 0 ) {
  10642. prefixFragment += '\n';
  10643. }
  10644. } else {
  10645. prefixVertex = [
  10646. 'precision ' + parameters.precision + ' float;',
  10647. 'precision ' + parameters.precision + ' int;',
  10648. '#define SHADER_NAME ' + shader.name,
  10649. customDefines,
  10650. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10651. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10652. '#define MAX_BONES ' + parameters.maxBones,
  10653. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10654. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10655. parameters.map ? '#define USE_MAP' : '',
  10656. parameters.envMap ? '#define USE_ENVMAP' : '',
  10657. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10658. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10659. parameters.aoMap ? '#define USE_AOMAP' : '',
  10660. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10661. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10662. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10663. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10664. parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10665. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10666. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10667. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10668. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10669. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10670. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10671. parameters.vertexColors ? '#define USE_COLOR' : '',
  10672. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10673. parameters.skinning ? '#define USE_SKINNING' : '',
  10674. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10675. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10676. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10677. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10678. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10679. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10680. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10681. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10682. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10683. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10684. 'uniform mat4 modelMatrix;',
  10685. 'uniform mat4 modelViewMatrix;',
  10686. 'uniform mat4 projectionMatrix;',
  10687. 'uniform mat4 viewMatrix;',
  10688. 'uniform mat3 normalMatrix;',
  10689. 'uniform vec3 cameraPosition;',
  10690. 'attribute vec3 position;',
  10691. 'attribute vec3 normal;',
  10692. 'attribute vec2 uv;',
  10693. '#ifdef USE_TANGENT',
  10694. ' attribute vec4 tangent;',
  10695. '#endif',
  10696. '#ifdef USE_COLOR',
  10697. ' attribute vec3 color;',
  10698. '#endif',
  10699. '#ifdef USE_MORPHTARGETS',
  10700. ' attribute vec3 morphTarget0;',
  10701. ' attribute vec3 morphTarget1;',
  10702. ' attribute vec3 morphTarget2;',
  10703. ' attribute vec3 morphTarget3;',
  10704. ' #ifdef USE_MORPHNORMALS',
  10705. ' attribute vec3 morphNormal0;',
  10706. ' attribute vec3 morphNormal1;',
  10707. ' attribute vec3 morphNormal2;',
  10708. ' attribute vec3 morphNormal3;',
  10709. ' #else',
  10710. ' attribute vec3 morphTarget4;',
  10711. ' attribute vec3 morphTarget5;',
  10712. ' attribute vec3 morphTarget6;',
  10713. ' attribute vec3 morphTarget7;',
  10714. ' #endif',
  10715. '#endif',
  10716. '#ifdef USE_SKINNING',
  10717. ' attribute vec4 skinIndex;',
  10718. ' attribute vec4 skinWeight;',
  10719. '#endif',
  10720. '\n'
  10721. ].filter( filterEmptyLine ).join( '\n' );
  10722. prefixFragment = [
  10723. customExtensions,
  10724. 'precision ' + parameters.precision + ' float;',
  10725. 'precision ' + parameters.precision + ' int;',
  10726. '#define SHADER_NAME ' + shader.name,
  10727. customDefines,
  10728. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10729. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10730. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10731. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10732. parameters.map ? '#define USE_MAP' : '',
  10733. parameters.matcap ? '#define USE_MATCAP' : '',
  10734. parameters.envMap ? '#define USE_ENVMAP' : '',
  10735. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10736. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10737. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10738. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10739. parameters.aoMap ? '#define USE_AOMAP' : '',
  10740. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10741. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10742. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10743. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10744. parameters.clearCoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10745. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10746. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10747. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10748. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10749. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10750. parameters.vertexColors ? '#define USE_COLOR' : '',
  10751. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10752. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10753. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10754. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10755. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10756. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10757. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10758. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10759. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10760. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10761. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10762. 'uniform mat4 viewMatrix;',
  10763. 'uniform vec3 cameraPosition;',
  10764. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10765. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10766. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10767. parameters.dithering ? '#define DITHERING' : '',
  10768. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10769. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10770. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10771. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10772. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10773. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10774. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10775. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10776. '\n'
  10777. ].filter( filterEmptyLine ).join( '\n' );
  10778. }
  10779. vertexShader = parseIncludes( vertexShader );
  10780. vertexShader = replaceLightNums( vertexShader, parameters );
  10781. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10782. fragmentShader = parseIncludes( fragmentShader );
  10783. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10784. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10785. vertexShader = unrollLoops( vertexShader );
  10786. fragmentShader = unrollLoops( fragmentShader );
  10787. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10788. var isGLSL3ShaderMaterial = false;
  10789. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10790. if ( material.isShaderMaterial &&
  10791. vertexShader.match( versionRegex ) !== null &&
  10792. fragmentShader.match( versionRegex ) !== null ) {
  10793. isGLSL3ShaderMaterial = true;
  10794. vertexShader = vertexShader.replace( versionRegex, '' );
  10795. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10796. }
  10797. // GLSL 3.0 conversion
  10798. prefixVertex = [
  10799. '#version 300 es\n',
  10800. '#define attribute in',
  10801. '#define varying out',
  10802. '#define texture2D texture'
  10803. ].join( '\n' ) + '\n' + prefixVertex;
  10804. prefixFragment = [
  10805. '#version 300 es\n',
  10806. '#define varying in',
  10807. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10808. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10809. '#define gl_FragDepthEXT gl_FragDepth',
  10810. '#define texture2D texture',
  10811. '#define textureCube texture',
  10812. '#define texture2DProj textureProj',
  10813. '#define texture2DLodEXT textureLod',
  10814. '#define texture2DProjLodEXT textureProjLod',
  10815. '#define textureCubeLodEXT textureLod',
  10816. '#define texture2DGradEXT textureGrad',
  10817. '#define texture2DProjGradEXT textureProjGrad',
  10818. '#define textureCubeGradEXT textureGrad'
  10819. ].join( '\n' ) + '\n' + prefixFragment;
  10820. }
  10821. var vertexGlsl = prefixVertex + vertexShader;
  10822. var fragmentGlsl = prefixFragment + fragmentShader;
  10823. // console.log( '*VERTEX*', vertexGlsl );
  10824. // console.log( '*FRAGMENT*', fragmentGlsl );
  10825. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10826. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10827. gl.attachShader( program, glVertexShader );
  10828. gl.attachShader( program, glFragmentShader );
  10829. // Force a particular attribute to index 0.
  10830. if ( material.index0AttributeName !== undefined ) {
  10831. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10832. } else if ( parameters.morphTargets === true ) {
  10833. // programs with morphTargets displace position out of attribute 0
  10834. gl.bindAttribLocation( program, 0, 'position' );
  10835. }
  10836. gl.linkProgram( program );
  10837. // check for link errors
  10838. if ( renderer.debug.checkShaderErrors ) {
  10839. var programLog = gl.getProgramInfoLog( program ).trim();
  10840. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10841. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10842. var runnable = true;
  10843. var haveDiagnostics = true;
  10844. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10845. runnable = false;
  10846. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10847. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10848. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10849. } else if ( programLog !== '' ) {
  10850. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10851. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10852. haveDiagnostics = false;
  10853. }
  10854. if ( haveDiagnostics ) {
  10855. this.diagnostics = {
  10856. runnable: runnable,
  10857. material: material,
  10858. programLog: programLog,
  10859. vertexShader: {
  10860. log: vertexLog,
  10861. prefix: prefixVertex
  10862. },
  10863. fragmentShader: {
  10864. log: fragmentLog,
  10865. prefix: prefixFragment
  10866. }
  10867. };
  10868. }
  10869. }
  10870. // clean up
  10871. gl.deleteShader( glVertexShader );
  10872. gl.deleteShader( glFragmentShader );
  10873. // set up caching for uniform locations
  10874. var cachedUniforms;
  10875. this.getUniforms = function () {
  10876. if ( cachedUniforms === undefined ) {
  10877. cachedUniforms = new WebGLUniforms( gl, program );
  10878. }
  10879. return cachedUniforms;
  10880. };
  10881. // set up caching for attribute locations
  10882. var cachedAttributes;
  10883. this.getAttributes = function () {
  10884. if ( cachedAttributes === undefined ) {
  10885. cachedAttributes = fetchAttributeLocations( gl, program );
  10886. }
  10887. return cachedAttributes;
  10888. };
  10889. // free resource
  10890. this.destroy = function () {
  10891. gl.deleteProgram( program );
  10892. this.program = undefined;
  10893. };
  10894. //
  10895. this.name = shader.name;
  10896. this.id = programIdCount ++;
  10897. this.code = code;
  10898. this.usedTimes = 1;
  10899. this.program = program;
  10900. this.vertexShader = glVertexShader;
  10901. this.fragmentShader = glFragmentShader;
  10902. return this;
  10903. }
  10904. /**
  10905. * @author mrdoob / http://mrdoob.com/
  10906. */
  10907. function WebGLPrograms( renderer, extensions, capabilities ) {
  10908. var programs = [];
  10909. var shaderIDs = {
  10910. MeshDepthMaterial: 'depth',
  10911. MeshDistanceMaterial: 'distanceRGBA',
  10912. MeshNormalMaterial: 'normal',
  10913. MeshBasicMaterial: 'basic',
  10914. MeshLambertMaterial: 'lambert',
  10915. MeshPhongMaterial: 'phong',
  10916. MeshToonMaterial: 'phong',
  10917. MeshStandardMaterial: 'physical',
  10918. MeshPhysicalMaterial: 'physical',
  10919. MeshMatcapMaterial: 'matcap',
  10920. LineBasicMaterial: 'basic',
  10921. LineDashedMaterial: 'dashed',
  10922. PointsMaterial: 'points',
  10923. ShadowMaterial: 'shadow',
  10924. SpriteMaterial: 'sprite'
  10925. };
  10926. var parameterNames = [
  10927. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10928. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "clearCoatNormalMap", "displacementMap", "specularMap",
  10929. "roughnessMap", "metalnessMap", "gradientMap",
  10930. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10931. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10932. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10933. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10934. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10935. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10936. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10937. ];
  10938. function allocateBones( object ) {
  10939. var skeleton = object.skeleton;
  10940. var bones = skeleton.bones;
  10941. if ( capabilities.floatVertexTextures ) {
  10942. return 1024;
  10943. } else {
  10944. // default for when object is not specified
  10945. // ( for example when prebuilding shader to be used with multiple objects )
  10946. //
  10947. // - leave some extra space for other uniforms
  10948. // - limit here is ANGLE's 254 max uniform vectors
  10949. // (up to 54 should be safe)
  10950. var nVertexUniforms = capabilities.maxVertexUniforms;
  10951. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10952. var maxBones = Math.min( nVertexMatrices, bones.length );
  10953. if ( maxBones < bones.length ) {
  10954. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10955. return 0;
  10956. }
  10957. return maxBones;
  10958. }
  10959. }
  10960. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10961. var encoding;
  10962. if ( ! map ) {
  10963. encoding = LinearEncoding;
  10964. } else if ( map.isTexture ) {
  10965. encoding = map.encoding;
  10966. } else if ( map.isWebGLRenderTarget ) {
  10967. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10968. encoding = map.texture.encoding;
  10969. }
  10970. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10971. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10972. encoding = GammaEncoding;
  10973. }
  10974. return encoding;
  10975. }
  10976. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10977. var shaderID = shaderIDs[ material.type ];
  10978. // heuristics to create shader parameters according to lights in the scene
  10979. // (not to blow over maxLights budget)
  10980. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10981. var precision = capabilities.precision;
  10982. if ( material.precision !== null ) {
  10983. precision = capabilities.getMaxPrecision( material.precision );
  10984. if ( precision !== material.precision ) {
  10985. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10986. }
  10987. }
  10988. var currentRenderTarget = renderer.getRenderTarget();
  10989. var parameters = {
  10990. shaderID: shaderID,
  10991. precision: precision,
  10992. supportsVertexTextures: capabilities.vertexTextures,
  10993. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10994. map: !! material.map,
  10995. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10996. matcap: !! material.matcap,
  10997. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10998. envMap: !! material.envMap,
  10999. envMapMode: material.envMap && material.envMap.mapping,
  11000. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  11001. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  11002. lightMap: !! material.lightMap,
  11003. aoMap: !! material.aoMap,
  11004. emissiveMap: !! material.emissiveMap,
  11005. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  11006. bumpMap: !! material.bumpMap,
  11007. normalMap: !! material.normalMap,
  11008. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11009. clearCoatNormalMap: !! material.clearCoatNormalMap,
  11010. displacementMap: !! material.displacementMap,
  11011. roughnessMap: !! material.roughnessMap,
  11012. metalnessMap: !! material.metalnessMap,
  11013. specularMap: !! material.specularMap,
  11014. alphaMap: !! material.alphaMap,
  11015. gradientMap: !! material.gradientMap,
  11016. combine: material.combine,
  11017. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11018. vertexColors: material.vertexColors,
  11019. fog: !! fog,
  11020. useFog: material.fog,
  11021. fogExp: ( fog && fog.isFogExp2 ),
  11022. flatShading: material.flatShading,
  11023. sizeAttenuation: material.sizeAttenuation,
  11024. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  11025. skinning: material.skinning && maxBones > 0,
  11026. maxBones: maxBones,
  11027. useVertexTexture: capabilities.floatVertexTextures,
  11028. morphTargets: material.morphTargets,
  11029. morphNormals: material.morphNormals,
  11030. maxMorphTargets: renderer.maxMorphTargets,
  11031. maxMorphNormals: renderer.maxMorphNormals,
  11032. numDirLights: lights.directional.length,
  11033. numPointLights: lights.point.length,
  11034. numSpotLights: lights.spot.length,
  11035. numRectAreaLights: lights.rectArea.length,
  11036. numHemiLights: lights.hemi.length,
  11037. numDirLightShadows: lights.directionalShadowMap.length,
  11038. numPointLightShadows: lights.pointShadowMap.length,
  11039. numSpotLightShadows: lights.spotShadowMap.length,
  11040. numClippingPlanes: nClipPlanes,
  11041. numClipIntersection: nClipIntersection,
  11042. dithering: material.dithering,
  11043. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  11044. shadowMapType: renderer.shadowMap.type,
  11045. toneMapping: renderer.toneMapping,
  11046. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11047. premultipliedAlpha: material.premultipliedAlpha,
  11048. alphaTest: material.alphaTest,
  11049. doubleSided: material.side === DoubleSide,
  11050. flipSided: material.side === BackSide,
  11051. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  11052. };
  11053. return parameters;
  11054. };
  11055. this.getProgramCode = function ( material, parameters ) {
  11056. var array = [];
  11057. if ( parameters.shaderID ) {
  11058. array.push( parameters.shaderID );
  11059. } else {
  11060. array.push( material.fragmentShader );
  11061. array.push( material.vertexShader );
  11062. }
  11063. if ( material.defines !== undefined ) {
  11064. for ( var name in material.defines ) {
  11065. array.push( name );
  11066. array.push( material.defines[ name ] );
  11067. }
  11068. }
  11069. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11070. array.push( parameters[ parameterNames[ i ] ] );
  11071. }
  11072. array.push( material.onBeforeCompile.toString() );
  11073. array.push( renderer.gammaOutput );
  11074. array.push( renderer.gammaFactor );
  11075. return array.join();
  11076. };
  11077. this.acquireProgram = function ( material, shader, parameters, code ) {
  11078. var program;
  11079. // Check if code has been already compiled
  11080. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11081. var programInfo = programs[ p ];
  11082. if ( programInfo.code === code ) {
  11083. program = programInfo;
  11084. ++ program.usedTimes;
  11085. break;
  11086. }
  11087. }
  11088. if ( program === undefined ) {
  11089. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  11090. programs.push( program );
  11091. }
  11092. return program;
  11093. };
  11094. this.releaseProgram = function ( program ) {
  11095. if ( -- program.usedTimes === 0 ) {
  11096. // Remove from unordered set
  11097. var i = programs.indexOf( program );
  11098. programs[ i ] = programs[ programs.length - 1 ];
  11099. programs.pop();
  11100. // Free WebGL resources
  11101. program.destroy();
  11102. }
  11103. };
  11104. // Exposed for resource monitoring & error feedback via renderer.info:
  11105. this.programs = programs;
  11106. }
  11107. /**
  11108. * @author fordacious / fordacious.github.io
  11109. */
  11110. function WebGLProperties() {
  11111. var properties = new WeakMap();
  11112. function get( object ) {
  11113. var map = properties.get( object );
  11114. if ( map === undefined ) {
  11115. map = {};
  11116. properties.set( object, map );
  11117. }
  11118. return map;
  11119. }
  11120. function remove( object ) {
  11121. properties.delete( object );
  11122. }
  11123. function update( object, key, value ) {
  11124. properties.get( object )[ key ] = value;
  11125. }
  11126. function dispose() {
  11127. properties = new WeakMap();
  11128. }
  11129. return {
  11130. get: get,
  11131. remove: remove,
  11132. update: update,
  11133. dispose: dispose
  11134. };
  11135. }
  11136. /**
  11137. * @author mrdoob / http://mrdoob.com/
  11138. */
  11139. function painterSortStable( a, b ) {
  11140. if ( a.groupOrder !== b.groupOrder ) {
  11141. return a.groupOrder - b.groupOrder;
  11142. } else if ( a.renderOrder !== b.renderOrder ) {
  11143. return a.renderOrder - b.renderOrder;
  11144. } else if ( a.program !== b.program ) {
  11145. return a.program.id - b.program.id;
  11146. } else if ( a.material.id !== b.material.id ) {
  11147. return a.material.id - b.material.id;
  11148. } else if ( a.z !== b.z ) {
  11149. return a.z - b.z;
  11150. } else {
  11151. return a.id - b.id;
  11152. }
  11153. }
  11154. function reversePainterSortStable( a, b ) {
  11155. if ( a.groupOrder !== b.groupOrder ) {
  11156. return a.groupOrder - b.groupOrder;
  11157. } else if ( a.renderOrder !== b.renderOrder ) {
  11158. return a.renderOrder - b.renderOrder;
  11159. } else if ( a.z !== b.z ) {
  11160. return b.z - a.z;
  11161. } else {
  11162. return a.id - b.id;
  11163. }
  11164. }
  11165. function WebGLRenderList() {
  11166. var renderItems = [];
  11167. var renderItemsIndex = 0;
  11168. var opaque = [];
  11169. var transparent = [];
  11170. var defaultProgram = { id: - 1 };
  11171. function init() {
  11172. renderItemsIndex = 0;
  11173. opaque.length = 0;
  11174. transparent.length = 0;
  11175. }
  11176. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11177. var renderItem = renderItems[ renderItemsIndex ];
  11178. if ( renderItem === undefined ) {
  11179. renderItem = {
  11180. id: object.id,
  11181. object: object,
  11182. geometry: geometry,
  11183. material: material,
  11184. program: material.program || defaultProgram,
  11185. groupOrder: groupOrder,
  11186. renderOrder: object.renderOrder,
  11187. z: z,
  11188. group: group
  11189. };
  11190. renderItems[ renderItemsIndex ] = renderItem;
  11191. } else {
  11192. renderItem.id = object.id;
  11193. renderItem.object = object;
  11194. renderItem.geometry = geometry;
  11195. renderItem.material = material;
  11196. renderItem.program = material.program || defaultProgram;
  11197. renderItem.groupOrder = groupOrder;
  11198. renderItem.renderOrder = object.renderOrder;
  11199. renderItem.z = z;
  11200. renderItem.group = group;
  11201. }
  11202. renderItemsIndex ++;
  11203. return renderItem;
  11204. }
  11205. function push( object, geometry, material, groupOrder, z, group ) {
  11206. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11207. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11208. }
  11209. function unshift( object, geometry, material, groupOrder, z, group ) {
  11210. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11211. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11212. }
  11213. function sort() {
  11214. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  11215. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  11216. }
  11217. return {
  11218. opaque: opaque,
  11219. transparent: transparent,
  11220. init: init,
  11221. push: push,
  11222. unshift: unshift,
  11223. sort: sort
  11224. };
  11225. }
  11226. function WebGLRenderLists() {
  11227. var lists = {};
  11228. function onSceneDispose( event ) {
  11229. var scene = event.target;
  11230. scene.removeEventListener( 'dispose', onSceneDispose );
  11231. delete lists[ scene.id ];
  11232. }
  11233. function get( scene, camera ) {
  11234. var cameras = lists[ scene.id ];
  11235. var list;
  11236. if ( cameras === undefined ) {
  11237. list = new WebGLRenderList();
  11238. lists[ scene.id ] = {};
  11239. lists[ scene.id ][ camera.id ] = list;
  11240. scene.addEventListener( 'dispose', onSceneDispose );
  11241. } else {
  11242. list = cameras[ camera.id ];
  11243. if ( list === undefined ) {
  11244. list = new WebGLRenderList();
  11245. cameras[ camera.id ] = list;
  11246. }
  11247. }
  11248. return list;
  11249. }
  11250. function dispose() {
  11251. lists = {};
  11252. }
  11253. return {
  11254. get: get,
  11255. dispose: dispose
  11256. };
  11257. }
  11258. /**
  11259. * @author mrdoob / http://mrdoob.com/
  11260. */
  11261. function UniformsCache() {
  11262. var lights = {};
  11263. return {
  11264. get: function ( light ) {
  11265. if ( lights[ light.id ] !== undefined ) {
  11266. return lights[ light.id ];
  11267. }
  11268. var uniforms;
  11269. switch ( light.type ) {
  11270. case 'DirectionalLight':
  11271. uniforms = {
  11272. direction: new Vector3(),
  11273. color: new Color(),
  11274. shadow: false,
  11275. shadowBias: 0,
  11276. shadowRadius: 1,
  11277. shadowMapSize: new Vector2()
  11278. };
  11279. break;
  11280. case 'SpotLight':
  11281. uniforms = {
  11282. position: new Vector3(),
  11283. direction: new Vector3(),
  11284. color: new Color(),
  11285. distance: 0,
  11286. coneCos: 0,
  11287. penumbraCos: 0,
  11288. decay: 0,
  11289. shadow: false,
  11290. shadowBias: 0,
  11291. shadowRadius: 1,
  11292. shadowMapSize: new Vector2()
  11293. };
  11294. break;
  11295. case 'PointLight':
  11296. uniforms = {
  11297. position: new Vector3(),
  11298. color: new Color(),
  11299. distance: 0,
  11300. decay: 0,
  11301. shadow: false,
  11302. shadowBias: 0,
  11303. shadowRadius: 1,
  11304. shadowMapSize: new Vector2(),
  11305. shadowCameraNear: 1,
  11306. shadowCameraFar: 1000
  11307. };
  11308. break;
  11309. case 'HemisphereLight':
  11310. uniforms = {
  11311. direction: new Vector3(),
  11312. skyColor: new Color(),
  11313. groundColor: new Color()
  11314. };
  11315. break;
  11316. case 'RectAreaLight':
  11317. uniforms = {
  11318. color: new Color(),
  11319. position: new Vector3(),
  11320. halfWidth: new Vector3(),
  11321. halfHeight: new Vector3()
  11322. // TODO (abelnation): set RectAreaLight shadow uniforms
  11323. };
  11324. break;
  11325. }
  11326. lights[ light.id ] = uniforms;
  11327. return uniforms;
  11328. }
  11329. };
  11330. }
  11331. var nextVersion = 0;
  11332. function shadowCastingLightsFirst( lightA, lightB ) {
  11333. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  11334. }
  11335. function WebGLLights() {
  11336. var cache = new UniformsCache();
  11337. var state = {
  11338. version: 0,
  11339. hash: {
  11340. directionalLength: - 1,
  11341. pointLength: - 1,
  11342. spotLength: - 1,
  11343. rectAreaLength: - 1,
  11344. hemiLength: - 1,
  11345. numDirectionalShadows: - 1,
  11346. numPointShadows: - 1,
  11347. numSpotShadows: - 1,
  11348. },
  11349. ambient: [ 0, 0, 0 ],
  11350. probe: [],
  11351. directional: [],
  11352. directionalShadowMap: [],
  11353. directionalShadowMatrix: [],
  11354. spot: [],
  11355. spotShadowMap: [],
  11356. spotShadowMatrix: [],
  11357. rectArea: [],
  11358. point: [],
  11359. pointShadowMap: [],
  11360. pointShadowMatrix: [],
  11361. hemi: [],
  11362. numDirectionalShadows: - 1,
  11363. numPointShadows: - 1,
  11364. numSpotShadows: - 1
  11365. };
  11366. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11367. var vector3 = new Vector3();
  11368. var matrix4 = new Matrix4();
  11369. var matrix42 = new Matrix4();
  11370. function setup( lights, shadows, camera ) {
  11371. var r = 0, g = 0, b = 0;
  11372. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11373. var directionalLength = 0;
  11374. var pointLength = 0;
  11375. var spotLength = 0;
  11376. var rectAreaLength = 0;
  11377. var hemiLength = 0;
  11378. var numDirectionalShadows = 0;
  11379. var numPointShadows = 0;
  11380. var numSpotShadows = 0;
  11381. var viewMatrix = camera.matrixWorldInverse;
  11382. lights.sort( shadowCastingLightsFirst );
  11383. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  11384. var light = lights[ i ];
  11385. var color = light.color;
  11386. var intensity = light.intensity;
  11387. var distance = light.distance;
  11388. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11389. if ( light.isAmbientLight ) {
  11390. r += color.r * intensity;
  11391. g += color.g * intensity;
  11392. b += color.b * intensity;
  11393. } else if ( light.isLightProbe ) {
  11394. for ( var j = 0; j < 9; j ++ ) {
  11395. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11396. }
  11397. } else if ( light.isDirectionalLight ) {
  11398. var uniforms = cache.get( light );
  11399. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11400. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11401. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11402. uniforms.direction.sub( vector3 );
  11403. uniforms.direction.transformDirection( viewMatrix );
  11404. uniforms.shadow = light.castShadow;
  11405. if ( light.castShadow ) {
  11406. var shadow = light.shadow;
  11407. uniforms.shadowBias = shadow.bias;
  11408. uniforms.shadowRadius = shadow.radius;
  11409. uniforms.shadowMapSize = shadow.mapSize;
  11410. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11411. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11412. numDirectionalShadows ++;
  11413. }
  11414. state.directional[ directionalLength ] = uniforms;
  11415. directionalLength ++;
  11416. } else if ( light.isSpotLight ) {
  11417. var uniforms = cache.get( light );
  11418. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11419. uniforms.position.applyMatrix4( viewMatrix );
  11420. uniforms.color.copy( color ).multiplyScalar( intensity );
  11421. uniforms.distance = distance;
  11422. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11423. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11424. uniforms.direction.sub( vector3 );
  11425. uniforms.direction.transformDirection( viewMatrix );
  11426. uniforms.coneCos = Math.cos( light.angle );
  11427. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11428. uniforms.decay = light.decay;
  11429. uniforms.shadow = light.castShadow;
  11430. if ( light.castShadow ) {
  11431. var shadow = light.shadow;
  11432. uniforms.shadowBias = shadow.bias;
  11433. uniforms.shadowRadius = shadow.radius;
  11434. uniforms.shadowMapSize = shadow.mapSize;
  11435. state.spotShadowMap[ spotLength ] = shadowMap;
  11436. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11437. numSpotShadows ++;
  11438. }
  11439. state.spot[ spotLength ] = uniforms;
  11440. spotLength ++;
  11441. } else if ( light.isRectAreaLight ) {
  11442. var uniforms = cache.get( light );
  11443. // (a) intensity is the total visible light emitted
  11444. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11445. // (b) intensity is the brightness of the light
  11446. uniforms.color.copy( color ).multiplyScalar( intensity );
  11447. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11448. uniforms.position.applyMatrix4( viewMatrix );
  11449. // extract local rotation of light to derive width/height half vectors
  11450. matrix42.identity();
  11451. matrix4.copy( light.matrixWorld );
  11452. matrix4.premultiply( viewMatrix );
  11453. matrix42.extractRotation( matrix4 );
  11454. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11455. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11456. uniforms.halfWidth.applyMatrix4( matrix42 );
  11457. uniforms.halfHeight.applyMatrix4( matrix42 );
  11458. // TODO (abelnation): RectAreaLight distance?
  11459. // uniforms.distance = distance;
  11460. state.rectArea[ rectAreaLength ] = uniforms;
  11461. rectAreaLength ++;
  11462. } else if ( light.isPointLight ) {
  11463. var uniforms = cache.get( light );
  11464. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11465. uniforms.position.applyMatrix4( viewMatrix );
  11466. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11467. uniforms.distance = light.distance;
  11468. uniforms.decay = light.decay;
  11469. uniforms.shadow = light.castShadow;
  11470. if ( light.castShadow ) {
  11471. var shadow = light.shadow;
  11472. uniforms.shadowBias = shadow.bias;
  11473. uniforms.shadowRadius = shadow.radius;
  11474. uniforms.shadowMapSize = shadow.mapSize;
  11475. uniforms.shadowCameraNear = shadow.camera.near;
  11476. uniforms.shadowCameraFar = shadow.camera.far;
  11477. state.pointShadowMap[ pointLength ] = shadowMap;
  11478. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11479. numPointShadows ++;
  11480. }
  11481. state.point[ pointLength ] = uniforms;
  11482. pointLength ++;
  11483. } else if ( light.isHemisphereLight ) {
  11484. var uniforms = cache.get( light );
  11485. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11486. uniforms.direction.transformDirection( viewMatrix );
  11487. uniforms.direction.normalize();
  11488. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11489. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11490. state.hemi[ hemiLength ] = uniforms;
  11491. hemiLength ++;
  11492. }
  11493. }
  11494. state.ambient[ 0 ] = r;
  11495. state.ambient[ 1 ] = g;
  11496. state.ambient[ 2 ] = b;
  11497. var hash = state.hash;
  11498. if ( hash.directionalLength !== directionalLength ||
  11499. hash.pointLength !== pointLength ||
  11500. hash.spotLength !== spotLength ||
  11501. hash.rectAreaLength !== rectAreaLength ||
  11502. hash.hemiLength !== hemiLength ||
  11503. hash.numDirectionalShadows !== numDirectionalShadows ||
  11504. hash.numPointShadows !== numPointShadows ||
  11505. hash.numSpotShadows !== numSpotShadows ) {
  11506. state.directional.length = directionalLength;
  11507. state.spot.length = spotLength;
  11508. state.rectArea.length = rectAreaLength;
  11509. state.point.length = pointLength;
  11510. state.hemi.length = hemiLength;
  11511. state.directionalShadowMap.length = numDirectionalShadows;
  11512. state.pointShadowMap.length = numPointShadows;
  11513. state.spotShadowMap.length = numSpotShadows;
  11514. state.directionalShadowMatrix.length = numDirectionalShadows;
  11515. state.pointShadowMatrix.length = numPointShadows;
  11516. state.spotShadowMatrix.length = numSpotShadows;
  11517. hash.directionalLength = directionalLength;
  11518. hash.pointLength = pointLength;
  11519. hash.spotLength = spotLength;
  11520. hash.rectAreaLength = rectAreaLength;
  11521. hash.hemiLength = hemiLength;
  11522. hash.numDirectionalShadows = numDirectionalShadows;
  11523. hash.numPointShadows = numPointShadows;
  11524. hash.numSpotShadows = numSpotShadows;
  11525. state.version = nextVersion ++;
  11526. }
  11527. }
  11528. return {
  11529. setup: setup,
  11530. state: state
  11531. };
  11532. }
  11533. /**
  11534. * @author Mugen87 / https://github.com/Mugen87
  11535. */
  11536. function WebGLRenderState() {
  11537. var lights = new WebGLLights();
  11538. var lightsArray = [];
  11539. var shadowsArray = [];
  11540. function init() {
  11541. lightsArray.length = 0;
  11542. shadowsArray.length = 0;
  11543. }
  11544. function pushLight( light ) {
  11545. lightsArray.push( light );
  11546. }
  11547. function pushShadow( shadowLight ) {
  11548. shadowsArray.push( shadowLight );
  11549. }
  11550. function setupLights( camera ) {
  11551. lights.setup( lightsArray, shadowsArray, camera );
  11552. }
  11553. var state = {
  11554. lightsArray: lightsArray,
  11555. shadowsArray: shadowsArray,
  11556. lights: lights
  11557. };
  11558. return {
  11559. init: init,
  11560. state: state,
  11561. setupLights: setupLights,
  11562. pushLight: pushLight,
  11563. pushShadow: pushShadow
  11564. };
  11565. }
  11566. function WebGLRenderStates() {
  11567. var renderStates = {};
  11568. function onSceneDispose( event ) {
  11569. var scene = event.target;
  11570. scene.removeEventListener( 'dispose', onSceneDispose );
  11571. delete renderStates[ scene.id ];
  11572. }
  11573. function get( scene, camera ) {
  11574. var renderState;
  11575. if ( renderStates[ scene.id ] === undefined ) {
  11576. renderState = new WebGLRenderState();
  11577. renderStates[ scene.id ] = {};
  11578. renderStates[ scene.id ][ camera.id ] = renderState;
  11579. scene.addEventListener( 'dispose', onSceneDispose );
  11580. } else {
  11581. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11582. renderState = new WebGLRenderState();
  11583. renderStates[ scene.id ][ camera.id ] = renderState;
  11584. } else {
  11585. renderState = renderStates[ scene.id ][ camera.id ];
  11586. }
  11587. }
  11588. return renderState;
  11589. }
  11590. function dispose() {
  11591. renderStates = {};
  11592. }
  11593. return {
  11594. get: get,
  11595. dispose: dispose
  11596. };
  11597. }
  11598. /**
  11599. * @author mrdoob / http://mrdoob.com/
  11600. * @author alteredq / http://alteredqualia.com/
  11601. * @author bhouston / https://clara.io
  11602. * @author WestLangley / http://github.com/WestLangley
  11603. *
  11604. * parameters = {
  11605. *
  11606. * opacity: <float>,
  11607. *
  11608. * map: new THREE.Texture( <Image> ),
  11609. *
  11610. * alphaMap: new THREE.Texture( <Image> ),
  11611. *
  11612. * displacementMap: new THREE.Texture( <Image> ),
  11613. * displacementScale: <float>,
  11614. * displacementBias: <float>,
  11615. *
  11616. * wireframe: <boolean>,
  11617. * wireframeLinewidth: <float>
  11618. * }
  11619. */
  11620. function MeshDepthMaterial( parameters ) {
  11621. Material.call( this );
  11622. this.type = 'MeshDepthMaterial';
  11623. this.depthPacking = BasicDepthPacking;
  11624. this.skinning = false;
  11625. this.morphTargets = false;
  11626. this.map = null;
  11627. this.alphaMap = null;
  11628. this.displacementMap = null;
  11629. this.displacementScale = 1;
  11630. this.displacementBias = 0;
  11631. this.wireframe = false;
  11632. this.wireframeLinewidth = 1;
  11633. this.fog = false;
  11634. this.lights = false;
  11635. this.setValues( parameters );
  11636. }
  11637. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11638. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11639. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11640. MeshDepthMaterial.prototype.copy = function ( source ) {
  11641. Material.prototype.copy.call( this, source );
  11642. this.depthPacking = source.depthPacking;
  11643. this.skinning = source.skinning;
  11644. this.morphTargets = source.morphTargets;
  11645. this.map = source.map;
  11646. this.alphaMap = source.alphaMap;
  11647. this.displacementMap = source.displacementMap;
  11648. this.displacementScale = source.displacementScale;
  11649. this.displacementBias = source.displacementBias;
  11650. this.wireframe = source.wireframe;
  11651. this.wireframeLinewidth = source.wireframeLinewidth;
  11652. return this;
  11653. };
  11654. /**
  11655. * @author WestLangley / http://github.com/WestLangley
  11656. *
  11657. * parameters = {
  11658. *
  11659. * referencePosition: <float>,
  11660. * nearDistance: <float>,
  11661. * farDistance: <float>,
  11662. *
  11663. * skinning: <bool>,
  11664. * morphTargets: <bool>,
  11665. *
  11666. * map: new THREE.Texture( <Image> ),
  11667. *
  11668. * alphaMap: new THREE.Texture( <Image> ),
  11669. *
  11670. * displacementMap: new THREE.Texture( <Image> ),
  11671. * displacementScale: <float>,
  11672. * displacementBias: <float>
  11673. *
  11674. * }
  11675. */
  11676. function MeshDistanceMaterial( parameters ) {
  11677. Material.call( this );
  11678. this.type = 'MeshDistanceMaterial';
  11679. this.referencePosition = new Vector3();
  11680. this.nearDistance = 1;
  11681. this.farDistance = 1000;
  11682. this.skinning = false;
  11683. this.morphTargets = false;
  11684. this.map = null;
  11685. this.alphaMap = null;
  11686. this.displacementMap = null;
  11687. this.displacementScale = 1;
  11688. this.displacementBias = 0;
  11689. this.fog = false;
  11690. this.lights = false;
  11691. this.setValues( parameters );
  11692. }
  11693. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11694. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11695. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11696. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11697. Material.prototype.copy.call( this, source );
  11698. this.referencePosition.copy( source.referencePosition );
  11699. this.nearDistance = source.nearDistance;
  11700. this.farDistance = source.farDistance;
  11701. this.skinning = source.skinning;
  11702. this.morphTargets = source.morphTargets;
  11703. this.map = source.map;
  11704. this.alphaMap = source.alphaMap;
  11705. this.displacementMap = source.displacementMap;
  11706. this.displacementScale = source.displacementScale;
  11707. this.displacementBias = source.displacementBias;
  11708. return this;
  11709. };
  11710. /**
  11711. * @author alteredq / http://alteredqualia.com/
  11712. * @author mrdoob / http://mrdoob.com/
  11713. */
  11714. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11715. var _frustum = new Frustum(),
  11716. _projScreenMatrix = new Matrix4(),
  11717. _shadowMapSize = new Vector2(),
  11718. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11719. _lookTarget = new Vector3(),
  11720. _lightPositionWorld = new Vector3(),
  11721. _MorphingFlag = 1,
  11722. _SkinningFlag = 2,
  11723. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11724. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11725. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11726. _materialCache = {};
  11727. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11728. var cubeDirections = [
  11729. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11730. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11731. ];
  11732. var cubeUps = [
  11733. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11734. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11735. ];
  11736. var cube2DViewPorts = [
  11737. new Vector4(), new Vector4(), new Vector4(),
  11738. new Vector4(), new Vector4(), new Vector4()
  11739. ];
  11740. // init
  11741. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11742. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11743. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11744. var depthMaterial = new MeshDepthMaterial( {
  11745. depthPacking: RGBADepthPacking,
  11746. morphTargets: useMorphing,
  11747. skinning: useSkinning
  11748. } );
  11749. _depthMaterials[ i ] = depthMaterial;
  11750. //
  11751. var distanceMaterial = new MeshDistanceMaterial( {
  11752. morphTargets: useMorphing,
  11753. skinning: useSkinning
  11754. } );
  11755. _distanceMaterials[ i ] = distanceMaterial;
  11756. }
  11757. //
  11758. var scope = this;
  11759. this.enabled = false;
  11760. this.autoUpdate = true;
  11761. this.needsUpdate = false;
  11762. this.type = PCFShadowMap;
  11763. this.render = function ( lights, scene, camera ) {
  11764. if ( scope.enabled === false ) return;
  11765. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11766. if ( lights.length === 0 ) return;
  11767. var currentRenderTarget = _renderer.getRenderTarget();
  11768. var activeCubeFace = _renderer.getActiveCubeFace();
  11769. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11770. var _state = _renderer.state;
  11771. // Set GL state for depth map.
  11772. _state.setBlending( NoBlending );
  11773. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11774. _state.buffers.depth.setTest( true );
  11775. _state.setScissorTest( false );
  11776. // render depth map
  11777. var faceCount;
  11778. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11779. var light = lights[ i ];
  11780. var shadow = light.shadow;
  11781. var isPointLight = light && light.isPointLight;
  11782. if ( shadow === undefined ) {
  11783. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11784. continue;
  11785. }
  11786. var shadowCamera = shadow.camera;
  11787. _shadowMapSize.copy( shadow.mapSize );
  11788. _shadowMapSize.min( _maxShadowMapSize );
  11789. if ( isPointLight ) {
  11790. var vpWidth = _shadowMapSize.x;
  11791. var vpHeight = _shadowMapSize.y;
  11792. // These viewports map a cube-map onto a 2D texture with the
  11793. // following orientation:
  11794. //
  11795. // xzXZ
  11796. // y Y
  11797. //
  11798. // X - Positive x direction
  11799. // x - Negative x direction
  11800. // Y - Positive y direction
  11801. // y - Negative y direction
  11802. // Z - Positive z direction
  11803. // z - Negative z direction
  11804. // positive X
  11805. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11806. // negative X
  11807. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11808. // positive Z
  11809. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11810. // negative Z
  11811. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11812. // positive Y
  11813. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11814. // negative Y
  11815. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11816. _shadowMapSize.x *= 4.0;
  11817. _shadowMapSize.y *= 2.0;
  11818. }
  11819. if ( shadow.map === null ) {
  11820. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11821. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11822. shadow.map.texture.name = light.name + ".shadowMap";
  11823. shadowCamera.updateProjectionMatrix();
  11824. }
  11825. if ( shadow.isSpotLightShadow ) {
  11826. shadow.update( light );
  11827. }
  11828. var shadowMap = shadow.map;
  11829. var shadowMatrix = shadow.matrix;
  11830. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11831. shadowCamera.position.copy( _lightPositionWorld );
  11832. if ( isPointLight ) {
  11833. faceCount = 6;
  11834. // for point lights we set the shadow matrix to be a translation-only matrix
  11835. // equal to inverse of the light's position
  11836. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11837. } else {
  11838. faceCount = 1;
  11839. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11840. shadowCamera.lookAt( _lookTarget );
  11841. shadowCamera.updateMatrixWorld();
  11842. // compute shadow matrix
  11843. shadowMatrix.set(
  11844. 0.5, 0.0, 0.0, 0.5,
  11845. 0.0, 0.5, 0.0, 0.5,
  11846. 0.0, 0.0, 0.5, 0.5,
  11847. 0.0, 0.0, 0.0, 1.0
  11848. );
  11849. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11850. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11851. }
  11852. _renderer.setRenderTarget( shadowMap );
  11853. _renderer.clear();
  11854. // render shadow map for each cube face (if omni-directional) or
  11855. // run a single pass if not
  11856. for ( var face = 0; face < faceCount; face ++ ) {
  11857. if ( isPointLight ) {
  11858. _lookTarget.copy( shadowCamera.position );
  11859. _lookTarget.add( cubeDirections[ face ] );
  11860. shadowCamera.up.copy( cubeUps[ face ] );
  11861. shadowCamera.lookAt( _lookTarget );
  11862. shadowCamera.updateMatrixWorld();
  11863. var vpDimensions = cube2DViewPorts[ face ];
  11864. _state.viewport( vpDimensions );
  11865. }
  11866. // update camera matrices and frustum
  11867. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11868. _frustum.setFromMatrix( _projScreenMatrix );
  11869. // set object matrices & frustum culling
  11870. renderObject( scene, camera, shadowCamera, isPointLight );
  11871. }
  11872. }
  11873. scope.needsUpdate = false;
  11874. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11875. };
  11876. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11877. var geometry = object.geometry;
  11878. var result = null;
  11879. var materialVariants = _depthMaterials;
  11880. var customMaterial = object.customDepthMaterial;
  11881. if ( isPointLight ) {
  11882. materialVariants = _distanceMaterials;
  11883. customMaterial = object.customDistanceMaterial;
  11884. }
  11885. if ( ! customMaterial ) {
  11886. var useMorphing = false;
  11887. if ( material.morphTargets ) {
  11888. if ( geometry && geometry.isBufferGeometry ) {
  11889. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11890. } else if ( geometry && geometry.isGeometry ) {
  11891. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11892. }
  11893. }
  11894. if ( object.isSkinnedMesh && material.skinning === false ) {
  11895. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11896. }
  11897. var useSkinning = object.isSkinnedMesh && material.skinning;
  11898. var variantIndex = 0;
  11899. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11900. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11901. result = materialVariants[ variantIndex ];
  11902. } else {
  11903. result = customMaterial;
  11904. }
  11905. if ( _renderer.localClippingEnabled &&
  11906. material.clipShadows === true &&
  11907. material.clippingPlanes.length !== 0 ) {
  11908. // in this case we need a unique material instance reflecting the
  11909. // appropriate state
  11910. var keyA = result.uuid, keyB = material.uuid;
  11911. var materialsForVariant = _materialCache[ keyA ];
  11912. if ( materialsForVariant === undefined ) {
  11913. materialsForVariant = {};
  11914. _materialCache[ keyA ] = materialsForVariant;
  11915. }
  11916. var cachedMaterial = materialsForVariant[ keyB ];
  11917. if ( cachedMaterial === undefined ) {
  11918. cachedMaterial = result.clone();
  11919. materialsForVariant[ keyB ] = cachedMaterial;
  11920. }
  11921. result = cachedMaterial;
  11922. }
  11923. result.visible = material.visible;
  11924. result.wireframe = material.wireframe;
  11925. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11926. result.clipShadows = material.clipShadows;
  11927. result.clippingPlanes = material.clippingPlanes;
  11928. result.clipIntersection = material.clipIntersection;
  11929. result.wireframeLinewidth = material.wireframeLinewidth;
  11930. result.linewidth = material.linewidth;
  11931. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11932. result.referencePosition.copy( lightPositionWorld );
  11933. result.nearDistance = shadowCameraNear;
  11934. result.farDistance = shadowCameraFar;
  11935. }
  11936. return result;
  11937. }
  11938. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11939. if ( object.visible === false ) return;
  11940. var visible = object.layers.test( camera.layers );
  11941. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11942. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11943. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11944. var geometry = _objects.update( object );
  11945. var material = object.material;
  11946. if ( Array.isArray( material ) ) {
  11947. var groups = geometry.groups;
  11948. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11949. var group = groups[ k ];
  11950. var groupMaterial = material[ group.materialIndex ];
  11951. if ( groupMaterial && groupMaterial.visible ) {
  11952. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11953. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11954. }
  11955. }
  11956. } else if ( material.visible ) {
  11957. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11958. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11959. }
  11960. }
  11961. }
  11962. var children = object.children;
  11963. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11964. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11965. }
  11966. }
  11967. }
  11968. /**
  11969. * @author mrdoob / http://mrdoob.com/
  11970. */
  11971. function WebGLState( gl, extensions, utils, capabilities ) {
  11972. function ColorBuffer() {
  11973. var locked = false;
  11974. var color = new Vector4();
  11975. var currentColorMask = null;
  11976. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11977. return {
  11978. setMask: function ( colorMask ) {
  11979. if ( currentColorMask !== colorMask && ! locked ) {
  11980. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11981. currentColorMask = colorMask;
  11982. }
  11983. },
  11984. setLocked: function ( lock ) {
  11985. locked = lock;
  11986. },
  11987. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11988. if ( premultipliedAlpha === true ) {
  11989. r *= a; g *= a; b *= a;
  11990. }
  11991. color.set( r, g, b, a );
  11992. if ( currentColorClear.equals( color ) === false ) {
  11993. gl.clearColor( r, g, b, a );
  11994. currentColorClear.copy( color );
  11995. }
  11996. },
  11997. reset: function () {
  11998. locked = false;
  11999. currentColorMask = null;
  12000. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  12001. }
  12002. };
  12003. }
  12004. function DepthBuffer() {
  12005. var locked = false;
  12006. var currentDepthMask = null;
  12007. var currentDepthFunc = null;
  12008. var currentDepthClear = null;
  12009. return {
  12010. setTest: function ( depthTest ) {
  12011. if ( depthTest ) {
  12012. enable( 2929 );
  12013. } else {
  12014. disable( 2929 );
  12015. }
  12016. },
  12017. setMask: function ( depthMask ) {
  12018. if ( currentDepthMask !== depthMask && ! locked ) {
  12019. gl.depthMask( depthMask );
  12020. currentDepthMask = depthMask;
  12021. }
  12022. },
  12023. setFunc: function ( depthFunc ) {
  12024. if ( currentDepthFunc !== depthFunc ) {
  12025. if ( depthFunc ) {
  12026. switch ( depthFunc ) {
  12027. case NeverDepth:
  12028. gl.depthFunc( 512 );
  12029. break;
  12030. case AlwaysDepth:
  12031. gl.depthFunc( 519 );
  12032. break;
  12033. case LessDepth:
  12034. gl.depthFunc( 513 );
  12035. break;
  12036. case LessEqualDepth:
  12037. gl.depthFunc( 515 );
  12038. break;
  12039. case EqualDepth:
  12040. gl.depthFunc( 514 );
  12041. break;
  12042. case GreaterEqualDepth:
  12043. gl.depthFunc( 518 );
  12044. break;
  12045. case GreaterDepth:
  12046. gl.depthFunc( 516 );
  12047. break;
  12048. case NotEqualDepth:
  12049. gl.depthFunc( 517 );
  12050. break;
  12051. default:
  12052. gl.depthFunc( 515 );
  12053. }
  12054. } else {
  12055. gl.depthFunc( 515 );
  12056. }
  12057. currentDepthFunc = depthFunc;
  12058. }
  12059. },
  12060. setLocked: function ( lock ) {
  12061. locked = lock;
  12062. },
  12063. setClear: function ( depth ) {
  12064. if ( currentDepthClear !== depth ) {
  12065. gl.clearDepth( depth );
  12066. currentDepthClear = depth;
  12067. }
  12068. },
  12069. reset: function () {
  12070. locked = false;
  12071. currentDepthMask = null;
  12072. currentDepthFunc = null;
  12073. currentDepthClear = null;
  12074. }
  12075. };
  12076. }
  12077. function StencilBuffer() {
  12078. var locked = false;
  12079. var currentStencilMask = null;
  12080. var currentStencilFunc = null;
  12081. var currentStencilRef = null;
  12082. var currentStencilFuncMask = null;
  12083. var currentStencilFail = null;
  12084. var currentStencilZFail = null;
  12085. var currentStencilZPass = null;
  12086. var currentStencilClear = null;
  12087. return {
  12088. setTest: function ( stencilTest ) {
  12089. if ( ! locked ) {
  12090. if ( stencilTest ) {
  12091. enable( 2960 );
  12092. } else {
  12093. disable( 2960 );
  12094. }
  12095. }
  12096. },
  12097. setMask: function ( stencilMask ) {
  12098. if ( currentStencilMask !== stencilMask && ! locked ) {
  12099. gl.stencilMask( stencilMask );
  12100. currentStencilMask = stencilMask;
  12101. }
  12102. },
  12103. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12104. if ( currentStencilFunc !== stencilFunc ||
  12105. currentStencilRef !== stencilRef ||
  12106. currentStencilFuncMask !== stencilMask ) {
  12107. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12108. currentStencilFunc = stencilFunc;
  12109. currentStencilRef = stencilRef;
  12110. currentStencilFuncMask = stencilMask;
  12111. }
  12112. },
  12113. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12114. if ( currentStencilFail !== stencilFail ||
  12115. currentStencilZFail !== stencilZFail ||
  12116. currentStencilZPass !== stencilZPass ) {
  12117. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12118. currentStencilFail = stencilFail;
  12119. currentStencilZFail = stencilZFail;
  12120. currentStencilZPass = stencilZPass;
  12121. }
  12122. },
  12123. setLocked: function ( lock ) {
  12124. locked = lock;
  12125. },
  12126. setClear: function ( stencil ) {
  12127. if ( currentStencilClear !== stencil ) {
  12128. gl.clearStencil( stencil );
  12129. currentStencilClear = stencil;
  12130. }
  12131. },
  12132. reset: function () {
  12133. locked = false;
  12134. currentStencilMask = null;
  12135. currentStencilFunc = null;
  12136. currentStencilRef = null;
  12137. currentStencilFuncMask = null;
  12138. currentStencilFail = null;
  12139. currentStencilZFail = null;
  12140. currentStencilZPass = null;
  12141. currentStencilClear = null;
  12142. }
  12143. };
  12144. }
  12145. //
  12146. var colorBuffer = new ColorBuffer();
  12147. var depthBuffer = new DepthBuffer();
  12148. var stencilBuffer = new StencilBuffer();
  12149. var maxVertexAttributes = gl.getParameter( 34921 );
  12150. var newAttributes = new Uint8Array( maxVertexAttributes );
  12151. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  12152. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  12153. var enabledCapabilities = {};
  12154. var compressedTextureFormats = null;
  12155. var currentProgram = null;
  12156. var currentBlendingEnabled = null;
  12157. var currentBlending = null;
  12158. var currentBlendEquation = null;
  12159. var currentBlendSrc = null;
  12160. var currentBlendDst = null;
  12161. var currentBlendEquationAlpha = null;
  12162. var currentBlendSrcAlpha = null;
  12163. var currentBlendDstAlpha = null;
  12164. var currentPremultipledAlpha = false;
  12165. var currentFlipSided = null;
  12166. var currentCullFace = null;
  12167. var currentLineWidth = null;
  12168. var currentPolygonOffsetFactor = null;
  12169. var currentPolygonOffsetUnits = null;
  12170. var maxTextures = gl.getParameter( 35661 );
  12171. var lineWidthAvailable = false;
  12172. var version = 0;
  12173. var glVersion = gl.getParameter( 7938 );
  12174. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12175. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12176. lineWidthAvailable = ( version >= 1.0 );
  12177. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12178. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12179. lineWidthAvailable = ( version >= 2.0 );
  12180. }
  12181. var currentTextureSlot = null;
  12182. var currentBoundTextures = {};
  12183. var currentScissor = new Vector4();
  12184. var currentViewport = new Vector4();
  12185. function createTexture( type, target, count ) {
  12186. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12187. var texture = gl.createTexture();
  12188. gl.bindTexture( type, texture );
  12189. gl.texParameteri( type, 10241, 9728 );
  12190. gl.texParameteri( type, 10240, 9728 );
  12191. for ( var i = 0; i < count; i ++ ) {
  12192. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12193. }
  12194. return texture;
  12195. }
  12196. var emptyTextures = {};
  12197. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12198. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12199. // init
  12200. colorBuffer.setClear( 0, 0, 0, 1 );
  12201. depthBuffer.setClear( 1 );
  12202. stencilBuffer.setClear( 0 );
  12203. enable( 2929 );
  12204. depthBuffer.setFunc( LessEqualDepth );
  12205. setFlipSided( false );
  12206. setCullFace( CullFaceBack );
  12207. enable( 2884 );
  12208. setBlending( NoBlending );
  12209. //
  12210. function initAttributes() {
  12211. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  12212. newAttributes[ i ] = 0;
  12213. }
  12214. }
  12215. function enableAttribute( attribute ) {
  12216. enableAttributeAndDivisor( attribute, 0 );
  12217. }
  12218. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  12219. newAttributes[ attribute ] = 1;
  12220. if ( enabledAttributes[ attribute ] === 0 ) {
  12221. gl.enableVertexAttribArray( attribute );
  12222. enabledAttributes[ attribute ] = 1;
  12223. }
  12224. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  12225. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  12226. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  12227. attributeDivisors[ attribute ] = meshPerAttribute;
  12228. }
  12229. }
  12230. function disableUnusedAttributes() {
  12231. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  12232. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  12233. gl.disableVertexAttribArray( i );
  12234. enabledAttributes[ i ] = 0;
  12235. }
  12236. }
  12237. }
  12238. function enable( id ) {
  12239. if ( enabledCapabilities[ id ] !== true ) {
  12240. gl.enable( id );
  12241. enabledCapabilities[ id ] = true;
  12242. }
  12243. }
  12244. function disable( id ) {
  12245. if ( enabledCapabilities[ id ] !== false ) {
  12246. gl.disable( id );
  12247. enabledCapabilities[ id ] = false;
  12248. }
  12249. }
  12250. function getCompressedTextureFormats() {
  12251. if ( compressedTextureFormats === null ) {
  12252. compressedTextureFormats = [];
  12253. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  12254. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  12255. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  12256. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  12257. var formats = gl.getParameter( 34467 );
  12258. for ( var i = 0; i < formats.length; i ++ ) {
  12259. compressedTextureFormats.push( formats[ i ] );
  12260. }
  12261. }
  12262. }
  12263. return compressedTextureFormats;
  12264. }
  12265. function useProgram( program ) {
  12266. if ( currentProgram !== program ) {
  12267. gl.useProgram( program );
  12268. currentProgram = program;
  12269. return true;
  12270. }
  12271. return false;
  12272. }
  12273. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12274. if ( blending === NoBlending ) {
  12275. if ( currentBlendingEnabled ) {
  12276. disable( 3042 );
  12277. currentBlendingEnabled = false;
  12278. }
  12279. return;
  12280. }
  12281. if ( ! currentBlendingEnabled ) {
  12282. enable( 3042 );
  12283. currentBlendingEnabled = true;
  12284. }
  12285. if ( blending !== CustomBlending ) {
  12286. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12287. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12288. gl.blendEquation( 32774 );
  12289. currentBlendEquation = AddEquation;
  12290. currentBlendEquationAlpha = AddEquation;
  12291. }
  12292. if ( premultipliedAlpha ) {
  12293. switch ( blending ) {
  12294. case NormalBlending:
  12295. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12296. break;
  12297. case AdditiveBlending:
  12298. gl.blendFunc( 1, 1 );
  12299. break;
  12300. case SubtractiveBlending:
  12301. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12302. break;
  12303. case MultiplyBlending:
  12304. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12305. break;
  12306. default:
  12307. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12308. break;
  12309. }
  12310. } else {
  12311. switch ( blending ) {
  12312. case NormalBlending:
  12313. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12314. break;
  12315. case AdditiveBlending:
  12316. gl.blendFunc( 770, 1 );
  12317. break;
  12318. case SubtractiveBlending:
  12319. gl.blendFunc( 0, 769 );
  12320. break;
  12321. case MultiplyBlending:
  12322. gl.blendFunc( 0, 768 );
  12323. break;
  12324. default:
  12325. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12326. break;
  12327. }
  12328. }
  12329. currentBlendSrc = null;
  12330. currentBlendDst = null;
  12331. currentBlendSrcAlpha = null;
  12332. currentBlendDstAlpha = null;
  12333. currentBlending = blending;
  12334. currentPremultipledAlpha = premultipliedAlpha;
  12335. }
  12336. return;
  12337. }
  12338. // custom blending
  12339. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12340. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12341. blendDstAlpha = blendDstAlpha || blendDst;
  12342. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12343. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  12344. currentBlendEquation = blendEquation;
  12345. currentBlendEquationAlpha = blendEquationAlpha;
  12346. }
  12347. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12348. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  12349. currentBlendSrc = blendSrc;
  12350. currentBlendDst = blendDst;
  12351. currentBlendSrcAlpha = blendSrcAlpha;
  12352. currentBlendDstAlpha = blendDstAlpha;
  12353. }
  12354. currentBlending = blending;
  12355. currentPremultipledAlpha = null;
  12356. }
  12357. function setMaterial( material, frontFaceCW ) {
  12358. material.side === DoubleSide
  12359. ? disable( 2884 )
  12360. : enable( 2884 );
  12361. var flipSided = ( material.side === BackSide );
  12362. if ( frontFaceCW ) flipSided = ! flipSided;
  12363. setFlipSided( flipSided );
  12364. ( material.blending === NormalBlending && material.transparent === false )
  12365. ? setBlending( NoBlending )
  12366. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12367. depthBuffer.setFunc( material.depthFunc );
  12368. depthBuffer.setTest( material.depthTest );
  12369. depthBuffer.setMask( material.depthWrite );
  12370. colorBuffer.setMask( material.colorWrite );
  12371. var stencilWrite = material.stencilWrite;
  12372. stencilBuffer.setTest( stencilWrite );
  12373. if ( stencilWrite ) {
  12374. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilMask );
  12375. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12376. }
  12377. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12378. }
  12379. //
  12380. function setFlipSided( flipSided ) {
  12381. if ( currentFlipSided !== flipSided ) {
  12382. if ( flipSided ) {
  12383. gl.frontFace( 2304 );
  12384. } else {
  12385. gl.frontFace( 2305 );
  12386. }
  12387. currentFlipSided = flipSided;
  12388. }
  12389. }
  12390. function setCullFace( cullFace ) {
  12391. if ( cullFace !== CullFaceNone ) {
  12392. enable( 2884 );
  12393. if ( cullFace !== currentCullFace ) {
  12394. if ( cullFace === CullFaceBack ) {
  12395. gl.cullFace( 1029 );
  12396. } else if ( cullFace === CullFaceFront ) {
  12397. gl.cullFace( 1028 );
  12398. } else {
  12399. gl.cullFace( 1032 );
  12400. }
  12401. }
  12402. } else {
  12403. disable( 2884 );
  12404. }
  12405. currentCullFace = cullFace;
  12406. }
  12407. function setLineWidth( width ) {
  12408. if ( width !== currentLineWidth ) {
  12409. if ( lineWidthAvailable ) gl.lineWidth( width );
  12410. currentLineWidth = width;
  12411. }
  12412. }
  12413. function setPolygonOffset( polygonOffset, factor, units ) {
  12414. if ( polygonOffset ) {
  12415. enable( 32823 );
  12416. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12417. gl.polygonOffset( factor, units );
  12418. currentPolygonOffsetFactor = factor;
  12419. currentPolygonOffsetUnits = units;
  12420. }
  12421. } else {
  12422. disable( 32823 );
  12423. }
  12424. }
  12425. function setScissorTest( scissorTest ) {
  12426. if ( scissorTest ) {
  12427. enable( 3089 );
  12428. } else {
  12429. disable( 3089 );
  12430. }
  12431. }
  12432. // texture
  12433. function activeTexture( webglSlot ) {
  12434. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12435. if ( currentTextureSlot !== webglSlot ) {
  12436. gl.activeTexture( webglSlot );
  12437. currentTextureSlot = webglSlot;
  12438. }
  12439. }
  12440. function bindTexture( webglType, webglTexture ) {
  12441. if ( currentTextureSlot === null ) {
  12442. activeTexture();
  12443. }
  12444. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12445. if ( boundTexture === undefined ) {
  12446. boundTexture = { type: undefined, texture: undefined };
  12447. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12448. }
  12449. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12450. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12451. boundTexture.type = webglType;
  12452. boundTexture.texture = webglTexture;
  12453. }
  12454. }
  12455. function compressedTexImage2D() {
  12456. try {
  12457. gl.compressedTexImage2D.apply( gl, arguments );
  12458. } catch ( error ) {
  12459. console.error( 'THREE.WebGLState:', error );
  12460. }
  12461. }
  12462. function texImage2D() {
  12463. try {
  12464. gl.texImage2D.apply( gl, arguments );
  12465. } catch ( error ) {
  12466. console.error( 'THREE.WebGLState:', error );
  12467. }
  12468. }
  12469. function texImage3D() {
  12470. try {
  12471. gl.texImage3D.apply( gl, arguments );
  12472. } catch ( error ) {
  12473. console.error( 'THREE.WebGLState:', error );
  12474. }
  12475. }
  12476. //
  12477. function scissor( scissor ) {
  12478. if ( currentScissor.equals( scissor ) === false ) {
  12479. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12480. currentScissor.copy( scissor );
  12481. }
  12482. }
  12483. function viewport( viewport ) {
  12484. if ( currentViewport.equals( viewport ) === false ) {
  12485. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12486. currentViewport.copy( viewport );
  12487. }
  12488. }
  12489. //
  12490. function reset() {
  12491. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12492. if ( enabledAttributes[ i ] === 1 ) {
  12493. gl.disableVertexAttribArray( i );
  12494. enabledAttributes[ i ] = 0;
  12495. }
  12496. }
  12497. enabledCapabilities = {};
  12498. compressedTextureFormats = null;
  12499. currentTextureSlot = null;
  12500. currentBoundTextures = {};
  12501. currentProgram = null;
  12502. currentBlending = null;
  12503. currentFlipSided = null;
  12504. currentCullFace = null;
  12505. colorBuffer.reset();
  12506. depthBuffer.reset();
  12507. stencilBuffer.reset();
  12508. }
  12509. return {
  12510. buffers: {
  12511. color: colorBuffer,
  12512. depth: depthBuffer,
  12513. stencil: stencilBuffer
  12514. },
  12515. initAttributes: initAttributes,
  12516. enableAttribute: enableAttribute,
  12517. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12518. disableUnusedAttributes: disableUnusedAttributes,
  12519. enable: enable,
  12520. disable: disable,
  12521. getCompressedTextureFormats: getCompressedTextureFormats,
  12522. useProgram: useProgram,
  12523. setBlending: setBlending,
  12524. setMaterial: setMaterial,
  12525. setFlipSided: setFlipSided,
  12526. setCullFace: setCullFace,
  12527. setLineWidth: setLineWidth,
  12528. setPolygonOffset: setPolygonOffset,
  12529. setScissorTest: setScissorTest,
  12530. activeTexture: activeTexture,
  12531. bindTexture: bindTexture,
  12532. compressedTexImage2D: compressedTexImage2D,
  12533. texImage2D: texImage2D,
  12534. texImage3D: texImage3D,
  12535. scissor: scissor,
  12536. viewport: viewport,
  12537. reset: reset
  12538. };
  12539. }
  12540. /**
  12541. * @author mrdoob / http://mrdoob.com/
  12542. */
  12543. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12544. var _videoTextures = {};
  12545. var _canvas;
  12546. //
  12547. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12548. function createCanvas( width, height ) {
  12549. // Use OffscreenCanvas when available. Specially needed in web workers
  12550. return useOffscreenCanvas ?
  12551. new OffscreenCanvas( width, height ) :
  12552. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12553. }
  12554. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12555. var scale = 1;
  12556. // handle case if texture exceeds max size
  12557. if ( image.width > maxSize || image.height > maxSize ) {
  12558. scale = maxSize / Math.max( image.width, image.height );
  12559. }
  12560. // only perform resize if necessary
  12561. if ( scale < 1 || needsPowerOfTwo === true ) {
  12562. // only perform resize for certain image types
  12563. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12564. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12565. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12566. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12567. var width = floor( scale * image.width );
  12568. var height = floor( scale * image.height );
  12569. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12570. // cube textures can't reuse the same canvas
  12571. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12572. canvas.width = width;
  12573. canvas.height = height;
  12574. var context = canvas.getContext( '2d' );
  12575. context.drawImage( image, 0, 0, width, height );
  12576. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12577. return canvas;
  12578. } else {
  12579. if ( 'data' in image ) {
  12580. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12581. }
  12582. return image;
  12583. }
  12584. }
  12585. return image;
  12586. }
  12587. function isPowerOfTwo( image ) {
  12588. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12589. }
  12590. function textureNeedsPowerOfTwo( texture ) {
  12591. if ( capabilities.isWebGL2 ) return false;
  12592. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12593. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12594. }
  12595. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12596. return texture.generateMipmaps && supportsMips &&
  12597. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12598. }
  12599. function generateMipmap( target, texture, width, height ) {
  12600. _gl.generateMipmap( target );
  12601. var textureProperties = properties.get( texture );
  12602. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12603. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12604. }
  12605. function getInternalFormat( glFormat, glType ) {
  12606. if ( ! capabilities.isWebGL2 ) return glFormat;
  12607. var internalFormat = glFormat;
  12608. if ( glFormat === 6403 ) {
  12609. if ( glType === 5126 ) internalFormat = 33326;
  12610. if ( glType === 5131 ) internalFormat = 33325;
  12611. if ( glType === 5121 ) internalFormat = 33321;
  12612. }
  12613. if ( glFormat === 6407 ) {
  12614. if ( glType === 5126 ) internalFormat = 34837;
  12615. if ( glType === 5131 ) internalFormat = 34843;
  12616. if ( glType === 5121 ) internalFormat = 32849;
  12617. }
  12618. if ( glFormat === 6408 ) {
  12619. if ( glType === 5126 ) internalFormat = 34836;
  12620. if ( glType === 5131 ) internalFormat = 34842;
  12621. if ( glType === 5121 ) internalFormat = 32856;
  12622. }
  12623. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12624. internalFormat === 34842 || internalFormat === 34836 ) {
  12625. extensions.get( 'EXT_color_buffer_float' );
  12626. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12627. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12628. }
  12629. return internalFormat;
  12630. }
  12631. // Fallback filters for non-power-of-2 textures
  12632. function filterFallback( f ) {
  12633. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12634. return 9728;
  12635. }
  12636. return 9729;
  12637. }
  12638. //
  12639. function onTextureDispose( event ) {
  12640. var texture = event.target;
  12641. texture.removeEventListener( 'dispose', onTextureDispose );
  12642. deallocateTexture( texture );
  12643. if ( texture.isVideoTexture ) {
  12644. delete _videoTextures[ texture.id ];
  12645. }
  12646. info.memory.textures --;
  12647. }
  12648. function onRenderTargetDispose( event ) {
  12649. var renderTarget = event.target;
  12650. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12651. deallocateRenderTarget( renderTarget );
  12652. info.memory.textures --;
  12653. }
  12654. //
  12655. function deallocateTexture( texture ) {
  12656. var textureProperties = properties.get( texture );
  12657. if ( textureProperties.__webglInit === undefined ) return;
  12658. _gl.deleteTexture( textureProperties.__webglTexture );
  12659. properties.remove( texture );
  12660. }
  12661. function deallocateRenderTarget( renderTarget ) {
  12662. var renderTargetProperties = properties.get( renderTarget );
  12663. var textureProperties = properties.get( renderTarget.texture );
  12664. if ( ! renderTarget ) return;
  12665. if ( textureProperties.__webglTexture !== undefined ) {
  12666. _gl.deleteTexture( textureProperties.__webglTexture );
  12667. }
  12668. if ( renderTarget.depthTexture ) {
  12669. renderTarget.depthTexture.dispose();
  12670. }
  12671. if ( renderTarget.isWebGLRenderTargetCube ) {
  12672. for ( var i = 0; i < 6; i ++ ) {
  12673. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12674. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12675. }
  12676. } else {
  12677. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12678. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12679. }
  12680. properties.remove( renderTarget.texture );
  12681. properties.remove( renderTarget );
  12682. }
  12683. //
  12684. var textureUnits = 0;
  12685. function resetTextureUnits() {
  12686. textureUnits = 0;
  12687. }
  12688. function allocateTextureUnit() {
  12689. var textureUnit = textureUnits;
  12690. if ( textureUnit >= capabilities.maxTextures ) {
  12691. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12692. }
  12693. textureUnits += 1;
  12694. return textureUnit;
  12695. }
  12696. //
  12697. function setTexture2D( texture, slot ) {
  12698. var textureProperties = properties.get( texture );
  12699. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12700. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12701. var image = texture.image;
  12702. if ( image === undefined ) {
  12703. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12704. } else if ( image.complete === false ) {
  12705. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12706. } else {
  12707. uploadTexture( textureProperties, texture, slot );
  12708. return;
  12709. }
  12710. }
  12711. state.activeTexture( 33984 + slot );
  12712. state.bindTexture( 3553, textureProperties.__webglTexture );
  12713. }
  12714. function setTexture2DArray( texture, slot ) {
  12715. var textureProperties = properties.get( texture );
  12716. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12717. uploadTexture( textureProperties, texture, slot );
  12718. return;
  12719. }
  12720. state.activeTexture( 33984 + slot );
  12721. state.bindTexture( 35866, textureProperties.__webglTexture );
  12722. }
  12723. function setTexture3D( texture, slot ) {
  12724. var textureProperties = properties.get( texture );
  12725. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12726. uploadTexture( textureProperties, texture, slot );
  12727. return;
  12728. }
  12729. state.activeTexture( 33984 + slot );
  12730. state.bindTexture( 32879, textureProperties.__webglTexture );
  12731. }
  12732. function setTextureCube( texture, slot ) {
  12733. var textureProperties = properties.get( texture );
  12734. if ( texture.image.length === 6 ) {
  12735. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12736. initTexture( textureProperties, texture );
  12737. state.activeTexture( 33984 + slot );
  12738. state.bindTexture( 34067, textureProperties.__webglTexture );
  12739. _gl.pixelStorei( 37440, texture.flipY );
  12740. var isCompressed = ( texture && texture.isCompressedTexture );
  12741. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12742. var cubeImage = [];
  12743. for ( var i = 0; i < 6; i ++ ) {
  12744. if ( ! isCompressed && ! isDataTexture ) {
  12745. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12746. } else {
  12747. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12748. }
  12749. }
  12750. var image = cubeImage[ 0 ],
  12751. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12752. glFormat = utils.convert( texture.format ),
  12753. glType = utils.convert( texture.type ),
  12754. glInternalFormat = getInternalFormat( glFormat, glType );
  12755. setTextureParameters( 34067, texture, supportsMips );
  12756. var mipmaps = texture.mipmaps;
  12757. for ( var i = 0; i < 6; i ++ ) {
  12758. if ( ! isCompressed ) {
  12759. if ( isDataTexture ) {
  12760. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12761. for ( var j = 0; j < mipmaps.length; ++ j ) {
  12762. var mipmap = mipmaps[ j ];
  12763. var image = mipmap.image[ i ].image;
  12764. state.texImage2D( 34069 + i, j + 1, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12765. }
  12766. } else {
  12767. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12768. for ( var j = 0; j < mipmaps.length; ++ j ) {
  12769. var mipmap = mipmaps[ j ];
  12770. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  12771. }
  12772. }
  12773. } else {
  12774. var mipmaps = cubeImage[ i ].mipmaps;
  12775. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12776. var mipmap = mipmaps[ j ];
  12777. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12778. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12779. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12780. } else {
  12781. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12782. }
  12783. } else {
  12784. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12785. }
  12786. }
  12787. }
  12788. }
  12789. textureProperties.__maxMipLevel = isCompressed ? mipmaps.length - 1 : mipmaps.length;
  12790. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12791. // We assume images for cube map have the same size.
  12792. generateMipmap( 34067, texture, image.width, image.height );
  12793. }
  12794. textureProperties.__version = texture.version;
  12795. if ( texture.onUpdate ) texture.onUpdate( texture );
  12796. } else {
  12797. state.activeTexture( 33984 + slot );
  12798. state.bindTexture( 34067, textureProperties.__webglTexture );
  12799. }
  12800. }
  12801. }
  12802. function setTextureCubeDynamic( texture, slot ) {
  12803. state.activeTexture( 33984 + slot );
  12804. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12805. }
  12806. function setTextureParameters( textureType, texture, supportsMips ) {
  12807. var extension;
  12808. if ( supportsMips ) {
  12809. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12810. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12811. if ( textureType === 32879 || textureType === 35866 ) {
  12812. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12813. }
  12814. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12815. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12816. } else {
  12817. _gl.texParameteri( textureType, 10242, 33071 );
  12818. _gl.texParameteri( textureType, 10243, 33071 );
  12819. if ( textureType === 32879 || textureType === 35866 ) {
  12820. _gl.texParameteri( textureType, 32882, 33071 );
  12821. }
  12822. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12823. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12824. }
  12825. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12826. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12827. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12828. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12829. }
  12830. }
  12831. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12832. if ( extension ) {
  12833. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12834. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12835. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12836. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12837. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12838. }
  12839. }
  12840. }
  12841. function initTexture( textureProperties, texture ) {
  12842. if ( textureProperties.__webglInit === undefined ) {
  12843. textureProperties.__webglInit = true;
  12844. texture.addEventListener( 'dispose', onTextureDispose );
  12845. textureProperties.__webglTexture = _gl.createTexture();
  12846. info.memory.textures ++;
  12847. }
  12848. }
  12849. function uploadTexture( textureProperties, texture, slot ) {
  12850. var textureType = 3553;
  12851. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12852. if ( texture.isDataTexture3D ) textureType = 32879;
  12853. initTexture( textureProperties, texture );
  12854. state.activeTexture( 33984 + slot );
  12855. state.bindTexture( textureType, textureProperties.__webglTexture );
  12856. _gl.pixelStorei( 37440, texture.flipY );
  12857. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12858. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12859. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12860. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12861. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12862. glFormat = utils.convert( texture.format ),
  12863. glType = utils.convert( texture.type ),
  12864. glInternalFormat = getInternalFormat( glFormat, glType );
  12865. setTextureParameters( textureType, texture, supportsMips );
  12866. var mipmap, mipmaps = texture.mipmaps;
  12867. if ( texture.isDepthTexture ) {
  12868. // populate depth texture with dummy data
  12869. glInternalFormat = 6402;
  12870. if ( texture.type === FloatType ) {
  12871. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12872. glInternalFormat = 36012;
  12873. } else if ( capabilities.isWebGL2 ) {
  12874. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12875. glInternalFormat = 33189;
  12876. }
  12877. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12878. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12879. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12880. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12881. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12882. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12883. texture.type = UnsignedShortType;
  12884. glType = utils.convert( texture.type );
  12885. }
  12886. }
  12887. // Depth stencil textures need the DEPTH_STENCIL internal format
  12888. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12889. if ( texture.format === DepthStencilFormat ) {
  12890. glInternalFormat = 34041;
  12891. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12892. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12893. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12894. if ( texture.type !== UnsignedInt248Type ) {
  12895. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12896. texture.type = UnsignedInt248Type;
  12897. glType = utils.convert( texture.type );
  12898. }
  12899. }
  12900. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12901. } else if ( texture.isDataTexture ) {
  12902. // use manually created mipmaps if available
  12903. // if there are no manual mipmaps
  12904. // set 0 level mipmap and then use GL to generate other mipmap levels
  12905. if ( mipmaps.length > 0 && supportsMips ) {
  12906. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12907. mipmap = mipmaps[ i ];
  12908. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12909. }
  12910. texture.generateMipmaps = false;
  12911. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12912. } else {
  12913. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12914. textureProperties.__maxMipLevel = 0;
  12915. }
  12916. } else if ( texture.isCompressedTexture ) {
  12917. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12918. mipmap = mipmaps[ i ];
  12919. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12920. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12921. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12922. } else {
  12923. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12924. }
  12925. } else {
  12926. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12927. }
  12928. }
  12929. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12930. } else if ( texture.isDataTexture2DArray ) {
  12931. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12932. textureProperties.__maxMipLevel = 0;
  12933. } else if ( texture.isDataTexture3D ) {
  12934. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12935. textureProperties.__maxMipLevel = 0;
  12936. } else {
  12937. // regular Texture (image, video, canvas)
  12938. // use manually created mipmaps if available
  12939. // if there are no manual mipmaps
  12940. // set 0 level mipmap and then use GL to generate other mipmap levels
  12941. if ( mipmaps.length > 0 && supportsMips ) {
  12942. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12943. mipmap = mipmaps[ i ];
  12944. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12945. }
  12946. texture.generateMipmaps = false;
  12947. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12948. } else {
  12949. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12950. textureProperties.__maxMipLevel = 0;
  12951. }
  12952. }
  12953. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12954. generateMipmap( 3553, texture, image.width, image.height );
  12955. }
  12956. textureProperties.__version = texture.version;
  12957. if ( texture.onUpdate ) texture.onUpdate( texture );
  12958. }
  12959. // Render targets
  12960. // Setup storage for target texture and bind it to correct framebuffer
  12961. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12962. var glFormat = utils.convert( renderTarget.texture.format );
  12963. var glType = utils.convert( renderTarget.texture.type );
  12964. var glInternalFormat = getInternalFormat( glFormat, glType );
  12965. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12966. _gl.bindFramebuffer( 36160, framebuffer );
  12967. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12968. _gl.bindFramebuffer( 36160, null );
  12969. }
  12970. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12971. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12972. _gl.bindRenderbuffer( 36161, renderbuffer );
  12973. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12974. if ( isMultisample ) {
  12975. var samples = getRenderTargetSamples( renderTarget );
  12976. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12977. } else {
  12978. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12979. }
  12980. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12981. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12982. if ( isMultisample ) {
  12983. var samples = getRenderTargetSamples( renderTarget );
  12984. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  12985. } else {
  12986. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12987. }
  12988. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12989. } else {
  12990. var glFormat = utils.convert( renderTarget.texture.format );
  12991. var glType = utils.convert( renderTarget.texture.type );
  12992. var glInternalFormat = getInternalFormat( glFormat, glType );
  12993. if ( isMultisample ) {
  12994. var samples = getRenderTargetSamples( renderTarget );
  12995. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12996. } else {
  12997. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12998. }
  12999. }
  13000. _gl.bindRenderbuffer( 36161, null );
  13001. }
  13002. // Setup resources for a Depth Texture for a FBO (needs an extension)
  13003. function setupDepthTexture( framebuffer, renderTarget ) {
  13004. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  13005. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  13006. _gl.bindFramebuffer( 36160, framebuffer );
  13007. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  13008. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  13009. }
  13010. // upload an empty depth texture with framebuffer size
  13011. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  13012. renderTarget.depthTexture.image.width !== renderTarget.width ||
  13013. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13014. renderTarget.depthTexture.image.width = renderTarget.width;
  13015. renderTarget.depthTexture.image.height = renderTarget.height;
  13016. renderTarget.depthTexture.needsUpdate = true;
  13017. }
  13018. setTexture2D( renderTarget.depthTexture, 0 );
  13019. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13020. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13021. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13022. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13023. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13024. } else {
  13025. throw new Error( 'Unknown depthTexture format' );
  13026. }
  13027. }
  13028. // Setup GL resources for a non-texture depth buffer
  13029. function setupDepthRenderbuffer( renderTarget ) {
  13030. var renderTargetProperties = properties.get( renderTarget );
  13031. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13032. if ( renderTarget.depthTexture ) {
  13033. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13034. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13035. } else {
  13036. if ( isCube ) {
  13037. renderTargetProperties.__webglDepthbuffer = [];
  13038. for ( var i = 0; i < 6; i ++ ) {
  13039. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13040. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13041. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  13042. }
  13043. } else {
  13044. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13045. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13046. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  13047. }
  13048. }
  13049. _gl.bindFramebuffer( 36160, null );
  13050. }
  13051. // Set up GL resources for the render target
  13052. function setupRenderTarget( renderTarget ) {
  13053. var renderTargetProperties = properties.get( renderTarget );
  13054. var textureProperties = properties.get( renderTarget.texture );
  13055. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13056. textureProperties.__webglTexture = _gl.createTexture();
  13057. info.memory.textures ++;
  13058. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13059. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13060. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13061. // Setup framebuffer
  13062. if ( isCube ) {
  13063. renderTargetProperties.__webglFramebuffer = [];
  13064. for ( var i = 0; i < 6; i ++ ) {
  13065. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13066. }
  13067. } else {
  13068. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13069. if ( isMultisample ) {
  13070. if ( capabilities.isWebGL2 ) {
  13071. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13072. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13073. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13074. var glFormat = utils.convert( renderTarget.texture.format );
  13075. var glType = utils.convert( renderTarget.texture.type );
  13076. var glInternalFormat = getInternalFormat( glFormat, glType );
  13077. var samples = getRenderTargetSamples( renderTarget );
  13078. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13079. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13080. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13081. _gl.bindRenderbuffer( 36161, null );
  13082. if ( renderTarget.depthBuffer ) {
  13083. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13084. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13085. }
  13086. _gl.bindFramebuffer( 36160, null );
  13087. } else {
  13088. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13089. }
  13090. }
  13091. }
  13092. // Setup color buffer
  13093. if ( isCube ) {
  13094. state.bindTexture( 34067, textureProperties.__webglTexture );
  13095. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13096. for ( var i = 0; i < 6; i ++ ) {
  13097. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13098. }
  13099. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13100. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13101. }
  13102. state.bindTexture( 34067, null );
  13103. } else {
  13104. state.bindTexture( 3553, textureProperties.__webglTexture );
  13105. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13106. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13107. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13108. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13109. }
  13110. state.bindTexture( 3553, null );
  13111. }
  13112. // Setup depth and stencil buffers
  13113. if ( renderTarget.depthBuffer ) {
  13114. setupDepthRenderbuffer( renderTarget );
  13115. }
  13116. }
  13117. function updateRenderTargetMipmap( renderTarget ) {
  13118. var texture = renderTarget.texture;
  13119. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13120. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13121. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  13122. var webglTexture = properties.get( texture ).__webglTexture;
  13123. state.bindTexture( target, webglTexture );
  13124. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13125. state.bindTexture( target, null );
  13126. }
  13127. }
  13128. function updateMultisampleRenderTarget( renderTarget ) {
  13129. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13130. if ( capabilities.isWebGL2 ) {
  13131. var renderTargetProperties = properties.get( renderTarget );
  13132. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13133. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13134. var width = renderTarget.width;
  13135. var height = renderTarget.height;
  13136. var mask = 16384;
  13137. if ( renderTarget.depthBuffer ) mask |= 256;
  13138. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13139. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13140. } else {
  13141. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13142. }
  13143. }
  13144. }
  13145. function getRenderTargetSamples( renderTarget ) {
  13146. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13147. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  13148. }
  13149. function updateVideoTexture( texture ) {
  13150. var id = texture.id;
  13151. var frame = info.render.frame;
  13152. // Check the last frame we updated the VideoTexture
  13153. if ( _videoTextures[ id ] !== frame ) {
  13154. _videoTextures[ id ] = frame;
  13155. texture.update();
  13156. }
  13157. }
  13158. // backwards compatibility
  13159. var warnedTexture2D = false;
  13160. var warnedTextureCube = false;
  13161. function safeSetTexture2D( texture, slot ) {
  13162. if ( texture && texture.isWebGLRenderTarget ) {
  13163. if ( warnedTexture2D === false ) {
  13164. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13165. warnedTexture2D = true;
  13166. }
  13167. texture = texture.texture;
  13168. }
  13169. setTexture2D( texture, slot );
  13170. }
  13171. function safeSetTextureCube( texture, slot ) {
  13172. if ( texture && texture.isWebGLRenderTargetCube ) {
  13173. if ( warnedTextureCube === false ) {
  13174. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13175. warnedTextureCube = true;
  13176. }
  13177. texture = texture.texture;
  13178. }
  13179. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13180. // TODO: unify these code paths
  13181. if ( ( texture && texture.isCubeTexture ) ||
  13182. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13183. // CompressedTexture can have Array in image :/
  13184. // this function alone should take care of cube textures
  13185. setTextureCube( texture, slot );
  13186. } else {
  13187. // assumed: texture property of THREE.WebGLRenderTargetCube
  13188. setTextureCubeDynamic( texture, slot );
  13189. }
  13190. }
  13191. //
  13192. this.allocateTextureUnit = allocateTextureUnit;
  13193. this.resetTextureUnits = resetTextureUnits;
  13194. this.setTexture2D = setTexture2D;
  13195. this.setTexture2DArray = setTexture2DArray;
  13196. this.setTexture3D = setTexture3D;
  13197. this.setTextureCube = setTextureCube;
  13198. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13199. this.setupRenderTarget = setupRenderTarget;
  13200. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13201. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13202. this.safeSetTexture2D = safeSetTexture2D;
  13203. this.safeSetTextureCube = safeSetTextureCube;
  13204. }
  13205. /**
  13206. * @author thespite / http://www.twitter.com/thespite
  13207. */
  13208. function WebGLUtils( gl, extensions, capabilities ) {
  13209. function convert( p ) {
  13210. var extension;
  13211. if ( p === RepeatWrapping ) return 10497;
  13212. if ( p === ClampToEdgeWrapping ) return 33071;
  13213. if ( p === MirroredRepeatWrapping ) return 33648;
  13214. if ( p === NearestFilter ) return 9728;
  13215. if ( p === NearestMipmapNearestFilter ) return 9984;
  13216. if ( p === NearestMipmapLinearFilter ) return 9986;
  13217. if ( p === LinearFilter ) return 9729;
  13218. if ( p === LinearMipmapNearestFilter ) return 9985;
  13219. if ( p === LinearMipmapLinearFilter ) return 9987;
  13220. if ( p === UnsignedByteType ) return 5121;
  13221. if ( p === UnsignedShort4444Type ) return 32819;
  13222. if ( p === UnsignedShort5551Type ) return 32820;
  13223. if ( p === UnsignedShort565Type ) return 33635;
  13224. if ( p === ByteType ) return 5120;
  13225. if ( p === ShortType ) return 5122;
  13226. if ( p === UnsignedShortType ) return 5123;
  13227. if ( p === IntType ) return 5124;
  13228. if ( p === UnsignedIntType ) return 5125;
  13229. if ( p === FloatType ) return 5126;
  13230. if ( p === HalfFloatType ) {
  13231. if ( capabilities.isWebGL2 ) return 5131;
  13232. extension = extensions.get( 'OES_texture_half_float' );
  13233. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  13234. }
  13235. if ( p === AlphaFormat ) return 6406;
  13236. if ( p === RGBFormat ) return 6407;
  13237. if ( p === RGBAFormat ) return 6408;
  13238. if ( p === LuminanceFormat ) return 6409;
  13239. if ( p === LuminanceAlphaFormat ) return 6410;
  13240. if ( p === DepthFormat ) return 6402;
  13241. if ( p === DepthStencilFormat ) return 34041;
  13242. if ( p === RedFormat ) return 6403;
  13243. if ( p === AddEquation ) return 32774;
  13244. if ( p === SubtractEquation ) return 32778;
  13245. if ( p === ReverseSubtractEquation ) return 32779;
  13246. if ( p === ZeroFactor ) return 0;
  13247. if ( p === OneFactor ) return 1;
  13248. if ( p === SrcColorFactor ) return 768;
  13249. if ( p === OneMinusSrcColorFactor ) return 769;
  13250. if ( p === SrcAlphaFactor ) return 770;
  13251. if ( p === OneMinusSrcAlphaFactor ) return 771;
  13252. if ( p === DstAlphaFactor ) return 772;
  13253. if ( p === OneMinusDstAlphaFactor ) return 773;
  13254. if ( p === DstColorFactor ) return 774;
  13255. if ( p === OneMinusDstColorFactor ) return 775;
  13256. if ( p === SrcAlphaSaturateFactor ) return 776;
  13257. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13258. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13259. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13260. if ( extension !== null ) {
  13261. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13262. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13263. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13264. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13265. }
  13266. }
  13267. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13268. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13269. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13270. if ( extension !== null ) {
  13271. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13272. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13273. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13274. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13275. }
  13276. }
  13277. if ( p === RGB_ETC1_Format ) {
  13278. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13279. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13280. }
  13281. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13282. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13283. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13284. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13285. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  13286. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13287. if ( extension !== null ) {
  13288. return p;
  13289. }
  13290. }
  13291. if ( p === MinEquation || p === MaxEquation ) {
  13292. if ( capabilities.isWebGL2 ) {
  13293. if ( p === MinEquation ) return 32775;
  13294. if ( p === MaxEquation ) return 32776;
  13295. }
  13296. extension = extensions.get( 'EXT_blend_minmax' );
  13297. if ( extension !== null ) {
  13298. if ( p === MinEquation ) return extension.MIN_EXT;
  13299. if ( p === MaxEquation ) return extension.MAX_EXT;
  13300. }
  13301. }
  13302. if ( p === UnsignedInt248Type ) {
  13303. if ( capabilities.isWebGL2 ) return 34042;
  13304. extension = extensions.get( 'WEBGL_depth_texture' );
  13305. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  13306. }
  13307. return 0;
  13308. }
  13309. return { convert: convert };
  13310. }
  13311. /**
  13312. * @author mrdoob / http://mrdoob.com/
  13313. */
  13314. function Group() {
  13315. Object3D.call( this );
  13316. this.type = 'Group';
  13317. }
  13318. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13319. constructor: Group,
  13320. isGroup: true
  13321. } );
  13322. /**
  13323. * @author mrdoob / http://mrdoob.com/
  13324. */
  13325. function ArrayCamera( array ) {
  13326. PerspectiveCamera.call( this );
  13327. this.cameras = array || [];
  13328. }
  13329. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13330. constructor: ArrayCamera,
  13331. isArrayCamera: true
  13332. } );
  13333. /**
  13334. * @author jsantell / https://www.jsantell.com/
  13335. * @author mrdoob / http://mrdoob.com/
  13336. */
  13337. var cameraLPos = new Vector3();
  13338. var cameraRPos = new Vector3();
  13339. /**
  13340. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13341. * the cameras' projection and world matrices have already been set.
  13342. * And that near and far planes are identical for both cameras.
  13343. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13344. */
  13345. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13346. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13347. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13348. var ipd = cameraLPos.distanceTo( cameraRPos );
  13349. var projL = cameraL.projectionMatrix.elements;
  13350. var projR = cameraR.projectionMatrix.elements;
  13351. // VR systems will have identical far and near planes, and
  13352. // most likely identical top and bottom frustum extents.
  13353. // Use the left camera for these values.
  13354. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13355. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13356. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13357. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13358. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13359. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13360. var left = near * leftFov;
  13361. var right = near * rightFov;
  13362. // Calculate the new camera's position offset from the
  13363. // left camera. xOffset should be roughly half `ipd`.
  13364. var zOffset = ipd / ( - leftFov + rightFov );
  13365. var xOffset = zOffset * - leftFov;
  13366. // TODO: Better way to apply this offset?
  13367. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13368. camera.translateX( xOffset );
  13369. camera.translateZ( zOffset );
  13370. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13371. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13372. // Find the union of the frustum values of the cameras and scale
  13373. // the values so that the near plane's position does not change in world space,
  13374. // although must now be relative to the new union camera.
  13375. var near2 = near + zOffset;
  13376. var far2 = far + zOffset;
  13377. var left2 = left - xOffset;
  13378. var right2 = right + ( ipd - xOffset );
  13379. var top2 = topFov * far / far2 * near2;
  13380. var bottom2 = bottomFov * far / far2 * near2;
  13381. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13382. }
  13383. /**
  13384. * @author mrdoob / http://mrdoob.com/
  13385. */
  13386. function WebVRManager( renderer ) {
  13387. var renderWidth, renderHeight;
  13388. var scope = this;
  13389. var device = null;
  13390. var frameData = null;
  13391. var poseTarget = null;
  13392. var controllers = [];
  13393. var standingMatrix = new Matrix4();
  13394. var standingMatrixInverse = new Matrix4();
  13395. var framebufferScaleFactor = 1.0;
  13396. var referenceSpaceType = 'local-floor';
  13397. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13398. frameData = new window.VRFrameData();
  13399. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13400. }
  13401. var matrixWorldInverse = new Matrix4();
  13402. var tempQuaternion = new Quaternion();
  13403. var tempPosition = new Vector3();
  13404. var cameraL = new PerspectiveCamera();
  13405. cameraL.viewport = new Vector4();
  13406. cameraL.layers.enable( 1 );
  13407. var cameraR = new PerspectiveCamera();
  13408. cameraR.viewport = new Vector4();
  13409. cameraR.layers.enable( 2 );
  13410. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13411. cameraVR.layers.enable( 1 );
  13412. cameraVR.layers.enable( 2 );
  13413. //
  13414. function isPresenting() {
  13415. return device !== null && device.isPresenting === true;
  13416. }
  13417. var currentSize = new Vector2(), currentPixelRatio;
  13418. function onVRDisplayPresentChange() {
  13419. if ( isPresenting() ) {
  13420. var eyeParameters = device.getEyeParameters( 'left' );
  13421. renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
  13422. renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13423. currentPixelRatio = renderer.getPixelRatio();
  13424. renderer.getSize( currentSize );
  13425. renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
  13426. cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
  13427. cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
  13428. animation.start();
  13429. scope.dispatchEvent( { type: 'sessionstart' } );
  13430. } else {
  13431. if ( scope.enabled ) {
  13432. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13433. }
  13434. animation.stop();
  13435. scope.dispatchEvent( { type: 'sessionend' } );
  13436. }
  13437. }
  13438. //
  13439. var triggers = [];
  13440. function findGamepad( id ) {
  13441. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13442. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13443. var gamepad = gamepads[ i ];
  13444. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13445. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13446. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13447. gamepad.id.startsWith( 'HTC Vive Focus' ) ||
  13448. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13449. if ( j === id ) return gamepad;
  13450. j ++;
  13451. }
  13452. }
  13453. }
  13454. function updateControllers() {
  13455. for ( var i = 0; i < controllers.length; i ++ ) {
  13456. var controller = controllers[ i ];
  13457. var gamepad = findGamepad( i );
  13458. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13459. if ( gamepad.pose === null ) return;
  13460. // Pose
  13461. var pose = gamepad.pose;
  13462. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13463. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13464. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13465. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13466. controller.matrix.premultiply( standingMatrix );
  13467. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13468. controller.matrixWorldNeedsUpdate = true;
  13469. controller.visible = true;
  13470. // Trigger
  13471. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13472. if ( triggers[ i ] === undefined ) triggers[ i ] = false;
  13473. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13474. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13475. if ( triggers[ i ] === true ) {
  13476. controller.dispatchEvent( { type: 'selectstart' } );
  13477. } else {
  13478. controller.dispatchEvent( { type: 'selectend' } );
  13479. controller.dispatchEvent( { type: 'select' } );
  13480. }
  13481. }
  13482. } else {
  13483. controller.visible = false;
  13484. }
  13485. }
  13486. }
  13487. function updateViewportFromBounds( viewport, bounds ) {
  13488. if ( bounds !== null && bounds.length === 4 ) {
  13489. viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
  13490. }
  13491. }
  13492. //
  13493. this.enabled = false;
  13494. this.getController = function ( id ) {
  13495. var controller = controllers[ id ];
  13496. if ( controller === undefined ) {
  13497. controller = new Group();
  13498. controller.matrixAutoUpdate = false;
  13499. controller.visible = false;
  13500. controllers[ id ] = controller;
  13501. }
  13502. return controller;
  13503. };
  13504. this.getDevice = function () {
  13505. return device;
  13506. };
  13507. this.setDevice = function ( value ) {
  13508. if ( value !== undefined ) device = value;
  13509. animation.setContext( value );
  13510. };
  13511. this.setFramebufferScaleFactor = function ( value ) {
  13512. framebufferScaleFactor = value;
  13513. };
  13514. this.setReferenceSpaceType = function ( value ) {
  13515. referenceSpaceType = value;
  13516. };
  13517. this.setPoseTarget = function ( object ) {
  13518. if ( object !== undefined ) poseTarget = object;
  13519. };
  13520. this.getCamera = function ( camera ) {
  13521. var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
  13522. if ( isPresenting() === false ) {
  13523. camera.position.set( 0, userHeight, 0 );
  13524. camera.rotation.set( 0, 0, 0 );
  13525. return camera;
  13526. }
  13527. device.depthNear = camera.near;
  13528. device.depthFar = camera.far;
  13529. device.getFrameData( frameData );
  13530. //
  13531. if ( referenceSpaceType === 'local-floor' ) {
  13532. var stageParameters = device.stageParameters;
  13533. if ( stageParameters ) {
  13534. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13535. } else {
  13536. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13537. }
  13538. }
  13539. var pose = frameData.pose;
  13540. var poseObject = poseTarget !== null ? poseTarget : camera;
  13541. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13542. poseObject.matrix.copy( standingMatrix );
  13543. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13544. if ( pose.orientation !== null ) {
  13545. tempQuaternion.fromArray( pose.orientation );
  13546. poseObject.quaternion.multiply( tempQuaternion );
  13547. }
  13548. if ( pose.position !== null ) {
  13549. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13550. tempPosition.fromArray( pose.position );
  13551. tempPosition.applyQuaternion( tempQuaternion );
  13552. poseObject.position.add( tempPosition );
  13553. }
  13554. poseObject.updateMatrixWorld();
  13555. //
  13556. cameraL.near = camera.near;
  13557. cameraR.near = camera.near;
  13558. cameraL.far = camera.far;
  13559. cameraR.far = camera.far;
  13560. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13561. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13562. // TODO (mrdoob) Double check this code
  13563. standingMatrixInverse.getInverse( standingMatrix );
  13564. if ( referenceSpaceType === 'local-floor' ) {
  13565. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13566. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13567. }
  13568. var parent = poseObject.parent;
  13569. if ( parent !== null ) {
  13570. matrixWorldInverse.getInverse( parent.matrixWorld );
  13571. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13572. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13573. }
  13574. // envMap and Mirror needs camera.matrixWorld
  13575. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13576. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13577. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13578. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13579. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13580. //
  13581. var layers = device.getLayers();
  13582. if ( layers.length ) {
  13583. var layer = layers[ 0 ];
  13584. updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
  13585. updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
  13586. }
  13587. updateControllers();
  13588. return cameraVR;
  13589. };
  13590. this.getStandingMatrix = function () {
  13591. return standingMatrix;
  13592. };
  13593. this.isPresenting = isPresenting;
  13594. // Animation Loop
  13595. var animation = new WebGLAnimation();
  13596. this.setAnimationLoop = function ( callback ) {
  13597. animation.setAnimationLoop( callback );
  13598. if ( isPresenting() ) animation.start();
  13599. };
  13600. this.submitFrame = function () {
  13601. if ( isPresenting() ) device.submitFrame();
  13602. };
  13603. this.dispose = function () {
  13604. if ( typeof window !== 'undefined' ) {
  13605. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13606. }
  13607. };
  13608. // DEPRECATED
  13609. this.setFrameOfReferenceType = function () {
  13610. console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
  13611. };
  13612. }
  13613. Object.assign( WebVRManager.prototype, EventDispatcher.prototype );
  13614. /**
  13615. * @author mrdoob / http://mrdoob.com/
  13616. */
  13617. function WebXRManager( renderer, gl ) {
  13618. var scope = this;
  13619. var session = null;
  13620. var referenceSpace = null;
  13621. var referenceSpaceType = 'local-floor';
  13622. var pose = null;
  13623. var controllers = [];
  13624. var inputSources = [];
  13625. function isPresenting() {
  13626. return session !== null && referenceSpace !== null;
  13627. }
  13628. //
  13629. var cameraL = new PerspectiveCamera();
  13630. cameraL.layers.enable( 1 );
  13631. cameraL.viewport = new Vector4();
  13632. var cameraR = new PerspectiveCamera();
  13633. cameraR.layers.enable( 2 );
  13634. cameraR.viewport = new Vector4();
  13635. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13636. cameraVR.layers.enable( 1 );
  13637. cameraVR.layers.enable( 2 );
  13638. //
  13639. this.enabled = false;
  13640. this.getController = function ( id ) {
  13641. var controller = controllers[ id ];
  13642. if ( controller === undefined ) {
  13643. controller = new Group();
  13644. controller.matrixAutoUpdate = false;
  13645. controller.visible = false;
  13646. controllers[ id ] = controller;
  13647. }
  13648. return controller;
  13649. };
  13650. //
  13651. function onSessionEvent( event ) {
  13652. for ( var i = 0; i < controllers.length; i ++ ) {
  13653. if ( inputSources[ i ] === event.inputSource ) {
  13654. controllers[ i ].dispatchEvent( { type: event.type } );
  13655. }
  13656. }
  13657. }
  13658. function onSessionEnd() {
  13659. renderer.setFramebuffer( null );
  13660. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13661. animation.stop();
  13662. scope.dispatchEvent( { type: 'sessionend' } );
  13663. }
  13664. function onRequestReferenceSpace( value ) {
  13665. referenceSpace = value;
  13666. animation.setContext( session );
  13667. animation.start();
  13668. scope.dispatchEvent( { type: 'sessionstart' } );
  13669. }
  13670. this.setFramebufferScaleFactor = function ( value ) {
  13671. };
  13672. this.setReferenceSpaceType = function ( value ) {
  13673. referenceSpaceType = value;
  13674. };
  13675. this.getSession = function () {
  13676. return session;
  13677. };
  13678. this.setSession = function ( value ) {
  13679. session = value;
  13680. if ( session !== null ) {
  13681. session.addEventListener( 'select', onSessionEvent );
  13682. session.addEventListener( 'selectstart', onSessionEvent );
  13683. session.addEventListener( 'selectend', onSessionEvent );
  13684. session.addEventListener( 'end', onSessionEnd );
  13685. session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
  13686. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13687. //
  13688. inputSources = session.inputSources;
  13689. session.addEventListener( 'inputsourceschange', function () {
  13690. inputSources = session.inputSources;
  13691. console.log( inputSources );
  13692. for ( var i = 0; i < controllers.length; i ++ ) {
  13693. var controller = controllers[ i ];
  13694. controller.userData.inputSource = inputSources[ i ];
  13695. }
  13696. } );
  13697. }
  13698. };
  13699. function updateCamera( camera, parent ) {
  13700. if ( parent === null ) {
  13701. camera.matrixWorld.copy( camera.matrix );
  13702. } else {
  13703. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13704. }
  13705. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13706. }
  13707. this.getCamera = function ( camera ) {
  13708. if ( isPresenting() ) {
  13709. var parent = camera.parent;
  13710. var cameras = cameraVR.cameras;
  13711. updateCamera( cameraVR, parent );
  13712. for ( var i = 0; i < cameras.length; i ++ ) {
  13713. updateCamera( cameras[ i ], parent );
  13714. }
  13715. // update camera and its children
  13716. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13717. var children = camera.children;
  13718. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13719. children[ i ].updateMatrixWorld( true );
  13720. }
  13721. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13722. return cameraVR;
  13723. }
  13724. return camera;
  13725. };
  13726. this.isPresenting = isPresenting;
  13727. // Animation Loop
  13728. var onAnimationFrameCallback = null;
  13729. function onAnimationFrame( time, frame ) {
  13730. pose = frame.getViewerPose( referenceSpace );
  13731. if ( pose !== null ) {
  13732. var views = pose.views;
  13733. var baseLayer = session.renderState.baseLayer;
  13734. renderer.setFramebuffer( baseLayer.framebuffer );
  13735. for ( var i = 0; i < views.length; i ++ ) {
  13736. var view = views[ i ];
  13737. var viewport = baseLayer.getViewport( view );
  13738. var viewMatrix = view.transform.inverse.matrix;
  13739. var camera = cameraVR.cameras[ i ];
  13740. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13741. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13742. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13743. if ( i === 0 ) {
  13744. cameraVR.matrix.copy( camera.matrix );
  13745. }
  13746. }
  13747. }
  13748. //
  13749. for ( var i = 0; i < controllers.length; i ++ ) {
  13750. var controller = controllers[ i ];
  13751. var inputSource = inputSources[ i ];
  13752. if ( inputSource ) {
  13753. var inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13754. if ( inputPose !== null ) {
  13755. controller.matrix.fromArray( inputPose.transform.matrix );
  13756. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13757. controller.visible = true;
  13758. continue;
  13759. }
  13760. }
  13761. controller.visible = false;
  13762. }
  13763. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13764. }
  13765. var animation = new WebGLAnimation();
  13766. animation.setAnimationLoop( onAnimationFrame );
  13767. this.setAnimationLoop = function ( callback ) {
  13768. onAnimationFrameCallback = callback;
  13769. };
  13770. this.dispose = function () {};
  13771. // DEPRECATED
  13772. this.getStandingMatrix = function () {
  13773. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13774. return new Matrix4();
  13775. };
  13776. this.getDevice = function () {
  13777. console.warn( 'THREE.WebXRManager: getDevice() has been deprecated.' );
  13778. };
  13779. this.setDevice = function () {
  13780. console.warn( 'THREE.WebXRManager: setDevice() has been deprecated.' );
  13781. };
  13782. this.setFrameOfReferenceType = function () {
  13783. console.warn( 'THREE.WebXRManager: setFrameOfReferenceType() has been deprecated.' );
  13784. };
  13785. this.submitFrame = function () {};
  13786. }
  13787. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  13788. /**
  13789. * @author supereggbert / http://www.paulbrunt.co.uk/
  13790. * @author mrdoob / http://mrdoob.com/
  13791. * @author alteredq / http://alteredqualia.com/
  13792. * @author szimek / https://github.com/szimek/
  13793. * @author tschw
  13794. */
  13795. function WebGLRenderer( parameters ) {
  13796. parameters = parameters || {};
  13797. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13798. _context = parameters.context !== undefined ? parameters.context : null,
  13799. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13800. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13801. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13802. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13803. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13804. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13805. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13806. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13807. var currentRenderList = null;
  13808. var currentRenderState = null;
  13809. // public properties
  13810. this.domElement = _canvas;
  13811. // Debug configuration container
  13812. this.debug = {
  13813. /**
  13814. * Enables error checking and reporting when shader programs are being compiled
  13815. * @type {boolean}
  13816. */
  13817. checkShaderErrors: true
  13818. };
  13819. // clearing
  13820. this.autoClear = true;
  13821. this.autoClearColor = true;
  13822. this.autoClearDepth = true;
  13823. this.autoClearStencil = true;
  13824. // scene graph
  13825. this.sortObjects = true;
  13826. // user-defined clipping
  13827. this.clippingPlanes = [];
  13828. this.localClippingEnabled = false;
  13829. // physically based shading
  13830. this.gammaFactor = 2.0; // for backwards compatibility
  13831. this.gammaInput = false;
  13832. this.gammaOutput = false;
  13833. // physical lights
  13834. this.physicallyCorrectLights = false;
  13835. // tone mapping
  13836. this.toneMapping = LinearToneMapping;
  13837. this.toneMappingExposure = 1.0;
  13838. this.toneMappingWhitePoint = 1.0;
  13839. // morphs
  13840. this.maxMorphTargets = 8;
  13841. this.maxMorphNormals = 4;
  13842. // internal properties
  13843. var _this = this,
  13844. _isContextLost = false,
  13845. // internal state cache
  13846. _framebuffer = null,
  13847. _currentActiveCubeFace = 0,
  13848. _currentActiveMipmapLevel = 0,
  13849. _currentRenderTarget = null,
  13850. _currentFramebuffer = null,
  13851. _currentMaterialId = - 1,
  13852. // geometry and program caching
  13853. _currentGeometryProgram = {
  13854. geometry: null,
  13855. program: null,
  13856. wireframe: false
  13857. },
  13858. _currentCamera = null,
  13859. _currentArrayCamera = null,
  13860. _currentViewport = new Vector4(),
  13861. _currentScissor = new Vector4(),
  13862. _currentScissorTest = null,
  13863. //
  13864. _width = _canvas.width,
  13865. _height = _canvas.height,
  13866. _pixelRatio = 1,
  13867. _viewport = new Vector4( 0, 0, _width, _height ),
  13868. _scissor = new Vector4( 0, 0, _width, _height ),
  13869. _scissorTest = false,
  13870. // frustum
  13871. _frustum = new Frustum(),
  13872. // clipping
  13873. _clipping = new WebGLClipping(),
  13874. _clippingEnabled = false,
  13875. _localClippingEnabled = false,
  13876. // camera matrices cache
  13877. _projScreenMatrix = new Matrix4(),
  13878. _vector3 = new Vector3();
  13879. function getTargetPixelRatio() {
  13880. return _currentRenderTarget === null ? _pixelRatio : 1;
  13881. }
  13882. // initialize
  13883. var _gl;
  13884. try {
  13885. var contextAttributes = {
  13886. alpha: _alpha,
  13887. depth: _depth,
  13888. stencil: _stencil,
  13889. antialias: _antialias,
  13890. premultipliedAlpha: _premultipliedAlpha,
  13891. preserveDrawingBuffer: _preserveDrawingBuffer,
  13892. powerPreference: _powerPreference,
  13893. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
  13894. xrCompatible: true
  13895. };
  13896. // event listeners must be registered before WebGL context is created, see #12753
  13897. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13898. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13899. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13900. if ( _gl === null ) {
  13901. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13902. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13903. } else {
  13904. throw new Error( 'Error creating WebGL context.' );
  13905. }
  13906. }
  13907. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13908. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13909. _gl.getShaderPrecisionFormat = function () {
  13910. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13911. };
  13912. }
  13913. } catch ( error ) {
  13914. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13915. throw error;
  13916. }
  13917. var extensions, capabilities, state, info;
  13918. var properties, textures, attributes, geometries, objects;
  13919. var programCache, renderLists, renderStates;
  13920. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13921. var utils;
  13922. function initGLContext() {
  13923. extensions = new WebGLExtensions( _gl );
  13924. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13925. if ( ! capabilities.isWebGL2 ) {
  13926. extensions.get( 'WEBGL_depth_texture' );
  13927. extensions.get( 'OES_texture_float' );
  13928. extensions.get( 'OES_texture_half_float' );
  13929. extensions.get( 'OES_texture_half_float_linear' );
  13930. extensions.get( 'OES_standard_derivatives' );
  13931. extensions.get( 'OES_element_index_uint' );
  13932. extensions.get( 'ANGLE_instanced_arrays' );
  13933. }
  13934. extensions.get( 'OES_texture_float_linear' );
  13935. utils = new WebGLUtils( _gl, extensions, capabilities );
  13936. state = new WebGLState( _gl, extensions, utils, capabilities );
  13937. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  13938. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  13939. info = new WebGLInfo( _gl );
  13940. properties = new WebGLProperties();
  13941. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13942. attributes = new WebGLAttributes( _gl );
  13943. geometries = new WebGLGeometries( _gl, attributes, info );
  13944. objects = new WebGLObjects( geometries, info );
  13945. morphtargets = new WebGLMorphtargets( _gl );
  13946. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13947. renderLists = new WebGLRenderLists();
  13948. renderStates = new WebGLRenderStates();
  13949. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13950. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13951. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13952. info.programs = programCache.programs;
  13953. _this.capabilities = capabilities;
  13954. _this.extensions = extensions;
  13955. _this.properties = properties;
  13956. _this.renderLists = renderLists;
  13957. _this.state = state;
  13958. _this.info = info;
  13959. }
  13960. initGLContext();
  13961. // vr
  13962. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator && 'supportsSession' in navigator.xr ) ? new WebXRManager( _this, _gl ) : new WebVRManager( _this );
  13963. this.vr = vr;
  13964. // shadow map
  13965. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13966. this.shadowMap = shadowMap;
  13967. // API
  13968. this.getContext = function () {
  13969. return _gl;
  13970. };
  13971. this.getContextAttributes = function () {
  13972. return _gl.getContextAttributes();
  13973. };
  13974. this.forceContextLoss = function () {
  13975. var extension = extensions.get( 'WEBGL_lose_context' );
  13976. if ( extension ) extension.loseContext();
  13977. };
  13978. this.forceContextRestore = function () {
  13979. var extension = extensions.get( 'WEBGL_lose_context' );
  13980. if ( extension ) extension.restoreContext();
  13981. };
  13982. this.getPixelRatio = function () {
  13983. return _pixelRatio;
  13984. };
  13985. this.setPixelRatio = function ( value ) {
  13986. if ( value === undefined ) return;
  13987. _pixelRatio = value;
  13988. this.setSize( _width, _height, false );
  13989. };
  13990. this.getSize = function ( target ) {
  13991. if ( target === undefined ) {
  13992. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13993. target = new Vector2();
  13994. }
  13995. return target.set( _width, _height );
  13996. };
  13997. this.setSize = function ( width, height, updateStyle ) {
  13998. if ( vr.isPresenting() ) {
  13999. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  14000. return;
  14001. }
  14002. _width = width;
  14003. _height = height;
  14004. _canvas.width = Math.floor( width * _pixelRatio );
  14005. _canvas.height = Math.floor( height * _pixelRatio );
  14006. if ( updateStyle !== false ) {
  14007. _canvas.style.width = width + 'px';
  14008. _canvas.style.height = height + 'px';
  14009. }
  14010. this.setViewport( 0, 0, width, height );
  14011. };
  14012. this.getDrawingBufferSize = function ( target ) {
  14013. if ( target === undefined ) {
  14014. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  14015. target = new Vector2();
  14016. }
  14017. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  14018. };
  14019. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14020. _width = width;
  14021. _height = height;
  14022. _pixelRatio = pixelRatio;
  14023. _canvas.width = Math.floor( width * pixelRatio );
  14024. _canvas.height = Math.floor( height * pixelRatio );
  14025. this.setViewport( 0, 0, width, height );
  14026. };
  14027. this.getCurrentViewport = function ( target ) {
  14028. if ( target === undefined ) {
  14029. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14030. target = new Vector4();
  14031. }
  14032. return target.copy( _currentViewport );
  14033. };
  14034. this.getViewport = function ( target ) {
  14035. return target.copy( _viewport );
  14036. };
  14037. this.setViewport = function ( x, y, width, height ) {
  14038. if ( x.isVector4 ) {
  14039. _viewport.set( x.x, x.y, x.z, x.w );
  14040. } else {
  14041. _viewport.set( x, y, width, height );
  14042. }
  14043. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14044. };
  14045. this.getScissor = function ( target ) {
  14046. return target.copy( _scissor );
  14047. };
  14048. this.setScissor = function ( x, y, width, height ) {
  14049. if ( x.isVector4 ) {
  14050. _scissor.set( x.x, x.y, x.z, x.w );
  14051. } else {
  14052. _scissor.set( x, y, width, height );
  14053. }
  14054. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14055. };
  14056. this.getScissorTest = function () {
  14057. return _scissorTest;
  14058. };
  14059. this.setScissorTest = function ( boolean ) {
  14060. state.setScissorTest( _scissorTest = boolean );
  14061. };
  14062. // Clearing
  14063. this.getClearColor = function () {
  14064. return background.getClearColor();
  14065. };
  14066. this.setClearColor = function () {
  14067. background.setClearColor.apply( background, arguments );
  14068. };
  14069. this.getClearAlpha = function () {
  14070. return background.getClearAlpha();
  14071. };
  14072. this.setClearAlpha = function () {
  14073. background.setClearAlpha.apply( background, arguments );
  14074. };
  14075. this.clear = function ( color, depth, stencil ) {
  14076. var bits = 0;
  14077. if ( color === undefined || color ) bits |= 16384;
  14078. if ( depth === undefined || depth ) bits |= 256;
  14079. if ( stencil === undefined || stencil ) bits |= 1024;
  14080. _gl.clear( bits );
  14081. };
  14082. this.clearColor = function () {
  14083. this.clear( true, false, false );
  14084. };
  14085. this.clearDepth = function () {
  14086. this.clear( false, true, false );
  14087. };
  14088. this.clearStencil = function () {
  14089. this.clear( false, false, true );
  14090. };
  14091. //
  14092. this.dispose = function () {
  14093. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14094. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14095. renderLists.dispose();
  14096. renderStates.dispose();
  14097. properties.dispose();
  14098. objects.dispose();
  14099. vr.dispose();
  14100. animation.stop();
  14101. };
  14102. // Events
  14103. function onContextLost( event ) {
  14104. event.preventDefault();
  14105. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14106. _isContextLost = true;
  14107. }
  14108. function onContextRestore( /* event */ ) {
  14109. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14110. _isContextLost = false;
  14111. initGLContext();
  14112. }
  14113. function onMaterialDispose( event ) {
  14114. var material = event.target;
  14115. material.removeEventListener( 'dispose', onMaterialDispose );
  14116. deallocateMaterial( material );
  14117. }
  14118. // Buffer deallocation
  14119. function deallocateMaterial( material ) {
  14120. releaseMaterialProgramReference( material );
  14121. properties.remove( material );
  14122. }
  14123. function releaseMaterialProgramReference( material ) {
  14124. var programInfo = properties.get( material ).program;
  14125. material.program = undefined;
  14126. if ( programInfo !== undefined ) {
  14127. programCache.releaseProgram( programInfo );
  14128. }
  14129. }
  14130. // Buffer rendering
  14131. function renderObjectImmediate( object, program ) {
  14132. object.render( function ( object ) {
  14133. _this.renderBufferImmediate( object, program );
  14134. } );
  14135. }
  14136. this.renderBufferImmediate = function ( object, program ) {
  14137. state.initAttributes();
  14138. var buffers = properties.get( object );
  14139. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14140. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14141. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14142. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14143. var programAttributes = program.getAttributes();
  14144. if ( object.hasPositions ) {
  14145. _gl.bindBuffer( 34962, buffers.position );
  14146. _gl.bufferData( 34962, object.positionArray, 35048 );
  14147. state.enableAttribute( programAttributes.position );
  14148. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14149. }
  14150. if ( object.hasNormals ) {
  14151. _gl.bindBuffer( 34962, buffers.normal );
  14152. _gl.bufferData( 34962, object.normalArray, 35048 );
  14153. state.enableAttribute( programAttributes.normal );
  14154. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14155. }
  14156. if ( object.hasUvs ) {
  14157. _gl.bindBuffer( 34962, buffers.uv );
  14158. _gl.bufferData( 34962, object.uvArray, 35048 );
  14159. state.enableAttribute( programAttributes.uv );
  14160. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14161. }
  14162. if ( object.hasColors ) {
  14163. _gl.bindBuffer( 34962, buffers.color );
  14164. _gl.bufferData( 34962, object.colorArray, 35048 );
  14165. state.enableAttribute( programAttributes.color );
  14166. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14167. }
  14168. state.disableUnusedAttributes();
  14169. _gl.drawArrays( 4, 0, object.count );
  14170. object.count = 0;
  14171. };
  14172. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14173. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14174. state.setMaterial( material, frontFaceCW );
  14175. var program = setProgram( camera, fog, material, object );
  14176. var updateBuffers = false;
  14177. if ( _currentGeometryProgram.geometry !== geometry.id ||
  14178. _currentGeometryProgram.program !== program.id ||
  14179. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  14180. _currentGeometryProgram.geometry = geometry.id;
  14181. _currentGeometryProgram.program = program.id;
  14182. _currentGeometryProgram.wireframe = material.wireframe === true;
  14183. updateBuffers = true;
  14184. }
  14185. if ( object.morphTargetInfluences ) {
  14186. morphtargets.update( object, geometry, material, program );
  14187. updateBuffers = true;
  14188. }
  14189. //
  14190. var index = geometry.index;
  14191. var position = geometry.attributes.position;
  14192. var rangeFactor = 1;
  14193. if ( material.wireframe === true ) {
  14194. index = geometries.getWireframeAttribute( geometry );
  14195. rangeFactor = 2;
  14196. }
  14197. var attribute;
  14198. var renderer = bufferRenderer;
  14199. if ( index !== null ) {
  14200. attribute = attributes.get( index );
  14201. renderer = indexedBufferRenderer;
  14202. renderer.setIndex( attribute );
  14203. }
  14204. if ( updateBuffers ) {
  14205. setupVertexAttributes( material, program, geometry );
  14206. if ( index !== null ) {
  14207. _gl.bindBuffer( 34963, attribute.buffer );
  14208. }
  14209. }
  14210. //
  14211. var dataCount = Infinity;
  14212. if ( index !== null ) {
  14213. dataCount = index.count;
  14214. } else if ( position !== undefined ) {
  14215. dataCount = position.count;
  14216. }
  14217. var rangeStart = geometry.drawRange.start * rangeFactor;
  14218. var rangeCount = geometry.drawRange.count * rangeFactor;
  14219. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14220. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14221. var drawStart = Math.max( rangeStart, groupStart );
  14222. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14223. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14224. if ( drawCount === 0 ) return;
  14225. //
  14226. if ( object.isMesh ) {
  14227. if ( material.wireframe === true ) {
  14228. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14229. renderer.setMode( 1 );
  14230. } else {
  14231. switch ( object.drawMode ) {
  14232. case TrianglesDrawMode:
  14233. renderer.setMode( 4 );
  14234. break;
  14235. case TriangleStripDrawMode:
  14236. renderer.setMode( 5 );
  14237. break;
  14238. case TriangleFanDrawMode:
  14239. renderer.setMode( 6 );
  14240. break;
  14241. }
  14242. }
  14243. } else if ( object.isLine ) {
  14244. var lineWidth = material.linewidth;
  14245. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14246. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14247. if ( object.isLineSegments ) {
  14248. renderer.setMode( 1 );
  14249. } else if ( object.isLineLoop ) {
  14250. renderer.setMode( 2 );
  14251. } else {
  14252. renderer.setMode( 3 );
  14253. }
  14254. } else if ( object.isPoints ) {
  14255. renderer.setMode( 0 );
  14256. } else if ( object.isSprite ) {
  14257. renderer.setMode( 4 );
  14258. }
  14259. if ( geometry && geometry.isInstancedBufferGeometry ) {
  14260. if ( geometry.maxInstancedCount > 0 ) {
  14261. renderer.renderInstances( geometry, drawStart, drawCount );
  14262. }
  14263. } else {
  14264. renderer.render( drawStart, drawCount );
  14265. }
  14266. };
  14267. function setupVertexAttributes( material, program, geometry ) {
  14268. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  14269. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  14270. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14271. return;
  14272. }
  14273. }
  14274. state.initAttributes();
  14275. var geometryAttributes = geometry.attributes;
  14276. var programAttributes = program.getAttributes();
  14277. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14278. for ( var name in programAttributes ) {
  14279. var programAttribute = programAttributes[ name ];
  14280. if ( programAttribute >= 0 ) {
  14281. var geometryAttribute = geometryAttributes[ name ];
  14282. if ( geometryAttribute !== undefined ) {
  14283. var normalized = geometryAttribute.normalized;
  14284. var size = geometryAttribute.itemSize;
  14285. var attribute = attributes.get( geometryAttribute );
  14286. // TODO Attribute may not be available on context restore
  14287. if ( attribute === undefined ) continue;
  14288. var buffer = attribute.buffer;
  14289. var type = attribute.type;
  14290. var bytesPerElement = attribute.bytesPerElement;
  14291. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14292. var data = geometryAttribute.data;
  14293. var stride = data.stride;
  14294. var offset = geometryAttribute.offset;
  14295. if ( data && data.isInstancedInterleavedBuffer ) {
  14296. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14297. if ( geometry.maxInstancedCount === undefined ) {
  14298. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14299. }
  14300. } else {
  14301. state.enableAttribute( programAttribute );
  14302. }
  14303. _gl.bindBuffer( 34962, buffer );
  14304. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14305. } else {
  14306. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14307. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14308. if ( geometry.maxInstancedCount === undefined ) {
  14309. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14310. }
  14311. } else {
  14312. state.enableAttribute( programAttribute );
  14313. }
  14314. _gl.bindBuffer( 34962, buffer );
  14315. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14316. }
  14317. } else if ( materialDefaultAttributeValues !== undefined ) {
  14318. var value = materialDefaultAttributeValues[ name ];
  14319. if ( value !== undefined ) {
  14320. switch ( value.length ) {
  14321. case 2:
  14322. _gl.vertexAttrib2fv( programAttribute, value );
  14323. break;
  14324. case 3:
  14325. _gl.vertexAttrib3fv( programAttribute, value );
  14326. break;
  14327. case 4:
  14328. _gl.vertexAttrib4fv( programAttribute, value );
  14329. break;
  14330. default:
  14331. _gl.vertexAttrib1fv( programAttribute, value );
  14332. }
  14333. }
  14334. }
  14335. }
  14336. }
  14337. state.disableUnusedAttributes();
  14338. }
  14339. // Compile
  14340. this.compile = function ( scene, camera ) {
  14341. currentRenderState = renderStates.get( scene, camera );
  14342. currentRenderState.init();
  14343. scene.traverse( function ( object ) {
  14344. if ( object.isLight ) {
  14345. currentRenderState.pushLight( object );
  14346. if ( object.castShadow ) {
  14347. currentRenderState.pushShadow( object );
  14348. }
  14349. }
  14350. } );
  14351. currentRenderState.setupLights( camera );
  14352. scene.traverse( function ( object ) {
  14353. if ( object.material ) {
  14354. if ( Array.isArray( object.material ) ) {
  14355. for ( var i = 0; i < object.material.length; i ++ ) {
  14356. initMaterial( object.material[ i ], scene.fog, object );
  14357. }
  14358. } else {
  14359. initMaterial( object.material, scene.fog, object );
  14360. }
  14361. }
  14362. } );
  14363. };
  14364. // Animation Loop
  14365. var onAnimationFrameCallback = null;
  14366. function onAnimationFrame( time ) {
  14367. if ( vr.isPresenting() ) return;
  14368. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14369. }
  14370. var animation = new WebGLAnimation();
  14371. animation.setAnimationLoop( onAnimationFrame );
  14372. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14373. this.setAnimationLoop = function ( callback ) {
  14374. onAnimationFrameCallback = callback;
  14375. vr.setAnimationLoop( callback );
  14376. animation.start();
  14377. };
  14378. // Rendering
  14379. this.render = function ( scene, camera ) {
  14380. var renderTarget, forceClear;
  14381. if ( arguments[ 2 ] !== undefined ) {
  14382. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14383. renderTarget = arguments[ 2 ];
  14384. }
  14385. if ( arguments[ 3 ] !== undefined ) {
  14386. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14387. forceClear = arguments[ 3 ];
  14388. }
  14389. if ( ! ( camera && camera.isCamera ) ) {
  14390. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14391. return;
  14392. }
  14393. if ( _isContextLost ) return;
  14394. // reset caching for this frame
  14395. _currentGeometryProgram.geometry = null;
  14396. _currentGeometryProgram.program = null;
  14397. _currentGeometryProgram.wireframe = false;
  14398. _currentMaterialId = - 1;
  14399. _currentCamera = null;
  14400. // update scene graph
  14401. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14402. // update camera matrices and frustum
  14403. if ( camera.parent === null ) camera.updateMatrixWorld();
  14404. if ( vr.enabled ) {
  14405. camera = vr.getCamera( camera );
  14406. }
  14407. //
  14408. currentRenderState = renderStates.get( scene, camera );
  14409. currentRenderState.init();
  14410. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14411. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14412. _frustum.setFromMatrix( _projScreenMatrix );
  14413. _localClippingEnabled = this.localClippingEnabled;
  14414. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14415. currentRenderList = renderLists.get( scene, camera );
  14416. currentRenderList.init();
  14417. projectObject( scene, camera, 0, _this.sortObjects );
  14418. if ( _this.sortObjects === true ) {
  14419. currentRenderList.sort();
  14420. }
  14421. //
  14422. if ( _clippingEnabled ) _clipping.beginShadows();
  14423. var shadowsArray = currentRenderState.state.shadowsArray;
  14424. shadowMap.render( shadowsArray, scene, camera );
  14425. currentRenderState.setupLights( camera );
  14426. if ( _clippingEnabled ) _clipping.endShadows();
  14427. //
  14428. if ( this.info.autoReset ) this.info.reset();
  14429. if ( renderTarget !== undefined ) {
  14430. this.setRenderTarget( renderTarget );
  14431. }
  14432. //
  14433. background.render( currentRenderList, scene, camera, forceClear );
  14434. // render scene
  14435. var opaqueObjects = currentRenderList.opaque;
  14436. var transparentObjects = currentRenderList.transparent;
  14437. if ( scene.overrideMaterial ) {
  14438. var overrideMaterial = scene.overrideMaterial;
  14439. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14440. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14441. } else {
  14442. // opaque pass (front-to-back order)
  14443. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14444. // transparent pass (back-to-front order)
  14445. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14446. }
  14447. //
  14448. scene.onAfterRender( _this, scene, camera );
  14449. //
  14450. if ( _currentRenderTarget !== null ) {
  14451. // Generate mipmap if we're using any kind of mipmap filtering
  14452. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14453. // resolve multisample renderbuffers to a single-sample texture if necessary
  14454. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14455. }
  14456. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14457. state.buffers.depth.setTest( true );
  14458. state.buffers.depth.setMask( true );
  14459. state.buffers.color.setMask( true );
  14460. state.setPolygonOffset( false );
  14461. if ( vr.enabled ) {
  14462. vr.submitFrame();
  14463. }
  14464. // _gl.finish();
  14465. currentRenderList = null;
  14466. currentRenderState = null;
  14467. };
  14468. function projectObject( object, camera, groupOrder, sortObjects ) {
  14469. if ( object.visible === false ) return;
  14470. var visible = object.layers.test( camera.layers );
  14471. if ( visible ) {
  14472. if ( object.isGroup ) {
  14473. groupOrder = object.renderOrder;
  14474. } else if ( object.isLOD ) {
  14475. if ( object.autoUpdate === true ) object.update( camera );
  14476. } else if ( object.isLight ) {
  14477. currentRenderState.pushLight( object );
  14478. if ( object.castShadow ) {
  14479. currentRenderState.pushShadow( object );
  14480. }
  14481. } else if ( object.isSprite ) {
  14482. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14483. if ( sortObjects ) {
  14484. _vector3.setFromMatrixPosition( object.matrixWorld )
  14485. .applyMatrix4( _projScreenMatrix );
  14486. }
  14487. var geometry = objects.update( object );
  14488. var material = object.material;
  14489. if ( material.visible ) {
  14490. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14491. }
  14492. }
  14493. } else if ( object.isImmediateRenderObject ) {
  14494. if ( sortObjects ) {
  14495. _vector3.setFromMatrixPosition( object.matrixWorld )
  14496. .applyMatrix4( _projScreenMatrix );
  14497. }
  14498. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14499. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14500. if ( object.isSkinnedMesh ) {
  14501. object.skeleton.update();
  14502. }
  14503. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14504. if ( sortObjects ) {
  14505. _vector3.setFromMatrixPosition( object.matrixWorld )
  14506. .applyMatrix4( _projScreenMatrix );
  14507. }
  14508. var geometry = objects.update( object );
  14509. var material = object.material;
  14510. if ( Array.isArray( material ) ) {
  14511. var groups = geometry.groups;
  14512. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14513. var group = groups[ i ];
  14514. var groupMaterial = material[ group.materialIndex ];
  14515. if ( groupMaterial && groupMaterial.visible ) {
  14516. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14517. }
  14518. }
  14519. } else if ( material.visible ) {
  14520. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14521. }
  14522. }
  14523. }
  14524. }
  14525. var children = object.children;
  14526. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14527. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14528. }
  14529. }
  14530. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14531. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14532. var renderItem = renderList[ i ];
  14533. var object = renderItem.object;
  14534. var geometry = renderItem.geometry;
  14535. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14536. var group = renderItem.group;
  14537. if ( camera.isArrayCamera ) {
  14538. _currentArrayCamera = camera;
  14539. var cameras = camera.cameras;
  14540. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14541. var camera2 = cameras[ j ];
  14542. if ( object.layers.test( camera2.layers ) ) {
  14543. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14544. currentRenderState.setupLights( camera2 );
  14545. renderObject( object, scene, camera2, geometry, material, group );
  14546. }
  14547. }
  14548. } else {
  14549. _currentArrayCamera = null;
  14550. renderObject( object, scene, camera, geometry, material, group );
  14551. }
  14552. }
  14553. }
  14554. function renderObject( object, scene, camera, geometry, material, group ) {
  14555. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14556. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14557. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14558. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14559. if ( object.isImmediateRenderObject ) {
  14560. state.setMaterial( material );
  14561. var program = setProgram( camera, scene.fog, material, object );
  14562. _currentGeometryProgram.geometry = null;
  14563. _currentGeometryProgram.program = null;
  14564. _currentGeometryProgram.wireframe = false;
  14565. renderObjectImmediate( object, program );
  14566. } else {
  14567. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14568. }
  14569. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14570. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14571. }
  14572. function initMaterial( material, fog, object ) {
  14573. var materialProperties = properties.get( material );
  14574. var lights = currentRenderState.state.lights;
  14575. var shadowsArray = currentRenderState.state.shadowsArray;
  14576. var lightsStateVersion = lights.state.version;
  14577. var parameters = programCache.getParameters(
  14578. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14579. var code = programCache.getProgramCode( material, parameters );
  14580. var program = materialProperties.program;
  14581. var programChange = true;
  14582. if ( program === undefined ) {
  14583. // new material
  14584. material.addEventListener( 'dispose', onMaterialDispose );
  14585. } else if ( program.code !== code ) {
  14586. // changed glsl or parameters
  14587. releaseMaterialProgramReference( material );
  14588. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  14589. materialProperties.lightsStateVersion = lightsStateVersion;
  14590. programChange = false;
  14591. } else if ( parameters.shaderID !== undefined ) {
  14592. // same glsl and uniform list
  14593. return;
  14594. } else {
  14595. // only rebuild uniform list
  14596. programChange = false;
  14597. }
  14598. if ( programChange ) {
  14599. if ( parameters.shaderID ) {
  14600. var shader = ShaderLib[ parameters.shaderID ];
  14601. materialProperties.shader = {
  14602. name: material.type,
  14603. uniforms: cloneUniforms( shader.uniforms ),
  14604. vertexShader: shader.vertexShader,
  14605. fragmentShader: shader.fragmentShader
  14606. };
  14607. } else {
  14608. materialProperties.shader = {
  14609. name: material.type,
  14610. uniforms: material.uniforms,
  14611. vertexShader: material.vertexShader,
  14612. fragmentShader: material.fragmentShader
  14613. };
  14614. }
  14615. material.onBeforeCompile( materialProperties.shader, _this );
  14616. // Computing code again as onBeforeCompile may have changed the shaders
  14617. code = programCache.getProgramCode( material, parameters );
  14618. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14619. materialProperties.program = program;
  14620. material.program = program;
  14621. }
  14622. var programAttributes = program.getAttributes();
  14623. if ( material.morphTargets ) {
  14624. material.numSupportedMorphTargets = 0;
  14625. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14626. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14627. material.numSupportedMorphTargets ++;
  14628. }
  14629. }
  14630. }
  14631. if ( material.morphNormals ) {
  14632. material.numSupportedMorphNormals = 0;
  14633. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14634. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14635. material.numSupportedMorphNormals ++;
  14636. }
  14637. }
  14638. }
  14639. var uniforms = materialProperties.shader.uniforms;
  14640. if ( ! material.isShaderMaterial &&
  14641. ! material.isRawShaderMaterial ||
  14642. material.clipping === true ) {
  14643. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14644. materialProperties.numIntersection = _clipping.numIntersection;
  14645. uniforms.clippingPlanes = _clipping.uniform;
  14646. }
  14647. materialProperties.fog = fog;
  14648. // store the light setup it was created for
  14649. materialProperties.lightsStateVersion = lightsStateVersion;
  14650. if ( material.lights ) {
  14651. // wire up the material to this renderer's lighting state
  14652. uniforms.ambientLightColor.value = lights.state.ambient;
  14653. uniforms.lightProbe.value = lights.state.probe;
  14654. uniforms.directionalLights.value = lights.state.directional;
  14655. uniforms.spotLights.value = lights.state.spot;
  14656. uniforms.rectAreaLights.value = lights.state.rectArea;
  14657. uniforms.pointLights.value = lights.state.point;
  14658. uniforms.hemisphereLights.value = lights.state.hemi;
  14659. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14660. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14661. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14662. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14663. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14664. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14665. // TODO (abelnation): add area lights shadow info to uniforms
  14666. }
  14667. var progUniforms = materialProperties.program.getUniforms(),
  14668. uniformsList =
  14669. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14670. materialProperties.uniformsList = uniformsList;
  14671. }
  14672. function setProgram( camera, fog, material, object ) {
  14673. textures.resetTextureUnits();
  14674. var materialProperties = properties.get( material );
  14675. var lights = currentRenderState.state.lights;
  14676. if ( _clippingEnabled ) {
  14677. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14678. var useCache =
  14679. camera === _currentCamera &&
  14680. material.id === _currentMaterialId;
  14681. // we might want to call this function with some ClippingGroup
  14682. // object instead of the material, once it becomes feasible
  14683. // (#8465, #8379)
  14684. _clipping.setState(
  14685. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14686. camera, materialProperties, useCache );
  14687. }
  14688. }
  14689. if ( material.needsUpdate === false ) {
  14690. if ( materialProperties.program === undefined ) {
  14691. material.needsUpdate = true;
  14692. } else if ( material.fog && materialProperties.fog !== fog ) {
  14693. material.needsUpdate = true;
  14694. } else if ( material.lights && materialProperties.lightsStateVersion !== lights.state.version ) {
  14695. material.needsUpdate = true;
  14696. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14697. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14698. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14699. material.needsUpdate = true;
  14700. }
  14701. }
  14702. if ( material.needsUpdate ) {
  14703. initMaterial( material, fog, object );
  14704. material.needsUpdate = false;
  14705. }
  14706. var refreshProgram = false;
  14707. var refreshMaterial = false;
  14708. var refreshLights = false;
  14709. var program = materialProperties.program,
  14710. p_uniforms = program.getUniforms(),
  14711. m_uniforms = materialProperties.shader.uniforms;
  14712. if ( state.useProgram( program.program ) ) {
  14713. refreshProgram = true;
  14714. refreshMaterial = true;
  14715. refreshLights = true;
  14716. }
  14717. if ( material.id !== _currentMaterialId ) {
  14718. _currentMaterialId = material.id;
  14719. refreshMaterial = true;
  14720. }
  14721. if ( refreshProgram || _currentCamera !== camera ) {
  14722. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14723. if ( capabilities.logarithmicDepthBuffer ) {
  14724. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14725. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14726. }
  14727. if ( _currentCamera !== camera ) {
  14728. _currentCamera = camera;
  14729. // lighting uniforms depend on the camera so enforce an update
  14730. // now, in case this material supports lights - or later, when
  14731. // the next material that does gets activated:
  14732. refreshMaterial = true; // set to true on material change
  14733. refreshLights = true; // remains set until update done
  14734. }
  14735. // load material specific uniforms
  14736. // (shader material also gets them for the sake of genericity)
  14737. if ( material.isShaderMaterial ||
  14738. material.isMeshPhongMaterial ||
  14739. material.isMeshStandardMaterial ||
  14740. material.envMap ) {
  14741. var uCamPos = p_uniforms.map.cameraPosition;
  14742. if ( uCamPos !== undefined ) {
  14743. uCamPos.setValue( _gl,
  14744. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14745. }
  14746. }
  14747. if ( material.isMeshPhongMaterial ||
  14748. material.isMeshLambertMaterial ||
  14749. material.isMeshBasicMaterial ||
  14750. material.isMeshStandardMaterial ||
  14751. material.isShaderMaterial ||
  14752. material.skinning ) {
  14753. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14754. }
  14755. }
  14756. // skinning uniforms must be set even if material didn't change
  14757. // auto-setting of texture unit for bone texture must go before other textures
  14758. // not sure why, but otherwise weird things happen
  14759. if ( material.skinning ) {
  14760. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14761. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14762. var skeleton = object.skeleton;
  14763. if ( skeleton ) {
  14764. var bones = skeleton.bones;
  14765. if ( capabilities.floatVertexTextures ) {
  14766. if ( skeleton.boneTexture === undefined ) {
  14767. // layout (1 matrix = 4 pixels)
  14768. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14769. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14770. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14771. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14772. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14773. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14774. size = _Math.ceilPowerOfTwo( size );
  14775. size = Math.max( size, 4 );
  14776. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14777. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14778. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14779. boneTexture.needsUpdate = true;
  14780. skeleton.boneMatrices = boneMatrices;
  14781. skeleton.boneTexture = boneTexture;
  14782. skeleton.boneTextureSize = size;
  14783. }
  14784. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14785. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14786. } else {
  14787. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14788. }
  14789. }
  14790. }
  14791. if ( refreshMaterial ) {
  14792. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14793. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14794. if ( material.lights ) {
  14795. // the current material requires lighting info
  14796. // note: all lighting uniforms are always set correctly
  14797. // they simply reference the renderer's state for their
  14798. // values
  14799. //
  14800. // use the current material's .needsUpdate flags to set
  14801. // the GL state when required
  14802. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14803. }
  14804. // refresh uniforms common to several materials
  14805. if ( fog && material.fog ) {
  14806. refreshUniformsFog( m_uniforms, fog );
  14807. }
  14808. if ( material.isMeshBasicMaterial ) {
  14809. refreshUniformsCommon( m_uniforms, material );
  14810. } else if ( material.isMeshLambertMaterial ) {
  14811. refreshUniformsCommon( m_uniforms, material );
  14812. refreshUniformsLambert( m_uniforms, material );
  14813. } else if ( material.isMeshPhongMaterial ) {
  14814. refreshUniformsCommon( m_uniforms, material );
  14815. if ( material.isMeshToonMaterial ) {
  14816. refreshUniformsToon( m_uniforms, material );
  14817. } else {
  14818. refreshUniformsPhong( m_uniforms, material );
  14819. }
  14820. } else if ( material.isMeshStandardMaterial ) {
  14821. refreshUniformsCommon( m_uniforms, material );
  14822. if ( material.isMeshPhysicalMaterial ) {
  14823. refreshUniformsPhysical( m_uniforms, material );
  14824. } else {
  14825. refreshUniformsStandard( m_uniforms, material );
  14826. }
  14827. } else if ( material.isMeshMatcapMaterial ) {
  14828. refreshUniformsCommon( m_uniforms, material );
  14829. refreshUniformsMatcap( m_uniforms, material );
  14830. } else if ( material.isMeshDepthMaterial ) {
  14831. refreshUniformsCommon( m_uniforms, material );
  14832. refreshUniformsDepth( m_uniforms, material );
  14833. } else if ( material.isMeshDistanceMaterial ) {
  14834. refreshUniformsCommon( m_uniforms, material );
  14835. refreshUniformsDistance( m_uniforms, material );
  14836. } else if ( material.isMeshNormalMaterial ) {
  14837. refreshUniformsCommon( m_uniforms, material );
  14838. refreshUniformsNormal( m_uniforms, material );
  14839. } else if ( material.isLineBasicMaterial ) {
  14840. refreshUniformsLine( m_uniforms, material );
  14841. if ( material.isLineDashedMaterial ) {
  14842. refreshUniformsDash( m_uniforms, material );
  14843. }
  14844. } else if ( material.isPointsMaterial ) {
  14845. refreshUniformsPoints( m_uniforms, material );
  14846. } else if ( material.isSpriteMaterial ) {
  14847. refreshUniformsSprites( m_uniforms, material );
  14848. } else if ( material.isShadowMaterial ) {
  14849. m_uniforms.color.value.copy( material.color );
  14850. m_uniforms.opacity.value = material.opacity;
  14851. }
  14852. // RectAreaLight Texture
  14853. // TODO (mrdoob): Find a nicer implementation
  14854. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14855. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14856. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14857. }
  14858. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14859. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14860. material.uniformsNeedUpdate = false;
  14861. }
  14862. if ( material.isSpriteMaterial ) {
  14863. p_uniforms.setValue( _gl, 'center', object.center );
  14864. }
  14865. // common matrices
  14866. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14867. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14868. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14869. return program;
  14870. }
  14871. // Uniforms (refresh uniforms objects)
  14872. function refreshUniformsCommon( uniforms, material ) {
  14873. uniforms.opacity.value = material.opacity;
  14874. if ( material.color ) {
  14875. uniforms.diffuse.value.copy( material.color );
  14876. }
  14877. if ( material.emissive ) {
  14878. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14879. }
  14880. if ( material.map ) {
  14881. uniforms.map.value = material.map;
  14882. }
  14883. if ( material.alphaMap ) {
  14884. uniforms.alphaMap.value = material.alphaMap;
  14885. }
  14886. if ( material.specularMap ) {
  14887. uniforms.specularMap.value = material.specularMap;
  14888. }
  14889. if ( material.envMap ) {
  14890. uniforms.envMap.value = material.envMap;
  14891. // don't flip CubeTexture envMaps, flip everything else:
  14892. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14893. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14894. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14895. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14896. uniforms.reflectivity.value = material.reflectivity;
  14897. uniforms.refractionRatio.value = material.refractionRatio;
  14898. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14899. }
  14900. if ( material.lightMap ) {
  14901. uniforms.lightMap.value = material.lightMap;
  14902. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14903. }
  14904. if ( material.aoMap ) {
  14905. uniforms.aoMap.value = material.aoMap;
  14906. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14907. }
  14908. // uv repeat and offset setting priorities
  14909. // 1. color map
  14910. // 2. specular map
  14911. // 3. normal map
  14912. // 4. bump map
  14913. // 5. alpha map
  14914. // 6. emissive map
  14915. var uvScaleMap;
  14916. if ( material.map ) {
  14917. uvScaleMap = material.map;
  14918. } else if ( material.specularMap ) {
  14919. uvScaleMap = material.specularMap;
  14920. } else if ( material.displacementMap ) {
  14921. uvScaleMap = material.displacementMap;
  14922. } else if ( material.normalMap ) {
  14923. uvScaleMap = material.normalMap;
  14924. } else if ( material.bumpMap ) {
  14925. uvScaleMap = material.bumpMap;
  14926. } else if ( material.roughnessMap ) {
  14927. uvScaleMap = material.roughnessMap;
  14928. } else if ( material.metalnessMap ) {
  14929. uvScaleMap = material.metalnessMap;
  14930. } else if ( material.alphaMap ) {
  14931. uvScaleMap = material.alphaMap;
  14932. } else if ( material.emissiveMap ) {
  14933. uvScaleMap = material.emissiveMap;
  14934. }
  14935. if ( uvScaleMap !== undefined ) {
  14936. // backwards compatibility
  14937. if ( uvScaleMap.isWebGLRenderTarget ) {
  14938. uvScaleMap = uvScaleMap.texture;
  14939. }
  14940. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14941. uvScaleMap.updateMatrix();
  14942. }
  14943. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14944. }
  14945. }
  14946. function refreshUniformsLine( uniforms, material ) {
  14947. uniforms.diffuse.value.copy( material.color );
  14948. uniforms.opacity.value = material.opacity;
  14949. }
  14950. function refreshUniformsDash( uniforms, material ) {
  14951. uniforms.dashSize.value = material.dashSize;
  14952. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14953. uniforms.scale.value = material.scale;
  14954. }
  14955. function refreshUniformsPoints( uniforms, material ) {
  14956. uniforms.diffuse.value.copy( material.color );
  14957. uniforms.opacity.value = material.opacity;
  14958. uniforms.size.value = material.size * _pixelRatio;
  14959. uniforms.scale.value = _height * 0.5;
  14960. uniforms.map.value = material.map;
  14961. if ( material.map !== null ) {
  14962. if ( material.map.matrixAutoUpdate === true ) {
  14963. material.map.updateMatrix();
  14964. }
  14965. uniforms.uvTransform.value.copy( material.map.matrix );
  14966. }
  14967. }
  14968. function refreshUniformsSprites( uniforms, material ) {
  14969. uniforms.diffuse.value.copy( material.color );
  14970. uniforms.opacity.value = material.opacity;
  14971. uniforms.rotation.value = material.rotation;
  14972. uniforms.map.value = material.map;
  14973. if ( material.map !== null ) {
  14974. if ( material.map.matrixAutoUpdate === true ) {
  14975. material.map.updateMatrix();
  14976. }
  14977. uniforms.uvTransform.value.copy( material.map.matrix );
  14978. }
  14979. }
  14980. function refreshUniformsFog( uniforms, fog ) {
  14981. uniforms.fogColor.value.copy( fog.color );
  14982. if ( fog.isFog ) {
  14983. uniforms.fogNear.value = fog.near;
  14984. uniforms.fogFar.value = fog.far;
  14985. } else if ( fog.isFogExp2 ) {
  14986. uniforms.fogDensity.value = fog.density;
  14987. }
  14988. }
  14989. function refreshUniformsLambert( uniforms, material ) {
  14990. if ( material.emissiveMap ) {
  14991. uniforms.emissiveMap.value = material.emissiveMap;
  14992. }
  14993. }
  14994. function refreshUniformsPhong( uniforms, material ) {
  14995. uniforms.specular.value.copy( material.specular );
  14996. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14997. if ( material.emissiveMap ) {
  14998. uniforms.emissiveMap.value = material.emissiveMap;
  14999. }
  15000. if ( material.bumpMap ) {
  15001. uniforms.bumpMap.value = material.bumpMap;
  15002. uniforms.bumpScale.value = material.bumpScale;
  15003. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15004. }
  15005. if ( material.normalMap ) {
  15006. uniforms.normalMap.value = material.normalMap;
  15007. uniforms.normalScale.value.copy( material.normalScale );
  15008. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15009. }
  15010. if ( material.displacementMap ) {
  15011. uniforms.displacementMap.value = material.displacementMap;
  15012. uniforms.displacementScale.value = material.displacementScale;
  15013. uniforms.displacementBias.value = material.displacementBias;
  15014. }
  15015. }
  15016. function refreshUniformsToon( uniforms, material ) {
  15017. refreshUniformsPhong( uniforms, material );
  15018. if ( material.gradientMap ) {
  15019. uniforms.gradientMap.value = material.gradientMap;
  15020. }
  15021. }
  15022. function refreshUniformsStandard( uniforms, material ) {
  15023. uniforms.roughness.value = material.roughness;
  15024. uniforms.metalness.value = material.metalness;
  15025. if ( material.roughnessMap ) {
  15026. uniforms.roughnessMap.value = material.roughnessMap;
  15027. }
  15028. if ( material.metalnessMap ) {
  15029. uniforms.metalnessMap.value = material.metalnessMap;
  15030. }
  15031. if ( material.emissiveMap ) {
  15032. uniforms.emissiveMap.value = material.emissiveMap;
  15033. }
  15034. if ( material.bumpMap ) {
  15035. uniforms.bumpMap.value = material.bumpMap;
  15036. uniforms.bumpScale.value = material.bumpScale;
  15037. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15038. }
  15039. if ( material.normalMap ) {
  15040. uniforms.normalMap.value = material.normalMap;
  15041. uniforms.normalScale.value.copy( material.normalScale );
  15042. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15043. }
  15044. if ( material.displacementMap ) {
  15045. uniforms.displacementMap.value = material.displacementMap;
  15046. uniforms.displacementScale.value = material.displacementScale;
  15047. uniforms.displacementBias.value = material.displacementBias;
  15048. }
  15049. if ( material.envMap ) {
  15050. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15051. uniforms.envMapIntensity.value = material.envMapIntensity;
  15052. }
  15053. }
  15054. function refreshUniformsPhysical( uniforms, material ) {
  15055. refreshUniformsStandard( uniforms, material );
  15056. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  15057. uniforms.clearCoat.value = material.clearCoat;
  15058. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15059. if ( material.clearCoatNormalMap ) {
  15060. uniforms.clearCoatNormalScale.value.copy( material.clearCoatNormalScale );
  15061. uniforms.clearCoatNormalMap.value = material.clearCoatNormalMap;
  15062. if ( material.side === BackSide ) {
  15063. uniforms.clearCoatNormalScale.value.negate();
  15064. }
  15065. }
  15066. }
  15067. function refreshUniformsMatcap( uniforms, material ) {
  15068. if ( material.matcap ) {
  15069. uniforms.matcap.value = material.matcap;
  15070. }
  15071. if ( material.bumpMap ) {
  15072. uniforms.bumpMap.value = material.bumpMap;
  15073. uniforms.bumpScale.value = material.bumpScale;
  15074. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15075. }
  15076. if ( material.normalMap ) {
  15077. uniforms.normalMap.value = material.normalMap;
  15078. uniforms.normalScale.value.copy( material.normalScale );
  15079. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15080. }
  15081. if ( material.displacementMap ) {
  15082. uniforms.displacementMap.value = material.displacementMap;
  15083. uniforms.displacementScale.value = material.displacementScale;
  15084. uniforms.displacementBias.value = material.displacementBias;
  15085. }
  15086. }
  15087. function refreshUniformsDepth( uniforms, material ) {
  15088. if ( material.displacementMap ) {
  15089. uniforms.displacementMap.value = material.displacementMap;
  15090. uniforms.displacementScale.value = material.displacementScale;
  15091. uniforms.displacementBias.value = material.displacementBias;
  15092. }
  15093. }
  15094. function refreshUniformsDistance( uniforms, material ) {
  15095. if ( material.displacementMap ) {
  15096. uniforms.displacementMap.value = material.displacementMap;
  15097. uniforms.displacementScale.value = material.displacementScale;
  15098. uniforms.displacementBias.value = material.displacementBias;
  15099. }
  15100. uniforms.referencePosition.value.copy( material.referencePosition );
  15101. uniforms.nearDistance.value = material.nearDistance;
  15102. uniforms.farDistance.value = material.farDistance;
  15103. }
  15104. function refreshUniformsNormal( uniforms, material ) {
  15105. if ( material.bumpMap ) {
  15106. uniforms.bumpMap.value = material.bumpMap;
  15107. uniforms.bumpScale.value = material.bumpScale;
  15108. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15109. }
  15110. if ( material.normalMap ) {
  15111. uniforms.normalMap.value = material.normalMap;
  15112. uniforms.normalScale.value.copy( material.normalScale );
  15113. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15114. }
  15115. if ( material.displacementMap ) {
  15116. uniforms.displacementMap.value = material.displacementMap;
  15117. uniforms.displacementScale.value = material.displacementScale;
  15118. uniforms.displacementBias.value = material.displacementBias;
  15119. }
  15120. }
  15121. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15122. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15123. uniforms.ambientLightColor.needsUpdate = value;
  15124. uniforms.lightProbe.needsUpdate = value;
  15125. uniforms.directionalLights.needsUpdate = value;
  15126. uniforms.pointLights.needsUpdate = value;
  15127. uniforms.spotLights.needsUpdate = value;
  15128. uniforms.rectAreaLights.needsUpdate = value;
  15129. uniforms.hemisphereLights.needsUpdate = value;
  15130. }
  15131. //
  15132. this.setFramebuffer = function ( value ) {
  15133. if ( _framebuffer !== value ) _gl.bindFramebuffer( 36160, value );
  15134. _framebuffer = value;
  15135. };
  15136. this.getActiveCubeFace = function () {
  15137. return _currentActiveCubeFace;
  15138. };
  15139. this.getActiveMipmapLevel = function () {
  15140. return _currentActiveMipmapLevel;
  15141. };
  15142. this.getRenderTarget = function () {
  15143. return _currentRenderTarget;
  15144. };
  15145. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15146. _currentRenderTarget = renderTarget;
  15147. _currentActiveCubeFace = activeCubeFace;
  15148. _currentActiveMipmapLevel = activeMipmapLevel;
  15149. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15150. textures.setupRenderTarget( renderTarget );
  15151. }
  15152. var framebuffer = _framebuffer;
  15153. var isCube = false;
  15154. if ( renderTarget ) {
  15155. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15156. if ( renderTarget.isWebGLRenderTargetCube ) {
  15157. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15158. isCube = true;
  15159. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15160. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15161. } else {
  15162. framebuffer = __webglFramebuffer;
  15163. }
  15164. _currentViewport.copy( renderTarget.viewport );
  15165. _currentScissor.copy( renderTarget.scissor );
  15166. _currentScissorTest = renderTarget.scissorTest;
  15167. } else {
  15168. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15169. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15170. _currentScissorTest = _scissorTest;
  15171. }
  15172. if ( _currentFramebuffer !== framebuffer ) {
  15173. _gl.bindFramebuffer( 36160, framebuffer );
  15174. _currentFramebuffer = framebuffer;
  15175. }
  15176. state.viewport( _currentViewport );
  15177. state.scissor( _currentScissor );
  15178. state.setScissorTest( _currentScissorTest );
  15179. if ( isCube ) {
  15180. var textureProperties = properties.get( renderTarget.texture );
  15181. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15182. }
  15183. };
  15184. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15185. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15186. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15187. return;
  15188. }
  15189. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15190. if ( renderTarget.isWebGLRenderTargetCube && activeCubeFaceIndex !== undefined ) {
  15191. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15192. }
  15193. if ( framebuffer ) {
  15194. var restore = false;
  15195. if ( framebuffer !== _currentFramebuffer ) {
  15196. _gl.bindFramebuffer( 36160, framebuffer );
  15197. restore = true;
  15198. }
  15199. try {
  15200. var texture = renderTarget.texture;
  15201. var textureFormat = texture.format;
  15202. var textureType = texture.type;
  15203. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15204. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15205. return;
  15206. }
  15207. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15208. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15209. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15210. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15211. return;
  15212. }
  15213. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15214. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15215. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15216. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15217. }
  15218. } else {
  15219. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15220. }
  15221. } finally {
  15222. if ( restore ) {
  15223. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15224. }
  15225. }
  15226. }
  15227. };
  15228. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15229. var width = texture.image.width;
  15230. var height = texture.image.height;
  15231. var glFormat = utils.convert( texture.format );
  15232. textures.setTexture2D( texture, 0 );
  15233. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  15234. };
  15235. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15236. var width = srcTexture.image.width;
  15237. var height = srcTexture.image.height;
  15238. var glFormat = utils.convert( dstTexture.format );
  15239. var glType = utils.convert( dstTexture.type );
  15240. textures.setTexture2D( dstTexture, 0 );
  15241. if ( srcTexture.isDataTexture ) {
  15242. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15243. } else {
  15244. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  15245. }
  15246. };
  15247. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15248. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15249. }
  15250. }
  15251. /**
  15252. * @author mrdoob / http://mrdoob.com/
  15253. * @author alteredq / http://alteredqualia.com/
  15254. */
  15255. function FogExp2( color, density ) {
  15256. this.name = '';
  15257. this.color = new Color( color );
  15258. this.density = ( density !== undefined ) ? density : 0.00025;
  15259. }
  15260. Object.assign( FogExp2.prototype, {
  15261. isFogExp2: true,
  15262. clone: function () {
  15263. return new FogExp2( this.color, this.density );
  15264. },
  15265. toJSON: function ( /* meta */ ) {
  15266. return {
  15267. type: 'FogExp2',
  15268. color: this.color.getHex(),
  15269. density: this.density
  15270. };
  15271. }
  15272. } );
  15273. /**
  15274. * @author mrdoob / http://mrdoob.com/
  15275. * @author alteredq / http://alteredqualia.com/
  15276. */
  15277. function Fog( color, near, far ) {
  15278. this.name = '';
  15279. this.color = new Color( color );
  15280. this.near = ( near !== undefined ) ? near : 1;
  15281. this.far = ( far !== undefined ) ? far : 1000;
  15282. }
  15283. Object.assign( Fog.prototype, {
  15284. isFog: true,
  15285. clone: function () {
  15286. return new Fog( this.color, this.near, this.far );
  15287. },
  15288. toJSON: function ( /* meta */ ) {
  15289. return {
  15290. type: 'Fog',
  15291. color: this.color.getHex(),
  15292. near: this.near,
  15293. far: this.far
  15294. };
  15295. }
  15296. } );
  15297. /**
  15298. * @author benaadams / https://twitter.com/ben_a_adams
  15299. */
  15300. function InterleavedBuffer( array, stride ) {
  15301. this.array = array;
  15302. this.stride = stride;
  15303. this.count = array !== undefined ? array.length / stride : 0;
  15304. this.dynamic = false;
  15305. this.updateRange = { offset: 0, count: - 1 };
  15306. this.version = 0;
  15307. }
  15308. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15309. set: function ( value ) {
  15310. if ( value === true ) this.version ++;
  15311. }
  15312. } );
  15313. Object.assign( InterleavedBuffer.prototype, {
  15314. isInterleavedBuffer: true,
  15315. onUploadCallback: function () {},
  15316. setArray: function ( array ) {
  15317. if ( Array.isArray( array ) ) {
  15318. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15319. }
  15320. this.count = array !== undefined ? array.length / this.stride : 0;
  15321. this.array = array;
  15322. return this;
  15323. },
  15324. setDynamic: function ( value ) {
  15325. this.dynamic = value;
  15326. return this;
  15327. },
  15328. copy: function ( source ) {
  15329. this.array = new source.array.constructor( source.array );
  15330. this.count = source.count;
  15331. this.stride = source.stride;
  15332. this.dynamic = source.dynamic;
  15333. return this;
  15334. },
  15335. copyAt: function ( index1, attribute, index2 ) {
  15336. index1 *= this.stride;
  15337. index2 *= attribute.stride;
  15338. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15339. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15340. }
  15341. return this;
  15342. },
  15343. set: function ( value, offset ) {
  15344. if ( offset === undefined ) offset = 0;
  15345. this.array.set( value, offset );
  15346. return this;
  15347. },
  15348. clone: function () {
  15349. return new this.constructor().copy( this );
  15350. },
  15351. onUpload: function ( callback ) {
  15352. this.onUploadCallback = callback;
  15353. return this;
  15354. }
  15355. } );
  15356. /**
  15357. * @author benaadams / https://twitter.com/ben_a_adams
  15358. */
  15359. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15360. this.data = interleavedBuffer;
  15361. this.itemSize = itemSize;
  15362. this.offset = offset;
  15363. this.normalized = normalized === true;
  15364. }
  15365. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15366. count: {
  15367. get: function () {
  15368. return this.data.count;
  15369. }
  15370. },
  15371. array: {
  15372. get: function () {
  15373. return this.data.array;
  15374. }
  15375. }
  15376. } );
  15377. Object.assign( InterleavedBufferAttribute.prototype, {
  15378. isInterleavedBufferAttribute: true,
  15379. setX: function ( index, x ) {
  15380. this.data.array[ index * this.data.stride + this.offset ] = x;
  15381. return this;
  15382. },
  15383. setY: function ( index, y ) {
  15384. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15385. return this;
  15386. },
  15387. setZ: function ( index, z ) {
  15388. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15389. return this;
  15390. },
  15391. setW: function ( index, w ) {
  15392. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15393. return this;
  15394. },
  15395. getX: function ( index ) {
  15396. return this.data.array[ index * this.data.stride + this.offset ];
  15397. },
  15398. getY: function ( index ) {
  15399. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15400. },
  15401. getZ: function ( index ) {
  15402. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15403. },
  15404. getW: function ( index ) {
  15405. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15406. },
  15407. setXY: function ( index, x, y ) {
  15408. index = index * this.data.stride + this.offset;
  15409. this.data.array[ index + 0 ] = x;
  15410. this.data.array[ index + 1 ] = y;
  15411. return this;
  15412. },
  15413. setXYZ: function ( index, x, y, z ) {
  15414. index = index * this.data.stride + this.offset;
  15415. this.data.array[ index + 0 ] = x;
  15416. this.data.array[ index + 1 ] = y;
  15417. this.data.array[ index + 2 ] = z;
  15418. return this;
  15419. },
  15420. setXYZW: function ( index, x, y, z, w ) {
  15421. index = index * this.data.stride + this.offset;
  15422. this.data.array[ index + 0 ] = x;
  15423. this.data.array[ index + 1 ] = y;
  15424. this.data.array[ index + 2 ] = z;
  15425. this.data.array[ index + 3 ] = w;
  15426. return this;
  15427. }
  15428. } );
  15429. /**
  15430. * @author alteredq / http://alteredqualia.com/
  15431. *
  15432. * parameters = {
  15433. * color: <hex>,
  15434. * map: new THREE.Texture( <Image> ),
  15435. * rotation: <float>,
  15436. * sizeAttenuation: <bool>
  15437. * }
  15438. */
  15439. function SpriteMaterial( parameters ) {
  15440. Material.call( this );
  15441. this.type = 'SpriteMaterial';
  15442. this.color = new Color( 0xffffff );
  15443. this.map = null;
  15444. this.rotation = 0;
  15445. this.sizeAttenuation = true;
  15446. this.lights = false;
  15447. this.transparent = true;
  15448. this.setValues( parameters );
  15449. }
  15450. SpriteMaterial.prototype = Object.create( Material.prototype );
  15451. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15452. SpriteMaterial.prototype.isSpriteMaterial = true;
  15453. SpriteMaterial.prototype.copy = function ( source ) {
  15454. Material.prototype.copy.call( this, source );
  15455. this.color.copy( source.color );
  15456. this.map = source.map;
  15457. this.rotation = source.rotation;
  15458. this.sizeAttenuation = source.sizeAttenuation;
  15459. return this;
  15460. };
  15461. /**
  15462. * @author mikael emtinger / http://gomo.se/
  15463. * @author alteredq / http://alteredqualia.com/
  15464. */
  15465. var geometry;
  15466. function Sprite( material ) {
  15467. Object3D.call( this );
  15468. this.type = 'Sprite';
  15469. if ( geometry === undefined ) {
  15470. geometry = new BufferGeometry();
  15471. var float32Array = new Float32Array( [
  15472. - 0.5, - 0.5, 0, 0, 0,
  15473. 0.5, - 0.5, 0, 1, 0,
  15474. 0.5, 0.5, 0, 1, 1,
  15475. - 0.5, 0.5, 0, 0, 1
  15476. ] );
  15477. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15478. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15479. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15480. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15481. }
  15482. this.geometry = geometry;
  15483. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15484. this.center = new Vector2( 0.5, 0.5 );
  15485. }
  15486. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15487. constructor: Sprite,
  15488. isSprite: true,
  15489. raycast: ( function () {
  15490. var intersectPoint = new Vector3();
  15491. var worldScale = new Vector3();
  15492. var mvPosition = new Vector3();
  15493. var alignedPosition = new Vector2();
  15494. var rotatedPosition = new Vector2();
  15495. var viewWorldMatrix = new Matrix4();
  15496. var vA = new Vector3();
  15497. var vB = new Vector3();
  15498. var vC = new Vector3();
  15499. var uvA = new Vector2();
  15500. var uvB = new Vector2();
  15501. var uvC = new Vector2();
  15502. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15503. // compute position in camera space
  15504. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15505. // to check if rotation is not zero
  15506. if ( sin !== undefined ) {
  15507. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15508. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15509. } else {
  15510. rotatedPosition.copy( alignedPosition );
  15511. }
  15512. vertexPosition.copy( mvPosition );
  15513. vertexPosition.x += rotatedPosition.x;
  15514. vertexPosition.y += rotatedPosition.y;
  15515. // transform to world space
  15516. vertexPosition.applyMatrix4( viewWorldMatrix );
  15517. }
  15518. return function raycast( raycaster, intersects ) {
  15519. worldScale.setFromMatrixScale( this.matrixWorld );
  15520. viewWorldMatrix.copy( raycaster._camera.matrixWorld );
  15521. this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
  15522. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15523. if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15524. worldScale.multiplyScalar( - mvPosition.z );
  15525. }
  15526. var rotation = this.material.rotation;
  15527. var sin, cos;
  15528. if ( rotation !== 0 ) {
  15529. cos = Math.cos( rotation );
  15530. sin = Math.sin( rotation );
  15531. }
  15532. var center = this.center;
  15533. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15534. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15535. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15536. uvA.set( 0, 0 );
  15537. uvB.set( 1, 0 );
  15538. uvC.set( 1, 1 );
  15539. // check first triangle
  15540. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15541. if ( intersect === null ) {
  15542. // check second triangle
  15543. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15544. uvB.set( 0, 1 );
  15545. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15546. if ( intersect === null ) {
  15547. return;
  15548. }
  15549. }
  15550. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15551. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15552. intersects.push( {
  15553. distance: distance,
  15554. point: intersectPoint.clone(),
  15555. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15556. face: null,
  15557. object: this
  15558. } );
  15559. };
  15560. }() ),
  15561. clone: function () {
  15562. return new this.constructor( this.material ).copy( this );
  15563. },
  15564. copy: function ( source ) {
  15565. Object3D.prototype.copy.call( this, source );
  15566. if ( source.center !== undefined ) this.center.copy( source.center );
  15567. return this;
  15568. }
  15569. } );
  15570. /**
  15571. * @author mikael emtinger / http://gomo.se/
  15572. * @author alteredq / http://alteredqualia.com/
  15573. * @author mrdoob / http://mrdoob.com/
  15574. */
  15575. function LOD() {
  15576. Object3D.call( this );
  15577. this.type = 'LOD';
  15578. Object.defineProperties( this, {
  15579. levels: {
  15580. enumerable: true,
  15581. value: []
  15582. }
  15583. } );
  15584. this.autoUpdate = true;
  15585. }
  15586. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15587. constructor: LOD,
  15588. isLOD: true,
  15589. copy: function ( source ) {
  15590. Object3D.prototype.copy.call( this, source, false );
  15591. var levels = source.levels;
  15592. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15593. var level = levels[ i ];
  15594. this.addLevel( level.object.clone(), level.distance );
  15595. }
  15596. return this;
  15597. },
  15598. addLevel: function ( object, distance ) {
  15599. if ( distance === undefined ) distance = 0;
  15600. distance = Math.abs( distance );
  15601. var levels = this.levels;
  15602. for ( var l = 0; l < levels.length; l ++ ) {
  15603. if ( distance < levels[ l ].distance ) {
  15604. break;
  15605. }
  15606. }
  15607. levels.splice( l, 0, { distance: distance, object: object } );
  15608. this.add( object );
  15609. return this;
  15610. },
  15611. getObjectForDistance: function ( distance ) {
  15612. var levels = this.levels;
  15613. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15614. if ( distance < levels[ i ].distance ) {
  15615. break;
  15616. }
  15617. }
  15618. return levels[ i - 1 ].object;
  15619. },
  15620. raycast: ( function () {
  15621. var matrixPosition = new Vector3();
  15622. return function raycast( raycaster, intersects ) {
  15623. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15624. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15625. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15626. };
  15627. }() ),
  15628. update: function () {
  15629. var v1 = new Vector3();
  15630. var v2 = new Vector3();
  15631. return function update( camera ) {
  15632. var levels = this.levels;
  15633. if ( levels.length > 1 ) {
  15634. v1.setFromMatrixPosition( camera.matrixWorld );
  15635. v2.setFromMatrixPosition( this.matrixWorld );
  15636. var distance = v1.distanceTo( v2 );
  15637. levels[ 0 ].object.visible = true;
  15638. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15639. if ( distance >= levels[ i ].distance ) {
  15640. levels[ i - 1 ].object.visible = false;
  15641. levels[ i ].object.visible = true;
  15642. } else {
  15643. break;
  15644. }
  15645. }
  15646. for ( ; i < l; i ++ ) {
  15647. levels[ i ].object.visible = false;
  15648. }
  15649. }
  15650. };
  15651. }(),
  15652. toJSON: function ( meta ) {
  15653. var data = Object3D.prototype.toJSON.call( this, meta );
  15654. data.object.levels = [];
  15655. var levels = this.levels;
  15656. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15657. var level = levels[ i ];
  15658. data.object.levels.push( {
  15659. object: level.object.uuid,
  15660. distance: level.distance
  15661. } );
  15662. }
  15663. return data;
  15664. }
  15665. } );
  15666. /**
  15667. * @author mikael emtinger / http://gomo.se/
  15668. * @author alteredq / http://alteredqualia.com/
  15669. * @author ikerr / http://verold.com
  15670. */
  15671. function SkinnedMesh( geometry, material ) {
  15672. if ( geometry && geometry.isGeometry ) {
  15673. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15674. }
  15675. Mesh.call( this, geometry, material );
  15676. this.type = 'SkinnedMesh';
  15677. this.bindMode = 'attached';
  15678. this.bindMatrix = new Matrix4();
  15679. this.bindMatrixInverse = new Matrix4();
  15680. }
  15681. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15682. constructor: SkinnedMesh,
  15683. isSkinnedMesh: true,
  15684. bind: function ( skeleton, bindMatrix ) {
  15685. this.skeleton = skeleton;
  15686. if ( bindMatrix === undefined ) {
  15687. this.updateMatrixWorld( true );
  15688. this.skeleton.calculateInverses();
  15689. bindMatrix = this.matrixWorld;
  15690. }
  15691. this.bindMatrix.copy( bindMatrix );
  15692. this.bindMatrixInverse.getInverse( bindMatrix );
  15693. },
  15694. pose: function () {
  15695. this.skeleton.pose();
  15696. },
  15697. normalizeSkinWeights: function () {
  15698. var vector = new Vector4();
  15699. var skinWeight = this.geometry.attributes.skinWeight;
  15700. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15701. vector.x = skinWeight.getX( i );
  15702. vector.y = skinWeight.getY( i );
  15703. vector.z = skinWeight.getZ( i );
  15704. vector.w = skinWeight.getW( i );
  15705. var scale = 1.0 / vector.manhattanLength();
  15706. if ( scale !== Infinity ) {
  15707. vector.multiplyScalar( scale );
  15708. } else {
  15709. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15710. }
  15711. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15712. }
  15713. },
  15714. updateMatrixWorld: function ( force ) {
  15715. Mesh.prototype.updateMatrixWorld.call( this, force );
  15716. if ( this.bindMode === 'attached' ) {
  15717. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15718. } else if ( this.bindMode === 'detached' ) {
  15719. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15720. } else {
  15721. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15722. }
  15723. },
  15724. clone: function () {
  15725. return new this.constructor( this.geometry, this.material ).copy( this );
  15726. }
  15727. } );
  15728. /**
  15729. * @author mikael emtinger / http://gomo.se/
  15730. * @author alteredq / http://alteredqualia.com/
  15731. * @author michael guerrero / http://realitymeltdown.com
  15732. * @author ikerr / http://verold.com
  15733. */
  15734. function Skeleton( bones, boneInverses ) {
  15735. // copy the bone array
  15736. bones = bones || [];
  15737. this.bones = bones.slice( 0 );
  15738. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15739. // use the supplied bone inverses or calculate the inverses
  15740. if ( boneInverses === undefined ) {
  15741. this.calculateInverses();
  15742. } else {
  15743. if ( this.bones.length === boneInverses.length ) {
  15744. this.boneInverses = boneInverses.slice( 0 );
  15745. } else {
  15746. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15747. this.boneInverses = [];
  15748. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15749. this.boneInverses.push( new Matrix4() );
  15750. }
  15751. }
  15752. }
  15753. }
  15754. Object.assign( Skeleton.prototype, {
  15755. calculateInverses: function () {
  15756. this.boneInverses = [];
  15757. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15758. var inverse = new Matrix4();
  15759. if ( this.bones[ i ] ) {
  15760. inverse.getInverse( this.bones[ i ].matrixWorld );
  15761. }
  15762. this.boneInverses.push( inverse );
  15763. }
  15764. },
  15765. pose: function () {
  15766. var bone, i, il;
  15767. // recover the bind-time world matrices
  15768. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15769. bone = this.bones[ i ];
  15770. if ( bone ) {
  15771. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15772. }
  15773. }
  15774. // compute the local matrices, positions, rotations and scales
  15775. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15776. bone = this.bones[ i ];
  15777. if ( bone ) {
  15778. if ( bone.parent && bone.parent.isBone ) {
  15779. bone.matrix.getInverse( bone.parent.matrixWorld );
  15780. bone.matrix.multiply( bone.matrixWorld );
  15781. } else {
  15782. bone.matrix.copy( bone.matrixWorld );
  15783. }
  15784. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15785. }
  15786. }
  15787. },
  15788. update: ( function () {
  15789. var offsetMatrix = new Matrix4();
  15790. var identityMatrix = new Matrix4();
  15791. return function update() {
  15792. var bones = this.bones;
  15793. var boneInverses = this.boneInverses;
  15794. var boneMatrices = this.boneMatrices;
  15795. var boneTexture = this.boneTexture;
  15796. // flatten bone matrices to array
  15797. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15798. // compute the offset between the current and the original transform
  15799. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15800. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15801. offsetMatrix.toArray( boneMatrices, i * 16 );
  15802. }
  15803. if ( boneTexture !== undefined ) {
  15804. boneTexture.needsUpdate = true;
  15805. }
  15806. };
  15807. } )(),
  15808. clone: function () {
  15809. return new Skeleton( this.bones, this.boneInverses );
  15810. },
  15811. getBoneByName: function ( name ) {
  15812. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15813. var bone = this.bones[ i ];
  15814. if ( bone.name === name ) {
  15815. return bone;
  15816. }
  15817. }
  15818. return undefined;
  15819. }
  15820. } );
  15821. /**
  15822. * @author mikael emtinger / http://gomo.se/
  15823. * @author alteredq / http://alteredqualia.com/
  15824. * @author ikerr / http://verold.com
  15825. */
  15826. function Bone() {
  15827. Object3D.call( this );
  15828. this.type = 'Bone';
  15829. }
  15830. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15831. constructor: Bone,
  15832. isBone: true
  15833. } );
  15834. /**
  15835. * @author mrdoob / http://mrdoob.com/
  15836. * @author alteredq / http://alteredqualia.com/
  15837. *
  15838. * parameters = {
  15839. * color: <hex>,
  15840. * opacity: <float>,
  15841. *
  15842. * linewidth: <float>,
  15843. * linecap: "round",
  15844. * linejoin: "round"
  15845. * }
  15846. */
  15847. function LineBasicMaterial( parameters ) {
  15848. Material.call( this );
  15849. this.type = 'LineBasicMaterial';
  15850. this.color = new Color( 0xffffff );
  15851. this.linewidth = 1;
  15852. this.linecap = 'round';
  15853. this.linejoin = 'round';
  15854. this.lights = false;
  15855. this.setValues( parameters );
  15856. }
  15857. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15858. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15859. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15860. LineBasicMaterial.prototype.copy = function ( source ) {
  15861. Material.prototype.copy.call( this, source );
  15862. this.color.copy( source.color );
  15863. this.linewidth = source.linewidth;
  15864. this.linecap = source.linecap;
  15865. this.linejoin = source.linejoin;
  15866. return this;
  15867. };
  15868. /**
  15869. * @author mrdoob / http://mrdoob.com/
  15870. */
  15871. function Line( geometry, material, mode ) {
  15872. if ( mode === 1 ) {
  15873. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15874. }
  15875. Object3D.call( this );
  15876. this.type = 'Line';
  15877. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15878. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15879. }
  15880. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15881. constructor: Line,
  15882. isLine: true,
  15883. computeLineDistances: ( function () {
  15884. var start = new Vector3();
  15885. var end = new Vector3();
  15886. return function computeLineDistances() {
  15887. var geometry = this.geometry;
  15888. if ( geometry.isBufferGeometry ) {
  15889. // we assume non-indexed geometry
  15890. if ( geometry.index === null ) {
  15891. var positionAttribute = geometry.attributes.position;
  15892. var lineDistances = [ 0 ];
  15893. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15894. start.fromBufferAttribute( positionAttribute, i - 1 );
  15895. end.fromBufferAttribute( positionAttribute, i );
  15896. lineDistances[ i ] = lineDistances[ i - 1 ];
  15897. lineDistances[ i ] += start.distanceTo( end );
  15898. }
  15899. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15900. } else {
  15901. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15902. }
  15903. } else if ( geometry.isGeometry ) {
  15904. var vertices = geometry.vertices;
  15905. var lineDistances = geometry.lineDistances;
  15906. lineDistances[ 0 ] = 0;
  15907. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15908. lineDistances[ i ] = lineDistances[ i - 1 ];
  15909. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15910. }
  15911. }
  15912. return this;
  15913. };
  15914. }() ),
  15915. raycast: ( function () {
  15916. var inverseMatrix = new Matrix4();
  15917. var ray = new Ray();
  15918. var sphere = new Sphere();
  15919. return function raycast( raycaster, intersects ) {
  15920. var precision = raycaster.linePrecision;
  15921. var geometry = this.geometry;
  15922. var matrixWorld = this.matrixWorld;
  15923. // Checking boundingSphere distance to ray
  15924. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15925. sphere.copy( geometry.boundingSphere );
  15926. sphere.applyMatrix4( matrixWorld );
  15927. sphere.radius += precision;
  15928. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15929. //
  15930. inverseMatrix.getInverse( matrixWorld );
  15931. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15932. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15933. var localPrecisionSq = localPrecision * localPrecision;
  15934. var vStart = new Vector3();
  15935. var vEnd = new Vector3();
  15936. var interSegment = new Vector3();
  15937. var interRay = new Vector3();
  15938. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15939. if ( geometry.isBufferGeometry ) {
  15940. var index = geometry.index;
  15941. var attributes = geometry.attributes;
  15942. var positions = attributes.position.array;
  15943. if ( index !== null ) {
  15944. var indices = index.array;
  15945. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15946. var a = indices[ i ];
  15947. var b = indices[ i + 1 ];
  15948. vStart.fromArray( positions, a * 3 );
  15949. vEnd.fromArray( positions, b * 3 );
  15950. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15951. if ( distSq > localPrecisionSq ) continue;
  15952. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15953. var distance = raycaster.ray.origin.distanceTo( interRay );
  15954. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15955. intersects.push( {
  15956. distance: distance,
  15957. // What do we want? intersection point on the ray or on the segment??
  15958. // point: raycaster.ray.at( distance ),
  15959. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15960. index: i,
  15961. face: null,
  15962. faceIndex: null,
  15963. object: this
  15964. } );
  15965. }
  15966. } else {
  15967. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15968. vStart.fromArray( positions, 3 * i );
  15969. vEnd.fromArray( positions, 3 * i + 3 );
  15970. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15971. if ( distSq > localPrecisionSq ) continue;
  15972. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15973. var distance = raycaster.ray.origin.distanceTo( interRay );
  15974. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15975. intersects.push( {
  15976. distance: distance,
  15977. // What do we want? intersection point on the ray or on the segment??
  15978. // point: raycaster.ray.at( distance ),
  15979. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15980. index: i,
  15981. face: null,
  15982. faceIndex: null,
  15983. object: this
  15984. } );
  15985. }
  15986. }
  15987. } else if ( geometry.isGeometry ) {
  15988. var vertices = geometry.vertices;
  15989. var nbVertices = vertices.length;
  15990. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15991. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15992. if ( distSq > localPrecisionSq ) continue;
  15993. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15994. var distance = raycaster.ray.origin.distanceTo( interRay );
  15995. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15996. intersects.push( {
  15997. distance: distance,
  15998. // What do we want? intersection point on the ray or on the segment??
  15999. // point: raycaster.ray.at( distance ),
  16000. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16001. index: i,
  16002. face: null,
  16003. faceIndex: null,
  16004. object: this
  16005. } );
  16006. }
  16007. }
  16008. };
  16009. }() ),
  16010. clone: function () {
  16011. return new this.constructor( this.geometry, this.material ).copy( this );
  16012. }
  16013. } );
  16014. /**
  16015. * @author mrdoob / http://mrdoob.com/
  16016. */
  16017. function LineSegments( geometry, material ) {
  16018. Line.call( this, geometry, material );
  16019. this.type = 'LineSegments';
  16020. }
  16021. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16022. constructor: LineSegments,
  16023. isLineSegments: true,
  16024. computeLineDistances: ( function () {
  16025. var start = new Vector3();
  16026. var end = new Vector3();
  16027. return function computeLineDistances() {
  16028. var geometry = this.geometry;
  16029. if ( geometry.isBufferGeometry ) {
  16030. // we assume non-indexed geometry
  16031. if ( geometry.index === null ) {
  16032. var positionAttribute = geometry.attributes.position;
  16033. var lineDistances = [];
  16034. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16035. start.fromBufferAttribute( positionAttribute, i );
  16036. end.fromBufferAttribute( positionAttribute, i + 1 );
  16037. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16038. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16039. }
  16040. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16041. } else {
  16042. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16043. }
  16044. } else if ( geometry.isGeometry ) {
  16045. var vertices = geometry.vertices;
  16046. var lineDistances = geometry.lineDistances;
  16047. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  16048. start.copy( vertices[ i ] );
  16049. end.copy( vertices[ i + 1 ] );
  16050. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16051. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16052. }
  16053. }
  16054. return this;
  16055. };
  16056. }() )
  16057. } );
  16058. /**
  16059. * @author mgreter / http://github.com/mgreter
  16060. */
  16061. function LineLoop( geometry, material ) {
  16062. Line.call( this, geometry, material );
  16063. this.type = 'LineLoop';
  16064. }
  16065. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16066. constructor: LineLoop,
  16067. isLineLoop: true,
  16068. } );
  16069. /**
  16070. * @author mrdoob / http://mrdoob.com/
  16071. * @author alteredq / http://alteredqualia.com/
  16072. *
  16073. * parameters = {
  16074. * color: <hex>,
  16075. * opacity: <float>,
  16076. * map: new THREE.Texture( <Image> ),
  16077. *
  16078. * size: <float>,
  16079. * sizeAttenuation: <bool>
  16080. *
  16081. * morphTargets: <bool>
  16082. * }
  16083. */
  16084. function PointsMaterial( parameters ) {
  16085. Material.call( this );
  16086. this.type = 'PointsMaterial';
  16087. this.color = new Color( 0xffffff );
  16088. this.map = null;
  16089. this.size = 1;
  16090. this.sizeAttenuation = true;
  16091. this.morphTargets = false;
  16092. this.lights = false;
  16093. this.setValues( parameters );
  16094. }
  16095. PointsMaterial.prototype = Object.create( Material.prototype );
  16096. PointsMaterial.prototype.constructor = PointsMaterial;
  16097. PointsMaterial.prototype.isPointsMaterial = true;
  16098. PointsMaterial.prototype.copy = function ( source ) {
  16099. Material.prototype.copy.call( this, source );
  16100. this.color.copy( source.color );
  16101. this.map = source.map;
  16102. this.size = source.size;
  16103. this.sizeAttenuation = source.sizeAttenuation;
  16104. this.morphTargets = source.morphTargets;
  16105. return this;
  16106. };
  16107. /**
  16108. * @author alteredq / http://alteredqualia.com/
  16109. */
  16110. function Points( geometry, material ) {
  16111. Object3D.call( this );
  16112. this.type = 'Points';
  16113. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16114. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  16115. this.updateMorphTargets();
  16116. }
  16117. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16118. constructor: Points,
  16119. isPoints: true,
  16120. raycast: ( function () {
  16121. var inverseMatrix = new Matrix4();
  16122. var ray = new Ray();
  16123. var sphere = new Sphere();
  16124. return function raycast( raycaster, intersects ) {
  16125. var object = this;
  16126. var geometry = this.geometry;
  16127. var matrixWorld = this.matrixWorld;
  16128. var threshold = raycaster.params.Points.threshold;
  16129. // Checking boundingSphere distance to ray
  16130. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16131. sphere.copy( geometry.boundingSphere );
  16132. sphere.applyMatrix4( matrixWorld );
  16133. sphere.radius += threshold;
  16134. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  16135. //
  16136. inverseMatrix.getInverse( matrixWorld );
  16137. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  16138. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16139. var localThresholdSq = localThreshold * localThreshold;
  16140. var position = new Vector3();
  16141. var intersectPoint = new Vector3();
  16142. function testPoint( point, index ) {
  16143. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  16144. if ( rayPointDistanceSq < localThresholdSq ) {
  16145. ray.closestPointToPoint( point, intersectPoint );
  16146. intersectPoint.applyMatrix4( matrixWorld );
  16147. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16148. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16149. intersects.push( {
  16150. distance: distance,
  16151. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16152. point: intersectPoint.clone(),
  16153. index: index,
  16154. face: null,
  16155. object: object
  16156. } );
  16157. }
  16158. }
  16159. if ( geometry.isBufferGeometry ) {
  16160. var index = geometry.index;
  16161. var attributes = geometry.attributes;
  16162. var positions = attributes.position.array;
  16163. if ( index !== null ) {
  16164. var indices = index.array;
  16165. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  16166. var a = indices[ i ];
  16167. position.fromArray( positions, a * 3 );
  16168. testPoint( position, a );
  16169. }
  16170. } else {
  16171. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  16172. position.fromArray( positions, i * 3 );
  16173. testPoint( position, i );
  16174. }
  16175. }
  16176. } else {
  16177. var vertices = geometry.vertices;
  16178. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  16179. testPoint( vertices[ i ], i );
  16180. }
  16181. }
  16182. };
  16183. }() ),
  16184. updateMorphTargets: function () {
  16185. var geometry = this.geometry;
  16186. var m, ml, name;
  16187. if ( geometry.isBufferGeometry ) {
  16188. var morphAttributes = geometry.morphAttributes;
  16189. var keys = Object.keys( morphAttributes );
  16190. if ( keys.length > 0 ) {
  16191. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16192. if ( morphAttribute !== undefined ) {
  16193. this.morphTargetInfluences = [];
  16194. this.morphTargetDictionary = {};
  16195. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16196. name = morphAttribute[ m ].name || String( m );
  16197. this.morphTargetInfluences.push( 0 );
  16198. this.morphTargetDictionary[ name ] = m;
  16199. }
  16200. }
  16201. }
  16202. } else {
  16203. var morphTargets = geometry.morphTargets;
  16204. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16205. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16206. }
  16207. }
  16208. },
  16209. clone: function () {
  16210. return new this.constructor( this.geometry, this.material ).copy( this );
  16211. }
  16212. } );
  16213. /**
  16214. * @author mrdoob / http://mrdoob.com/
  16215. */
  16216. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16217. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16218. this.format = format !== undefined ? format : RGBFormat;
  16219. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16220. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16221. this.generateMipmaps = false;
  16222. }
  16223. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16224. constructor: VideoTexture,
  16225. isVideoTexture: true,
  16226. update: function () {
  16227. var video = this.image;
  16228. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  16229. this.needsUpdate = true;
  16230. }
  16231. }
  16232. } );
  16233. /**
  16234. * @author alteredq / http://alteredqualia.com/
  16235. */
  16236. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16237. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16238. this.image = { width: width, height: height };
  16239. this.mipmaps = mipmaps;
  16240. // no flipping for cube textures
  16241. // (also flipping doesn't work for compressed textures )
  16242. this.flipY = false;
  16243. // can't generate mipmaps for compressed textures
  16244. // mips must be embedded in DDS files
  16245. this.generateMipmaps = false;
  16246. }
  16247. CompressedTexture.prototype = Object.create( Texture.prototype );
  16248. CompressedTexture.prototype.constructor = CompressedTexture;
  16249. CompressedTexture.prototype.isCompressedTexture = true;
  16250. /**
  16251. * @author mrdoob / http://mrdoob.com/
  16252. */
  16253. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16254. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16255. this.needsUpdate = true;
  16256. }
  16257. CanvasTexture.prototype = Object.create( Texture.prototype );
  16258. CanvasTexture.prototype.constructor = CanvasTexture;
  16259. CanvasTexture.prototype.isCanvasTexture = true;
  16260. /**
  16261. * @author Matt DesLauriers / @mattdesl
  16262. * @author atix / arthursilber.de
  16263. */
  16264. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16265. format = format !== undefined ? format : DepthFormat;
  16266. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16267. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16268. }
  16269. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16270. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16271. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16272. this.image = { width: width, height: height };
  16273. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16274. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16275. this.flipY = false;
  16276. this.generateMipmaps = false;
  16277. }
  16278. DepthTexture.prototype = Object.create( Texture.prototype );
  16279. DepthTexture.prototype.constructor = DepthTexture;
  16280. DepthTexture.prototype.isDepthTexture = true;
  16281. /**
  16282. * @author mrdoob / http://mrdoob.com/
  16283. * @author Mugen87 / https://github.com/Mugen87
  16284. */
  16285. function WireframeGeometry( geometry ) {
  16286. BufferGeometry.call( this );
  16287. this.type = 'WireframeGeometry';
  16288. // buffer
  16289. var vertices = [];
  16290. // helper variables
  16291. var i, j, l, o, ol;
  16292. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16293. var key, keys = [ 'a', 'b', 'c' ];
  16294. var vertex;
  16295. // different logic for Geometry and BufferGeometry
  16296. if ( geometry && geometry.isGeometry ) {
  16297. // create a data structure that contains all edges without duplicates
  16298. var faces = geometry.faces;
  16299. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16300. var face = faces[ i ];
  16301. for ( j = 0; j < 3; j ++ ) {
  16302. edge1 = face[ keys[ j ] ];
  16303. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16304. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16305. edge[ 1 ] = Math.max( edge1, edge2 );
  16306. key = edge[ 0 ] + ',' + edge[ 1 ];
  16307. if ( edges[ key ] === undefined ) {
  16308. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16309. }
  16310. }
  16311. }
  16312. // generate vertices
  16313. for ( key in edges ) {
  16314. e = edges[ key ];
  16315. vertex = geometry.vertices[ e.index1 ];
  16316. vertices.push( vertex.x, vertex.y, vertex.z );
  16317. vertex = geometry.vertices[ e.index2 ];
  16318. vertices.push( vertex.x, vertex.y, vertex.z );
  16319. }
  16320. } else if ( geometry && geometry.isBufferGeometry ) {
  16321. var position, indices, groups;
  16322. var group, start, count;
  16323. var index1, index2;
  16324. vertex = new Vector3();
  16325. if ( geometry.index !== null ) {
  16326. // indexed BufferGeometry
  16327. position = geometry.attributes.position;
  16328. indices = geometry.index;
  16329. groups = geometry.groups;
  16330. if ( groups.length === 0 ) {
  16331. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16332. }
  16333. // create a data structure that contains all eges without duplicates
  16334. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16335. group = groups[ o ];
  16336. start = group.start;
  16337. count = group.count;
  16338. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16339. for ( j = 0; j < 3; j ++ ) {
  16340. edge1 = indices.getX( i + j );
  16341. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16342. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16343. edge[ 1 ] = Math.max( edge1, edge2 );
  16344. key = edge[ 0 ] + ',' + edge[ 1 ];
  16345. if ( edges[ key ] === undefined ) {
  16346. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16347. }
  16348. }
  16349. }
  16350. }
  16351. // generate vertices
  16352. for ( key in edges ) {
  16353. e = edges[ key ];
  16354. vertex.fromBufferAttribute( position, e.index1 );
  16355. vertices.push( vertex.x, vertex.y, vertex.z );
  16356. vertex.fromBufferAttribute( position, e.index2 );
  16357. vertices.push( vertex.x, vertex.y, vertex.z );
  16358. }
  16359. } else {
  16360. // non-indexed BufferGeometry
  16361. position = geometry.attributes.position;
  16362. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16363. for ( j = 0; j < 3; j ++ ) {
  16364. // three edges per triangle, an edge is represented as (index1, index2)
  16365. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16366. index1 = 3 * i + j;
  16367. vertex.fromBufferAttribute( position, index1 );
  16368. vertices.push( vertex.x, vertex.y, vertex.z );
  16369. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16370. vertex.fromBufferAttribute( position, index2 );
  16371. vertices.push( vertex.x, vertex.y, vertex.z );
  16372. }
  16373. }
  16374. }
  16375. }
  16376. // build geometry
  16377. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16378. }
  16379. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16380. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16381. /**
  16382. * @author zz85 / https://github.com/zz85
  16383. * @author Mugen87 / https://github.com/Mugen87
  16384. *
  16385. * Parametric Surfaces Geometry
  16386. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16387. */
  16388. // ParametricGeometry
  16389. function ParametricGeometry( func, slices, stacks ) {
  16390. Geometry.call( this );
  16391. this.type = 'ParametricGeometry';
  16392. this.parameters = {
  16393. func: func,
  16394. slices: slices,
  16395. stacks: stacks
  16396. };
  16397. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16398. this.mergeVertices();
  16399. }
  16400. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16401. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16402. // ParametricBufferGeometry
  16403. function ParametricBufferGeometry( func, slices, stacks ) {
  16404. BufferGeometry.call( this );
  16405. this.type = 'ParametricBufferGeometry';
  16406. this.parameters = {
  16407. func: func,
  16408. slices: slices,
  16409. stacks: stacks
  16410. };
  16411. // buffers
  16412. var indices = [];
  16413. var vertices = [];
  16414. var normals = [];
  16415. var uvs = [];
  16416. var EPS = 0.00001;
  16417. var normal = new Vector3();
  16418. var p0 = new Vector3(), p1 = new Vector3();
  16419. var pu = new Vector3(), pv = new Vector3();
  16420. var i, j;
  16421. if ( func.length < 3 ) {
  16422. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16423. }
  16424. // generate vertices, normals and uvs
  16425. var sliceCount = slices + 1;
  16426. for ( i = 0; i <= stacks; i ++ ) {
  16427. var v = i / stacks;
  16428. for ( j = 0; j <= slices; j ++ ) {
  16429. var u = j / slices;
  16430. // vertex
  16431. func( u, v, p0 );
  16432. vertices.push( p0.x, p0.y, p0.z );
  16433. // normal
  16434. // approximate tangent vectors via finite differences
  16435. if ( u - EPS >= 0 ) {
  16436. func( u - EPS, v, p1 );
  16437. pu.subVectors( p0, p1 );
  16438. } else {
  16439. func( u + EPS, v, p1 );
  16440. pu.subVectors( p1, p0 );
  16441. }
  16442. if ( v - EPS >= 0 ) {
  16443. func( u, v - EPS, p1 );
  16444. pv.subVectors( p0, p1 );
  16445. } else {
  16446. func( u, v + EPS, p1 );
  16447. pv.subVectors( p1, p0 );
  16448. }
  16449. // cross product of tangent vectors returns surface normal
  16450. normal.crossVectors( pu, pv ).normalize();
  16451. normals.push( normal.x, normal.y, normal.z );
  16452. // uv
  16453. uvs.push( u, v );
  16454. }
  16455. }
  16456. // generate indices
  16457. for ( i = 0; i < stacks; i ++ ) {
  16458. for ( j = 0; j < slices; j ++ ) {
  16459. var a = i * sliceCount + j;
  16460. var b = i * sliceCount + j + 1;
  16461. var c = ( i + 1 ) * sliceCount + j + 1;
  16462. var d = ( i + 1 ) * sliceCount + j;
  16463. // faces one and two
  16464. indices.push( a, b, d );
  16465. indices.push( b, c, d );
  16466. }
  16467. }
  16468. // build geometry
  16469. this.setIndex( indices );
  16470. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16471. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16472. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16473. }
  16474. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16475. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16476. /**
  16477. * @author clockworkgeek / https://github.com/clockworkgeek
  16478. * @author timothypratley / https://github.com/timothypratley
  16479. * @author WestLangley / http://github.com/WestLangley
  16480. * @author Mugen87 / https://github.com/Mugen87
  16481. */
  16482. // PolyhedronGeometry
  16483. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16484. Geometry.call( this );
  16485. this.type = 'PolyhedronGeometry';
  16486. this.parameters = {
  16487. vertices: vertices,
  16488. indices: indices,
  16489. radius: radius,
  16490. detail: detail
  16491. };
  16492. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16493. this.mergeVertices();
  16494. }
  16495. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16496. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16497. // PolyhedronBufferGeometry
  16498. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16499. BufferGeometry.call( this );
  16500. this.type = 'PolyhedronBufferGeometry';
  16501. this.parameters = {
  16502. vertices: vertices,
  16503. indices: indices,
  16504. radius: radius,
  16505. detail: detail
  16506. };
  16507. radius = radius || 1;
  16508. detail = detail || 0;
  16509. // default buffer data
  16510. var vertexBuffer = [];
  16511. var uvBuffer = [];
  16512. // the subdivision creates the vertex buffer data
  16513. subdivide( detail );
  16514. // all vertices should lie on a conceptual sphere with a given radius
  16515. applyRadius( radius );
  16516. // finally, create the uv data
  16517. generateUVs();
  16518. // build non-indexed geometry
  16519. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16520. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16521. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16522. if ( detail === 0 ) {
  16523. this.computeVertexNormals(); // flat normals
  16524. } else {
  16525. this.normalizeNormals(); // smooth normals
  16526. }
  16527. // helper functions
  16528. function subdivide( detail ) {
  16529. var a = new Vector3();
  16530. var b = new Vector3();
  16531. var c = new Vector3();
  16532. // iterate over all faces and apply a subdivison with the given detail value
  16533. for ( var i = 0; i < indices.length; i += 3 ) {
  16534. // get the vertices of the face
  16535. getVertexByIndex( indices[ i + 0 ], a );
  16536. getVertexByIndex( indices[ i + 1 ], b );
  16537. getVertexByIndex( indices[ i + 2 ], c );
  16538. // perform subdivision
  16539. subdivideFace( a, b, c, detail );
  16540. }
  16541. }
  16542. function subdivideFace( a, b, c, detail ) {
  16543. var cols = Math.pow( 2, detail );
  16544. // we use this multidimensional array as a data structure for creating the subdivision
  16545. var v = [];
  16546. var i, j;
  16547. // construct all of the vertices for this subdivision
  16548. for ( i = 0; i <= cols; i ++ ) {
  16549. v[ i ] = [];
  16550. var aj = a.clone().lerp( c, i / cols );
  16551. var bj = b.clone().lerp( c, i / cols );
  16552. var rows = cols - i;
  16553. for ( j = 0; j <= rows; j ++ ) {
  16554. if ( j === 0 && i === cols ) {
  16555. v[ i ][ j ] = aj;
  16556. } else {
  16557. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16558. }
  16559. }
  16560. }
  16561. // construct all of the faces
  16562. for ( i = 0; i < cols; i ++ ) {
  16563. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16564. var k = Math.floor( j / 2 );
  16565. if ( j % 2 === 0 ) {
  16566. pushVertex( v[ i ][ k + 1 ] );
  16567. pushVertex( v[ i + 1 ][ k ] );
  16568. pushVertex( v[ i ][ k ] );
  16569. } else {
  16570. pushVertex( v[ i ][ k + 1 ] );
  16571. pushVertex( v[ i + 1 ][ k + 1 ] );
  16572. pushVertex( v[ i + 1 ][ k ] );
  16573. }
  16574. }
  16575. }
  16576. }
  16577. function applyRadius( radius ) {
  16578. var vertex = new Vector3();
  16579. // iterate over the entire buffer and apply the radius to each vertex
  16580. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16581. vertex.x = vertexBuffer[ i + 0 ];
  16582. vertex.y = vertexBuffer[ i + 1 ];
  16583. vertex.z = vertexBuffer[ i + 2 ];
  16584. vertex.normalize().multiplyScalar( radius );
  16585. vertexBuffer[ i + 0 ] = vertex.x;
  16586. vertexBuffer[ i + 1 ] = vertex.y;
  16587. vertexBuffer[ i + 2 ] = vertex.z;
  16588. }
  16589. }
  16590. function generateUVs() {
  16591. var vertex = new Vector3();
  16592. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16593. vertex.x = vertexBuffer[ i + 0 ];
  16594. vertex.y = vertexBuffer[ i + 1 ];
  16595. vertex.z = vertexBuffer[ i + 2 ];
  16596. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16597. var v = inclination( vertex ) / Math.PI + 0.5;
  16598. uvBuffer.push( u, 1 - v );
  16599. }
  16600. correctUVs();
  16601. correctSeam();
  16602. }
  16603. function correctSeam() {
  16604. // handle case when face straddles the seam, see #3269
  16605. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16606. // uv data of a single face
  16607. var x0 = uvBuffer[ i + 0 ];
  16608. var x1 = uvBuffer[ i + 2 ];
  16609. var x2 = uvBuffer[ i + 4 ];
  16610. var max = Math.max( x0, x1, x2 );
  16611. var min = Math.min( x0, x1, x2 );
  16612. // 0.9 is somewhat arbitrary
  16613. if ( max > 0.9 && min < 0.1 ) {
  16614. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16615. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16616. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16617. }
  16618. }
  16619. }
  16620. function pushVertex( vertex ) {
  16621. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16622. }
  16623. function getVertexByIndex( index, vertex ) {
  16624. var stride = index * 3;
  16625. vertex.x = vertices[ stride + 0 ];
  16626. vertex.y = vertices[ stride + 1 ];
  16627. vertex.z = vertices[ stride + 2 ];
  16628. }
  16629. function correctUVs() {
  16630. var a = new Vector3();
  16631. var b = new Vector3();
  16632. var c = new Vector3();
  16633. var centroid = new Vector3();
  16634. var uvA = new Vector2();
  16635. var uvB = new Vector2();
  16636. var uvC = new Vector2();
  16637. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16638. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16639. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16640. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16641. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16642. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16643. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16644. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16645. var azi = azimuth( centroid );
  16646. correctUV( uvA, j + 0, a, azi );
  16647. correctUV( uvB, j + 2, b, azi );
  16648. correctUV( uvC, j + 4, c, azi );
  16649. }
  16650. }
  16651. function correctUV( uv, stride, vector, azimuth ) {
  16652. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16653. uvBuffer[ stride ] = uv.x - 1;
  16654. }
  16655. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16656. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16657. }
  16658. }
  16659. // Angle around the Y axis, counter-clockwise when looking from above.
  16660. function azimuth( vector ) {
  16661. return Math.atan2( vector.z, - vector.x );
  16662. }
  16663. // Angle above the XZ plane.
  16664. function inclination( vector ) {
  16665. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16666. }
  16667. }
  16668. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16669. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16670. /**
  16671. * @author timothypratley / https://github.com/timothypratley
  16672. * @author Mugen87 / https://github.com/Mugen87
  16673. */
  16674. // TetrahedronGeometry
  16675. function TetrahedronGeometry( radius, detail ) {
  16676. Geometry.call( this );
  16677. this.type = 'TetrahedronGeometry';
  16678. this.parameters = {
  16679. radius: radius,
  16680. detail: detail
  16681. };
  16682. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16683. this.mergeVertices();
  16684. }
  16685. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16686. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16687. // TetrahedronBufferGeometry
  16688. function TetrahedronBufferGeometry( radius, detail ) {
  16689. var vertices = [
  16690. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16691. ];
  16692. var indices = [
  16693. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16694. ];
  16695. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16696. this.type = 'TetrahedronBufferGeometry';
  16697. this.parameters = {
  16698. radius: radius,
  16699. detail: detail
  16700. };
  16701. }
  16702. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16703. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16704. /**
  16705. * @author timothypratley / https://github.com/timothypratley
  16706. * @author Mugen87 / https://github.com/Mugen87
  16707. */
  16708. // OctahedronGeometry
  16709. function OctahedronGeometry( radius, detail ) {
  16710. Geometry.call( this );
  16711. this.type = 'OctahedronGeometry';
  16712. this.parameters = {
  16713. radius: radius,
  16714. detail: detail
  16715. };
  16716. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16717. this.mergeVertices();
  16718. }
  16719. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16720. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16721. // OctahedronBufferGeometry
  16722. function OctahedronBufferGeometry( radius, detail ) {
  16723. var vertices = [
  16724. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16725. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16726. ];
  16727. var indices = [
  16728. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16729. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16730. 1, 3, 4, 1, 4, 2
  16731. ];
  16732. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16733. this.type = 'OctahedronBufferGeometry';
  16734. this.parameters = {
  16735. radius: radius,
  16736. detail: detail
  16737. };
  16738. }
  16739. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16740. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16741. /**
  16742. * @author timothypratley / https://github.com/timothypratley
  16743. * @author Mugen87 / https://github.com/Mugen87
  16744. */
  16745. // IcosahedronGeometry
  16746. function IcosahedronGeometry( radius, detail ) {
  16747. Geometry.call( this );
  16748. this.type = 'IcosahedronGeometry';
  16749. this.parameters = {
  16750. radius: radius,
  16751. detail: detail
  16752. };
  16753. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16754. this.mergeVertices();
  16755. }
  16756. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16757. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16758. // IcosahedronBufferGeometry
  16759. function IcosahedronBufferGeometry( radius, detail ) {
  16760. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16761. var vertices = [
  16762. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16763. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16764. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16765. ];
  16766. var indices = [
  16767. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16768. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16769. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16770. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16771. ];
  16772. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16773. this.type = 'IcosahedronBufferGeometry';
  16774. this.parameters = {
  16775. radius: radius,
  16776. detail: detail
  16777. };
  16778. }
  16779. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16780. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16781. /**
  16782. * @author Abe Pazos / https://hamoid.com
  16783. * @author Mugen87 / https://github.com/Mugen87
  16784. */
  16785. // DodecahedronGeometry
  16786. function DodecahedronGeometry( radius, detail ) {
  16787. Geometry.call( this );
  16788. this.type = 'DodecahedronGeometry';
  16789. this.parameters = {
  16790. radius: radius,
  16791. detail: detail
  16792. };
  16793. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16794. this.mergeVertices();
  16795. }
  16796. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16797. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16798. // DodecahedronBufferGeometry
  16799. function DodecahedronBufferGeometry( radius, detail ) {
  16800. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16801. var r = 1 / t;
  16802. var vertices = [
  16803. // (±1, ±1, ±1)
  16804. - 1, - 1, - 1, - 1, - 1, 1,
  16805. - 1, 1, - 1, - 1, 1, 1,
  16806. 1, - 1, - 1, 1, - 1, 1,
  16807. 1, 1, - 1, 1, 1, 1,
  16808. // (0, ±1/φ, ±φ)
  16809. 0, - r, - t, 0, - r, t,
  16810. 0, r, - t, 0, r, t,
  16811. // (±1/φ, ±φ, 0)
  16812. - r, - t, 0, - r, t, 0,
  16813. r, - t, 0, r, t, 0,
  16814. // (±φ, 0, ±1/φ)
  16815. - t, 0, - r, t, 0, - r,
  16816. - t, 0, r, t, 0, r
  16817. ];
  16818. var indices = [
  16819. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16820. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16821. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16822. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16823. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16824. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16825. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16826. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16827. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16828. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16829. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16830. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16831. ];
  16832. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16833. this.type = 'DodecahedronBufferGeometry';
  16834. this.parameters = {
  16835. radius: radius,
  16836. detail: detail
  16837. };
  16838. }
  16839. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16840. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16841. /**
  16842. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16843. * @author WestLangley / https://github.com/WestLangley
  16844. * @author zz85 / https://github.com/zz85
  16845. * @author miningold / https://github.com/miningold
  16846. * @author jonobr1 / https://github.com/jonobr1
  16847. * @author Mugen87 / https://github.com/Mugen87
  16848. *
  16849. */
  16850. // TubeGeometry
  16851. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16852. Geometry.call( this );
  16853. this.type = 'TubeGeometry';
  16854. this.parameters = {
  16855. path: path,
  16856. tubularSegments: tubularSegments,
  16857. radius: radius,
  16858. radialSegments: radialSegments,
  16859. closed: closed
  16860. };
  16861. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16862. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16863. // expose internals
  16864. this.tangents = bufferGeometry.tangents;
  16865. this.normals = bufferGeometry.normals;
  16866. this.binormals = bufferGeometry.binormals;
  16867. // create geometry
  16868. this.fromBufferGeometry( bufferGeometry );
  16869. this.mergeVertices();
  16870. }
  16871. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16872. TubeGeometry.prototype.constructor = TubeGeometry;
  16873. // TubeBufferGeometry
  16874. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16875. BufferGeometry.call( this );
  16876. this.type = 'TubeBufferGeometry';
  16877. this.parameters = {
  16878. path: path,
  16879. tubularSegments: tubularSegments,
  16880. radius: radius,
  16881. radialSegments: radialSegments,
  16882. closed: closed
  16883. };
  16884. tubularSegments = tubularSegments || 64;
  16885. radius = radius || 1;
  16886. radialSegments = radialSegments || 8;
  16887. closed = closed || false;
  16888. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16889. // expose internals
  16890. this.tangents = frames.tangents;
  16891. this.normals = frames.normals;
  16892. this.binormals = frames.binormals;
  16893. // helper variables
  16894. var vertex = new Vector3();
  16895. var normal = new Vector3();
  16896. var uv = new Vector2();
  16897. var P = new Vector3();
  16898. var i, j;
  16899. // buffer
  16900. var vertices = [];
  16901. var normals = [];
  16902. var uvs = [];
  16903. var indices = [];
  16904. // create buffer data
  16905. generateBufferData();
  16906. // build geometry
  16907. this.setIndex( indices );
  16908. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16909. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16910. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16911. // functions
  16912. function generateBufferData() {
  16913. for ( i = 0; i < tubularSegments; i ++ ) {
  16914. generateSegment( i );
  16915. }
  16916. // if the geometry is not closed, generate the last row of vertices and normals
  16917. // at the regular position on the given path
  16918. //
  16919. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16920. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16921. // uvs are generated in a separate function.
  16922. // this makes it easy compute correct values for closed geometries
  16923. generateUVs();
  16924. // finally create faces
  16925. generateIndices();
  16926. }
  16927. function generateSegment( i ) {
  16928. // we use getPointAt to sample evenly distributed points from the given path
  16929. P = path.getPointAt( i / tubularSegments, P );
  16930. // retrieve corresponding normal and binormal
  16931. var N = frames.normals[ i ];
  16932. var B = frames.binormals[ i ];
  16933. // generate normals and vertices for the current segment
  16934. for ( j = 0; j <= radialSegments; j ++ ) {
  16935. var v = j / radialSegments * Math.PI * 2;
  16936. var sin = Math.sin( v );
  16937. var cos = - Math.cos( v );
  16938. // normal
  16939. normal.x = ( cos * N.x + sin * B.x );
  16940. normal.y = ( cos * N.y + sin * B.y );
  16941. normal.z = ( cos * N.z + sin * B.z );
  16942. normal.normalize();
  16943. normals.push( normal.x, normal.y, normal.z );
  16944. // vertex
  16945. vertex.x = P.x + radius * normal.x;
  16946. vertex.y = P.y + radius * normal.y;
  16947. vertex.z = P.z + radius * normal.z;
  16948. vertices.push( vertex.x, vertex.y, vertex.z );
  16949. }
  16950. }
  16951. function generateIndices() {
  16952. for ( j = 1; j <= tubularSegments; j ++ ) {
  16953. for ( i = 1; i <= radialSegments; i ++ ) {
  16954. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16955. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16956. var c = ( radialSegments + 1 ) * j + i;
  16957. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16958. // faces
  16959. indices.push( a, b, d );
  16960. indices.push( b, c, d );
  16961. }
  16962. }
  16963. }
  16964. function generateUVs() {
  16965. for ( i = 0; i <= tubularSegments; i ++ ) {
  16966. for ( j = 0; j <= radialSegments; j ++ ) {
  16967. uv.x = i / tubularSegments;
  16968. uv.y = j / radialSegments;
  16969. uvs.push( uv.x, uv.y );
  16970. }
  16971. }
  16972. }
  16973. }
  16974. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16975. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16976. TubeBufferGeometry.prototype.toJSON = function () {
  16977. var data = BufferGeometry.prototype.toJSON.call( this );
  16978. data.path = this.parameters.path.toJSON();
  16979. return data;
  16980. };
  16981. /**
  16982. * @author oosmoxiecode
  16983. * @author Mugen87 / https://github.com/Mugen87
  16984. *
  16985. * based on http://www.blackpawn.com/texts/pqtorus/
  16986. */
  16987. // TorusKnotGeometry
  16988. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16989. Geometry.call( this );
  16990. this.type = 'TorusKnotGeometry';
  16991. this.parameters = {
  16992. radius: radius,
  16993. tube: tube,
  16994. tubularSegments: tubularSegments,
  16995. radialSegments: radialSegments,
  16996. p: p,
  16997. q: q
  16998. };
  16999. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  17000. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  17001. this.mergeVertices();
  17002. }
  17003. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  17004. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  17005. // TorusKnotBufferGeometry
  17006. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  17007. BufferGeometry.call( this );
  17008. this.type = 'TorusKnotBufferGeometry';
  17009. this.parameters = {
  17010. radius: radius,
  17011. tube: tube,
  17012. tubularSegments: tubularSegments,
  17013. radialSegments: radialSegments,
  17014. p: p,
  17015. q: q
  17016. };
  17017. radius = radius || 1;
  17018. tube = tube || 0.4;
  17019. tubularSegments = Math.floor( tubularSegments ) || 64;
  17020. radialSegments = Math.floor( radialSegments ) || 8;
  17021. p = p || 2;
  17022. q = q || 3;
  17023. // buffers
  17024. var indices = [];
  17025. var vertices = [];
  17026. var normals = [];
  17027. var uvs = [];
  17028. // helper variables
  17029. var i, j;
  17030. var vertex = new Vector3();
  17031. var normal = new Vector3();
  17032. var P1 = new Vector3();
  17033. var P2 = new Vector3();
  17034. var B = new Vector3();
  17035. var T = new Vector3();
  17036. var N = new Vector3();
  17037. // generate vertices, normals and uvs
  17038. for ( i = 0; i <= tubularSegments; ++ i ) {
  17039. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17040. var u = i / tubularSegments * p * Math.PI * 2;
  17041. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17042. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17043. calculatePositionOnCurve( u, p, q, radius, P1 );
  17044. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17045. // calculate orthonormal basis
  17046. T.subVectors( P2, P1 );
  17047. N.addVectors( P2, P1 );
  17048. B.crossVectors( T, N );
  17049. N.crossVectors( B, T );
  17050. // normalize B, N. T can be ignored, we don't use it
  17051. B.normalize();
  17052. N.normalize();
  17053. for ( j = 0; j <= radialSegments; ++ j ) {
  17054. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17055. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17056. var v = j / radialSegments * Math.PI * 2;
  17057. var cx = - tube * Math.cos( v );
  17058. var cy = tube * Math.sin( v );
  17059. // now calculate the final vertex position.
  17060. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17061. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17062. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17063. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17064. vertices.push( vertex.x, vertex.y, vertex.z );
  17065. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17066. normal.subVectors( vertex, P1 ).normalize();
  17067. normals.push( normal.x, normal.y, normal.z );
  17068. // uv
  17069. uvs.push( i / tubularSegments );
  17070. uvs.push( j / radialSegments );
  17071. }
  17072. }
  17073. // generate indices
  17074. for ( j = 1; j <= tubularSegments; j ++ ) {
  17075. for ( i = 1; i <= radialSegments; i ++ ) {
  17076. // indices
  17077. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17078. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17079. var c = ( radialSegments + 1 ) * j + i;
  17080. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17081. // faces
  17082. indices.push( a, b, d );
  17083. indices.push( b, c, d );
  17084. }
  17085. }
  17086. // build geometry
  17087. this.setIndex( indices );
  17088. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17089. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17090. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17091. // this function calculates the current position on the torus curve
  17092. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17093. var cu = Math.cos( u );
  17094. var su = Math.sin( u );
  17095. var quOverP = q / p * u;
  17096. var cs = Math.cos( quOverP );
  17097. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17098. position.y = radius * ( 2 + cs ) * su * 0.5;
  17099. position.z = radius * Math.sin( quOverP ) * 0.5;
  17100. }
  17101. }
  17102. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17103. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17104. /**
  17105. * @author oosmoxiecode
  17106. * @author mrdoob / http://mrdoob.com/
  17107. * @author Mugen87 / https://github.com/Mugen87
  17108. */
  17109. // TorusGeometry
  17110. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17111. Geometry.call( this );
  17112. this.type = 'TorusGeometry';
  17113. this.parameters = {
  17114. radius: radius,
  17115. tube: tube,
  17116. radialSegments: radialSegments,
  17117. tubularSegments: tubularSegments,
  17118. arc: arc
  17119. };
  17120. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17121. this.mergeVertices();
  17122. }
  17123. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17124. TorusGeometry.prototype.constructor = TorusGeometry;
  17125. // TorusBufferGeometry
  17126. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17127. BufferGeometry.call( this );
  17128. this.type = 'TorusBufferGeometry';
  17129. this.parameters = {
  17130. radius: radius,
  17131. tube: tube,
  17132. radialSegments: radialSegments,
  17133. tubularSegments: tubularSegments,
  17134. arc: arc
  17135. };
  17136. radius = radius || 1;
  17137. tube = tube || 0.4;
  17138. radialSegments = Math.floor( radialSegments ) || 8;
  17139. tubularSegments = Math.floor( tubularSegments ) || 6;
  17140. arc = arc || Math.PI * 2;
  17141. // buffers
  17142. var indices = [];
  17143. var vertices = [];
  17144. var normals = [];
  17145. var uvs = [];
  17146. // helper variables
  17147. var center = new Vector3();
  17148. var vertex = new Vector3();
  17149. var normal = new Vector3();
  17150. var j, i;
  17151. // generate vertices, normals and uvs
  17152. for ( j = 0; j <= radialSegments; j ++ ) {
  17153. for ( i = 0; i <= tubularSegments; i ++ ) {
  17154. var u = i / tubularSegments * arc;
  17155. var v = j / radialSegments * Math.PI * 2;
  17156. // vertex
  17157. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  17158. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  17159. vertex.z = tube * Math.sin( v );
  17160. vertices.push( vertex.x, vertex.y, vertex.z );
  17161. // normal
  17162. center.x = radius * Math.cos( u );
  17163. center.y = radius * Math.sin( u );
  17164. normal.subVectors( vertex, center ).normalize();
  17165. normals.push( normal.x, normal.y, normal.z );
  17166. // uv
  17167. uvs.push( i / tubularSegments );
  17168. uvs.push( j / radialSegments );
  17169. }
  17170. }
  17171. // generate indices
  17172. for ( j = 1; j <= radialSegments; j ++ ) {
  17173. for ( i = 1; i <= tubularSegments; i ++ ) {
  17174. // indices
  17175. var a = ( tubularSegments + 1 ) * j + i - 1;
  17176. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  17177. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  17178. var d = ( tubularSegments + 1 ) * j + i;
  17179. // faces
  17180. indices.push( a, b, d );
  17181. indices.push( b, c, d );
  17182. }
  17183. }
  17184. // build geometry
  17185. this.setIndex( indices );
  17186. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17187. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17188. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17189. }
  17190. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17191. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  17192. /**
  17193. * @author Mugen87 / https://github.com/Mugen87
  17194. * Port from https://github.com/mapbox/earcut (v2.1.5)
  17195. */
  17196. var Earcut = {
  17197. triangulate: function ( data, holeIndices, dim ) {
  17198. dim = dim || 2;
  17199. var hasHoles = holeIndices && holeIndices.length,
  17200. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  17201. outerNode = linkedList( data, 0, outerLen, dim, true ),
  17202. triangles = [];
  17203. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  17204. var minX, minY, maxX, maxY, x, y, invSize;
  17205. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  17206. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17207. if ( data.length > 80 * dim ) {
  17208. minX = maxX = data[ 0 ];
  17209. minY = maxY = data[ 1 ];
  17210. for ( var i = dim; i < outerLen; i += dim ) {
  17211. x = data[ i ];
  17212. y = data[ i + 1 ];
  17213. if ( x < minX ) minX = x;
  17214. if ( y < minY ) minY = y;
  17215. if ( x > maxX ) maxX = x;
  17216. if ( y > maxY ) maxY = y;
  17217. }
  17218. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17219. invSize = Math.max( maxX - minX, maxY - minY );
  17220. invSize = invSize !== 0 ? 1 / invSize : 0;
  17221. }
  17222. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  17223. return triangles;
  17224. }
  17225. };
  17226. // create a circular doubly linked list from polygon points in the specified winding order
  17227. function linkedList( data, start, end, dim, clockwise ) {
  17228. var i, last;
  17229. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  17230. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17231. } else {
  17232. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17233. }
  17234. if ( last && equals( last, last.next ) ) {
  17235. removeNode( last );
  17236. last = last.next;
  17237. }
  17238. return last;
  17239. }
  17240. // eliminate colinear or duplicate points
  17241. function filterPoints( start, end ) {
  17242. if ( ! start ) return start;
  17243. if ( ! end ) end = start;
  17244. var p = start,
  17245. again;
  17246. do {
  17247. again = false;
  17248. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17249. removeNode( p );
  17250. p = end = p.prev;
  17251. if ( p === p.next ) break;
  17252. again = true;
  17253. } else {
  17254. p = p.next;
  17255. }
  17256. } while ( again || p !== end );
  17257. return end;
  17258. }
  17259. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17260. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17261. if ( ! ear ) return;
  17262. // interlink polygon nodes in z-order
  17263. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17264. var stop = ear,
  17265. prev, next;
  17266. // iterate through ears, slicing them one by one
  17267. while ( ear.prev !== ear.next ) {
  17268. prev = ear.prev;
  17269. next = ear.next;
  17270. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17271. // cut off the triangle
  17272. triangles.push( prev.i / dim );
  17273. triangles.push( ear.i / dim );
  17274. triangles.push( next.i / dim );
  17275. removeNode( ear );
  17276. // skipping the next vertex leads to less sliver triangles
  17277. ear = next.next;
  17278. stop = next.next;
  17279. continue;
  17280. }
  17281. ear = next;
  17282. // if we looped through the whole remaining polygon and can't find any more ears
  17283. if ( ear === stop ) {
  17284. // try filtering points and slicing again
  17285. if ( ! pass ) {
  17286. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17287. // if this didn't work, try curing all small self-intersections locally
  17288. } else if ( pass === 1 ) {
  17289. ear = cureLocalIntersections( ear, triangles, dim );
  17290. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17291. // as a last resort, try splitting the remaining polygon into two
  17292. } else if ( pass === 2 ) {
  17293. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17294. }
  17295. break;
  17296. }
  17297. }
  17298. }
  17299. // check whether a polygon node forms a valid ear with adjacent nodes
  17300. function isEar( ear ) {
  17301. var a = ear.prev,
  17302. b = ear,
  17303. c = ear.next;
  17304. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17305. // now make sure we don't have other points inside the potential ear
  17306. var p = ear.next.next;
  17307. while ( p !== ear.prev ) {
  17308. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17309. area( p.prev, p, p.next ) >= 0 ) return false;
  17310. p = p.next;
  17311. }
  17312. return true;
  17313. }
  17314. function isEarHashed( ear, minX, minY, invSize ) {
  17315. var a = ear.prev,
  17316. b = ear,
  17317. c = ear.next;
  17318. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17319. // triangle bbox; min & max are calculated like this for speed
  17320. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17321. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17322. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17323. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17324. // z-order range for the current triangle bbox;
  17325. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17326. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17327. var p = ear.prevZ,
  17328. n = ear.nextZ;
  17329. // look for points inside the triangle in both directions
  17330. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  17331. if ( p !== ear.prev && p !== ear.next &&
  17332. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17333. area( p.prev, p, p.next ) >= 0 ) return false;
  17334. p = p.prevZ;
  17335. if ( n !== ear.prev && n !== ear.next &&
  17336. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17337. area( n.prev, n, n.next ) >= 0 ) return false;
  17338. n = n.nextZ;
  17339. }
  17340. // look for remaining points in decreasing z-order
  17341. while ( p && p.z >= minZ ) {
  17342. if ( p !== ear.prev && p !== ear.next &&
  17343. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17344. area( p.prev, p, p.next ) >= 0 ) return false;
  17345. p = p.prevZ;
  17346. }
  17347. // look for remaining points in increasing z-order
  17348. while ( n && n.z <= maxZ ) {
  17349. if ( n !== ear.prev && n !== ear.next &&
  17350. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17351. area( n.prev, n, n.next ) >= 0 ) return false;
  17352. n = n.nextZ;
  17353. }
  17354. return true;
  17355. }
  17356. // go through all polygon nodes and cure small local self-intersections
  17357. function cureLocalIntersections( start, triangles, dim ) {
  17358. var p = start;
  17359. do {
  17360. var a = p.prev,
  17361. b = p.next.next;
  17362. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17363. triangles.push( a.i / dim );
  17364. triangles.push( p.i / dim );
  17365. triangles.push( b.i / dim );
  17366. // remove two nodes involved
  17367. removeNode( p );
  17368. removeNode( p.next );
  17369. p = start = b;
  17370. }
  17371. p = p.next;
  17372. } while ( p !== start );
  17373. return p;
  17374. }
  17375. // try splitting polygon into two and triangulate them independently
  17376. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17377. // look for a valid diagonal that divides the polygon into two
  17378. var a = start;
  17379. do {
  17380. var b = a.next.next;
  17381. while ( b !== a.prev ) {
  17382. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17383. // split the polygon in two by the diagonal
  17384. var c = splitPolygon( a, b );
  17385. // filter colinear points around the cuts
  17386. a = filterPoints( a, a.next );
  17387. c = filterPoints( c, c.next );
  17388. // run earcut on each half
  17389. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17390. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17391. return;
  17392. }
  17393. b = b.next;
  17394. }
  17395. a = a.next;
  17396. } while ( a !== start );
  17397. }
  17398. // link every hole into the outer loop, producing a single-ring polygon without holes
  17399. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17400. var queue = [],
  17401. i, len, start, end, list;
  17402. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17403. start = holeIndices[ i ] * dim;
  17404. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17405. list = linkedList( data, start, end, dim, false );
  17406. if ( list === list.next ) list.steiner = true;
  17407. queue.push( getLeftmost( list ) );
  17408. }
  17409. queue.sort( compareX );
  17410. // process holes from left to right
  17411. for ( i = 0; i < queue.length; i ++ ) {
  17412. eliminateHole( queue[ i ], outerNode );
  17413. outerNode = filterPoints( outerNode, outerNode.next );
  17414. }
  17415. return outerNode;
  17416. }
  17417. function compareX( a, b ) {
  17418. return a.x - b.x;
  17419. }
  17420. // find a bridge between vertices that connects hole with an outer ring and and link it
  17421. function eliminateHole( hole, outerNode ) {
  17422. outerNode = findHoleBridge( hole, outerNode );
  17423. if ( outerNode ) {
  17424. var b = splitPolygon( outerNode, hole );
  17425. filterPoints( b, b.next );
  17426. }
  17427. }
  17428. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17429. function findHoleBridge( hole, outerNode ) {
  17430. var p = outerNode,
  17431. hx = hole.x,
  17432. hy = hole.y,
  17433. qx = - Infinity,
  17434. m;
  17435. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17436. // segment's endpoint with lesser x will be potential connection point
  17437. do {
  17438. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17439. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17440. if ( x <= hx && x > qx ) {
  17441. qx = x;
  17442. if ( x === hx ) {
  17443. if ( hy === p.y ) return p;
  17444. if ( hy === p.next.y ) return p.next;
  17445. }
  17446. m = p.x < p.next.x ? p : p.next;
  17447. }
  17448. }
  17449. p = p.next;
  17450. } while ( p !== outerNode );
  17451. if ( ! m ) return null;
  17452. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17453. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17454. // if there are no points found, we have a valid connection;
  17455. // otherwise choose the point of the minimum angle with the ray as connection point
  17456. var stop = m,
  17457. mx = m.x,
  17458. my = m.y,
  17459. tanMin = Infinity,
  17460. tan;
  17461. p = m.next;
  17462. while ( p !== stop ) {
  17463. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17464. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17465. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17466. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17467. m = p;
  17468. tanMin = tan;
  17469. }
  17470. }
  17471. p = p.next;
  17472. }
  17473. return m;
  17474. }
  17475. // interlink polygon nodes in z-order
  17476. function indexCurve( start, minX, minY, invSize ) {
  17477. var p = start;
  17478. do {
  17479. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17480. p.prevZ = p.prev;
  17481. p.nextZ = p.next;
  17482. p = p.next;
  17483. } while ( p !== start );
  17484. p.prevZ.nextZ = null;
  17485. p.prevZ = null;
  17486. sortLinked( p );
  17487. }
  17488. // Simon Tatham's linked list merge sort algorithm
  17489. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17490. function sortLinked( list ) {
  17491. var i, p, q, e, tail, numMerges, pSize, qSize,
  17492. inSize = 1;
  17493. do {
  17494. p = list;
  17495. list = null;
  17496. tail = null;
  17497. numMerges = 0;
  17498. while ( p ) {
  17499. numMerges ++;
  17500. q = p;
  17501. pSize = 0;
  17502. for ( i = 0; i < inSize; i ++ ) {
  17503. pSize ++;
  17504. q = q.nextZ;
  17505. if ( ! q ) break;
  17506. }
  17507. qSize = inSize;
  17508. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17509. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17510. e = p;
  17511. p = p.nextZ;
  17512. pSize --;
  17513. } else {
  17514. e = q;
  17515. q = q.nextZ;
  17516. qSize --;
  17517. }
  17518. if ( tail ) tail.nextZ = e;
  17519. else list = e;
  17520. e.prevZ = tail;
  17521. tail = e;
  17522. }
  17523. p = q;
  17524. }
  17525. tail.nextZ = null;
  17526. inSize *= 2;
  17527. } while ( numMerges > 1 );
  17528. return list;
  17529. }
  17530. // z-order of a point given coords and inverse of the longer side of data bbox
  17531. function zOrder( x, y, minX, minY, invSize ) {
  17532. // coords are transformed into non-negative 15-bit integer range
  17533. x = 32767 * ( x - minX ) * invSize;
  17534. y = 32767 * ( y - minY ) * invSize;
  17535. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17536. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17537. x = ( x | ( x << 2 ) ) & 0x33333333;
  17538. x = ( x | ( x << 1 ) ) & 0x55555555;
  17539. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17540. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17541. y = ( y | ( y << 2 ) ) & 0x33333333;
  17542. y = ( y | ( y << 1 ) ) & 0x55555555;
  17543. return x | ( y << 1 );
  17544. }
  17545. // find the leftmost node of a polygon ring
  17546. function getLeftmost( start ) {
  17547. var p = start,
  17548. leftmost = start;
  17549. do {
  17550. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  17551. p = p.next;
  17552. } while ( p !== start );
  17553. return leftmost;
  17554. }
  17555. // check if a point lies within a convex triangle
  17556. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17557. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17558. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17559. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17560. }
  17561. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17562. function isValidDiagonal( a, b ) {
  17563. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17564. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17565. }
  17566. // signed area of a triangle
  17567. function area( p, q, r ) {
  17568. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17569. }
  17570. // check if two points are equal
  17571. function equals( p1, p2 ) {
  17572. return p1.x === p2.x && p1.y === p2.y;
  17573. }
  17574. // check if two segments intersect
  17575. function intersects( p1, q1, p2, q2 ) {
  17576. if ( ( equals( p1, p2 ) && equals( q1, q2 ) ) ||
  17577. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17578. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17579. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17580. }
  17581. // check if a polygon diagonal intersects any polygon segments
  17582. function intersectsPolygon( a, b ) {
  17583. var p = a;
  17584. do {
  17585. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17586. intersects( p, p.next, a, b ) ) return true;
  17587. p = p.next;
  17588. } while ( p !== a );
  17589. return false;
  17590. }
  17591. // check if a polygon diagonal is locally inside the polygon
  17592. function locallyInside( a, b ) {
  17593. return area( a.prev, a, a.next ) < 0 ?
  17594. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17595. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17596. }
  17597. // check if the middle point of a polygon diagonal is inside the polygon
  17598. function middleInside( a, b ) {
  17599. var p = a,
  17600. inside = false,
  17601. px = ( a.x + b.x ) / 2,
  17602. py = ( a.y + b.y ) / 2;
  17603. do {
  17604. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17605. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  17606. inside = ! inside;
  17607. p = p.next;
  17608. } while ( p !== a );
  17609. return inside;
  17610. }
  17611. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17612. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17613. function splitPolygon( a, b ) {
  17614. var a2 = new Node( a.i, a.x, a.y ),
  17615. b2 = new Node( b.i, b.x, b.y ),
  17616. an = a.next,
  17617. bp = b.prev;
  17618. a.next = b;
  17619. b.prev = a;
  17620. a2.next = an;
  17621. an.prev = a2;
  17622. b2.next = a2;
  17623. a2.prev = b2;
  17624. bp.next = b2;
  17625. b2.prev = bp;
  17626. return b2;
  17627. }
  17628. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17629. function insertNode( i, x, y, last ) {
  17630. var p = new Node( i, x, y );
  17631. if ( ! last ) {
  17632. p.prev = p;
  17633. p.next = p;
  17634. } else {
  17635. p.next = last.next;
  17636. p.prev = last;
  17637. last.next.prev = p;
  17638. last.next = p;
  17639. }
  17640. return p;
  17641. }
  17642. function removeNode( p ) {
  17643. p.next.prev = p.prev;
  17644. p.prev.next = p.next;
  17645. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17646. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17647. }
  17648. function Node( i, x, y ) {
  17649. // vertex index in coordinates array
  17650. this.i = i;
  17651. // vertex coordinates
  17652. this.x = x;
  17653. this.y = y;
  17654. // previous and next vertex nodes in a polygon ring
  17655. this.prev = null;
  17656. this.next = null;
  17657. // z-order curve value
  17658. this.z = null;
  17659. // previous and next nodes in z-order
  17660. this.prevZ = null;
  17661. this.nextZ = null;
  17662. // indicates whether this is a steiner point
  17663. this.steiner = false;
  17664. }
  17665. function signedArea( data, start, end, dim ) {
  17666. var sum = 0;
  17667. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17668. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17669. j = i;
  17670. }
  17671. return sum;
  17672. }
  17673. /**
  17674. * @author zz85 / http://www.lab4games.net/zz85/blog
  17675. */
  17676. var ShapeUtils = {
  17677. // calculate area of the contour polygon
  17678. area: function ( contour ) {
  17679. var n = contour.length;
  17680. var a = 0.0;
  17681. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17682. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17683. }
  17684. return a * 0.5;
  17685. },
  17686. isClockWise: function ( pts ) {
  17687. return ShapeUtils.area( pts ) < 0;
  17688. },
  17689. triangulateShape: function ( contour, holes ) {
  17690. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17691. var holeIndices = []; // array of hole indices
  17692. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17693. removeDupEndPts( contour );
  17694. addContour( vertices, contour );
  17695. //
  17696. var holeIndex = contour.length;
  17697. holes.forEach( removeDupEndPts );
  17698. for ( var i = 0; i < holes.length; i ++ ) {
  17699. holeIndices.push( holeIndex );
  17700. holeIndex += holes[ i ].length;
  17701. addContour( vertices, holes[ i ] );
  17702. }
  17703. //
  17704. var triangles = Earcut.triangulate( vertices, holeIndices );
  17705. //
  17706. for ( var i = 0; i < triangles.length; i += 3 ) {
  17707. faces.push( triangles.slice( i, i + 3 ) );
  17708. }
  17709. return faces;
  17710. }
  17711. };
  17712. function removeDupEndPts( points ) {
  17713. var l = points.length;
  17714. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17715. points.pop();
  17716. }
  17717. }
  17718. function addContour( vertices, contour ) {
  17719. for ( var i = 0; i < contour.length; i ++ ) {
  17720. vertices.push( contour[ i ].x );
  17721. vertices.push( contour[ i ].y );
  17722. }
  17723. }
  17724. /**
  17725. * @author zz85 / http://www.lab4games.net/zz85/blog
  17726. *
  17727. * Creates extruded geometry from a path shape.
  17728. *
  17729. * parameters = {
  17730. *
  17731. * curveSegments: <int>, // number of points on the curves
  17732. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17733. * depth: <float>, // Depth to extrude the shape
  17734. *
  17735. * bevelEnabled: <bool>, // turn on bevel
  17736. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17737. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17738. * bevelOffset: <float>, // how far from shape outline does bevel start
  17739. * bevelSegments: <int>, // number of bevel layers
  17740. *
  17741. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17742. *
  17743. * UVGenerator: <Object> // object that provides UV generator functions
  17744. *
  17745. * }
  17746. */
  17747. // ExtrudeGeometry
  17748. function ExtrudeGeometry( shapes, options ) {
  17749. Geometry.call( this );
  17750. this.type = 'ExtrudeGeometry';
  17751. this.parameters = {
  17752. shapes: shapes,
  17753. options: options
  17754. };
  17755. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17756. this.mergeVertices();
  17757. }
  17758. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17759. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17760. ExtrudeGeometry.prototype.toJSON = function () {
  17761. var data = Geometry.prototype.toJSON.call( this );
  17762. var shapes = this.parameters.shapes;
  17763. var options = this.parameters.options;
  17764. return toJSON( shapes, options, data );
  17765. };
  17766. // ExtrudeBufferGeometry
  17767. function ExtrudeBufferGeometry( shapes, options ) {
  17768. BufferGeometry.call( this );
  17769. this.type = 'ExtrudeBufferGeometry';
  17770. this.parameters = {
  17771. shapes: shapes,
  17772. options: options
  17773. };
  17774. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17775. var scope = this;
  17776. var verticesArray = [];
  17777. var uvArray = [];
  17778. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17779. var shape = shapes[ i ];
  17780. addShape( shape );
  17781. }
  17782. // build geometry
  17783. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17784. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17785. this.computeVertexNormals();
  17786. // functions
  17787. function addShape( shape ) {
  17788. var placeholder = [];
  17789. // options
  17790. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17791. var steps = options.steps !== undefined ? options.steps : 1;
  17792. var depth = options.depth !== undefined ? options.depth : 100;
  17793. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17794. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17795. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17796. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17797. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17798. var extrudePath = options.extrudePath;
  17799. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17800. // deprecated options
  17801. if ( options.amount !== undefined ) {
  17802. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17803. depth = options.amount;
  17804. }
  17805. //
  17806. var extrudePts, extrudeByPath = false;
  17807. var splineTube, binormal, normal, position2;
  17808. if ( extrudePath ) {
  17809. extrudePts = extrudePath.getSpacedPoints( steps );
  17810. extrudeByPath = true;
  17811. bevelEnabled = false; // bevels not supported for path extrusion
  17812. // SETUP TNB variables
  17813. // TODO1 - have a .isClosed in spline?
  17814. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17815. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17816. binormal = new Vector3();
  17817. normal = new Vector3();
  17818. position2 = new Vector3();
  17819. }
  17820. // Safeguards if bevels are not enabled
  17821. if ( ! bevelEnabled ) {
  17822. bevelSegments = 0;
  17823. bevelThickness = 0;
  17824. bevelSize = 0;
  17825. bevelOffset = 0;
  17826. }
  17827. // Variables initialization
  17828. var ahole, h, hl; // looping of holes
  17829. var shapePoints = shape.extractPoints( curveSegments );
  17830. var vertices = shapePoints.shape;
  17831. var holes = shapePoints.holes;
  17832. var reverse = ! ShapeUtils.isClockWise( vertices );
  17833. if ( reverse ) {
  17834. vertices = vertices.reverse();
  17835. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17836. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17837. ahole = holes[ h ];
  17838. if ( ShapeUtils.isClockWise( ahole ) ) {
  17839. holes[ h ] = ahole.reverse();
  17840. }
  17841. }
  17842. }
  17843. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17844. /* Vertices */
  17845. var contour = vertices; // vertices has all points but contour has only points of circumference
  17846. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17847. ahole = holes[ h ];
  17848. vertices = vertices.concat( ahole );
  17849. }
  17850. function scalePt2( pt, vec, size ) {
  17851. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17852. return vec.clone().multiplyScalar( size ).add( pt );
  17853. }
  17854. var b, bs, t, z,
  17855. vert, vlen = vertices.length,
  17856. face, flen = faces.length;
  17857. // Find directions for point movement
  17858. function getBevelVec( inPt, inPrev, inNext ) {
  17859. // computes for inPt the corresponding point inPt' on a new contour
  17860. // shifted by 1 unit (length of normalized vector) to the left
  17861. // if we walk along contour clockwise, this new contour is outside the old one
  17862. //
  17863. // inPt' is the intersection of the two lines parallel to the two
  17864. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17865. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17866. // good reading for geometry algorithms (here: line-line intersection)
  17867. // http://geomalgorithms.com/a05-_intersect-1.html
  17868. var v_prev_x = inPt.x - inPrev.x,
  17869. v_prev_y = inPt.y - inPrev.y;
  17870. var v_next_x = inNext.x - inPt.x,
  17871. v_next_y = inNext.y - inPt.y;
  17872. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17873. // check for collinear edges
  17874. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17875. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17876. // not collinear
  17877. // length of vectors for normalizing
  17878. var v_prev_len = Math.sqrt( v_prev_lensq );
  17879. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17880. // shift adjacent points by unit vectors to the left
  17881. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17882. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17883. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17884. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17885. // scaling factor for v_prev to intersection point
  17886. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17887. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17888. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17889. // vector from inPt to intersection point
  17890. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17891. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17892. // Don't normalize!, otherwise sharp corners become ugly
  17893. // but prevent crazy spikes
  17894. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17895. if ( v_trans_lensq <= 2 ) {
  17896. return new Vector2( v_trans_x, v_trans_y );
  17897. } else {
  17898. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17899. }
  17900. } else {
  17901. // handle special case of collinear edges
  17902. var direction_eq = false; // assumes: opposite
  17903. if ( v_prev_x > Number.EPSILON ) {
  17904. if ( v_next_x > Number.EPSILON ) {
  17905. direction_eq = true;
  17906. }
  17907. } else {
  17908. if ( v_prev_x < - Number.EPSILON ) {
  17909. if ( v_next_x < - Number.EPSILON ) {
  17910. direction_eq = true;
  17911. }
  17912. } else {
  17913. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17914. direction_eq = true;
  17915. }
  17916. }
  17917. }
  17918. if ( direction_eq ) {
  17919. // console.log("Warning: lines are a straight sequence");
  17920. v_trans_x = - v_prev_y;
  17921. v_trans_y = v_prev_x;
  17922. shrink_by = Math.sqrt( v_prev_lensq );
  17923. } else {
  17924. // console.log("Warning: lines are a straight spike");
  17925. v_trans_x = v_prev_x;
  17926. v_trans_y = v_prev_y;
  17927. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17928. }
  17929. }
  17930. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17931. }
  17932. var contourMovements = [];
  17933. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17934. if ( j === il ) j = 0;
  17935. if ( k === il ) k = 0;
  17936. // (j)---(i)---(k)
  17937. // console.log('i,j,k', i, j , k)
  17938. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17939. }
  17940. var holesMovements = [],
  17941. oneHoleMovements, verticesMovements = contourMovements.concat();
  17942. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17943. ahole = holes[ h ];
  17944. oneHoleMovements = [];
  17945. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17946. if ( j === il ) j = 0;
  17947. if ( k === il ) k = 0;
  17948. // (j)---(i)---(k)
  17949. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17950. }
  17951. holesMovements.push( oneHoleMovements );
  17952. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17953. }
  17954. // Loop bevelSegments, 1 for the front, 1 for the back
  17955. for ( b = 0; b < bevelSegments; b ++ ) {
  17956. //for ( b = bevelSegments; b > 0; b -- ) {
  17957. t = b / bevelSegments;
  17958. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17959. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17960. // contract shape
  17961. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17962. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17963. v( vert.x, vert.y, - z );
  17964. }
  17965. // expand holes
  17966. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17967. ahole = holes[ h ];
  17968. oneHoleMovements = holesMovements[ h ];
  17969. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17970. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17971. v( vert.x, vert.y, - z );
  17972. }
  17973. }
  17974. }
  17975. bs = bevelSize + bevelOffset;
  17976. // Back facing vertices
  17977. for ( i = 0; i < vlen; i ++ ) {
  17978. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17979. if ( ! extrudeByPath ) {
  17980. v( vert.x, vert.y, 0 );
  17981. } else {
  17982. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17983. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17984. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17985. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17986. v( position2.x, position2.y, position2.z );
  17987. }
  17988. }
  17989. // Add stepped vertices...
  17990. // Including front facing vertices
  17991. var s;
  17992. for ( s = 1; s <= steps; s ++ ) {
  17993. for ( i = 0; i < vlen; i ++ ) {
  17994. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17995. if ( ! extrudeByPath ) {
  17996. v( vert.x, vert.y, depth / steps * s );
  17997. } else {
  17998. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17999. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  18000. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  18001. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18002. v( position2.x, position2.y, position2.z );
  18003. }
  18004. }
  18005. }
  18006. // Add bevel segments planes
  18007. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18008. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18009. t = b / bevelSegments;
  18010. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18011. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18012. // contract shape
  18013. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18014. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18015. v( vert.x, vert.y, depth + z );
  18016. }
  18017. // expand holes
  18018. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18019. ahole = holes[ h ];
  18020. oneHoleMovements = holesMovements[ h ];
  18021. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18022. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18023. if ( ! extrudeByPath ) {
  18024. v( vert.x, vert.y, depth + z );
  18025. } else {
  18026. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18027. }
  18028. }
  18029. }
  18030. }
  18031. /* Faces */
  18032. // Top and bottom faces
  18033. buildLidFaces();
  18034. // Sides faces
  18035. buildSideFaces();
  18036. ///// Internal functions
  18037. function buildLidFaces() {
  18038. var start = verticesArray.length / 3;
  18039. if ( bevelEnabled ) {
  18040. var layer = 0; // steps + 1
  18041. var offset = vlen * layer;
  18042. // Bottom faces
  18043. for ( i = 0; i < flen; i ++ ) {
  18044. face = faces[ i ];
  18045. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18046. }
  18047. layer = steps + bevelSegments * 2;
  18048. offset = vlen * layer;
  18049. // Top faces
  18050. for ( i = 0; i < flen; i ++ ) {
  18051. face = faces[ i ];
  18052. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18053. }
  18054. } else {
  18055. // Bottom faces
  18056. for ( i = 0; i < flen; i ++ ) {
  18057. face = faces[ i ];
  18058. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18059. }
  18060. // Top faces
  18061. for ( i = 0; i < flen; i ++ ) {
  18062. face = faces[ i ];
  18063. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18064. }
  18065. }
  18066. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18067. }
  18068. // Create faces for the z-sides of the shape
  18069. function buildSideFaces() {
  18070. var start = verticesArray.length / 3;
  18071. var layeroffset = 0;
  18072. sidewalls( contour, layeroffset );
  18073. layeroffset += contour.length;
  18074. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18075. ahole = holes[ h ];
  18076. sidewalls( ahole, layeroffset );
  18077. //, true
  18078. layeroffset += ahole.length;
  18079. }
  18080. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18081. }
  18082. function sidewalls( contour, layeroffset ) {
  18083. var j, k;
  18084. i = contour.length;
  18085. while ( -- i >= 0 ) {
  18086. j = i;
  18087. k = i - 1;
  18088. if ( k < 0 ) k = contour.length - 1;
  18089. //console.log('b', i,j, i-1, k,vertices.length);
  18090. var s = 0,
  18091. sl = steps + bevelSegments * 2;
  18092. for ( s = 0; s < sl; s ++ ) {
  18093. var slen1 = vlen * s;
  18094. var slen2 = vlen * ( s + 1 );
  18095. var a = layeroffset + j + slen1,
  18096. b = layeroffset + k + slen1,
  18097. c = layeroffset + k + slen2,
  18098. d = layeroffset + j + slen2;
  18099. f4( a, b, c, d );
  18100. }
  18101. }
  18102. }
  18103. function v( x, y, z ) {
  18104. placeholder.push( x );
  18105. placeholder.push( y );
  18106. placeholder.push( z );
  18107. }
  18108. function f3( a, b, c ) {
  18109. addVertex( a );
  18110. addVertex( b );
  18111. addVertex( c );
  18112. var nextIndex = verticesArray.length / 3;
  18113. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18114. addUV( uvs[ 0 ] );
  18115. addUV( uvs[ 1 ] );
  18116. addUV( uvs[ 2 ] );
  18117. }
  18118. function f4( a, b, c, d ) {
  18119. addVertex( a );
  18120. addVertex( b );
  18121. addVertex( d );
  18122. addVertex( b );
  18123. addVertex( c );
  18124. addVertex( d );
  18125. var nextIndex = verticesArray.length / 3;
  18126. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18127. addUV( uvs[ 0 ] );
  18128. addUV( uvs[ 1 ] );
  18129. addUV( uvs[ 3 ] );
  18130. addUV( uvs[ 1 ] );
  18131. addUV( uvs[ 2 ] );
  18132. addUV( uvs[ 3 ] );
  18133. }
  18134. function addVertex( index ) {
  18135. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18136. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18137. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18138. }
  18139. function addUV( vector2 ) {
  18140. uvArray.push( vector2.x );
  18141. uvArray.push( vector2.y );
  18142. }
  18143. }
  18144. }
  18145. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18146. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  18147. ExtrudeBufferGeometry.prototype.toJSON = function () {
  18148. var data = BufferGeometry.prototype.toJSON.call( this );
  18149. var shapes = this.parameters.shapes;
  18150. var options = this.parameters.options;
  18151. return toJSON( shapes, options, data );
  18152. };
  18153. //
  18154. var WorldUVGenerator = {
  18155. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18156. var a_x = vertices[ indexA * 3 ];
  18157. var a_y = vertices[ indexA * 3 + 1 ];
  18158. var b_x = vertices[ indexB * 3 ];
  18159. var b_y = vertices[ indexB * 3 + 1 ];
  18160. var c_x = vertices[ indexC * 3 ];
  18161. var c_y = vertices[ indexC * 3 + 1 ];
  18162. return [
  18163. new Vector2( a_x, a_y ),
  18164. new Vector2( b_x, b_y ),
  18165. new Vector2( c_x, c_y )
  18166. ];
  18167. },
  18168. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  18169. var a_x = vertices[ indexA * 3 ];
  18170. var a_y = vertices[ indexA * 3 + 1 ];
  18171. var a_z = vertices[ indexA * 3 + 2 ];
  18172. var b_x = vertices[ indexB * 3 ];
  18173. var b_y = vertices[ indexB * 3 + 1 ];
  18174. var b_z = vertices[ indexB * 3 + 2 ];
  18175. var c_x = vertices[ indexC * 3 ];
  18176. var c_y = vertices[ indexC * 3 + 1 ];
  18177. var c_z = vertices[ indexC * 3 + 2 ];
  18178. var d_x = vertices[ indexD * 3 ];
  18179. var d_y = vertices[ indexD * 3 + 1 ];
  18180. var d_z = vertices[ indexD * 3 + 2 ];
  18181. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  18182. return [
  18183. new Vector2( a_x, 1 - a_z ),
  18184. new Vector2( b_x, 1 - b_z ),
  18185. new Vector2( c_x, 1 - c_z ),
  18186. new Vector2( d_x, 1 - d_z )
  18187. ];
  18188. } else {
  18189. return [
  18190. new Vector2( a_y, 1 - a_z ),
  18191. new Vector2( b_y, 1 - b_z ),
  18192. new Vector2( c_y, 1 - c_z ),
  18193. new Vector2( d_y, 1 - d_z )
  18194. ];
  18195. }
  18196. }
  18197. };
  18198. function toJSON( shapes, options, data ) {
  18199. //
  18200. data.shapes = [];
  18201. if ( Array.isArray( shapes ) ) {
  18202. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18203. var shape = shapes[ i ];
  18204. data.shapes.push( shape.uuid );
  18205. }
  18206. } else {
  18207. data.shapes.push( shapes.uuid );
  18208. }
  18209. //
  18210. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18211. return data;
  18212. }
  18213. /**
  18214. * @author zz85 / http://www.lab4games.net/zz85/blog
  18215. * @author alteredq / http://alteredqualia.com/
  18216. *
  18217. * Text = 3D Text
  18218. *
  18219. * parameters = {
  18220. * font: <THREE.Font>, // font
  18221. *
  18222. * size: <float>, // size of the text
  18223. * height: <float>, // thickness to extrude text
  18224. * curveSegments: <int>, // number of points on the curves
  18225. *
  18226. * bevelEnabled: <bool>, // turn on bevel
  18227. * bevelThickness: <float>, // how deep into text bevel goes
  18228. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18229. * bevelOffset: <float> // how far from text outline does bevel start
  18230. * }
  18231. */
  18232. // TextGeometry
  18233. function TextGeometry( text, parameters ) {
  18234. Geometry.call( this );
  18235. this.type = 'TextGeometry';
  18236. this.parameters = {
  18237. text: text,
  18238. parameters: parameters
  18239. };
  18240. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  18241. this.mergeVertices();
  18242. }
  18243. TextGeometry.prototype = Object.create( Geometry.prototype );
  18244. TextGeometry.prototype.constructor = TextGeometry;
  18245. // TextBufferGeometry
  18246. function TextBufferGeometry( text, parameters ) {
  18247. parameters = parameters || {};
  18248. var font = parameters.font;
  18249. if ( ! ( font && font.isFont ) ) {
  18250. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18251. return new Geometry();
  18252. }
  18253. var shapes = font.generateShapes( text, parameters.size );
  18254. // translate parameters to ExtrudeGeometry API
  18255. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18256. // defaults
  18257. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18258. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18259. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18260. ExtrudeBufferGeometry.call( this, shapes, parameters );
  18261. this.type = 'TextBufferGeometry';
  18262. }
  18263. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  18264. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  18265. /**
  18266. * @author mrdoob / http://mrdoob.com/
  18267. * @author benaadams / https://twitter.com/ben_a_adams
  18268. * @author Mugen87 / https://github.com/Mugen87
  18269. */
  18270. // SphereGeometry
  18271. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18272. Geometry.call( this );
  18273. this.type = 'SphereGeometry';
  18274. this.parameters = {
  18275. radius: radius,
  18276. widthSegments: widthSegments,
  18277. heightSegments: heightSegments,
  18278. phiStart: phiStart,
  18279. phiLength: phiLength,
  18280. thetaStart: thetaStart,
  18281. thetaLength: thetaLength
  18282. };
  18283. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  18284. this.mergeVertices();
  18285. }
  18286. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18287. SphereGeometry.prototype.constructor = SphereGeometry;
  18288. // SphereBufferGeometry
  18289. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18290. BufferGeometry.call( this );
  18291. this.type = 'SphereBufferGeometry';
  18292. this.parameters = {
  18293. radius: radius,
  18294. widthSegments: widthSegments,
  18295. heightSegments: heightSegments,
  18296. phiStart: phiStart,
  18297. phiLength: phiLength,
  18298. thetaStart: thetaStart,
  18299. thetaLength: thetaLength
  18300. };
  18301. radius = radius || 1;
  18302. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18303. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18304. phiStart = phiStart !== undefined ? phiStart : 0;
  18305. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18306. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18307. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18308. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18309. var ix, iy;
  18310. var index = 0;
  18311. var grid = [];
  18312. var vertex = new Vector3();
  18313. var normal = new Vector3();
  18314. // buffers
  18315. var indices = [];
  18316. var vertices = [];
  18317. var normals = [];
  18318. var uvs = [];
  18319. // generate vertices, normals and uvs
  18320. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18321. var verticesRow = [];
  18322. var v = iy / heightSegments;
  18323. // special case for the poles
  18324. var uOffset = 0;
  18325. if ( iy == 0 && thetaStart == 0 ) {
  18326. uOffset = 0.5 / widthSegments;
  18327. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18328. uOffset = - 0.5 / widthSegments;
  18329. }
  18330. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18331. var u = ix / widthSegments;
  18332. // vertex
  18333. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18334. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18335. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18336. vertices.push( vertex.x, vertex.y, vertex.z );
  18337. // normal
  18338. normal.copy( vertex ).normalize();
  18339. normals.push( normal.x, normal.y, normal.z );
  18340. // uv
  18341. uvs.push( u + uOffset, 1 - v );
  18342. verticesRow.push( index ++ );
  18343. }
  18344. grid.push( verticesRow );
  18345. }
  18346. // indices
  18347. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18348. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18349. var a = grid[ iy ][ ix + 1 ];
  18350. var b = grid[ iy ][ ix ];
  18351. var c = grid[ iy + 1 ][ ix ];
  18352. var d = grid[ iy + 1 ][ ix + 1 ];
  18353. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18354. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18355. }
  18356. }
  18357. // build geometry
  18358. this.setIndex( indices );
  18359. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18360. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18361. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18362. }
  18363. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18364. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18365. /**
  18366. * @author Kaleb Murphy
  18367. * @author Mugen87 / https://github.com/Mugen87
  18368. */
  18369. // RingGeometry
  18370. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18371. Geometry.call( this );
  18372. this.type = 'RingGeometry';
  18373. this.parameters = {
  18374. innerRadius: innerRadius,
  18375. outerRadius: outerRadius,
  18376. thetaSegments: thetaSegments,
  18377. phiSegments: phiSegments,
  18378. thetaStart: thetaStart,
  18379. thetaLength: thetaLength
  18380. };
  18381. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18382. this.mergeVertices();
  18383. }
  18384. RingGeometry.prototype = Object.create( Geometry.prototype );
  18385. RingGeometry.prototype.constructor = RingGeometry;
  18386. // RingBufferGeometry
  18387. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18388. BufferGeometry.call( this );
  18389. this.type = 'RingBufferGeometry';
  18390. this.parameters = {
  18391. innerRadius: innerRadius,
  18392. outerRadius: outerRadius,
  18393. thetaSegments: thetaSegments,
  18394. phiSegments: phiSegments,
  18395. thetaStart: thetaStart,
  18396. thetaLength: thetaLength
  18397. };
  18398. innerRadius = innerRadius || 0.5;
  18399. outerRadius = outerRadius || 1;
  18400. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18401. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18402. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18403. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18404. // buffers
  18405. var indices = [];
  18406. var vertices = [];
  18407. var normals = [];
  18408. var uvs = [];
  18409. // some helper variables
  18410. var segment;
  18411. var radius = innerRadius;
  18412. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18413. var vertex = new Vector3();
  18414. var uv = new Vector2();
  18415. var j, i;
  18416. // generate vertices, normals and uvs
  18417. for ( j = 0; j <= phiSegments; j ++ ) {
  18418. for ( i = 0; i <= thetaSegments; i ++ ) {
  18419. // values are generate from the inside of the ring to the outside
  18420. segment = thetaStart + i / thetaSegments * thetaLength;
  18421. // vertex
  18422. vertex.x = radius * Math.cos( segment );
  18423. vertex.y = radius * Math.sin( segment );
  18424. vertices.push( vertex.x, vertex.y, vertex.z );
  18425. // normal
  18426. normals.push( 0, 0, 1 );
  18427. // uv
  18428. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18429. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18430. uvs.push( uv.x, uv.y );
  18431. }
  18432. // increase the radius for next row of vertices
  18433. radius += radiusStep;
  18434. }
  18435. // indices
  18436. for ( j = 0; j < phiSegments; j ++ ) {
  18437. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18438. for ( i = 0; i < thetaSegments; i ++ ) {
  18439. segment = i + thetaSegmentLevel;
  18440. var a = segment;
  18441. var b = segment + thetaSegments + 1;
  18442. var c = segment + thetaSegments + 2;
  18443. var d = segment + 1;
  18444. // faces
  18445. indices.push( a, b, d );
  18446. indices.push( b, c, d );
  18447. }
  18448. }
  18449. // build geometry
  18450. this.setIndex( indices );
  18451. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18452. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18453. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18454. }
  18455. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18456. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18457. /**
  18458. * @author zz85 / https://github.com/zz85
  18459. * @author bhouston / http://clara.io
  18460. * @author Mugen87 / https://github.com/Mugen87
  18461. */
  18462. // LatheGeometry
  18463. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18464. Geometry.call( this );
  18465. this.type = 'LatheGeometry';
  18466. this.parameters = {
  18467. points: points,
  18468. segments: segments,
  18469. phiStart: phiStart,
  18470. phiLength: phiLength
  18471. };
  18472. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18473. this.mergeVertices();
  18474. }
  18475. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18476. LatheGeometry.prototype.constructor = LatheGeometry;
  18477. // LatheBufferGeometry
  18478. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18479. BufferGeometry.call( this );
  18480. this.type = 'LatheBufferGeometry';
  18481. this.parameters = {
  18482. points: points,
  18483. segments: segments,
  18484. phiStart: phiStart,
  18485. phiLength: phiLength
  18486. };
  18487. segments = Math.floor( segments ) || 12;
  18488. phiStart = phiStart || 0;
  18489. phiLength = phiLength || Math.PI * 2;
  18490. // clamp phiLength so it's in range of [ 0, 2PI ]
  18491. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18492. // buffers
  18493. var indices = [];
  18494. var vertices = [];
  18495. var uvs = [];
  18496. // helper variables
  18497. var base;
  18498. var inverseSegments = 1.0 / segments;
  18499. var vertex = new Vector3();
  18500. var uv = new Vector2();
  18501. var i, j;
  18502. // generate vertices and uvs
  18503. for ( i = 0; i <= segments; i ++ ) {
  18504. var phi = phiStart + i * inverseSegments * phiLength;
  18505. var sin = Math.sin( phi );
  18506. var cos = Math.cos( phi );
  18507. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18508. // vertex
  18509. vertex.x = points[ j ].x * sin;
  18510. vertex.y = points[ j ].y;
  18511. vertex.z = points[ j ].x * cos;
  18512. vertices.push( vertex.x, vertex.y, vertex.z );
  18513. // uv
  18514. uv.x = i / segments;
  18515. uv.y = j / ( points.length - 1 );
  18516. uvs.push( uv.x, uv.y );
  18517. }
  18518. }
  18519. // indices
  18520. for ( i = 0; i < segments; i ++ ) {
  18521. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18522. base = j + i * points.length;
  18523. var a = base;
  18524. var b = base + points.length;
  18525. var c = base + points.length + 1;
  18526. var d = base + 1;
  18527. // faces
  18528. indices.push( a, b, d );
  18529. indices.push( b, c, d );
  18530. }
  18531. }
  18532. // build geometry
  18533. this.setIndex( indices );
  18534. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18535. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18536. // generate normals
  18537. this.computeVertexNormals();
  18538. // if the geometry is closed, we need to average the normals along the seam.
  18539. // because the corresponding vertices are identical (but still have different UVs).
  18540. if ( phiLength === Math.PI * 2 ) {
  18541. var normals = this.attributes.normal.array;
  18542. var n1 = new Vector3();
  18543. var n2 = new Vector3();
  18544. var n = new Vector3();
  18545. // this is the buffer offset for the last line of vertices
  18546. base = segments * points.length * 3;
  18547. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18548. // select the normal of the vertex in the first line
  18549. n1.x = normals[ j + 0 ];
  18550. n1.y = normals[ j + 1 ];
  18551. n1.z = normals[ j + 2 ];
  18552. // select the normal of the vertex in the last line
  18553. n2.x = normals[ base + j + 0 ];
  18554. n2.y = normals[ base + j + 1 ];
  18555. n2.z = normals[ base + j + 2 ];
  18556. // average normals
  18557. n.addVectors( n1, n2 ).normalize();
  18558. // assign the new values to both normals
  18559. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18560. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18561. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18562. }
  18563. }
  18564. }
  18565. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18566. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18567. /**
  18568. * @author jonobr1 / http://jonobr1.com
  18569. * @author Mugen87 / https://github.com/Mugen87
  18570. */
  18571. // ShapeGeometry
  18572. function ShapeGeometry( shapes, curveSegments ) {
  18573. Geometry.call( this );
  18574. this.type = 'ShapeGeometry';
  18575. if ( typeof curveSegments === 'object' ) {
  18576. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18577. curveSegments = curveSegments.curveSegments;
  18578. }
  18579. this.parameters = {
  18580. shapes: shapes,
  18581. curveSegments: curveSegments
  18582. };
  18583. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18584. this.mergeVertices();
  18585. }
  18586. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18587. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18588. ShapeGeometry.prototype.toJSON = function () {
  18589. var data = Geometry.prototype.toJSON.call( this );
  18590. var shapes = this.parameters.shapes;
  18591. return toJSON$1( shapes, data );
  18592. };
  18593. // ShapeBufferGeometry
  18594. function ShapeBufferGeometry( shapes, curveSegments ) {
  18595. BufferGeometry.call( this );
  18596. this.type = 'ShapeBufferGeometry';
  18597. this.parameters = {
  18598. shapes: shapes,
  18599. curveSegments: curveSegments
  18600. };
  18601. curveSegments = curveSegments || 12;
  18602. // buffers
  18603. var indices = [];
  18604. var vertices = [];
  18605. var normals = [];
  18606. var uvs = [];
  18607. // helper variables
  18608. var groupStart = 0;
  18609. var groupCount = 0;
  18610. // allow single and array values for "shapes" parameter
  18611. if ( Array.isArray( shapes ) === false ) {
  18612. addShape( shapes );
  18613. } else {
  18614. for ( var i = 0; i < shapes.length; i ++ ) {
  18615. addShape( shapes[ i ] );
  18616. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18617. groupStart += groupCount;
  18618. groupCount = 0;
  18619. }
  18620. }
  18621. // build geometry
  18622. this.setIndex( indices );
  18623. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18624. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18625. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18626. // helper functions
  18627. function addShape( shape ) {
  18628. var i, l, shapeHole;
  18629. var indexOffset = vertices.length / 3;
  18630. var points = shape.extractPoints( curveSegments );
  18631. var shapeVertices = points.shape;
  18632. var shapeHoles = points.holes;
  18633. // check direction of vertices
  18634. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18635. shapeVertices = shapeVertices.reverse();
  18636. }
  18637. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18638. shapeHole = shapeHoles[ i ];
  18639. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18640. shapeHoles[ i ] = shapeHole.reverse();
  18641. }
  18642. }
  18643. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18644. // join vertices of inner and outer paths to a single array
  18645. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18646. shapeHole = shapeHoles[ i ];
  18647. shapeVertices = shapeVertices.concat( shapeHole );
  18648. }
  18649. // vertices, normals, uvs
  18650. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18651. var vertex = shapeVertices[ i ];
  18652. vertices.push( vertex.x, vertex.y, 0 );
  18653. normals.push( 0, 0, 1 );
  18654. uvs.push( vertex.x, vertex.y ); // world uvs
  18655. }
  18656. // incides
  18657. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18658. var face = faces[ i ];
  18659. var a = face[ 0 ] + indexOffset;
  18660. var b = face[ 1 ] + indexOffset;
  18661. var c = face[ 2 ] + indexOffset;
  18662. indices.push( a, b, c );
  18663. groupCount += 3;
  18664. }
  18665. }
  18666. }
  18667. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18668. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18669. ShapeBufferGeometry.prototype.toJSON = function () {
  18670. var data = BufferGeometry.prototype.toJSON.call( this );
  18671. var shapes = this.parameters.shapes;
  18672. return toJSON$1( shapes, data );
  18673. };
  18674. //
  18675. function toJSON$1( shapes, data ) {
  18676. data.shapes = [];
  18677. if ( Array.isArray( shapes ) ) {
  18678. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18679. var shape = shapes[ i ];
  18680. data.shapes.push( shape.uuid );
  18681. }
  18682. } else {
  18683. data.shapes.push( shapes.uuid );
  18684. }
  18685. return data;
  18686. }
  18687. /**
  18688. * @author WestLangley / http://github.com/WestLangley
  18689. * @author Mugen87 / https://github.com/Mugen87
  18690. */
  18691. function EdgesGeometry( geometry, thresholdAngle ) {
  18692. BufferGeometry.call( this );
  18693. this.type = 'EdgesGeometry';
  18694. this.parameters = {
  18695. thresholdAngle: thresholdAngle
  18696. };
  18697. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18698. // buffer
  18699. var vertices = [];
  18700. // helper variables
  18701. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18702. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18703. var key, keys = [ 'a', 'b', 'c' ];
  18704. // prepare source geometry
  18705. var geometry2;
  18706. if ( geometry.isBufferGeometry ) {
  18707. geometry2 = new Geometry();
  18708. geometry2.fromBufferGeometry( geometry );
  18709. } else {
  18710. geometry2 = geometry.clone();
  18711. }
  18712. geometry2.mergeVertices();
  18713. geometry2.computeFaceNormals();
  18714. var sourceVertices = geometry2.vertices;
  18715. var faces = geometry2.faces;
  18716. // now create a data structure where each entry represents an edge with its adjoining faces
  18717. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18718. var face = faces[ i ];
  18719. for ( var j = 0; j < 3; j ++ ) {
  18720. edge1 = face[ keys[ j ] ];
  18721. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18722. edge[ 0 ] = Math.min( edge1, edge2 );
  18723. edge[ 1 ] = Math.max( edge1, edge2 );
  18724. key = edge[ 0 ] + ',' + edge[ 1 ];
  18725. if ( edges[ key ] === undefined ) {
  18726. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18727. } else {
  18728. edges[ key ].face2 = i;
  18729. }
  18730. }
  18731. }
  18732. // generate vertices
  18733. for ( key in edges ) {
  18734. var e = edges[ key ];
  18735. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18736. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18737. var vertex = sourceVertices[ e.index1 ];
  18738. vertices.push( vertex.x, vertex.y, vertex.z );
  18739. vertex = sourceVertices[ e.index2 ];
  18740. vertices.push( vertex.x, vertex.y, vertex.z );
  18741. }
  18742. }
  18743. // build geometry
  18744. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18745. }
  18746. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18747. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18748. /**
  18749. * @author mrdoob / http://mrdoob.com/
  18750. * @author Mugen87 / https://github.com/Mugen87
  18751. */
  18752. // CylinderGeometry
  18753. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18754. Geometry.call( this );
  18755. this.type = 'CylinderGeometry';
  18756. this.parameters = {
  18757. radiusTop: radiusTop,
  18758. radiusBottom: radiusBottom,
  18759. height: height,
  18760. radialSegments: radialSegments,
  18761. heightSegments: heightSegments,
  18762. openEnded: openEnded,
  18763. thetaStart: thetaStart,
  18764. thetaLength: thetaLength
  18765. };
  18766. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18767. this.mergeVertices();
  18768. }
  18769. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18770. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18771. // CylinderBufferGeometry
  18772. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18773. BufferGeometry.call( this );
  18774. this.type = 'CylinderBufferGeometry';
  18775. this.parameters = {
  18776. radiusTop: radiusTop,
  18777. radiusBottom: radiusBottom,
  18778. height: height,
  18779. radialSegments: radialSegments,
  18780. heightSegments: heightSegments,
  18781. openEnded: openEnded,
  18782. thetaStart: thetaStart,
  18783. thetaLength: thetaLength
  18784. };
  18785. var scope = this;
  18786. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18787. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18788. height = height || 1;
  18789. radialSegments = Math.floor( radialSegments ) || 8;
  18790. heightSegments = Math.floor( heightSegments ) || 1;
  18791. openEnded = openEnded !== undefined ? openEnded : false;
  18792. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18793. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18794. // buffers
  18795. var indices = [];
  18796. var vertices = [];
  18797. var normals = [];
  18798. var uvs = [];
  18799. // helper variables
  18800. var index = 0;
  18801. var indexArray = [];
  18802. var halfHeight = height / 2;
  18803. var groupStart = 0;
  18804. // generate geometry
  18805. generateTorso();
  18806. if ( openEnded === false ) {
  18807. if ( radiusTop > 0 ) generateCap( true );
  18808. if ( radiusBottom > 0 ) generateCap( false );
  18809. }
  18810. // build geometry
  18811. this.setIndex( indices );
  18812. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18813. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18814. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18815. function generateTorso() {
  18816. var x, y;
  18817. var normal = new Vector3();
  18818. var vertex = new Vector3();
  18819. var groupCount = 0;
  18820. // this will be used to calculate the normal
  18821. var slope = ( radiusBottom - radiusTop ) / height;
  18822. // generate vertices, normals and uvs
  18823. for ( y = 0; y <= heightSegments; y ++ ) {
  18824. var indexRow = [];
  18825. var v = y / heightSegments;
  18826. // calculate the radius of the current row
  18827. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18828. for ( x = 0; x <= radialSegments; x ++ ) {
  18829. var u = x / radialSegments;
  18830. var theta = u * thetaLength + thetaStart;
  18831. var sinTheta = Math.sin( theta );
  18832. var cosTheta = Math.cos( theta );
  18833. // vertex
  18834. vertex.x = radius * sinTheta;
  18835. vertex.y = - v * height + halfHeight;
  18836. vertex.z = radius * cosTheta;
  18837. vertices.push( vertex.x, vertex.y, vertex.z );
  18838. // normal
  18839. normal.set( sinTheta, slope, cosTheta ).normalize();
  18840. normals.push( normal.x, normal.y, normal.z );
  18841. // uv
  18842. uvs.push( u, 1 - v );
  18843. // save index of vertex in respective row
  18844. indexRow.push( index ++ );
  18845. }
  18846. // now save vertices of the row in our index array
  18847. indexArray.push( indexRow );
  18848. }
  18849. // generate indices
  18850. for ( x = 0; x < radialSegments; x ++ ) {
  18851. for ( y = 0; y < heightSegments; y ++ ) {
  18852. // we use the index array to access the correct indices
  18853. var a = indexArray[ y ][ x ];
  18854. var b = indexArray[ y + 1 ][ x ];
  18855. var c = indexArray[ y + 1 ][ x + 1 ];
  18856. var d = indexArray[ y ][ x + 1 ];
  18857. // faces
  18858. indices.push( a, b, d );
  18859. indices.push( b, c, d );
  18860. // update group counter
  18861. groupCount += 6;
  18862. }
  18863. }
  18864. // add a group to the geometry. this will ensure multi material support
  18865. scope.addGroup( groupStart, groupCount, 0 );
  18866. // calculate new start value for groups
  18867. groupStart += groupCount;
  18868. }
  18869. function generateCap( top ) {
  18870. var x, centerIndexStart, centerIndexEnd;
  18871. var uv = new Vector2();
  18872. var vertex = new Vector3();
  18873. var groupCount = 0;
  18874. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18875. var sign = ( top === true ) ? 1 : - 1;
  18876. // save the index of the first center vertex
  18877. centerIndexStart = index;
  18878. // first we generate the center vertex data of the cap.
  18879. // because the geometry needs one set of uvs per face,
  18880. // we must generate a center vertex per face/segment
  18881. for ( x = 1; x <= radialSegments; x ++ ) {
  18882. // vertex
  18883. vertices.push( 0, halfHeight * sign, 0 );
  18884. // normal
  18885. normals.push( 0, sign, 0 );
  18886. // uv
  18887. uvs.push( 0.5, 0.5 );
  18888. // increase index
  18889. index ++;
  18890. }
  18891. // save the index of the last center vertex
  18892. centerIndexEnd = index;
  18893. // now we generate the surrounding vertices, normals and uvs
  18894. for ( x = 0; x <= radialSegments; x ++ ) {
  18895. var u = x / radialSegments;
  18896. var theta = u * thetaLength + thetaStart;
  18897. var cosTheta = Math.cos( theta );
  18898. var sinTheta = Math.sin( theta );
  18899. // vertex
  18900. vertex.x = radius * sinTheta;
  18901. vertex.y = halfHeight * sign;
  18902. vertex.z = radius * cosTheta;
  18903. vertices.push( vertex.x, vertex.y, vertex.z );
  18904. // normal
  18905. normals.push( 0, sign, 0 );
  18906. // uv
  18907. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18908. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18909. uvs.push( uv.x, uv.y );
  18910. // increase index
  18911. index ++;
  18912. }
  18913. // generate indices
  18914. for ( x = 0; x < radialSegments; x ++ ) {
  18915. var c = centerIndexStart + x;
  18916. var i = centerIndexEnd + x;
  18917. if ( top === true ) {
  18918. // face top
  18919. indices.push( i, i + 1, c );
  18920. } else {
  18921. // face bottom
  18922. indices.push( i + 1, i, c );
  18923. }
  18924. groupCount += 3;
  18925. }
  18926. // add a group to the geometry. this will ensure multi material support
  18927. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18928. // calculate new start value for groups
  18929. groupStart += groupCount;
  18930. }
  18931. }
  18932. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18933. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18934. /**
  18935. * @author abelnation / http://github.com/abelnation
  18936. */
  18937. // ConeGeometry
  18938. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18939. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18940. this.type = 'ConeGeometry';
  18941. this.parameters = {
  18942. radius: radius,
  18943. height: height,
  18944. radialSegments: radialSegments,
  18945. heightSegments: heightSegments,
  18946. openEnded: openEnded,
  18947. thetaStart: thetaStart,
  18948. thetaLength: thetaLength
  18949. };
  18950. }
  18951. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18952. ConeGeometry.prototype.constructor = ConeGeometry;
  18953. // ConeBufferGeometry
  18954. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18955. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18956. this.type = 'ConeBufferGeometry';
  18957. this.parameters = {
  18958. radius: radius,
  18959. height: height,
  18960. radialSegments: radialSegments,
  18961. heightSegments: heightSegments,
  18962. openEnded: openEnded,
  18963. thetaStart: thetaStart,
  18964. thetaLength: thetaLength
  18965. };
  18966. }
  18967. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18968. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18969. /**
  18970. * @author benaadams / https://twitter.com/ben_a_adams
  18971. * @author Mugen87 / https://github.com/Mugen87
  18972. * @author hughes
  18973. */
  18974. // CircleGeometry
  18975. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18976. Geometry.call( this );
  18977. this.type = 'CircleGeometry';
  18978. this.parameters = {
  18979. radius: radius,
  18980. segments: segments,
  18981. thetaStart: thetaStart,
  18982. thetaLength: thetaLength
  18983. };
  18984. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18985. this.mergeVertices();
  18986. }
  18987. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18988. CircleGeometry.prototype.constructor = CircleGeometry;
  18989. // CircleBufferGeometry
  18990. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18991. BufferGeometry.call( this );
  18992. this.type = 'CircleBufferGeometry';
  18993. this.parameters = {
  18994. radius: radius,
  18995. segments: segments,
  18996. thetaStart: thetaStart,
  18997. thetaLength: thetaLength
  18998. };
  18999. radius = radius || 1;
  19000. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19001. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19002. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19003. // buffers
  19004. var indices = [];
  19005. var vertices = [];
  19006. var normals = [];
  19007. var uvs = [];
  19008. // helper variables
  19009. var i, s;
  19010. var vertex = new Vector3();
  19011. var uv = new Vector2();
  19012. // center point
  19013. vertices.push( 0, 0, 0 );
  19014. normals.push( 0, 0, 1 );
  19015. uvs.push( 0.5, 0.5 );
  19016. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  19017. var segment = thetaStart + s / segments * thetaLength;
  19018. // vertex
  19019. vertex.x = radius * Math.cos( segment );
  19020. vertex.y = radius * Math.sin( segment );
  19021. vertices.push( vertex.x, vertex.y, vertex.z );
  19022. // normal
  19023. normals.push( 0, 0, 1 );
  19024. // uvs
  19025. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19026. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19027. uvs.push( uv.x, uv.y );
  19028. }
  19029. // indices
  19030. for ( i = 1; i <= segments; i ++ ) {
  19031. indices.push( i, i + 1, 0 );
  19032. }
  19033. // build geometry
  19034. this.setIndex( indices );
  19035. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19036. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19037. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19038. }
  19039. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19040. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19041. var Geometries = /*#__PURE__*/Object.freeze({
  19042. WireframeGeometry: WireframeGeometry,
  19043. ParametricGeometry: ParametricGeometry,
  19044. ParametricBufferGeometry: ParametricBufferGeometry,
  19045. TetrahedronGeometry: TetrahedronGeometry,
  19046. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19047. OctahedronGeometry: OctahedronGeometry,
  19048. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19049. IcosahedronGeometry: IcosahedronGeometry,
  19050. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19051. DodecahedronGeometry: DodecahedronGeometry,
  19052. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19053. PolyhedronGeometry: PolyhedronGeometry,
  19054. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19055. TubeGeometry: TubeGeometry,
  19056. TubeBufferGeometry: TubeBufferGeometry,
  19057. TorusKnotGeometry: TorusKnotGeometry,
  19058. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19059. TorusGeometry: TorusGeometry,
  19060. TorusBufferGeometry: TorusBufferGeometry,
  19061. TextGeometry: TextGeometry,
  19062. TextBufferGeometry: TextBufferGeometry,
  19063. SphereGeometry: SphereGeometry,
  19064. SphereBufferGeometry: SphereBufferGeometry,
  19065. RingGeometry: RingGeometry,
  19066. RingBufferGeometry: RingBufferGeometry,
  19067. PlaneGeometry: PlaneGeometry,
  19068. PlaneBufferGeometry: PlaneBufferGeometry,
  19069. LatheGeometry: LatheGeometry,
  19070. LatheBufferGeometry: LatheBufferGeometry,
  19071. ShapeGeometry: ShapeGeometry,
  19072. ShapeBufferGeometry: ShapeBufferGeometry,
  19073. ExtrudeGeometry: ExtrudeGeometry,
  19074. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19075. EdgesGeometry: EdgesGeometry,
  19076. ConeGeometry: ConeGeometry,
  19077. ConeBufferGeometry: ConeBufferGeometry,
  19078. CylinderGeometry: CylinderGeometry,
  19079. CylinderBufferGeometry: CylinderBufferGeometry,
  19080. CircleGeometry: CircleGeometry,
  19081. CircleBufferGeometry: CircleBufferGeometry,
  19082. BoxGeometry: BoxGeometry,
  19083. BoxBufferGeometry: BoxBufferGeometry
  19084. });
  19085. /**
  19086. * @author mrdoob / http://mrdoob.com/
  19087. *
  19088. * parameters = {
  19089. * color: <THREE.Color>
  19090. * }
  19091. */
  19092. function ShadowMaterial( parameters ) {
  19093. Material.call( this );
  19094. this.type = 'ShadowMaterial';
  19095. this.color = new Color( 0x000000 );
  19096. this.transparent = true;
  19097. this.setValues( parameters );
  19098. }
  19099. ShadowMaterial.prototype = Object.create( Material.prototype );
  19100. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19101. ShadowMaterial.prototype.isShadowMaterial = true;
  19102. ShadowMaterial.prototype.copy = function ( source ) {
  19103. Material.prototype.copy.call( this, source );
  19104. this.color.copy( source.color );
  19105. return this;
  19106. };
  19107. /**
  19108. * @author mrdoob / http://mrdoob.com/
  19109. */
  19110. function RawShaderMaterial( parameters ) {
  19111. ShaderMaterial.call( this, parameters );
  19112. this.type = 'RawShaderMaterial';
  19113. }
  19114. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19115. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19116. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19117. /**
  19118. * @author WestLangley / http://github.com/WestLangley
  19119. *
  19120. * parameters = {
  19121. * color: <hex>,
  19122. * roughness: <float>,
  19123. * metalness: <float>,
  19124. * opacity: <float>,
  19125. *
  19126. * map: new THREE.Texture( <Image> ),
  19127. *
  19128. * lightMap: new THREE.Texture( <Image> ),
  19129. * lightMapIntensity: <float>
  19130. *
  19131. * aoMap: new THREE.Texture( <Image> ),
  19132. * aoMapIntensity: <float>
  19133. *
  19134. * emissive: <hex>,
  19135. * emissiveIntensity: <float>
  19136. * emissiveMap: new THREE.Texture( <Image> ),
  19137. *
  19138. * bumpMap: new THREE.Texture( <Image> ),
  19139. * bumpScale: <float>,
  19140. *
  19141. * normalMap: new THREE.Texture( <Image> ),
  19142. * normalMapType: THREE.TangentSpaceNormalMap,
  19143. * normalScale: <Vector2>,
  19144. *
  19145. * displacementMap: new THREE.Texture( <Image> ),
  19146. * displacementScale: <float>,
  19147. * displacementBias: <float>,
  19148. *
  19149. * roughnessMap: new THREE.Texture( <Image> ),
  19150. *
  19151. * metalnessMap: new THREE.Texture( <Image> ),
  19152. *
  19153. * alphaMap: new THREE.Texture( <Image> ),
  19154. *
  19155. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19156. * envMapIntensity: <float>
  19157. *
  19158. * refractionRatio: <float>,
  19159. *
  19160. * wireframe: <boolean>,
  19161. * wireframeLinewidth: <float>,
  19162. *
  19163. * skinning: <bool>,
  19164. * morphTargets: <bool>,
  19165. * morphNormals: <bool>
  19166. * }
  19167. */
  19168. function MeshStandardMaterial( parameters ) {
  19169. Material.call( this );
  19170. this.defines = { 'STANDARD': '' };
  19171. this.type = 'MeshStandardMaterial';
  19172. this.color = new Color( 0xffffff ); // diffuse
  19173. this.roughness = 0.5;
  19174. this.metalness = 0.5;
  19175. this.map = null;
  19176. this.lightMap = null;
  19177. this.lightMapIntensity = 1.0;
  19178. this.aoMap = null;
  19179. this.aoMapIntensity = 1.0;
  19180. this.emissive = new Color( 0x000000 );
  19181. this.emissiveIntensity = 1.0;
  19182. this.emissiveMap = null;
  19183. this.bumpMap = null;
  19184. this.bumpScale = 1;
  19185. this.normalMap = null;
  19186. this.normalMapType = TangentSpaceNormalMap;
  19187. this.normalScale = new Vector2( 1, 1 );
  19188. this.displacementMap = null;
  19189. this.displacementScale = 1;
  19190. this.displacementBias = 0;
  19191. this.roughnessMap = null;
  19192. this.metalnessMap = null;
  19193. this.alphaMap = null;
  19194. this.envMap = null;
  19195. this.envMapIntensity = 1.0;
  19196. this.refractionRatio = 0.98;
  19197. this.wireframe = false;
  19198. this.wireframeLinewidth = 1;
  19199. this.wireframeLinecap = 'round';
  19200. this.wireframeLinejoin = 'round';
  19201. this.skinning = false;
  19202. this.morphTargets = false;
  19203. this.morphNormals = false;
  19204. this.setValues( parameters );
  19205. }
  19206. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  19207. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19208. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19209. MeshStandardMaterial.prototype.copy = function ( source ) {
  19210. Material.prototype.copy.call( this, source );
  19211. this.defines = { 'STANDARD': '' };
  19212. this.color.copy( source.color );
  19213. this.roughness = source.roughness;
  19214. this.metalness = source.metalness;
  19215. this.map = source.map;
  19216. this.lightMap = source.lightMap;
  19217. this.lightMapIntensity = source.lightMapIntensity;
  19218. this.aoMap = source.aoMap;
  19219. this.aoMapIntensity = source.aoMapIntensity;
  19220. this.emissive.copy( source.emissive );
  19221. this.emissiveMap = source.emissiveMap;
  19222. this.emissiveIntensity = source.emissiveIntensity;
  19223. this.bumpMap = source.bumpMap;
  19224. this.bumpScale = source.bumpScale;
  19225. this.normalMap = source.normalMap;
  19226. this.normalMapType = source.normalMapType;
  19227. this.normalScale.copy( source.normalScale );
  19228. this.displacementMap = source.displacementMap;
  19229. this.displacementScale = source.displacementScale;
  19230. this.displacementBias = source.displacementBias;
  19231. this.roughnessMap = source.roughnessMap;
  19232. this.metalnessMap = source.metalnessMap;
  19233. this.alphaMap = source.alphaMap;
  19234. this.envMap = source.envMap;
  19235. this.envMapIntensity = source.envMapIntensity;
  19236. this.refractionRatio = source.refractionRatio;
  19237. this.wireframe = source.wireframe;
  19238. this.wireframeLinewidth = source.wireframeLinewidth;
  19239. this.wireframeLinecap = source.wireframeLinecap;
  19240. this.wireframeLinejoin = source.wireframeLinejoin;
  19241. this.skinning = source.skinning;
  19242. this.morphTargets = source.morphTargets;
  19243. this.morphNormals = source.morphNormals;
  19244. return this;
  19245. };
  19246. /**
  19247. * @author WestLangley / http://github.com/WestLangley
  19248. *
  19249. * parameters = {
  19250. * reflectivity: <float>
  19251. * clearCoat: <float>
  19252. * clearCoatRoughness: <float>
  19253. *
  19254. * clearCoatNormalScale: <Vector2>,
  19255. * clearCoatNormalMap: new THREE.Texture( <Image> ),
  19256. * }
  19257. */
  19258. function MeshPhysicalMaterial( parameters ) {
  19259. MeshStandardMaterial.call( this );
  19260. this.defines = { 'PHYSICAL': '' };
  19261. this.type = 'MeshPhysicalMaterial';
  19262. this.reflectivity = 0.5; // maps to F0 = 0.04
  19263. this.clearCoat = 0.0;
  19264. this.clearCoatRoughness = 0.0;
  19265. this.clearCoatNormalScale = new Vector2( 1, 1 );
  19266. this.clearCoatNormalMap = null;
  19267. this.setValues( parameters );
  19268. }
  19269. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  19270. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19271. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19272. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  19273. MeshStandardMaterial.prototype.copy.call( this, source );
  19274. this.defines = { 'PHYSICAL': '' };
  19275. this.reflectivity = source.reflectivity;
  19276. this.clearCoat = source.clearCoat;
  19277. this.clearCoatRoughness = source.clearCoatRoughness;
  19278. this.clearCoatNormalMap = source.clearCoatNormalMap;
  19279. this.clearCoatNormalScale.copy( source.clearCoatNormalScale );
  19280. return this;
  19281. };
  19282. /**
  19283. * @author mrdoob / http://mrdoob.com/
  19284. * @author alteredq / http://alteredqualia.com/
  19285. *
  19286. * parameters = {
  19287. * color: <hex>,
  19288. * specular: <hex>,
  19289. * shininess: <float>,
  19290. * opacity: <float>,
  19291. *
  19292. * map: new THREE.Texture( <Image> ),
  19293. *
  19294. * lightMap: new THREE.Texture( <Image> ),
  19295. * lightMapIntensity: <float>
  19296. *
  19297. * aoMap: new THREE.Texture( <Image> ),
  19298. * aoMapIntensity: <float>
  19299. *
  19300. * emissive: <hex>,
  19301. * emissiveIntensity: <float>
  19302. * emissiveMap: new THREE.Texture( <Image> ),
  19303. *
  19304. * bumpMap: new THREE.Texture( <Image> ),
  19305. * bumpScale: <float>,
  19306. *
  19307. * normalMap: new THREE.Texture( <Image> ),
  19308. * normalMapType: THREE.TangentSpaceNormalMap,
  19309. * normalScale: <Vector2>,
  19310. *
  19311. * displacementMap: new THREE.Texture( <Image> ),
  19312. * displacementScale: <float>,
  19313. * displacementBias: <float>,
  19314. *
  19315. * specularMap: new THREE.Texture( <Image> ),
  19316. *
  19317. * alphaMap: new THREE.Texture( <Image> ),
  19318. *
  19319. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19320. * combine: THREE.Multiply,
  19321. * reflectivity: <float>,
  19322. * refractionRatio: <float>,
  19323. *
  19324. * wireframe: <boolean>,
  19325. * wireframeLinewidth: <float>,
  19326. *
  19327. * skinning: <bool>,
  19328. * morphTargets: <bool>,
  19329. * morphNormals: <bool>
  19330. * }
  19331. */
  19332. function MeshPhongMaterial( parameters ) {
  19333. Material.call( this );
  19334. this.type = 'MeshPhongMaterial';
  19335. this.color = new Color( 0xffffff ); // diffuse
  19336. this.specular = new Color( 0x111111 );
  19337. this.shininess = 30;
  19338. this.map = null;
  19339. this.lightMap = null;
  19340. this.lightMapIntensity = 1.0;
  19341. this.aoMap = null;
  19342. this.aoMapIntensity = 1.0;
  19343. this.emissive = new Color( 0x000000 );
  19344. this.emissiveIntensity = 1.0;
  19345. this.emissiveMap = null;
  19346. this.bumpMap = null;
  19347. this.bumpScale = 1;
  19348. this.normalMap = null;
  19349. this.normalMapType = TangentSpaceNormalMap;
  19350. this.normalScale = new Vector2( 1, 1 );
  19351. this.displacementMap = null;
  19352. this.displacementScale = 1;
  19353. this.displacementBias = 0;
  19354. this.specularMap = null;
  19355. this.alphaMap = null;
  19356. this.envMap = null;
  19357. this.combine = MultiplyOperation;
  19358. this.reflectivity = 1;
  19359. this.refractionRatio = 0.98;
  19360. this.wireframe = false;
  19361. this.wireframeLinewidth = 1;
  19362. this.wireframeLinecap = 'round';
  19363. this.wireframeLinejoin = 'round';
  19364. this.skinning = false;
  19365. this.morphTargets = false;
  19366. this.morphNormals = false;
  19367. this.setValues( parameters );
  19368. }
  19369. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19370. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19371. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19372. MeshPhongMaterial.prototype.copy = function ( source ) {
  19373. Material.prototype.copy.call( this, source );
  19374. this.color.copy( source.color );
  19375. this.specular.copy( source.specular );
  19376. this.shininess = source.shininess;
  19377. this.map = source.map;
  19378. this.lightMap = source.lightMap;
  19379. this.lightMapIntensity = source.lightMapIntensity;
  19380. this.aoMap = source.aoMap;
  19381. this.aoMapIntensity = source.aoMapIntensity;
  19382. this.emissive.copy( source.emissive );
  19383. this.emissiveMap = source.emissiveMap;
  19384. this.emissiveIntensity = source.emissiveIntensity;
  19385. this.bumpMap = source.bumpMap;
  19386. this.bumpScale = source.bumpScale;
  19387. this.normalMap = source.normalMap;
  19388. this.normalMapType = source.normalMapType;
  19389. this.normalScale.copy( source.normalScale );
  19390. this.displacementMap = source.displacementMap;
  19391. this.displacementScale = source.displacementScale;
  19392. this.displacementBias = source.displacementBias;
  19393. this.specularMap = source.specularMap;
  19394. this.alphaMap = source.alphaMap;
  19395. this.envMap = source.envMap;
  19396. this.combine = source.combine;
  19397. this.reflectivity = source.reflectivity;
  19398. this.refractionRatio = source.refractionRatio;
  19399. this.wireframe = source.wireframe;
  19400. this.wireframeLinewidth = source.wireframeLinewidth;
  19401. this.wireframeLinecap = source.wireframeLinecap;
  19402. this.wireframeLinejoin = source.wireframeLinejoin;
  19403. this.skinning = source.skinning;
  19404. this.morphTargets = source.morphTargets;
  19405. this.morphNormals = source.morphNormals;
  19406. return this;
  19407. };
  19408. /**
  19409. * @author takahirox / http://github.com/takahirox
  19410. *
  19411. * parameters = {
  19412. * gradientMap: new THREE.Texture( <Image> )
  19413. * }
  19414. */
  19415. function MeshToonMaterial( parameters ) {
  19416. MeshPhongMaterial.call( this );
  19417. this.defines = { 'TOON': '' };
  19418. this.type = 'MeshToonMaterial';
  19419. this.gradientMap = null;
  19420. this.setValues( parameters );
  19421. }
  19422. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19423. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19424. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19425. MeshToonMaterial.prototype.copy = function ( source ) {
  19426. MeshPhongMaterial.prototype.copy.call( this, source );
  19427. this.gradientMap = source.gradientMap;
  19428. return this;
  19429. };
  19430. /**
  19431. * @author mrdoob / http://mrdoob.com/
  19432. * @author WestLangley / http://github.com/WestLangley
  19433. *
  19434. * parameters = {
  19435. * opacity: <float>,
  19436. *
  19437. * bumpMap: new THREE.Texture( <Image> ),
  19438. * bumpScale: <float>,
  19439. *
  19440. * normalMap: new THREE.Texture( <Image> ),
  19441. * normalMapType: THREE.TangentSpaceNormalMap,
  19442. * normalScale: <Vector2>,
  19443. *
  19444. * displacementMap: new THREE.Texture( <Image> ),
  19445. * displacementScale: <float>,
  19446. * displacementBias: <float>,
  19447. *
  19448. * wireframe: <boolean>,
  19449. * wireframeLinewidth: <float>
  19450. *
  19451. * skinning: <bool>,
  19452. * morphTargets: <bool>,
  19453. * morphNormals: <bool>
  19454. * }
  19455. */
  19456. function MeshNormalMaterial( parameters ) {
  19457. Material.call( this );
  19458. this.type = 'MeshNormalMaterial';
  19459. this.bumpMap = null;
  19460. this.bumpScale = 1;
  19461. this.normalMap = null;
  19462. this.normalMapType = TangentSpaceNormalMap;
  19463. this.normalScale = new Vector2( 1, 1 );
  19464. this.displacementMap = null;
  19465. this.displacementScale = 1;
  19466. this.displacementBias = 0;
  19467. this.wireframe = false;
  19468. this.wireframeLinewidth = 1;
  19469. this.fog = false;
  19470. this.lights = false;
  19471. this.skinning = false;
  19472. this.morphTargets = false;
  19473. this.morphNormals = false;
  19474. this.setValues( parameters );
  19475. }
  19476. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19477. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19478. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19479. MeshNormalMaterial.prototype.copy = function ( source ) {
  19480. Material.prototype.copy.call( this, source );
  19481. this.bumpMap = source.bumpMap;
  19482. this.bumpScale = source.bumpScale;
  19483. this.normalMap = source.normalMap;
  19484. this.normalMapType = source.normalMapType;
  19485. this.normalScale.copy( source.normalScale );
  19486. this.displacementMap = source.displacementMap;
  19487. this.displacementScale = source.displacementScale;
  19488. this.displacementBias = source.displacementBias;
  19489. this.wireframe = source.wireframe;
  19490. this.wireframeLinewidth = source.wireframeLinewidth;
  19491. this.skinning = source.skinning;
  19492. this.morphTargets = source.morphTargets;
  19493. this.morphNormals = source.morphNormals;
  19494. return this;
  19495. };
  19496. /**
  19497. * @author mrdoob / http://mrdoob.com/
  19498. * @author alteredq / http://alteredqualia.com/
  19499. *
  19500. * parameters = {
  19501. * color: <hex>,
  19502. * opacity: <float>,
  19503. *
  19504. * map: new THREE.Texture( <Image> ),
  19505. *
  19506. * lightMap: new THREE.Texture( <Image> ),
  19507. * lightMapIntensity: <float>
  19508. *
  19509. * aoMap: new THREE.Texture( <Image> ),
  19510. * aoMapIntensity: <float>
  19511. *
  19512. * emissive: <hex>,
  19513. * emissiveIntensity: <float>
  19514. * emissiveMap: new THREE.Texture( <Image> ),
  19515. *
  19516. * specularMap: new THREE.Texture( <Image> ),
  19517. *
  19518. * alphaMap: new THREE.Texture( <Image> ),
  19519. *
  19520. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19521. * combine: THREE.Multiply,
  19522. * reflectivity: <float>,
  19523. * refractionRatio: <float>,
  19524. *
  19525. * wireframe: <boolean>,
  19526. * wireframeLinewidth: <float>,
  19527. *
  19528. * skinning: <bool>,
  19529. * morphTargets: <bool>,
  19530. * morphNormals: <bool>
  19531. * }
  19532. */
  19533. function MeshLambertMaterial( parameters ) {
  19534. Material.call( this );
  19535. this.type = 'MeshLambertMaterial';
  19536. this.color = new Color( 0xffffff ); // diffuse
  19537. this.map = null;
  19538. this.lightMap = null;
  19539. this.lightMapIntensity = 1.0;
  19540. this.aoMap = null;
  19541. this.aoMapIntensity = 1.0;
  19542. this.emissive = new Color( 0x000000 );
  19543. this.emissiveIntensity = 1.0;
  19544. this.emissiveMap = null;
  19545. this.specularMap = null;
  19546. this.alphaMap = null;
  19547. this.envMap = null;
  19548. this.combine = MultiplyOperation;
  19549. this.reflectivity = 1;
  19550. this.refractionRatio = 0.98;
  19551. this.wireframe = false;
  19552. this.wireframeLinewidth = 1;
  19553. this.wireframeLinecap = 'round';
  19554. this.wireframeLinejoin = 'round';
  19555. this.skinning = false;
  19556. this.morphTargets = false;
  19557. this.morphNormals = false;
  19558. this.setValues( parameters );
  19559. }
  19560. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19561. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19562. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19563. MeshLambertMaterial.prototype.copy = function ( source ) {
  19564. Material.prototype.copy.call( this, source );
  19565. this.color.copy( source.color );
  19566. this.map = source.map;
  19567. this.lightMap = source.lightMap;
  19568. this.lightMapIntensity = source.lightMapIntensity;
  19569. this.aoMap = source.aoMap;
  19570. this.aoMapIntensity = source.aoMapIntensity;
  19571. this.emissive.copy( source.emissive );
  19572. this.emissiveMap = source.emissiveMap;
  19573. this.emissiveIntensity = source.emissiveIntensity;
  19574. this.specularMap = source.specularMap;
  19575. this.alphaMap = source.alphaMap;
  19576. this.envMap = source.envMap;
  19577. this.combine = source.combine;
  19578. this.reflectivity = source.reflectivity;
  19579. this.refractionRatio = source.refractionRatio;
  19580. this.wireframe = source.wireframe;
  19581. this.wireframeLinewidth = source.wireframeLinewidth;
  19582. this.wireframeLinecap = source.wireframeLinecap;
  19583. this.wireframeLinejoin = source.wireframeLinejoin;
  19584. this.skinning = source.skinning;
  19585. this.morphTargets = source.morphTargets;
  19586. this.morphNormals = source.morphNormals;
  19587. return this;
  19588. };
  19589. /**
  19590. * @author WestLangley / http://github.com/WestLangley
  19591. *
  19592. * parameters = {
  19593. * color: <hex>,
  19594. * opacity: <float>,
  19595. *
  19596. * matcap: new THREE.Texture( <Image> ),
  19597. *
  19598. * map: new THREE.Texture( <Image> ),
  19599. *
  19600. * bumpMap: new THREE.Texture( <Image> ),
  19601. * bumpScale: <float>,
  19602. *
  19603. * normalMap: new THREE.Texture( <Image> ),
  19604. * normalMapType: THREE.TangentSpaceNormalMap,
  19605. * normalScale: <Vector2>,
  19606. *
  19607. * displacementMap: new THREE.Texture( <Image> ),
  19608. * displacementScale: <float>,
  19609. * displacementBias: <float>,
  19610. *
  19611. * alphaMap: new THREE.Texture( <Image> ),
  19612. *
  19613. * skinning: <bool>,
  19614. * morphTargets: <bool>,
  19615. * morphNormals: <bool>
  19616. * }
  19617. */
  19618. function MeshMatcapMaterial( parameters ) {
  19619. Material.call( this );
  19620. this.defines = { 'MATCAP': '' };
  19621. this.type = 'MeshMatcapMaterial';
  19622. this.color = new Color( 0xffffff ); // diffuse
  19623. this.matcap = null;
  19624. this.map = null;
  19625. this.bumpMap = null;
  19626. this.bumpScale = 1;
  19627. this.normalMap = null;
  19628. this.normalMapType = TangentSpaceNormalMap;
  19629. this.normalScale = new Vector2( 1, 1 );
  19630. this.displacementMap = null;
  19631. this.displacementScale = 1;
  19632. this.displacementBias = 0;
  19633. this.alphaMap = null;
  19634. this.skinning = false;
  19635. this.morphTargets = false;
  19636. this.morphNormals = false;
  19637. this.lights = false;
  19638. this.setValues( parameters );
  19639. }
  19640. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19641. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19642. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19643. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19644. Material.prototype.copy.call( this, source );
  19645. this.defines = { 'MATCAP': '' };
  19646. this.color.copy( source.color );
  19647. this.matcap = source.matcap;
  19648. this.map = source.map;
  19649. this.bumpMap = source.bumpMap;
  19650. this.bumpScale = source.bumpScale;
  19651. this.normalMap = source.normalMap;
  19652. this.normalMapType = source.normalMapType;
  19653. this.normalScale.copy( source.normalScale );
  19654. this.displacementMap = source.displacementMap;
  19655. this.displacementScale = source.displacementScale;
  19656. this.displacementBias = source.displacementBias;
  19657. this.alphaMap = source.alphaMap;
  19658. this.skinning = source.skinning;
  19659. this.morphTargets = source.morphTargets;
  19660. this.morphNormals = source.morphNormals;
  19661. return this;
  19662. };
  19663. /**
  19664. * @author alteredq / http://alteredqualia.com/
  19665. *
  19666. * parameters = {
  19667. * color: <hex>,
  19668. * opacity: <float>,
  19669. *
  19670. * linewidth: <float>,
  19671. *
  19672. * scale: <float>,
  19673. * dashSize: <float>,
  19674. * gapSize: <float>
  19675. * }
  19676. */
  19677. function LineDashedMaterial( parameters ) {
  19678. LineBasicMaterial.call( this );
  19679. this.type = 'LineDashedMaterial';
  19680. this.scale = 1;
  19681. this.dashSize = 3;
  19682. this.gapSize = 1;
  19683. this.setValues( parameters );
  19684. }
  19685. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19686. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19687. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19688. LineDashedMaterial.prototype.copy = function ( source ) {
  19689. LineBasicMaterial.prototype.copy.call( this, source );
  19690. this.scale = source.scale;
  19691. this.dashSize = source.dashSize;
  19692. this.gapSize = source.gapSize;
  19693. return this;
  19694. };
  19695. var Materials = /*#__PURE__*/Object.freeze({
  19696. ShadowMaterial: ShadowMaterial,
  19697. SpriteMaterial: SpriteMaterial,
  19698. RawShaderMaterial: RawShaderMaterial,
  19699. ShaderMaterial: ShaderMaterial,
  19700. PointsMaterial: PointsMaterial,
  19701. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19702. MeshStandardMaterial: MeshStandardMaterial,
  19703. MeshPhongMaterial: MeshPhongMaterial,
  19704. MeshToonMaterial: MeshToonMaterial,
  19705. MeshNormalMaterial: MeshNormalMaterial,
  19706. MeshLambertMaterial: MeshLambertMaterial,
  19707. MeshDepthMaterial: MeshDepthMaterial,
  19708. MeshDistanceMaterial: MeshDistanceMaterial,
  19709. MeshBasicMaterial: MeshBasicMaterial,
  19710. MeshMatcapMaterial: MeshMatcapMaterial,
  19711. LineDashedMaterial: LineDashedMaterial,
  19712. LineBasicMaterial: LineBasicMaterial,
  19713. Material: Material
  19714. });
  19715. /**
  19716. * @author tschw
  19717. * @author Ben Houston / http://clara.io/
  19718. * @author David Sarno / http://lighthaus.us/
  19719. */
  19720. var AnimationUtils = {
  19721. // same as Array.prototype.slice, but also works on typed arrays
  19722. arraySlice: function ( array, from, to ) {
  19723. if ( AnimationUtils.isTypedArray( array ) ) {
  19724. // in ios9 array.subarray(from, undefined) will return empty array
  19725. // but array.subarray(from) or array.subarray(from, len) is correct
  19726. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19727. }
  19728. return array.slice( from, to );
  19729. },
  19730. // converts an array to a specific type
  19731. convertArray: function ( array, type, forceClone ) {
  19732. if ( ! array || // let 'undefined' and 'null' pass
  19733. ! forceClone && array.constructor === type ) return array;
  19734. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19735. return new type( array ); // create typed array
  19736. }
  19737. return Array.prototype.slice.call( array ); // create Array
  19738. },
  19739. isTypedArray: function ( object ) {
  19740. return ArrayBuffer.isView( object ) &&
  19741. ! ( object instanceof DataView );
  19742. },
  19743. // returns an array by which times and values can be sorted
  19744. getKeyframeOrder: function ( times ) {
  19745. function compareTime( i, j ) {
  19746. return times[ i ] - times[ j ];
  19747. }
  19748. var n = times.length;
  19749. var result = new Array( n );
  19750. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19751. result.sort( compareTime );
  19752. return result;
  19753. },
  19754. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19755. sortedArray: function ( values, stride, order ) {
  19756. var nValues = values.length;
  19757. var result = new values.constructor( nValues );
  19758. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19759. var srcOffset = order[ i ] * stride;
  19760. for ( var j = 0; j !== stride; ++ j ) {
  19761. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19762. }
  19763. }
  19764. return result;
  19765. },
  19766. // function for parsing AOS keyframe formats
  19767. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19768. var i = 1, key = jsonKeys[ 0 ];
  19769. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19770. key = jsonKeys[ i ++ ];
  19771. }
  19772. if ( key === undefined ) return; // no data
  19773. var value = key[ valuePropertyName ];
  19774. if ( value === undefined ) return; // no data
  19775. if ( Array.isArray( value ) ) {
  19776. do {
  19777. value = key[ valuePropertyName ];
  19778. if ( value !== undefined ) {
  19779. times.push( key.time );
  19780. values.push.apply( values, value ); // push all elements
  19781. }
  19782. key = jsonKeys[ i ++ ];
  19783. } while ( key !== undefined );
  19784. } else if ( value.toArray !== undefined ) {
  19785. // ...assume THREE.Math-ish
  19786. do {
  19787. value = key[ valuePropertyName ];
  19788. if ( value !== undefined ) {
  19789. times.push( key.time );
  19790. value.toArray( values, values.length );
  19791. }
  19792. key = jsonKeys[ i ++ ];
  19793. } while ( key !== undefined );
  19794. } else {
  19795. // otherwise push as-is
  19796. do {
  19797. value = key[ valuePropertyName ];
  19798. if ( value !== undefined ) {
  19799. times.push( key.time );
  19800. values.push( value );
  19801. }
  19802. key = jsonKeys[ i ++ ];
  19803. } while ( key !== undefined );
  19804. }
  19805. }
  19806. };
  19807. /**
  19808. * Abstract base class of interpolants over parametric samples.
  19809. *
  19810. * The parameter domain is one dimensional, typically the time or a path
  19811. * along a curve defined by the data.
  19812. *
  19813. * The sample values can have any dimensionality and derived classes may
  19814. * apply special interpretations to the data.
  19815. *
  19816. * This class provides the interval seek in a Template Method, deferring
  19817. * the actual interpolation to derived classes.
  19818. *
  19819. * Time complexity is O(1) for linear access crossing at most two points
  19820. * and O(log N) for random access, where N is the number of positions.
  19821. *
  19822. * References:
  19823. *
  19824. * http://www.oodesign.com/template-method-pattern.html
  19825. *
  19826. * @author tschw
  19827. */
  19828. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19829. this.parameterPositions = parameterPositions;
  19830. this._cachedIndex = 0;
  19831. this.resultBuffer = resultBuffer !== undefined ?
  19832. resultBuffer : new sampleValues.constructor( sampleSize );
  19833. this.sampleValues = sampleValues;
  19834. this.valueSize = sampleSize;
  19835. }
  19836. Object.assign( Interpolant.prototype, {
  19837. evaluate: function ( t ) {
  19838. var pp = this.parameterPositions,
  19839. i1 = this._cachedIndex,
  19840. t1 = pp[ i1 ],
  19841. t0 = pp[ i1 - 1 ];
  19842. validate_interval: {
  19843. seek: {
  19844. var right;
  19845. linear_scan: {
  19846. //- See http://jsperf.com/comparison-to-undefined/3
  19847. //- slower code:
  19848. //-
  19849. //- if ( t >= t1 || t1 === undefined ) {
  19850. forward_scan: if ( ! ( t < t1 ) ) {
  19851. for ( var giveUpAt = i1 + 2; ; ) {
  19852. if ( t1 === undefined ) {
  19853. if ( t < t0 ) break forward_scan;
  19854. // after end
  19855. i1 = pp.length;
  19856. this._cachedIndex = i1;
  19857. return this.afterEnd_( i1 - 1, t, t0 );
  19858. }
  19859. if ( i1 === giveUpAt ) break; // this loop
  19860. t0 = t1;
  19861. t1 = pp[ ++ i1 ];
  19862. if ( t < t1 ) {
  19863. // we have arrived at the sought interval
  19864. break seek;
  19865. }
  19866. }
  19867. // prepare binary search on the right side of the index
  19868. right = pp.length;
  19869. break linear_scan;
  19870. }
  19871. //- slower code:
  19872. //- if ( t < t0 || t0 === undefined ) {
  19873. if ( ! ( t >= t0 ) ) {
  19874. // looping?
  19875. var t1global = pp[ 1 ];
  19876. if ( t < t1global ) {
  19877. i1 = 2; // + 1, using the scan for the details
  19878. t0 = t1global;
  19879. }
  19880. // linear reverse scan
  19881. for ( var giveUpAt = i1 - 2; ; ) {
  19882. if ( t0 === undefined ) {
  19883. // before start
  19884. this._cachedIndex = 0;
  19885. return this.beforeStart_( 0, t, t1 );
  19886. }
  19887. if ( i1 === giveUpAt ) break; // this loop
  19888. t1 = t0;
  19889. t0 = pp[ -- i1 - 1 ];
  19890. if ( t >= t0 ) {
  19891. // we have arrived at the sought interval
  19892. break seek;
  19893. }
  19894. }
  19895. // prepare binary search on the left side of the index
  19896. right = i1;
  19897. i1 = 0;
  19898. break linear_scan;
  19899. }
  19900. // the interval is valid
  19901. break validate_interval;
  19902. } // linear scan
  19903. // binary search
  19904. while ( i1 < right ) {
  19905. var mid = ( i1 + right ) >>> 1;
  19906. if ( t < pp[ mid ] ) {
  19907. right = mid;
  19908. } else {
  19909. i1 = mid + 1;
  19910. }
  19911. }
  19912. t1 = pp[ i1 ];
  19913. t0 = pp[ i1 - 1 ];
  19914. // check boundary cases, again
  19915. if ( t0 === undefined ) {
  19916. this._cachedIndex = 0;
  19917. return this.beforeStart_( 0, t, t1 );
  19918. }
  19919. if ( t1 === undefined ) {
  19920. i1 = pp.length;
  19921. this._cachedIndex = i1;
  19922. return this.afterEnd_( i1 - 1, t0, t );
  19923. }
  19924. } // seek
  19925. this._cachedIndex = i1;
  19926. this.intervalChanged_( i1, t0, t1 );
  19927. } // validate_interval
  19928. return this.interpolate_( i1, t0, t, t1 );
  19929. },
  19930. settings: null, // optional, subclass-specific settings structure
  19931. // Note: The indirection allows central control of many interpolants.
  19932. // --- Protected interface
  19933. DefaultSettings_: {},
  19934. getSettings_: function () {
  19935. return this.settings || this.DefaultSettings_;
  19936. },
  19937. copySampleValue_: function ( index ) {
  19938. // copies a sample value to the result buffer
  19939. var result = this.resultBuffer,
  19940. values = this.sampleValues,
  19941. stride = this.valueSize,
  19942. offset = index * stride;
  19943. for ( var i = 0; i !== stride; ++ i ) {
  19944. result[ i ] = values[ offset + i ];
  19945. }
  19946. return result;
  19947. },
  19948. // Template methods for derived classes:
  19949. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19950. throw new Error( 'call to abstract method' );
  19951. // implementations shall return this.resultBuffer
  19952. },
  19953. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19954. // empty
  19955. }
  19956. } );
  19957. //!\ DECLARE ALIAS AFTER assign prototype !
  19958. Object.assign( Interpolant.prototype, {
  19959. //( 0, t, t0 ), returns this.resultBuffer
  19960. beforeStart_: Interpolant.prototype.copySampleValue_,
  19961. //( N-1, tN-1, t ), returns this.resultBuffer
  19962. afterEnd_: Interpolant.prototype.copySampleValue_,
  19963. } );
  19964. /**
  19965. * Fast and simple cubic spline interpolant.
  19966. *
  19967. * It was derived from a Hermitian construction setting the first derivative
  19968. * at each sample position to the linear slope between neighboring positions
  19969. * over their parameter interval.
  19970. *
  19971. * @author tschw
  19972. */
  19973. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19974. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19975. this._weightPrev = - 0;
  19976. this._offsetPrev = - 0;
  19977. this._weightNext = - 0;
  19978. this._offsetNext = - 0;
  19979. }
  19980. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19981. constructor: CubicInterpolant,
  19982. DefaultSettings_: {
  19983. endingStart: ZeroCurvatureEnding,
  19984. endingEnd: ZeroCurvatureEnding
  19985. },
  19986. intervalChanged_: function ( i1, t0, t1 ) {
  19987. var pp = this.parameterPositions,
  19988. iPrev = i1 - 2,
  19989. iNext = i1 + 1,
  19990. tPrev = pp[ iPrev ],
  19991. tNext = pp[ iNext ];
  19992. if ( tPrev === undefined ) {
  19993. switch ( this.getSettings_().endingStart ) {
  19994. case ZeroSlopeEnding:
  19995. // f'(t0) = 0
  19996. iPrev = i1;
  19997. tPrev = 2 * t0 - t1;
  19998. break;
  19999. case WrapAroundEnding:
  20000. // use the other end of the curve
  20001. iPrev = pp.length - 2;
  20002. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20003. break;
  20004. default: // ZeroCurvatureEnding
  20005. // f''(t0) = 0 a.k.a. Natural Spline
  20006. iPrev = i1;
  20007. tPrev = t1;
  20008. }
  20009. }
  20010. if ( tNext === undefined ) {
  20011. switch ( this.getSettings_().endingEnd ) {
  20012. case ZeroSlopeEnding:
  20013. // f'(tN) = 0
  20014. iNext = i1;
  20015. tNext = 2 * t1 - t0;
  20016. break;
  20017. case WrapAroundEnding:
  20018. // use the other end of the curve
  20019. iNext = 1;
  20020. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20021. break;
  20022. default: // ZeroCurvatureEnding
  20023. // f''(tN) = 0, a.k.a. Natural Spline
  20024. iNext = i1 - 1;
  20025. tNext = t0;
  20026. }
  20027. }
  20028. var halfDt = ( t1 - t0 ) * 0.5,
  20029. stride = this.valueSize;
  20030. this._weightPrev = halfDt / ( t0 - tPrev );
  20031. this._weightNext = halfDt / ( tNext - t1 );
  20032. this._offsetPrev = iPrev * stride;
  20033. this._offsetNext = iNext * stride;
  20034. },
  20035. interpolate_: function ( i1, t0, t, t1 ) {
  20036. var result = this.resultBuffer,
  20037. values = this.sampleValues,
  20038. stride = this.valueSize,
  20039. o1 = i1 * stride, o0 = o1 - stride,
  20040. oP = this._offsetPrev, oN = this._offsetNext,
  20041. wP = this._weightPrev, wN = this._weightNext,
  20042. p = ( t - t0 ) / ( t1 - t0 ),
  20043. pp = p * p,
  20044. ppp = pp * p;
  20045. // evaluate polynomials
  20046. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20047. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20048. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20049. var sN = wN * ppp - wN * pp;
  20050. // combine data linearly
  20051. for ( var i = 0; i !== stride; ++ i ) {
  20052. result[ i ] =
  20053. sP * values[ oP + i ] +
  20054. s0 * values[ o0 + i ] +
  20055. s1 * values[ o1 + i ] +
  20056. sN * values[ oN + i ];
  20057. }
  20058. return result;
  20059. }
  20060. } );
  20061. /**
  20062. * @author tschw
  20063. */
  20064. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20065. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20066. }
  20067. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20068. constructor: LinearInterpolant,
  20069. interpolate_: function ( i1, t0, t, t1 ) {
  20070. var result = this.resultBuffer,
  20071. values = this.sampleValues,
  20072. stride = this.valueSize,
  20073. offset1 = i1 * stride,
  20074. offset0 = offset1 - stride,
  20075. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20076. weight0 = 1 - weight1;
  20077. for ( var i = 0; i !== stride; ++ i ) {
  20078. result[ i ] =
  20079. values[ offset0 + i ] * weight0 +
  20080. values[ offset1 + i ] * weight1;
  20081. }
  20082. return result;
  20083. }
  20084. } );
  20085. /**
  20086. *
  20087. * Interpolant that evaluates to the sample value at the position preceeding
  20088. * the parameter.
  20089. *
  20090. * @author tschw
  20091. */
  20092. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20093. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20094. }
  20095. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20096. constructor: DiscreteInterpolant,
  20097. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20098. return this.copySampleValue_( i1 - 1 );
  20099. }
  20100. } );
  20101. /**
  20102. *
  20103. * A timed sequence of keyframes for a specific property.
  20104. *
  20105. *
  20106. * @author Ben Houston / http://clara.io/
  20107. * @author David Sarno / http://lighthaus.us/
  20108. * @author tschw
  20109. */
  20110. function KeyframeTrack( name, times, values, interpolation ) {
  20111. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20112. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20113. this.name = name;
  20114. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20115. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20116. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20117. }
  20118. // Static methods
  20119. Object.assign( KeyframeTrack, {
  20120. // Serialization (in static context, because of constructor invocation
  20121. // and automatic invocation of .toJSON):
  20122. toJSON: function ( track ) {
  20123. var trackType = track.constructor;
  20124. var json;
  20125. // derived classes can define a static toJSON method
  20126. if ( trackType.toJSON !== undefined ) {
  20127. json = trackType.toJSON( track );
  20128. } else {
  20129. // by default, we assume the data can be serialized as-is
  20130. json = {
  20131. 'name': track.name,
  20132. 'times': AnimationUtils.convertArray( track.times, Array ),
  20133. 'values': AnimationUtils.convertArray( track.values, Array )
  20134. };
  20135. var interpolation = track.getInterpolation();
  20136. if ( interpolation !== track.DefaultInterpolation ) {
  20137. json.interpolation = interpolation;
  20138. }
  20139. }
  20140. json.type = track.ValueTypeName; // mandatory
  20141. return json;
  20142. }
  20143. } );
  20144. Object.assign( KeyframeTrack.prototype, {
  20145. constructor: KeyframeTrack,
  20146. TimeBufferType: Float32Array,
  20147. ValueBufferType: Float32Array,
  20148. DefaultInterpolation: InterpolateLinear,
  20149. InterpolantFactoryMethodDiscrete: function ( result ) {
  20150. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20151. },
  20152. InterpolantFactoryMethodLinear: function ( result ) {
  20153. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20154. },
  20155. InterpolantFactoryMethodSmooth: function ( result ) {
  20156. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  20157. },
  20158. setInterpolation: function ( interpolation ) {
  20159. var factoryMethod;
  20160. switch ( interpolation ) {
  20161. case InterpolateDiscrete:
  20162. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20163. break;
  20164. case InterpolateLinear:
  20165. factoryMethod = this.InterpolantFactoryMethodLinear;
  20166. break;
  20167. case InterpolateSmooth:
  20168. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20169. break;
  20170. }
  20171. if ( factoryMethod === undefined ) {
  20172. var message = "unsupported interpolation for " +
  20173. this.ValueTypeName + " keyframe track named " + this.name;
  20174. if ( this.createInterpolant === undefined ) {
  20175. // fall back to default, unless the default itself is messed up
  20176. if ( interpolation !== this.DefaultInterpolation ) {
  20177. this.setInterpolation( this.DefaultInterpolation );
  20178. } else {
  20179. throw new Error( message ); // fatal, in this case
  20180. }
  20181. }
  20182. console.warn( 'THREE.KeyframeTrack:', message );
  20183. return this;
  20184. }
  20185. this.createInterpolant = factoryMethod;
  20186. return this;
  20187. },
  20188. getInterpolation: function () {
  20189. switch ( this.createInterpolant ) {
  20190. case this.InterpolantFactoryMethodDiscrete:
  20191. return InterpolateDiscrete;
  20192. case this.InterpolantFactoryMethodLinear:
  20193. return InterpolateLinear;
  20194. case this.InterpolantFactoryMethodSmooth:
  20195. return InterpolateSmooth;
  20196. }
  20197. },
  20198. getValueSize: function () {
  20199. return this.values.length / this.times.length;
  20200. },
  20201. // move all keyframes either forwards or backwards in time
  20202. shift: function ( timeOffset ) {
  20203. if ( timeOffset !== 0.0 ) {
  20204. var times = this.times;
  20205. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20206. times[ i ] += timeOffset;
  20207. }
  20208. }
  20209. return this;
  20210. },
  20211. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20212. scale: function ( timeScale ) {
  20213. if ( timeScale !== 1.0 ) {
  20214. var times = this.times;
  20215. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20216. times[ i ] *= timeScale;
  20217. }
  20218. }
  20219. return this;
  20220. },
  20221. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20222. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20223. trim: function ( startTime, endTime ) {
  20224. var times = this.times,
  20225. nKeys = times.length,
  20226. from = 0,
  20227. to = nKeys - 1;
  20228. while ( from !== nKeys && times[ from ] < startTime ) {
  20229. ++ from;
  20230. }
  20231. while ( to !== - 1 && times[ to ] > endTime ) {
  20232. -- to;
  20233. }
  20234. ++ to; // inclusive -> exclusive bound
  20235. if ( from !== 0 || to !== nKeys ) {
  20236. // empty tracks are forbidden, so keep at least one keyframe
  20237. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  20238. var stride = this.getValueSize();
  20239. this.times = AnimationUtils.arraySlice( times, from, to );
  20240. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  20241. }
  20242. return this;
  20243. },
  20244. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20245. validate: function () {
  20246. var valid = true;
  20247. var valueSize = this.getValueSize();
  20248. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  20249. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  20250. valid = false;
  20251. }
  20252. var times = this.times,
  20253. values = this.values,
  20254. nKeys = times.length;
  20255. if ( nKeys === 0 ) {
  20256. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20257. valid = false;
  20258. }
  20259. var prevTime = null;
  20260. for ( var i = 0; i !== nKeys; i ++ ) {
  20261. var currTime = times[ i ];
  20262. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20263. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20264. valid = false;
  20265. break;
  20266. }
  20267. if ( prevTime !== null && prevTime > currTime ) {
  20268. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20269. valid = false;
  20270. break;
  20271. }
  20272. prevTime = currTime;
  20273. }
  20274. if ( values !== undefined ) {
  20275. if ( AnimationUtils.isTypedArray( values ) ) {
  20276. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20277. var value = values[ i ];
  20278. if ( isNaN( value ) ) {
  20279. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20280. valid = false;
  20281. break;
  20282. }
  20283. }
  20284. }
  20285. }
  20286. return valid;
  20287. },
  20288. // removes equivalent sequential keys as common in morph target sequences
  20289. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20290. optimize: function () {
  20291. var times = this.times,
  20292. values = this.values,
  20293. stride = this.getValueSize(),
  20294. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20295. writeIndex = 1,
  20296. lastIndex = times.length - 1;
  20297. for ( var i = 1; i < lastIndex; ++ i ) {
  20298. var keep = false;
  20299. var time = times[ i ];
  20300. var timeNext = times[ i + 1 ];
  20301. // remove adjacent keyframes scheduled at the same time
  20302. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20303. if ( ! smoothInterpolation ) {
  20304. // remove unnecessary keyframes same as their neighbors
  20305. var offset = i * stride,
  20306. offsetP = offset - stride,
  20307. offsetN = offset + stride;
  20308. for ( var j = 0; j !== stride; ++ j ) {
  20309. var value = values[ offset + j ];
  20310. if ( value !== values[ offsetP + j ] ||
  20311. value !== values[ offsetN + j ] ) {
  20312. keep = true;
  20313. break;
  20314. }
  20315. }
  20316. } else {
  20317. keep = true;
  20318. }
  20319. }
  20320. // in-place compaction
  20321. if ( keep ) {
  20322. if ( i !== writeIndex ) {
  20323. times[ writeIndex ] = times[ i ];
  20324. var readOffset = i * stride,
  20325. writeOffset = writeIndex * stride;
  20326. for ( var j = 0; j !== stride; ++ j ) {
  20327. values[ writeOffset + j ] = values[ readOffset + j ];
  20328. }
  20329. }
  20330. ++ writeIndex;
  20331. }
  20332. }
  20333. // flush last keyframe (compaction looks ahead)
  20334. if ( lastIndex > 0 ) {
  20335. times[ writeIndex ] = times[ lastIndex ];
  20336. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20337. values[ writeOffset + j ] = values[ readOffset + j ];
  20338. }
  20339. ++ writeIndex;
  20340. }
  20341. if ( writeIndex !== times.length ) {
  20342. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20343. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20344. }
  20345. return this;
  20346. },
  20347. clone: function () {
  20348. var times = AnimationUtils.arraySlice( this.times, 0 );
  20349. var values = AnimationUtils.arraySlice( this.values, 0 );
  20350. var TypedKeyframeTrack = this.constructor;
  20351. var track = new TypedKeyframeTrack( this.name, times, values );
  20352. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20353. track.createInterpolant = this.createInterpolant;
  20354. return track;
  20355. }
  20356. } );
  20357. /**
  20358. *
  20359. * A Track of Boolean keyframe values.
  20360. *
  20361. *
  20362. * @author Ben Houston / http://clara.io/
  20363. * @author David Sarno / http://lighthaus.us/
  20364. * @author tschw
  20365. */
  20366. function BooleanKeyframeTrack( name, times, values ) {
  20367. KeyframeTrack.call( this, name, times, values );
  20368. }
  20369. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20370. constructor: BooleanKeyframeTrack,
  20371. ValueTypeName: 'bool',
  20372. ValueBufferType: Array,
  20373. DefaultInterpolation: InterpolateDiscrete,
  20374. InterpolantFactoryMethodLinear: undefined,
  20375. InterpolantFactoryMethodSmooth: undefined
  20376. // Note: Actually this track could have a optimized / compressed
  20377. // representation of a single value and a custom interpolant that
  20378. // computes "firstValue ^ isOdd( index )".
  20379. } );
  20380. /**
  20381. *
  20382. * A Track of keyframe values that represent color.
  20383. *
  20384. *
  20385. * @author Ben Houston / http://clara.io/
  20386. * @author David Sarno / http://lighthaus.us/
  20387. * @author tschw
  20388. */
  20389. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20390. KeyframeTrack.call( this, name, times, values, interpolation );
  20391. }
  20392. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20393. constructor: ColorKeyframeTrack,
  20394. ValueTypeName: 'color'
  20395. // ValueBufferType is inherited
  20396. // DefaultInterpolation is inherited
  20397. // Note: Very basic implementation and nothing special yet.
  20398. // However, this is the place for color space parameterization.
  20399. } );
  20400. /**
  20401. *
  20402. * A Track of numeric keyframe values.
  20403. *
  20404. * @author Ben Houston / http://clara.io/
  20405. * @author David Sarno / http://lighthaus.us/
  20406. * @author tschw
  20407. */
  20408. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20409. KeyframeTrack.call( this, name, times, values, interpolation );
  20410. }
  20411. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20412. constructor: NumberKeyframeTrack,
  20413. ValueTypeName: 'number'
  20414. // ValueBufferType is inherited
  20415. // DefaultInterpolation is inherited
  20416. } );
  20417. /**
  20418. * Spherical linear unit quaternion interpolant.
  20419. *
  20420. * @author tschw
  20421. */
  20422. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20423. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20424. }
  20425. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20426. constructor: QuaternionLinearInterpolant,
  20427. interpolate_: function ( i1, t0, t, t1 ) {
  20428. var result = this.resultBuffer,
  20429. values = this.sampleValues,
  20430. stride = this.valueSize,
  20431. offset = i1 * stride,
  20432. alpha = ( t - t0 ) / ( t1 - t0 );
  20433. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20434. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20435. }
  20436. return result;
  20437. }
  20438. } );
  20439. /**
  20440. *
  20441. * A Track of quaternion keyframe values.
  20442. *
  20443. * @author Ben Houston / http://clara.io/
  20444. * @author David Sarno / http://lighthaus.us/
  20445. * @author tschw
  20446. */
  20447. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20448. KeyframeTrack.call( this, name, times, values, interpolation );
  20449. }
  20450. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20451. constructor: QuaternionKeyframeTrack,
  20452. ValueTypeName: 'quaternion',
  20453. // ValueBufferType is inherited
  20454. DefaultInterpolation: InterpolateLinear,
  20455. InterpolantFactoryMethodLinear: function ( result ) {
  20456. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20457. },
  20458. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20459. } );
  20460. /**
  20461. *
  20462. * A Track that interpolates Strings
  20463. *
  20464. *
  20465. * @author Ben Houston / http://clara.io/
  20466. * @author David Sarno / http://lighthaus.us/
  20467. * @author tschw
  20468. */
  20469. function StringKeyframeTrack( name, times, values, interpolation ) {
  20470. KeyframeTrack.call( this, name, times, values, interpolation );
  20471. }
  20472. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20473. constructor: StringKeyframeTrack,
  20474. ValueTypeName: 'string',
  20475. ValueBufferType: Array,
  20476. DefaultInterpolation: InterpolateDiscrete,
  20477. InterpolantFactoryMethodLinear: undefined,
  20478. InterpolantFactoryMethodSmooth: undefined
  20479. } );
  20480. /**
  20481. *
  20482. * A Track of vectored keyframe values.
  20483. *
  20484. *
  20485. * @author Ben Houston / http://clara.io/
  20486. * @author David Sarno / http://lighthaus.us/
  20487. * @author tschw
  20488. */
  20489. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20490. KeyframeTrack.call( this, name, times, values, interpolation );
  20491. }
  20492. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20493. constructor: VectorKeyframeTrack,
  20494. ValueTypeName: 'vector'
  20495. // ValueBufferType is inherited
  20496. // DefaultInterpolation is inherited
  20497. } );
  20498. /**
  20499. *
  20500. * Reusable set of Tracks that represent an animation.
  20501. *
  20502. * @author Ben Houston / http://clara.io/
  20503. * @author David Sarno / http://lighthaus.us/
  20504. */
  20505. function AnimationClip( name, duration, tracks ) {
  20506. this.name = name;
  20507. this.tracks = tracks;
  20508. this.duration = ( duration !== undefined ) ? duration : - 1;
  20509. this.uuid = _Math.generateUUID();
  20510. // this means it should figure out its duration by scanning the tracks
  20511. if ( this.duration < 0 ) {
  20512. this.resetDuration();
  20513. }
  20514. }
  20515. function getTrackTypeForValueTypeName( typeName ) {
  20516. switch ( typeName.toLowerCase() ) {
  20517. case 'scalar':
  20518. case 'double':
  20519. case 'float':
  20520. case 'number':
  20521. case 'integer':
  20522. return NumberKeyframeTrack;
  20523. case 'vector':
  20524. case 'vector2':
  20525. case 'vector3':
  20526. case 'vector4':
  20527. return VectorKeyframeTrack;
  20528. case 'color':
  20529. return ColorKeyframeTrack;
  20530. case 'quaternion':
  20531. return QuaternionKeyframeTrack;
  20532. case 'bool':
  20533. case 'boolean':
  20534. return BooleanKeyframeTrack;
  20535. case 'string':
  20536. return StringKeyframeTrack;
  20537. }
  20538. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20539. }
  20540. function parseKeyframeTrack( json ) {
  20541. if ( json.type === undefined ) {
  20542. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20543. }
  20544. var trackType = getTrackTypeForValueTypeName( json.type );
  20545. if ( json.times === undefined ) {
  20546. var times = [], values = [];
  20547. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20548. json.times = times;
  20549. json.values = values;
  20550. }
  20551. // derived classes can define a static parse method
  20552. if ( trackType.parse !== undefined ) {
  20553. return trackType.parse( json );
  20554. } else {
  20555. // by default, we assume a constructor compatible with the base
  20556. return new trackType( json.name, json.times, json.values, json.interpolation );
  20557. }
  20558. }
  20559. Object.assign( AnimationClip, {
  20560. parse: function ( json ) {
  20561. var tracks = [],
  20562. jsonTracks = json.tracks,
  20563. frameTime = 1.0 / ( json.fps || 1.0 );
  20564. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20565. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20566. }
  20567. return new AnimationClip( json.name, json.duration, tracks );
  20568. },
  20569. toJSON: function ( clip ) {
  20570. var tracks = [],
  20571. clipTracks = clip.tracks;
  20572. var json = {
  20573. 'name': clip.name,
  20574. 'duration': clip.duration,
  20575. 'tracks': tracks,
  20576. 'uuid': clip.uuid
  20577. };
  20578. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20579. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20580. }
  20581. return json;
  20582. },
  20583. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20584. var numMorphTargets = morphTargetSequence.length;
  20585. var tracks = [];
  20586. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20587. var times = [];
  20588. var values = [];
  20589. times.push(
  20590. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20591. i,
  20592. ( i + 1 ) % numMorphTargets );
  20593. values.push( 0, 1, 0 );
  20594. var order = AnimationUtils.getKeyframeOrder( times );
  20595. times = AnimationUtils.sortedArray( times, 1, order );
  20596. values = AnimationUtils.sortedArray( values, 1, order );
  20597. // if there is a key at the first frame, duplicate it as the
  20598. // last frame as well for perfect loop.
  20599. if ( ! noLoop && times[ 0 ] === 0 ) {
  20600. times.push( numMorphTargets );
  20601. values.push( values[ 0 ] );
  20602. }
  20603. tracks.push(
  20604. new NumberKeyframeTrack(
  20605. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20606. times, values
  20607. ).scale( 1.0 / fps ) );
  20608. }
  20609. return new AnimationClip( name, - 1, tracks );
  20610. },
  20611. findByName: function ( objectOrClipArray, name ) {
  20612. var clipArray = objectOrClipArray;
  20613. if ( ! Array.isArray( objectOrClipArray ) ) {
  20614. var o = objectOrClipArray;
  20615. clipArray = o.geometry && o.geometry.animations || o.animations;
  20616. }
  20617. for ( var i = 0; i < clipArray.length; i ++ ) {
  20618. if ( clipArray[ i ].name === name ) {
  20619. return clipArray[ i ];
  20620. }
  20621. }
  20622. return null;
  20623. },
  20624. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20625. var animationToMorphTargets = {};
  20626. // tested with https://regex101.com/ on trick sequences
  20627. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20628. var pattern = /^([\w-]*?)([\d]+)$/;
  20629. // sort morph target names into animation groups based
  20630. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20631. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20632. var morphTarget = morphTargets[ i ];
  20633. var parts = morphTarget.name.match( pattern );
  20634. if ( parts && parts.length > 1 ) {
  20635. var name = parts[ 1 ];
  20636. var animationMorphTargets = animationToMorphTargets[ name ];
  20637. if ( ! animationMorphTargets ) {
  20638. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20639. }
  20640. animationMorphTargets.push( morphTarget );
  20641. }
  20642. }
  20643. var clips = [];
  20644. for ( var name in animationToMorphTargets ) {
  20645. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20646. }
  20647. return clips;
  20648. },
  20649. // parse the animation.hierarchy format
  20650. parseAnimation: function ( animation, bones ) {
  20651. if ( ! animation ) {
  20652. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20653. return null;
  20654. }
  20655. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20656. // only return track if there are actually keys.
  20657. if ( animationKeys.length !== 0 ) {
  20658. var times = [];
  20659. var values = [];
  20660. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20661. // empty keys are filtered out, so check again
  20662. if ( times.length !== 0 ) {
  20663. destTracks.push( new trackType( trackName, times, values ) );
  20664. }
  20665. }
  20666. };
  20667. var tracks = [];
  20668. var clipName = animation.name || 'default';
  20669. // automatic length determination in AnimationClip.
  20670. var duration = animation.length || - 1;
  20671. var fps = animation.fps || 30;
  20672. var hierarchyTracks = animation.hierarchy || [];
  20673. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20674. var animationKeys = hierarchyTracks[ h ].keys;
  20675. // skip empty tracks
  20676. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20677. // process morph targets
  20678. if ( animationKeys[ 0 ].morphTargets ) {
  20679. // figure out all morph targets used in this track
  20680. var morphTargetNames = {};
  20681. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20682. if ( animationKeys[ k ].morphTargets ) {
  20683. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20684. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20685. }
  20686. }
  20687. }
  20688. // create a track for each morph target with all zero
  20689. // morphTargetInfluences except for the keys in which
  20690. // the morphTarget is named.
  20691. for ( var morphTargetName in morphTargetNames ) {
  20692. var times = [];
  20693. var values = [];
  20694. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20695. var animationKey = animationKeys[ k ];
  20696. times.push( animationKey.time );
  20697. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20698. }
  20699. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20700. }
  20701. duration = morphTargetNames.length * ( fps || 1.0 );
  20702. } else {
  20703. // ...assume skeletal animation
  20704. var boneName = '.bones[' + bones[ h ].name + ']';
  20705. addNonemptyTrack(
  20706. VectorKeyframeTrack, boneName + '.position',
  20707. animationKeys, 'pos', tracks );
  20708. addNonemptyTrack(
  20709. QuaternionKeyframeTrack, boneName + '.quaternion',
  20710. animationKeys, 'rot', tracks );
  20711. addNonemptyTrack(
  20712. VectorKeyframeTrack, boneName + '.scale',
  20713. animationKeys, 'scl', tracks );
  20714. }
  20715. }
  20716. if ( tracks.length === 0 ) {
  20717. return null;
  20718. }
  20719. var clip = new AnimationClip( clipName, duration, tracks );
  20720. return clip;
  20721. }
  20722. } );
  20723. Object.assign( AnimationClip.prototype, {
  20724. resetDuration: function () {
  20725. var tracks = this.tracks, duration = 0;
  20726. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20727. var track = this.tracks[ i ];
  20728. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20729. }
  20730. this.duration = duration;
  20731. return this;
  20732. },
  20733. trim: function () {
  20734. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20735. this.tracks[ i ].trim( 0, this.duration );
  20736. }
  20737. return this;
  20738. },
  20739. validate: function () {
  20740. var valid = true;
  20741. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20742. valid = valid && this.tracks[ i ].validate();
  20743. }
  20744. return valid;
  20745. },
  20746. optimize: function () {
  20747. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20748. this.tracks[ i ].optimize();
  20749. }
  20750. return this;
  20751. },
  20752. clone: function () {
  20753. var tracks = [];
  20754. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20755. tracks.push( this.tracks[ i ].clone() );
  20756. }
  20757. return new AnimationClip( this.name, this.duration, tracks );
  20758. }
  20759. } );
  20760. /**
  20761. * @author mrdoob / http://mrdoob.com/
  20762. */
  20763. var Cache = {
  20764. enabled: false,
  20765. files: {},
  20766. add: function ( key, file ) {
  20767. if ( this.enabled === false ) return;
  20768. // console.log( 'THREE.Cache', 'Adding key:', key );
  20769. this.files[ key ] = file;
  20770. },
  20771. get: function ( key ) {
  20772. if ( this.enabled === false ) return;
  20773. // console.log( 'THREE.Cache', 'Checking key:', key );
  20774. return this.files[ key ];
  20775. },
  20776. remove: function ( key ) {
  20777. delete this.files[ key ];
  20778. },
  20779. clear: function () {
  20780. this.files = {};
  20781. }
  20782. };
  20783. /**
  20784. * @author mrdoob / http://mrdoob.com/
  20785. */
  20786. function LoadingManager( onLoad, onProgress, onError ) {
  20787. var scope = this;
  20788. var isLoading = false;
  20789. var itemsLoaded = 0;
  20790. var itemsTotal = 0;
  20791. var urlModifier = undefined;
  20792. // Refer to #5689 for the reason why we don't set .onStart
  20793. // in the constructor
  20794. this.onStart = undefined;
  20795. this.onLoad = onLoad;
  20796. this.onProgress = onProgress;
  20797. this.onError = onError;
  20798. this.itemStart = function ( url ) {
  20799. itemsTotal ++;
  20800. if ( isLoading === false ) {
  20801. if ( scope.onStart !== undefined ) {
  20802. scope.onStart( url, itemsLoaded, itemsTotal );
  20803. }
  20804. }
  20805. isLoading = true;
  20806. };
  20807. this.itemEnd = function ( url ) {
  20808. itemsLoaded ++;
  20809. if ( scope.onProgress !== undefined ) {
  20810. scope.onProgress( url, itemsLoaded, itemsTotal );
  20811. }
  20812. if ( itemsLoaded === itemsTotal ) {
  20813. isLoading = false;
  20814. if ( scope.onLoad !== undefined ) {
  20815. scope.onLoad();
  20816. }
  20817. }
  20818. };
  20819. this.itemError = function ( url ) {
  20820. if ( scope.onError !== undefined ) {
  20821. scope.onError( url );
  20822. }
  20823. };
  20824. this.resolveURL = function ( url ) {
  20825. if ( urlModifier ) {
  20826. return urlModifier( url );
  20827. }
  20828. return url;
  20829. };
  20830. this.setURLModifier = function ( transform ) {
  20831. urlModifier = transform;
  20832. return this;
  20833. };
  20834. }
  20835. var DefaultLoadingManager = new LoadingManager();
  20836. /**
  20837. * @author mrdoob / http://mrdoob.com/
  20838. */
  20839. var loading = {};
  20840. function FileLoader( manager ) {
  20841. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20842. }
  20843. Object.assign( FileLoader.prototype, {
  20844. load: function ( url, onLoad, onProgress, onError ) {
  20845. if ( url === undefined ) url = '';
  20846. if ( this.path !== undefined ) url = this.path + url;
  20847. url = this.manager.resolveURL( url );
  20848. var scope = this;
  20849. var cached = Cache.get( url );
  20850. if ( cached !== undefined ) {
  20851. scope.manager.itemStart( url );
  20852. setTimeout( function () {
  20853. if ( onLoad ) onLoad( cached );
  20854. scope.manager.itemEnd( url );
  20855. }, 0 );
  20856. return cached;
  20857. }
  20858. // Check if request is duplicate
  20859. if ( loading[ url ] !== undefined ) {
  20860. loading[ url ].push( {
  20861. onLoad: onLoad,
  20862. onProgress: onProgress,
  20863. onError: onError
  20864. } );
  20865. return;
  20866. }
  20867. // Check for data: URI
  20868. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20869. var dataUriRegexResult = url.match( dataUriRegex );
  20870. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20871. if ( dataUriRegexResult ) {
  20872. var mimeType = dataUriRegexResult[ 1 ];
  20873. var isBase64 = !! dataUriRegexResult[ 2 ];
  20874. var data = dataUriRegexResult[ 3 ];
  20875. data = decodeURIComponent( data );
  20876. if ( isBase64 ) data = atob( data );
  20877. try {
  20878. var response;
  20879. var responseType = ( this.responseType || '' ).toLowerCase();
  20880. switch ( responseType ) {
  20881. case 'arraybuffer':
  20882. case 'blob':
  20883. var view = new Uint8Array( data.length );
  20884. for ( var i = 0; i < data.length; i ++ ) {
  20885. view[ i ] = data.charCodeAt( i );
  20886. }
  20887. if ( responseType === 'blob' ) {
  20888. response = new Blob( [ view.buffer ], { type: mimeType } );
  20889. } else {
  20890. response = view.buffer;
  20891. }
  20892. break;
  20893. case 'document':
  20894. var parser = new DOMParser();
  20895. response = parser.parseFromString( data, mimeType );
  20896. break;
  20897. case 'json':
  20898. response = JSON.parse( data );
  20899. break;
  20900. default: // 'text' or other
  20901. response = data;
  20902. break;
  20903. }
  20904. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20905. setTimeout( function () {
  20906. if ( onLoad ) onLoad( response );
  20907. scope.manager.itemEnd( url );
  20908. }, 0 );
  20909. } catch ( error ) {
  20910. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20911. setTimeout( function () {
  20912. if ( onError ) onError( error );
  20913. scope.manager.itemError( url );
  20914. scope.manager.itemEnd( url );
  20915. }, 0 );
  20916. }
  20917. } else {
  20918. // Initialise array for duplicate requests
  20919. loading[ url ] = [];
  20920. loading[ url ].push( {
  20921. onLoad: onLoad,
  20922. onProgress: onProgress,
  20923. onError: onError
  20924. } );
  20925. var request = new XMLHttpRequest();
  20926. request.open( 'GET', url, true );
  20927. request.addEventListener( 'load', function ( event ) {
  20928. var response = this.response;
  20929. Cache.add( url, response );
  20930. var callbacks = loading[ url ];
  20931. delete loading[ url ];
  20932. if ( this.status === 200 || this.status === 0 ) {
  20933. // Some browsers return HTTP Status 0 when using non-http protocol
  20934. // e.g. 'file://' or 'data://'. Handle as success.
  20935. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20936. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20937. var callback = callbacks[ i ];
  20938. if ( callback.onLoad ) callback.onLoad( response );
  20939. }
  20940. scope.manager.itemEnd( url );
  20941. } else {
  20942. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20943. var callback = callbacks[ i ];
  20944. if ( callback.onError ) callback.onError( event );
  20945. }
  20946. scope.manager.itemError( url );
  20947. scope.manager.itemEnd( url );
  20948. }
  20949. }, false );
  20950. request.addEventListener( 'progress', function ( event ) {
  20951. var callbacks = loading[ url ];
  20952. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20953. var callback = callbacks[ i ];
  20954. if ( callback.onProgress ) callback.onProgress( event );
  20955. }
  20956. }, false );
  20957. request.addEventListener( 'error', function ( event ) {
  20958. var callbacks = loading[ url ];
  20959. delete loading[ url ];
  20960. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20961. var callback = callbacks[ i ];
  20962. if ( callback.onError ) callback.onError( event );
  20963. }
  20964. scope.manager.itemError( url );
  20965. scope.manager.itemEnd( url );
  20966. }, false );
  20967. request.addEventListener( 'abort', function ( event ) {
  20968. var callbacks = loading[ url ];
  20969. delete loading[ url ];
  20970. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20971. var callback = callbacks[ i ];
  20972. if ( callback.onError ) callback.onError( event );
  20973. }
  20974. scope.manager.itemError( url );
  20975. scope.manager.itemEnd( url );
  20976. }, false );
  20977. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20978. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20979. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20980. for ( var header in this.requestHeader ) {
  20981. request.setRequestHeader( header, this.requestHeader[ header ] );
  20982. }
  20983. request.send( null );
  20984. }
  20985. scope.manager.itemStart( url );
  20986. return request;
  20987. },
  20988. setPath: function ( value ) {
  20989. this.path = value;
  20990. return this;
  20991. },
  20992. setResponseType: function ( value ) {
  20993. this.responseType = value;
  20994. return this;
  20995. },
  20996. setWithCredentials: function ( value ) {
  20997. this.withCredentials = value;
  20998. return this;
  20999. },
  21000. setMimeType: function ( value ) {
  21001. this.mimeType = value;
  21002. return this;
  21003. },
  21004. setRequestHeader: function ( value ) {
  21005. this.requestHeader = value;
  21006. return this;
  21007. }
  21008. } );
  21009. /**
  21010. * @author bhouston / http://clara.io/
  21011. */
  21012. function AnimationLoader( manager ) {
  21013. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21014. }
  21015. Object.assign( AnimationLoader.prototype, {
  21016. load: function ( url, onLoad, onProgress, onError ) {
  21017. var scope = this;
  21018. var loader = new FileLoader( scope.manager );
  21019. loader.setPath( scope.path );
  21020. loader.load( url, function ( text ) {
  21021. onLoad( scope.parse( JSON.parse( text ) ) );
  21022. }, onProgress, onError );
  21023. },
  21024. parse: function ( json ) {
  21025. var animations = [];
  21026. for ( var i = 0; i < json.length; i ++ ) {
  21027. var clip = AnimationClip.parse( json[ i ] );
  21028. animations.push( clip );
  21029. }
  21030. return animations;
  21031. },
  21032. setPath: function ( value ) {
  21033. this.path = value;
  21034. return this;
  21035. }
  21036. } );
  21037. /**
  21038. * @author mrdoob / http://mrdoob.com/
  21039. *
  21040. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21041. */
  21042. function CompressedTextureLoader( manager ) {
  21043. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21044. // override in sub classes
  21045. this._parser = null;
  21046. }
  21047. Object.assign( CompressedTextureLoader.prototype, {
  21048. load: function ( url, onLoad, onProgress, onError ) {
  21049. var scope = this;
  21050. var images = [];
  21051. var texture = new CompressedTexture();
  21052. texture.image = images;
  21053. var loader = new FileLoader( this.manager );
  21054. loader.setPath( this.path );
  21055. loader.setResponseType( 'arraybuffer' );
  21056. function loadTexture( i ) {
  21057. loader.load( url[ i ], function ( buffer ) {
  21058. var texDatas = scope._parser( buffer, true );
  21059. images[ i ] = {
  21060. width: texDatas.width,
  21061. height: texDatas.height,
  21062. format: texDatas.format,
  21063. mipmaps: texDatas.mipmaps
  21064. };
  21065. loaded += 1;
  21066. if ( loaded === 6 ) {
  21067. if ( texDatas.mipmapCount === 1 )
  21068. texture.minFilter = LinearFilter;
  21069. texture.format = texDatas.format;
  21070. texture.needsUpdate = true;
  21071. if ( onLoad ) onLoad( texture );
  21072. }
  21073. }, onProgress, onError );
  21074. }
  21075. if ( Array.isArray( url ) ) {
  21076. var loaded = 0;
  21077. for ( var i = 0, il = url.length; i < il; ++ i ) {
  21078. loadTexture( i );
  21079. }
  21080. } else {
  21081. // compressed cubemap texture stored in a single DDS file
  21082. loader.load( url, function ( buffer ) {
  21083. var texDatas = scope._parser( buffer, true );
  21084. if ( texDatas.isCubemap ) {
  21085. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21086. for ( var f = 0; f < faces; f ++ ) {
  21087. images[ f ] = { mipmaps: [] };
  21088. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  21089. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  21090. images[ f ].format = texDatas.format;
  21091. images[ f ].width = texDatas.width;
  21092. images[ f ].height = texDatas.height;
  21093. }
  21094. }
  21095. } else {
  21096. texture.image.width = texDatas.width;
  21097. texture.image.height = texDatas.height;
  21098. texture.mipmaps = texDatas.mipmaps;
  21099. }
  21100. if ( texDatas.mipmapCount === 1 ) {
  21101. texture.minFilter = LinearFilter;
  21102. }
  21103. texture.format = texDatas.format;
  21104. texture.needsUpdate = true;
  21105. if ( onLoad ) onLoad( texture );
  21106. }, onProgress, onError );
  21107. }
  21108. return texture;
  21109. },
  21110. setPath: function ( value ) {
  21111. this.path = value;
  21112. return this;
  21113. }
  21114. } );
  21115. /**
  21116. * @author Nikos M. / https://github.com/foo123/
  21117. *
  21118. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21119. */
  21120. function DataTextureLoader( manager ) {
  21121. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21122. // override in sub classes
  21123. this._parser = null;
  21124. }
  21125. Object.assign( DataTextureLoader.prototype, {
  21126. load: function ( url, onLoad, onProgress, onError ) {
  21127. var scope = this;
  21128. var texture = new DataTexture();
  21129. var loader = new FileLoader( this.manager );
  21130. loader.setResponseType( 'arraybuffer' );
  21131. loader.setPath( this.path );
  21132. loader.load( url, function ( buffer ) {
  21133. var texData = scope._parser( buffer );
  21134. if ( ! texData ) return;
  21135. if ( texData.image !== undefined ) {
  21136. texture.image = texData.image;
  21137. } else if ( texData.data !== undefined ) {
  21138. texture.image.width = texData.width;
  21139. texture.image.height = texData.height;
  21140. texture.image.data = texData.data;
  21141. }
  21142. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21143. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21144. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21145. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipmapLinearFilter;
  21146. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21147. if ( texData.format !== undefined ) {
  21148. texture.format = texData.format;
  21149. }
  21150. if ( texData.type !== undefined ) {
  21151. texture.type = texData.type;
  21152. }
  21153. if ( texData.mipmaps !== undefined ) {
  21154. texture.mipmaps = texData.mipmaps;
  21155. }
  21156. if ( texData.mipmapCount === 1 ) {
  21157. texture.minFilter = LinearFilter;
  21158. }
  21159. texture.needsUpdate = true;
  21160. if ( onLoad ) onLoad( texture, texData );
  21161. }, onProgress, onError );
  21162. return texture;
  21163. },
  21164. setPath: function ( value ) {
  21165. this.path = value;
  21166. return this;
  21167. }
  21168. } );
  21169. /**
  21170. * @author mrdoob / http://mrdoob.com/
  21171. */
  21172. function ImageLoader( manager ) {
  21173. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21174. }
  21175. Object.assign( ImageLoader.prototype, {
  21176. crossOrigin: 'anonymous',
  21177. load: function ( url, onLoad, onProgress, onError ) {
  21178. if ( url === undefined ) url = '';
  21179. if ( this.path !== undefined ) url = this.path + url;
  21180. url = this.manager.resolveURL( url );
  21181. var scope = this;
  21182. var cached = Cache.get( url );
  21183. if ( cached !== undefined ) {
  21184. scope.manager.itemStart( url );
  21185. setTimeout( function () {
  21186. if ( onLoad ) onLoad( cached );
  21187. scope.manager.itemEnd( url );
  21188. }, 0 );
  21189. return cached;
  21190. }
  21191. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  21192. function onImageLoad() {
  21193. image.removeEventListener( 'load', onImageLoad, false );
  21194. image.removeEventListener( 'error', onImageError, false );
  21195. Cache.add( url, this );
  21196. if ( onLoad ) onLoad( this );
  21197. scope.manager.itemEnd( url );
  21198. }
  21199. function onImageError( event ) {
  21200. image.removeEventListener( 'load', onImageLoad, false );
  21201. image.removeEventListener( 'error', onImageError, false );
  21202. if ( onError ) onError( event );
  21203. scope.manager.itemError( url );
  21204. scope.manager.itemEnd( url );
  21205. }
  21206. image.addEventListener( 'load', onImageLoad, false );
  21207. image.addEventListener( 'error', onImageError, false );
  21208. if ( url.substr( 0, 5 ) !== 'data:' ) {
  21209. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  21210. }
  21211. scope.manager.itemStart( url );
  21212. image.src = url;
  21213. return image;
  21214. },
  21215. setCrossOrigin: function ( value ) {
  21216. this.crossOrigin = value;
  21217. return this;
  21218. },
  21219. setPath: function ( value ) {
  21220. this.path = value;
  21221. return this;
  21222. }
  21223. } );
  21224. /**
  21225. * @author mrdoob / http://mrdoob.com/
  21226. */
  21227. function CubeTextureLoader( manager ) {
  21228. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21229. }
  21230. Object.assign( CubeTextureLoader.prototype, {
  21231. crossOrigin: 'anonymous',
  21232. load: function ( urls, onLoad, onProgress, onError ) {
  21233. var texture = new CubeTexture();
  21234. var loader = new ImageLoader( this.manager );
  21235. loader.setCrossOrigin( this.crossOrigin );
  21236. loader.setPath( this.path );
  21237. var loaded = 0;
  21238. function loadTexture( i ) {
  21239. loader.load( urls[ i ], function ( image ) {
  21240. texture.images[ i ] = image;
  21241. loaded ++;
  21242. if ( loaded === 6 ) {
  21243. texture.needsUpdate = true;
  21244. if ( onLoad ) onLoad( texture );
  21245. }
  21246. }, undefined, onError );
  21247. }
  21248. for ( var i = 0; i < urls.length; ++ i ) {
  21249. loadTexture( i );
  21250. }
  21251. return texture;
  21252. },
  21253. setCrossOrigin: function ( value ) {
  21254. this.crossOrigin = value;
  21255. return this;
  21256. },
  21257. setPath: function ( value ) {
  21258. this.path = value;
  21259. return this;
  21260. }
  21261. } );
  21262. /**
  21263. * @author mrdoob / http://mrdoob.com/
  21264. */
  21265. function TextureLoader( manager ) {
  21266. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21267. }
  21268. Object.assign( TextureLoader.prototype, {
  21269. crossOrigin: 'anonymous',
  21270. load: function ( url, onLoad, onProgress, onError ) {
  21271. var texture = new Texture();
  21272. var loader = new ImageLoader( this.manager );
  21273. loader.setCrossOrigin( this.crossOrigin );
  21274. loader.setPath( this.path );
  21275. loader.load( url, function ( image ) {
  21276. texture.image = image;
  21277. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21278. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  21279. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21280. texture.needsUpdate = true;
  21281. if ( onLoad !== undefined ) {
  21282. onLoad( texture );
  21283. }
  21284. }, onProgress, onError );
  21285. return texture;
  21286. },
  21287. setCrossOrigin: function ( value ) {
  21288. this.crossOrigin = value;
  21289. return this;
  21290. },
  21291. setPath: function ( value ) {
  21292. this.path = value;
  21293. return this;
  21294. }
  21295. } );
  21296. /**
  21297. * @author zz85 / http://www.lab4games.net/zz85/blog
  21298. * Extensible curve object
  21299. *
  21300. * Some common of curve methods:
  21301. * .getPoint( t, optionalTarget ), .getTangent( t )
  21302. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  21303. * .getPoints(), .getSpacedPoints()
  21304. * .getLength()
  21305. * .updateArcLengths()
  21306. *
  21307. * This following curves inherit from THREE.Curve:
  21308. *
  21309. * -- 2D curves --
  21310. * THREE.ArcCurve
  21311. * THREE.CubicBezierCurve
  21312. * THREE.EllipseCurve
  21313. * THREE.LineCurve
  21314. * THREE.QuadraticBezierCurve
  21315. * THREE.SplineCurve
  21316. *
  21317. * -- 3D curves --
  21318. * THREE.CatmullRomCurve3
  21319. * THREE.CubicBezierCurve3
  21320. * THREE.LineCurve3
  21321. * THREE.QuadraticBezierCurve3
  21322. *
  21323. * A series of curves can be represented as a THREE.CurvePath.
  21324. *
  21325. **/
  21326. /**************************************************************
  21327. * Abstract Curve base class
  21328. **************************************************************/
  21329. function Curve() {
  21330. this.type = 'Curve';
  21331. this.arcLengthDivisions = 200;
  21332. }
  21333. Object.assign( Curve.prototype, {
  21334. // Virtual base class method to overwrite and implement in subclasses
  21335. // - t [0 .. 1]
  21336. getPoint: function ( /* t, optionalTarget */ ) {
  21337. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21338. return null;
  21339. },
  21340. // Get point at relative position in curve according to arc length
  21341. // - u [0 .. 1]
  21342. getPointAt: function ( u, optionalTarget ) {
  21343. var t = this.getUtoTmapping( u );
  21344. return this.getPoint( t, optionalTarget );
  21345. },
  21346. // Get sequence of points using getPoint( t )
  21347. getPoints: function ( divisions ) {
  21348. if ( divisions === undefined ) divisions = 5;
  21349. var points = [];
  21350. for ( var d = 0; d <= divisions; d ++ ) {
  21351. points.push( this.getPoint( d / divisions ) );
  21352. }
  21353. return points;
  21354. },
  21355. // Get sequence of points using getPointAt( u )
  21356. getSpacedPoints: function ( divisions ) {
  21357. if ( divisions === undefined ) divisions = 5;
  21358. var points = [];
  21359. for ( var d = 0; d <= divisions; d ++ ) {
  21360. points.push( this.getPointAt( d / divisions ) );
  21361. }
  21362. return points;
  21363. },
  21364. // Get total curve arc length
  21365. getLength: function () {
  21366. var lengths = this.getLengths();
  21367. return lengths[ lengths.length - 1 ];
  21368. },
  21369. // Get list of cumulative segment lengths
  21370. getLengths: function ( divisions ) {
  21371. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21372. if ( this.cacheArcLengths &&
  21373. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21374. ! this.needsUpdate ) {
  21375. return this.cacheArcLengths;
  21376. }
  21377. this.needsUpdate = false;
  21378. var cache = [];
  21379. var current, last = this.getPoint( 0 );
  21380. var p, sum = 0;
  21381. cache.push( 0 );
  21382. for ( p = 1; p <= divisions; p ++ ) {
  21383. current = this.getPoint( p / divisions );
  21384. sum += current.distanceTo( last );
  21385. cache.push( sum );
  21386. last = current;
  21387. }
  21388. this.cacheArcLengths = cache;
  21389. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21390. },
  21391. updateArcLengths: function () {
  21392. this.needsUpdate = true;
  21393. this.getLengths();
  21394. },
  21395. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21396. getUtoTmapping: function ( u, distance ) {
  21397. var arcLengths = this.getLengths();
  21398. var i = 0, il = arcLengths.length;
  21399. var targetArcLength; // The targeted u distance value to get
  21400. if ( distance ) {
  21401. targetArcLength = distance;
  21402. } else {
  21403. targetArcLength = u * arcLengths[ il - 1 ];
  21404. }
  21405. // binary search for the index with largest value smaller than target u distance
  21406. var low = 0, high = il - 1, comparison;
  21407. while ( low <= high ) {
  21408. 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
  21409. comparison = arcLengths[ i ] - targetArcLength;
  21410. if ( comparison < 0 ) {
  21411. low = i + 1;
  21412. } else if ( comparison > 0 ) {
  21413. high = i - 1;
  21414. } else {
  21415. high = i;
  21416. break;
  21417. // DONE
  21418. }
  21419. }
  21420. i = high;
  21421. if ( arcLengths[ i ] === targetArcLength ) {
  21422. return i / ( il - 1 );
  21423. }
  21424. // we could get finer grain at lengths, or use simple interpolation between two points
  21425. var lengthBefore = arcLengths[ i ];
  21426. var lengthAfter = arcLengths[ i + 1 ];
  21427. var segmentLength = lengthAfter - lengthBefore;
  21428. // determine where we are between the 'before' and 'after' points
  21429. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21430. // add that fractional amount to t
  21431. var t = ( i + segmentFraction ) / ( il - 1 );
  21432. return t;
  21433. },
  21434. // Returns a unit vector tangent at t
  21435. // In case any sub curve does not implement its tangent derivation,
  21436. // 2 points a small delta apart will be used to find its gradient
  21437. // which seems to give a reasonable approximation
  21438. getTangent: function ( t ) {
  21439. var delta = 0.0001;
  21440. var t1 = t - delta;
  21441. var t2 = t + delta;
  21442. // Capping in case of danger
  21443. if ( t1 < 0 ) t1 = 0;
  21444. if ( t2 > 1 ) t2 = 1;
  21445. var pt1 = this.getPoint( t1 );
  21446. var pt2 = this.getPoint( t2 );
  21447. var vec = pt2.clone().sub( pt1 );
  21448. return vec.normalize();
  21449. },
  21450. getTangentAt: function ( u ) {
  21451. var t = this.getUtoTmapping( u );
  21452. return this.getTangent( t );
  21453. },
  21454. computeFrenetFrames: function ( segments, closed ) {
  21455. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21456. var normal = new Vector3();
  21457. var tangents = [];
  21458. var normals = [];
  21459. var binormals = [];
  21460. var vec = new Vector3();
  21461. var mat = new Matrix4();
  21462. var i, u, theta;
  21463. // compute the tangent vectors for each segment on the curve
  21464. for ( i = 0; i <= segments; i ++ ) {
  21465. u = i / segments;
  21466. tangents[ i ] = this.getTangentAt( u );
  21467. tangents[ i ].normalize();
  21468. }
  21469. // select an initial normal vector perpendicular to the first tangent vector,
  21470. // and in the direction of the minimum tangent xyz component
  21471. normals[ 0 ] = new Vector3();
  21472. binormals[ 0 ] = new Vector3();
  21473. var min = Number.MAX_VALUE;
  21474. var tx = Math.abs( tangents[ 0 ].x );
  21475. var ty = Math.abs( tangents[ 0 ].y );
  21476. var tz = Math.abs( tangents[ 0 ].z );
  21477. if ( tx <= min ) {
  21478. min = tx;
  21479. normal.set( 1, 0, 0 );
  21480. }
  21481. if ( ty <= min ) {
  21482. min = ty;
  21483. normal.set( 0, 1, 0 );
  21484. }
  21485. if ( tz <= min ) {
  21486. normal.set( 0, 0, 1 );
  21487. }
  21488. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21489. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21490. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21491. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21492. for ( i = 1; i <= segments; i ++ ) {
  21493. normals[ i ] = normals[ i - 1 ].clone();
  21494. binormals[ i ] = binormals[ i - 1 ].clone();
  21495. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21496. if ( vec.length() > Number.EPSILON ) {
  21497. vec.normalize();
  21498. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21499. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21500. }
  21501. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21502. }
  21503. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21504. if ( closed === true ) {
  21505. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21506. theta /= segments;
  21507. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21508. theta = - theta;
  21509. }
  21510. for ( i = 1; i <= segments; i ++ ) {
  21511. // twist a little...
  21512. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21513. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21514. }
  21515. }
  21516. return {
  21517. tangents: tangents,
  21518. normals: normals,
  21519. binormals: binormals
  21520. };
  21521. },
  21522. clone: function () {
  21523. return new this.constructor().copy( this );
  21524. },
  21525. copy: function ( source ) {
  21526. this.arcLengthDivisions = source.arcLengthDivisions;
  21527. return this;
  21528. },
  21529. toJSON: function () {
  21530. var data = {
  21531. metadata: {
  21532. version: 4.5,
  21533. type: 'Curve',
  21534. generator: 'Curve.toJSON'
  21535. }
  21536. };
  21537. data.arcLengthDivisions = this.arcLengthDivisions;
  21538. data.type = this.type;
  21539. return data;
  21540. },
  21541. fromJSON: function ( json ) {
  21542. this.arcLengthDivisions = json.arcLengthDivisions;
  21543. return this;
  21544. }
  21545. } );
  21546. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21547. Curve.call( this );
  21548. this.type = 'EllipseCurve';
  21549. this.aX = aX || 0;
  21550. this.aY = aY || 0;
  21551. this.xRadius = xRadius || 1;
  21552. this.yRadius = yRadius || 1;
  21553. this.aStartAngle = aStartAngle || 0;
  21554. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21555. this.aClockwise = aClockwise || false;
  21556. this.aRotation = aRotation || 0;
  21557. }
  21558. EllipseCurve.prototype = Object.create( Curve.prototype );
  21559. EllipseCurve.prototype.constructor = EllipseCurve;
  21560. EllipseCurve.prototype.isEllipseCurve = true;
  21561. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21562. var point = optionalTarget || new Vector2();
  21563. var twoPi = Math.PI * 2;
  21564. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21565. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21566. // ensures that deltaAngle is 0 .. 2 PI
  21567. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21568. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21569. if ( deltaAngle < Number.EPSILON ) {
  21570. if ( samePoints ) {
  21571. deltaAngle = 0;
  21572. } else {
  21573. deltaAngle = twoPi;
  21574. }
  21575. }
  21576. if ( this.aClockwise === true && ! samePoints ) {
  21577. if ( deltaAngle === twoPi ) {
  21578. deltaAngle = - twoPi;
  21579. } else {
  21580. deltaAngle = deltaAngle - twoPi;
  21581. }
  21582. }
  21583. var angle = this.aStartAngle + t * deltaAngle;
  21584. var x = this.aX + this.xRadius * Math.cos( angle );
  21585. var y = this.aY + this.yRadius * Math.sin( angle );
  21586. if ( this.aRotation !== 0 ) {
  21587. var cos = Math.cos( this.aRotation );
  21588. var sin = Math.sin( this.aRotation );
  21589. var tx = x - this.aX;
  21590. var ty = y - this.aY;
  21591. // Rotate the point about the center of the ellipse.
  21592. x = tx * cos - ty * sin + this.aX;
  21593. y = tx * sin + ty * cos + this.aY;
  21594. }
  21595. return point.set( x, y );
  21596. };
  21597. EllipseCurve.prototype.copy = function ( source ) {
  21598. Curve.prototype.copy.call( this, source );
  21599. this.aX = source.aX;
  21600. this.aY = source.aY;
  21601. this.xRadius = source.xRadius;
  21602. this.yRadius = source.yRadius;
  21603. this.aStartAngle = source.aStartAngle;
  21604. this.aEndAngle = source.aEndAngle;
  21605. this.aClockwise = source.aClockwise;
  21606. this.aRotation = source.aRotation;
  21607. return this;
  21608. };
  21609. EllipseCurve.prototype.toJSON = function () {
  21610. var data = Curve.prototype.toJSON.call( this );
  21611. data.aX = this.aX;
  21612. data.aY = this.aY;
  21613. data.xRadius = this.xRadius;
  21614. data.yRadius = this.yRadius;
  21615. data.aStartAngle = this.aStartAngle;
  21616. data.aEndAngle = this.aEndAngle;
  21617. data.aClockwise = this.aClockwise;
  21618. data.aRotation = this.aRotation;
  21619. return data;
  21620. };
  21621. EllipseCurve.prototype.fromJSON = function ( json ) {
  21622. Curve.prototype.fromJSON.call( this, json );
  21623. this.aX = json.aX;
  21624. this.aY = json.aY;
  21625. this.xRadius = json.xRadius;
  21626. this.yRadius = json.yRadius;
  21627. this.aStartAngle = json.aStartAngle;
  21628. this.aEndAngle = json.aEndAngle;
  21629. this.aClockwise = json.aClockwise;
  21630. this.aRotation = json.aRotation;
  21631. return this;
  21632. };
  21633. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21634. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21635. this.type = 'ArcCurve';
  21636. }
  21637. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21638. ArcCurve.prototype.constructor = ArcCurve;
  21639. ArcCurve.prototype.isArcCurve = true;
  21640. /**
  21641. * @author zz85 https://github.com/zz85
  21642. *
  21643. * Centripetal CatmullRom Curve - which is useful for avoiding
  21644. * cusps and self-intersections in non-uniform catmull rom curves.
  21645. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21646. *
  21647. * curve.type accepts centripetal(default), chordal and catmullrom
  21648. * curve.tension is used for catmullrom which defaults to 0.5
  21649. */
  21650. /*
  21651. Based on an optimized c++ solution in
  21652. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21653. - http://ideone.com/NoEbVM
  21654. This CubicPoly class could be used for reusing some variables and calculations,
  21655. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21656. which can be placed in CurveUtils.
  21657. */
  21658. function CubicPoly() {
  21659. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21660. /*
  21661. * Compute coefficients for a cubic polynomial
  21662. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21663. * such that
  21664. * p(0) = x0, p(1) = x1
  21665. * and
  21666. * p'(0) = t0, p'(1) = t1.
  21667. */
  21668. function init( x0, x1, t0, t1 ) {
  21669. c0 = x0;
  21670. c1 = t0;
  21671. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21672. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21673. }
  21674. return {
  21675. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21676. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21677. },
  21678. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21679. // compute tangents when parameterized in [t1,t2]
  21680. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21681. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21682. // rescale tangents for parametrization in [0,1]
  21683. t1 *= dt1;
  21684. t2 *= dt1;
  21685. init( x1, x2, t1, t2 );
  21686. },
  21687. calc: function ( t ) {
  21688. var t2 = t * t;
  21689. var t3 = t2 * t;
  21690. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21691. }
  21692. };
  21693. }
  21694. //
  21695. var tmp = new Vector3();
  21696. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21697. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21698. Curve.call( this );
  21699. this.type = 'CatmullRomCurve3';
  21700. this.points = points || [];
  21701. this.closed = closed || false;
  21702. this.curveType = curveType || 'centripetal';
  21703. this.tension = tension || 0.5;
  21704. }
  21705. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21706. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21707. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21708. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21709. var point = optionalTarget || new Vector3();
  21710. var points = this.points;
  21711. var l = points.length;
  21712. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21713. var intPoint = Math.floor( p );
  21714. var weight = p - intPoint;
  21715. if ( this.closed ) {
  21716. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21717. } else if ( weight === 0 && intPoint === l - 1 ) {
  21718. intPoint = l - 2;
  21719. weight = 1;
  21720. }
  21721. var p0, p1, p2, p3; // 4 points
  21722. if ( this.closed || intPoint > 0 ) {
  21723. p0 = points[ ( intPoint - 1 ) % l ];
  21724. } else {
  21725. // extrapolate first point
  21726. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21727. p0 = tmp;
  21728. }
  21729. p1 = points[ intPoint % l ];
  21730. p2 = points[ ( intPoint + 1 ) % l ];
  21731. if ( this.closed || intPoint + 2 < l ) {
  21732. p3 = points[ ( intPoint + 2 ) % l ];
  21733. } else {
  21734. // extrapolate last point
  21735. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21736. p3 = tmp;
  21737. }
  21738. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21739. // init Centripetal / Chordal Catmull-Rom
  21740. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21741. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21742. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21743. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21744. // safety check for repeated points
  21745. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21746. if ( dt0 < 1e-4 ) dt0 = dt1;
  21747. if ( dt2 < 1e-4 ) dt2 = dt1;
  21748. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21749. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21750. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21751. } else if ( this.curveType === 'catmullrom' ) {
  21752. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21753. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21754. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21755. }
  21756. point.set(
  21757. px.calc( weight ),
  21758. py.calc( weight ),
  21759. pz.calc( weight )
  21760. );
  21761. return point;
  21762. };
  21763. CatmullRomCurve3.prototype.copy = function ( source ) {
  21764. Curve.prototype.copy.call( this, source );
  21765. this.points = [];
  21766. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21767. var point = source.points[ i ];
  21768. this.points.push( point.clone() );
  21769. }
  21770. this.closed = source.closed;
  21771. this.curveType = source.curveType;
  21772. this.tension = source.tension;
  21773. return this;
  21774. };
  21775. CatmullRomCurve3.prototype.toJSON = function () {
  21776. var data = Curve.prototype.toJSON.call( this );
  21777. data.points = [];
  21778. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21779. var point = this.points[ i ];
  21780. data.points.push( point.toArray() );
  21781. }
  21782. data.closed = this.closed;
  21783. data.curveType = this.curveType;
  21784. data.tension = this.tension;
  21785. return data;
  21786. };
  21787. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21788. Curve.prototype.fromJSON.call( this, json );
  21789. this.points = [];
  21790. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21791. var point = json.points[ i ];
  21792. this.points.push( new Vector3().fromArray( point ) );
  21793. }
  21794. this.closed = json.closed;
  21795. this.curveType = json.curveType;
  21796. this.tension = json.tension;
  21797. return this;
  21798. };
  21799. /**
  21800. * @author zz85 / http://www.lab4games.net/zz85/blog
  21801. *
  21802. * Bezier Curves formulas obtained from
  21803. * http://en.wikipedia.org/wiki/Bézier_curve
  21804. */
  21805. function CatmullRom( t, p0, p1, p2, p3 ) {
  21806. var v0 = ( p2 - p0 ) * 0.5;
  21807. var v1 = ( p3 - p1 ) * 0.5;
  21808. var t2 = t * t;
  21809. var t3 = t * t2;
  21810. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21811. }
  21812. //
  21813. function QuadraticBezierP0( t, p ) {
  21814. var k = 1 - t;
  21815. return k * k * p;
  21816. }
  21817. function QuadraticBezierP1( t, p ) {
  21818. return 2 * ( 1 - t ) * t * p;
  21819. }
  21820. function QuadraticBezierP2( t, p ) {
  21821. return t * t * p;
  21822. }
  21823. function QuadraticBezier( t, p0, p1, p2 ) {
  21824. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21825. QuadraticBezierP2( t, p2 );
  21826. }
  21827. //
  21828. function CubicBezierP0( t, p ) {
  21829. var k = 1 - t;
  21830. return k * k * k * p;
  21831. }
  21832. function CubicBezierP1( t, p ) {
  21833. var k = 1 - t;
  21834. return 3 * k * k * t * p;
  21835. }
  21836. function CubicBezierP2( t, p ) {
  21837. return 3 * ( 1 - t ) * t * t * p;
  21838. }
  21839. function CubicBezierP3( t, p ) {
  21840. return t * t * t * p;
  21841. }
  21842. function CubicBezier( t, p0, p1, p2, p3 ) {
  21843. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21844. CubicBezierP3( t, p3 );
  21845. }
  21846. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21847. Curve.call( this );
  21848. this.type = 'CubicBezierCurve';
  21849. this.v0 = v0 || new Vector2();
  21850. this.v1 = v1 || new Vector2();
  21851. this.v2 = v2 || new Vector2();
  21852. this.v3 = v3 || new Vector2();
  21853. }
  21854. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21855. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21856. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21857. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21858. var point = optionalTarget || new Vector2();
  21859. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21860. point.set(
  21861. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21862. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21863. );
  21864. return point;
  21865. };
  21866. CubicBezierCurve.prototype.copy = function ( source ) {
  21867. Curve.prototype.copy.call( this, source );
  21868. this.v0.copy( source.v0 );
  21869. this.v1.copy( source.v1 );
  21870. this.v2.copy( source.v2 );
  21871. this.v3.copy( source.v3 );
  21872. return this;
  21873. };
  21874. CubicBezierCurve.prototype.toJSON = function () {
  21875. var data = Curve.prototype.toJSON.call( this );
  21876. data.v0 = this.v0.toArray();
  21877. data.v1 = this.v1.toArray();
  21878. data.v2 = this.v2.toArray();
  21879. data.v3 = this.v3.toArray();
  21880. return data;
  21881. };
  21882. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21883. Curve.prototype.fromJSON.call( this, json );
  21884. this.v0.fromArray( json.v0 );
  21885. this.v1.fromArray( json.v1 );
  21886. this.v2.fromArray( json.v2 );
  21887. this.v3.fromArray( json.v3 );
  21888. return this;
  21889. };
  21890. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21891. Curve.call( this );
  21892. this.type = 'CubicBezierCurve3';
  21893. this.v0 = v0 || new Vector3();
  21894. this.v1 = v1 || new Vector3();
  21895. this.v2 = v2 || new Vector3();
  21896. this.v3 = v3 || new Vector3();
  21897. }
  21898. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21899. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21900. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21901. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21902. var point = optionalTarget || new Vector3();
  21903. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21904. point.set(
  21905. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21906. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21907. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21908. );
  21909. return point;
  21910. };
  21911. CubicBezierCurve3.prototype.copy = function ( source ) {
  21912. Curve.prototype.copy.call( this, source );
  21913. this.v0.copy( source.v0 );
  21914. this.v1.copy( source.v1 );
  21915. this.v2.copy( source.v2 );
  21916. this.v3.copy( source.v3 );
  21917. return this;
  21918. };
  21919. CubicBezierCurve3.prototype.toJSON = function () {
  21920. var data = Curve.prototype.toJSON.call( this );
  21921. data.v0 = this.v0.toArray();
  21922. data.v1 = this.v1.toArray();
  21923. data.v2 = this.v2.toArray();
  21924. data.v3 = this.v3.toArray();
  21925. return data;
  21926. };
  21927. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21928. Curve.prototype.fromJSON.call( this, json );
  21929. this.v0.fromArray( json.v0 );
  21930. this.v1.fromArray( json.v1 );
  21931. this.v2.fromArray( json.v2 );
  21932. this.v3.fromArray( json.v3 );
  21933. return this;
  21934. };
  21935. function LineCurve( v1, v2 ) {
  21936. Curve.call( this );
  21937. this.type = 'LineCurve';
  21938. this.v1 = v1 || new Vector2();
  21939. this.v2 = v2 || new Vector2();
  21940. }
  21941. LineCurve.prototype = Object.create( Curve.prototype );
  21942. LineCurve.prototype.constructor = LineCurve;
  21943. LineCurve.prototype.isLineCurve = true;
  21944. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21945. var point = optionalTarget || new Vector2();
  21946. if ( t === 1 ) {
  21947. point.copy( this.v2 );
  21948. } else {
  21949. point.copy( this.v2 ).sub( this.v1 );
  21950. point.multiplyScalar( t ).add( this.v1 );
  21951. }
  21952. return point;
  21953. };
  21954. // Line curve is linear, so we can overwrite default getPointAt
  21955. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21956. return this.getPoint( u, optionalTarget );
  21957. };
  21958. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21959. var tangent = this.v2.clone().sub( this.v1 );
  21960. return tangent.normalize();
  21961. };
  21962. LineCurve.prototype.copy = function ( source ) {
  21963. Curve.prototype.copy.call( this, source );
  21964. this.v1.copy( source.v1 );
  21965. this.v2.copy( source.v2 );
  21966. return this;
  21967. };
  21968. LineCurve.prototype.toJSON = function () {
  21969. var data = Curve.prototype.toJSON.call( this );
  21970. data.v1 = this.v1.toArray();
  21971. data.v2 = this.v2.toArray();
  21972. return data;
  21973. };
  21974. LineCurve.prototype.fromJSON = function ( json ) {
  21975. Curve.prototype.fromJSON.call( this, json );
  21976. this.v1.fromArray( json.v1 );
  21977. this.v2.fromArray( json.v2 );
  21978. return this;
  21979. };
  21980. function LineCurve3( v1, v2 ) {
  21981. Curve.call( this );
  21982. this.type = 'LineCurve3';
  21983. this.v1 = v1 || new Vector3();
  21984. this.v2 = v2 || new Vector3();
  21985. }
  21986. LineCurve3.prototype = Object.create( Curve.prototype );
  21987. LineCurve3.prototype.constructor = LineCurve3;
  21988. LineCurve3.prototype.isLineCurve3 = true;
  21989. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21990. var point = optionalTarget || new Vector3();
  21991. if ( t === 1 ) {
  21992. point.copy( this.v2 );
  21993. } else {
  21994. point.copy( this.v2 ).sub( this.v1 );
  21995. point.multiplyScalar( t ).add( this.v1 );
  21996. }
  21997. return point;
  21998. };
  21999. // Line curve is linear, so we can overwrite default getPointAt
  22000. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  22001. return this.getPoint( u, optionalTarget );
  22002. };
  22003. LineCurve3.prototype.copy = function ( source ) {
  22004. Curve.prototype.copy.call( this, source );
  22005. this.v1.copy( source.v1 );
  22006. this.v2.copy( source.v2 );
  22007. return this;
  22008. };
  22009. LineCurve3.prototype.toJSON = function () {
  22010. var data = Curve.prototype.toJSON.call( this );
  22011. data.v1 = this.v1.toArray();
  22012. data.v2 = this.v2.toArray();
  22013. return data;
  22014. };
  22015. LineCurve3.prototype.fromJSON = function ( json ) {
  22016. Curve.prototype.fromJSON.call( this, json );
  22017. this.v1.fromArray( json.v1 );
  22018. this.v2.fromArray( json.v2 );
  22019. return this;
  22020. };
  22021. function QuadraticBezierCurve( v0, v1, v2 ) {
  22022. Curve.call( this );
  22023. this.type = 'QuadraticBezierCurve';
  22024. this.v0 = v0 || new Vector2();
  22025. this.v1 = v1 || new Vector2();
  22026. this.v2 = v2 || new Vector2();
  22027. }
  22028. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  22029. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22030. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22031. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22032. var point = optionalTarget || new Vector2();
  22033. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22034. point.set(
  22035. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22036. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22037. );
  22038. return point;
  22039. };
  22040. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22041. Curve.prototype.copy.call( this, source );
  22042. this.v0.copy( source.v0 );
  22043. this.v1.copy( source.v1 );
  22044. this.v2.copy( source.v2 );
  22045. return this;
  22046. };
  22047. QuadraticBezierCurve.prototype.toJSON = function () {
  22048. var data = Curve.prototype.toJSON.call( this );
  22049. data.v0 = this.v0.toArray();
  22050. data.v1 = this.v1.toArray();
  22051. data.v2 = this.v2.toArray();
  22052. return data;
  22053. };
  22054. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22055. Curve.prototype.fromJSON.call( this, json );
  22056. this.v0.fromArray( json.v0 );
  22057. this.v1.fromArray( json.v1 );
  22058. this.v2.fromArray( json.v2 );
  22059. return this;
  22060. };
  22061. function QuadraticBezierCurve3( v0, v1, v2 ) {
  22062. Curve.call( this );
  22063. this.type = 'QuadraticBezierCurve3';
  22064. this.v0 = v0 || new Vector3();
  22065. this.v1 = v1 || new Vector3();
  22066. this.v2 = v2 || new Vector3();
  22067. }
  22068. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22069. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22070. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22071. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22072. var point = optionalTarget || new Vector3();
  22073. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22074. point.set(
  22075. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22076. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22077. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22078. );
  22079. return point;
  22080. };
  22081. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22082. Curve.prototype.copy.call( this, source );
  22083. this.v0.copy( source.v0 );
  22084. this.v1.copy( source.v1 );
  22085. this.v2.copy( source.v2 );
  22086. return this;
  22087. };
  22088. QuadraticBezierCurve3.prototype.toJSON = function () {
  22089. var data = Curve.prototype.toJSON.call( this );
  22090. data.v0 = this.v0.toArray();
  22091. data.v1 = this.v1.toArray();
  22092. data.v2 = this.v2.toArray();
  22093. return data;
  22094. };
  22095. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  22096. Curve.prototype.fromJSON.call( this, json );
  22097. this.v0.fromArray( json.v0 );
  22098. this.v1.fromArray( json.v1 );
  22099. this.v2.fromArray( json.v2 );
  22100. return this;
  22101. };
  22102. function SplineCurve( points /* array of Vector2 */ ) {
  22103. Curve.call( this );
  22104. this.type = 'SplineCurve';
  22105. this.points = points || [];
  22106. }
  22107. SplineCurve.prototype = Object.create( Curve.prototype );
  22108. SplineCurve.prototype.constructor = SplineCurve;
  22109. SplineCurve.prototype.isSplineCurve = true;
  22110. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22111. var point = optionalTarget || new Vector2();
  22112. var points = this.points;
  22113. var p = ( points.length - 1 ) * t;
  22114. var intPoint = Math.floor( p );
  22115. var weight = p - intPoint;
  22116. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  22117. var p1 = points[ intPoint ];
  22118. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  22119. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  22120. point.set(
  22121. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  22122. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  22123. );
  22124. return point;
  22125. };
  22126. SplineCurve.prototype.copy = function ( source ) {
  22127. Curve.prototype.copy.call( this, source );
  22128. this.points = [];
  22129. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22130. var point = source.points[ i ];
  22131. this.points.push( point.clone() );
  22132. }
  22133. return this;
  22134. };
  22135. SplineCurve.prototype.toJSON = function () {
  22136. var data = Curve.prototype.toJSON.call( this );
  22137. data.points = [];
  22138. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22139. var point = this.points[ i ];
  22140. data.points.push( point.toArray() );
  22141. }
  22142. return data;
  22143. };
  22144. SplineCurve.prototype.fromJSON = function ( json ) {
  22145. Curve.prototype.fromJSON.call( this, json );
  22146. this.points = [];
  22147. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22148. var point = json.points[ i ];
  22149. this.points.push( new Vector2().fromArray( point ) );
  22150. }
  22151. return this;
  22152. };
  22153. var Curves = /*#__PURE__*/Object.freeze({
  22154. ArcCurve: ArcCurve,
  22155. CatmullRomCurve3: CatmullRomCurve3,
  22156. CubicBezierCurve: CubicBezierCurve,
  22157. CubicBezierCurve3: CubicBezierCurve3,
  22158. EllipseCurve: EllipseCurve,
  22159. LineCurve: LineCurve,
  22160. LineCurve3: LineCurve3,
  22161. QuadraticBezierCurve: QuadraticBezierCurve,
  22162. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22163. SplineCurve: SplineCurve
  22164. });
  22165. /**
  22166. * @author zz85 / http://www.lab4games.net/zz85/blog
  22167. *
  22168. **/
  22169. /**************************************************************
  22170. * Curved Path - a curve path is simply a array of connected
  22171. * curves, but retains the api of a curve
  22172. **************************************************************/
  22173. function CurvePath() {
  22174. Curve.call( this );
  22175. this.type = 'CurvePath';
  22176. this.curves = [];
  22177. this.autoClose = false; // Automatically closes the path
  22178. }
  22179. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  22180. constructor: CurvePath,
  22181. add: function ( curve ) {
  22182. this.curves.push( curve );
  22183. },
  22184. closePath: function () {
  22185. // Add a line curve if start and end of lines are not connected
  22186. var startPoint = this.curves[ 0 ].getPoint( 0 );
  22187. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  22188. if ( ! startPoint.equals( endPoint ) ) {
  22189. this.curves.push( new LineCurve( endPoint, startPoint ) );
  22190. }
  22191. },
  22192. // To get accurate point with reference to
  22193. // entire path distance at time t,
  22194. // following has to be done:
  22195. // 1. Length of each sub path have to be known
  22196. // 2. Locate and identify type of curve
  22197. // 3. Get t for the curve
  22198. // 4. Return curve.getPointAt(t')
  22199. getPoint: function ( t ) {
  22200. var d = t * this.getLength();
  22201. var curveLengths = this.getCurveLengths();
  22202. var i = 0;
  22203. // To think about boundaries points.
  22204. while ( i < curveLengths.length ) {
  22205. if ( curveLengths[ i ] >= d ) {
  22206. var diff = curveLengths[ i ] - d;
  22207. var curve = this.curves[ i ];
  22208. var segmentLength = curve.getLength();
  22209. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22210. return curve.getPointAt( u );
  22211. }
  22212. i ++;
  22213. }
  22214. return null;
  22215. // loop where sum != 0, sum > d , sum+1 <d
  22216. },
  22217. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22218. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22219. // getPoint() depends on getLength
  22220. getLength: function () {
  22221. var lens = this.getCurveLengths();
  22222. return lens[ lens.length - 1 ];
  22223. },
  22224. // cacheLengths must be recalculated.
  22225. updateArcLengths: function () {
  22226. this.needsUpdate = true;
  22227. this.cacheLengths = null;
  22228. this.getCurveLengths();
  22229. },
  22230. // Compute lengths and cache them
  22231. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22232. getCurveLengths: function () {
  22233. // We use cache values if curves and cache array are same length
  22234. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  22235. return this.cacheLengths;
  22236. }
  22237. // Get length of sub-curve
  22238. // Push sums into cached array
  22239. var lengths = [], sums = 0;
  22240. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22241. sums += this.curves[ i ].getLength();
  22242. lengths.push( sums );
  22243. }
  22244. this.cacheLengths = lengths;
  22245. return lengths;
  22246. },
  22247. getSpacedPoints: function ( divisions ) {
  22248. if ( divisions === undefined ) divisions = 40;
  22249. var points = [];
  22250. for ( var i = 0; i <= divisions; i ++ ) {
  22251. points.push( this.getPoint( i / divisions ) );
  22252. }
  22253. if ( this.autoClose ) {
  22254. points.push( points[ 0 ] );
  22255. }
  22256. return points;
  22257. },
  22258. getPoints: function ( divisions ) {
  22259. divisions = divisions || 12;
  22260. var points = [], last;
  22261. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  22262. var curve = curves[ i ];
  22263. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  22264. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  22265. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  22266. : divisions;
  22267. var pts = curve.getPoints( resolution );
  22268. for ( var j = 0; j < pts.length; j ++ ) {
  22269. var point = pts[ j ];
  22270. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  22271. points.push( point );
  22272. last = point;
  22273. }
  22274. }
  22275. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  22276. points.push( points[ 0 ] );
  22277. }
  22278. return points;
  22279. },
  22280. copy: function ( source ) {
  22281. Curve.prototype.copy.call( this, source );
  22282. this.curves = [];
  22283. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  22284. var curve = source.curves[ i ];
  22285. this.curves.push( curve.clone() );
  22286. }
  22287. this.autoClose = source.autoClose;
  22288. return this;
  22289. },
  22290. toJSON: function () {
  22291. var data = Curve.prototype.toJSON.call( this );
  22292. data.autoClose = this.autoClose;
  22293. data.curves = [];
  22294. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22295. var curve = this.curves[ i ];
  22296. data.curves.push( curve.toJSON() );
  22297. }
  22298. return data;
  22299. },
  22300. fromJSON: function ( json ) {
  22301. Curve.prototype.fromJSON.call( this, json );
  22302. this.autoClose = json.autoClose;
  22303. this.curves = [];
  22304. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  22305. var curve = json.curves[ i ];
  22306. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22307. }
  22308. return this;
  22309. }
  22310. } );
  22311. /**
  22312. * @author zz85 / http://www.lab4games.net/zz85/blog
  22313. * Creates free form 2d path using series of points, lines or curves.
  22314. **/
  22315. function Path( points ) {
  22316. CurvePath.call( this );
  22317. this.type = 'Path';
  22318. this.currentPoint = new Vector2();
  22319. if ( points ) {
  22320. this.setFromPoints( points );
  22321. }
  22322. }
  22323. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22324. constructor: Path,
  22325. setFromPoints: function ( points ) {
  22326. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22327. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22328. this.lineTo( points[ i ].x, points[ i ].y );
  22329. }
  22330. },
  22331. moveTo: function ( x, y ) {
  22332. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22333. },
  22334. lineTo: function ( x, y ) {
  22335. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22336. this.curves.push( curve );
  22337. this.currentPoint.set( x, y );
  22338. },
  22339. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22340. var curve = new QuadraticBezierCurve(
  22341. this.currentPoint.clone(),
  22342. new Vector2( aCPx, aCPy ),
  22343. new Vector2( aX, aY )
  22344. );
  22345. this.curves.push( curve );
  22346. this.currentPoint.set( aX, aY );
  22347. },
  22348. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22349. var curve = new CubicBezierCurve(
  22350. this.currentPoint.clone(),
  22351. new Vector2( aCP1x, aCP1y ),
  22352. new Vector2( aCP2x, aCP2y ),
  22353. new Vector2( aX, aY )
  22354. );
  22355. this.curves.push( curve );
  22356. this.currentPoint.set( aX, aY );
  22357. },
  22358. splineThru: function ( pts /*Array of Vector*/ ) {
  22359. var npts = [ this.currentPoint.clone() ].concat( pts );
  22360. var curve = new SplineCurve( npts );
  22361. this.curves.push( curve );
  22362. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22363. },
  22364. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22365. var x0 = this.currentPoint.x;
  22366. var y0 = this.currentPoint.y;
  22367. this.absarc( aX + x0, aY + y0, aRadius,
  22368. aStartAngle, aEndAngle, aClockwise );
  22369. },
  22370. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22371. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22372. },
  22373. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22374. var x0 = this.currentPoint.x;
  22375. var y0 = this.currentPoint.y;
  22376. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22377. },
  22378. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22379. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22380. if ( this.curves.length > 0 ) {
  22381. // if a previous curve is present, attempt to join
  22382. var firstPoint = curve.getPoint( 0 );
  22383. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22384. this.lineTo( firstPoint.x, firstPoint.y );
  22385. }
  22386. }
  22387. this.curves.push( curve );
  22388. var lastPoint = curve.getPoint( 1 );
  22389. this.currentPoint.copy( lastPoint );
  22390. },
  22391. copy: function ( source ) {
  22392. CurvePath.prototype.copy.call( this, source );
  22393. this.currentPoint.copy( source.currentPoint );
  22394. return this;
  22395. },
  22396. toJSON: function () {
  22397. var data = CurvePath.prototype.toJSON.call( this );
  22398. data.currentPoint = this.currentPoint.toArray();
  22399. return data;
  22400. },
  22401. fromJSON: function ( json ) {
  22402. CurvePath.prototype.fromJSON.call( this, json );
  22403. this.currentPoint.fromArray( json.currentPoint );
  22404. return this;
  22405. }
  22406. } );
  22407. /**
  22408. * @author zz85 / http://www.lab4games.net/zz85/blog
  22409. * Defines a 2d shape plane using paths.
  22410. **/
  22411. // STEP 1 Create a path.
  22412. // STEP 2 Turn path into shape.
  22413. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22414. // STEP 3a - Extract points from each shape, turn to vertices
  22415. // STEP 3b - Triangulate each shape, add faces.
  22416. function Shape( points ) {
  22417. Path.call( this, points );
  22418. this.uuid = _Math.generateUUID();
  22419. this.type = 'Shape';
  22420. this.holes = [];
  22421. }
  22422. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22423. constructor: Shape,
  22424. getPointsHoles: function ( divisions ) {
  22425. var holesPts = [];
  22426. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22427. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22428. }
  22429. return holesPts;
  22430. },
  22431. // get points of shape and holes (keypoints based on segments parameter)
  22432. extractPoints: function ( divisions ) {
  22433. return {
  22434. shape: this.getPoints( divisions ),
  22435. holes: this.getPointsHoles( divisions )
  22436. };
  22437. },
  22438. copy: function ( source ) {
  22439. Path.prototype.copy.call( this, source );
  22440. this.holes = [];
  22441. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22442. var hole = source.holes[ i ];
  22443. this.holes.push( hole.clone() );
  22444. }
  22445. return this;
  22446. },
  22447. toJSON: function () {
  22448. var data = Path.prototype.toJSON.call( this );
  22449. data.uuid = this.uuid;
  22450. data.holes = [];
  22451. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22452. var hole = this.holes[ i ];
  22453. data.holes.push( hole.toJSON() );
  22454. }
  22455. return data;
  22456. },
  22457. fromJSON: function ( json ) {
  22458. Path.prototype.fromJSON.call( this, json );
  22459. this.uuid = json.uuid;
  22460. this.holes = [];
  22461. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22462. var hole = json.holes[ i ];
  22463. this.holes.push( new Path().fromJSON( hole ) );
  22464. }
  22465. return this;
  22466. }
  22467. } );
  22468. /**
  22469. * @author mrdoob / http://mrdoob.com/
  22470. * @author alteredq / http://alteredqualia.com/
  22471. */
  22472. function Light( color, intensity ) {
  22473. Object3D.call( this );
  22474. this.type = 'Light';
  22475. this.color = new Color( color );
  22476. this.intensity = intensity !== undefined ? intensity : 1;
  22477. this.receiveShadow = undefined;
  22478. }
  22479. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22480. constructor: Light,
  22481. isLight: true,
  22482. copy: function ( source ) {
  22483. Object3D.prototype.copy.call( this, source );
  22484. this.color.copy( source.color );
  22485. this.intensity = source.intensity;
  22486. return this;
  22487. },
  22488. toJSON: function ( meta ) {
  22489. var data = Object3D.prototype.toJSON.call( this, meta );
  22490. data.object.color = this.color.getHex();
  22491. data.object.intensity = this.intensity;
  22492. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22493. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22494. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22495. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22496. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22497. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22498. return data;
  22499. }
  22500. } );
  22501. /**
  22502. * @author alteredq / http://alteredqualia.com/
  22503. */
  22504. function HemisphereLight( skyColor, groundColor, intensity ) {
  22505. Light.call( this, skyColor, intensity );
  22506. this.type = 'HemisphereLight';
  22507. this.castShadow = undefined;
  22508. this.position.copy( Object3D.DefaultUp );
  22509. this.updateMatrix();
  22510. this.groundColor = new Color( groundColor );
  22511. }
  22512. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22513. constructor: HemisphereLight,
  22514. isHemisphereLight: true,
  22515. copy: function ( source ) {
  22516. Light.prototype.copy.call( this, source );
  22517. this.groundColor.copy( source.groundColor );
  22518. return this;
  22519. }
  22520. } );
  22521. /**
  22522. * @author mrdoob / http://mrdoob.com/
  22523. */
  22524. function LightShadow( camera ) {
  22525. this.camera = camera;
  22526. this.bias = 0;
  22527. this.radius = 1;
  22528. this.mapSize = new Vector2( 512, 512 );
  22529. this.map = null;
  22530. this.matrix = new Matrix4();
  22531. }
  22532. Object.assign( LightShadow.prototype, {
  22533. copy: function ( source ) {
  22534. this.camera = source.camera.clone();
  22535. this.bias = source.bias;
  22536. this.radius = source.radius;
  22537. this.mapSize.copy( source.mapSize );
  22538. return this;
  22539. },
  22540. clone: function () {
  22541. return new this.constructor().copy( this );
  22542. },
  22543. toJSON: function () {
  22544. var object = {};
  22545. if ( this.bias !== 0 ) object.bias = this.bias;
  22546. if ( this.radius !== 1 ) object.radius = this.radius;
  22547. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22548. object.camera = this.camera.toJSON( false ).object;
  22549. delete object.camera.matrix;
  22550. return object;
  22551. }
  22552. } );
  22553. /**
  22554. * @author mrdoob / http://mrdoob.com/
  22555. */
  22556. function SpotLightShadow() {
  22557. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22558. }
  22559. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22560. constructor: SpotLightShadow,
  22561. isSpotLightShadow: true,
  22562. update: function ( light ) {
  22563. var camera = this.camera;
  22564. var fov = _Math.RAD2DEG * 2 * light.angle;
  22565. var aspect = this.mapSize.width / this.mapSize.height;
  22566. var far = light.distance || camera.far;
  22567. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22568. camera.fov = fov;
  22569. camera.aspect = aspect;
  22570. camera.far = far;
  22571. camera.updateProjectionMatrix();
  22572. }
  22573. }
  22574. } );
  22575. /**
  22576. * @author alteredq / http://alteredqualia.com/
  22577. */
  22578. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22579. Light.call( this, color, intensity );
  22580. this.type = 'SpotLight';
  22581. this.position.copy( Object3D.DefaultUp );
  22582. this.updateMatrix();
  22583. this.target = new Object3D();
  22584. Object.defineProperty( this, 'power', {
  22585. get: function () {
  22586. // intensity = power per solid angle.
  22587. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22588. return this.intensity * Math.PI;
  22589. },
  22590. set: function ( power ) {
  22591. // intensity = power per solid angle.
  22592. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22593. this.intensity = power / Math.PI;
  22594. }
  22595. } );
  22596. this.distance = ( distance !== undefined ) ? distance : 0;
  22597. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22598. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22599. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22600. this.shadow = new SpotLightShadow();
  22601. }
  22602. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22603. constructor: SpotLight,
  22604. isSpotLight: true,
  22605. copy: function ( source ) {
  22606. Light.prototype.copy.call( this, source );
  22607. this.distance = source.distance;
  22608. this.angle = source.angle;
  22609. this.penumbra = source.penumbra;
  22610. this.decay = source.decay;
  22611. this.target = source.target.clone();
  22612. this.shadow = source.shadow.clone();
  22613. return this;
  22614. }
  22615. } );
  22616. /**
  22617. * @author mrdoob / http://mrdoob.com/
  22618. */
  22619. function PointLight( color, intensity, distance, decay ) {
  22620. Light.call( this, color, intensity );
  22621. this.type = 'PointLight';
  22622. Object.defineProperty( this, 'power', {
  22623. get: function () {
  22624. // intensity = power per solid angle.
  22625. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22626. return this.intensity * 4 * Math.PI;
  22627. },
  22628. set: function ( power ) {
  22629. // intensity = power per solid angle.
  22630. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22631. this.intensity = power / ( 4 * Math.PI );
  22632. }
  22633. } );
  22634. this.distance = ( distance !== undefined ) ? distance : 0;
  22635. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22636. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22637. }
  22638. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22639. constructor: PointLight,
  22640. isPointLight: true,
  22641. copy: function ( source ) {
  22642. Light.prototype.copy.call( this, source );
  22643. this.distance = source.distance;
  22644. this.decay = source.decay;
  22645. this.shadow = source.shadow.clone();
  22646. return this;
  22647. }
  22648. } );
  22649. /**
  22650. * @author alteredq / http://alteredqualia.com/
  22651. * @author arose / http://github.com/arose
  22652. */
  22653. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22654. Camera.call( this );
  22655. this.type = 'OrthographicCamera';
  22656. this.zoom = 1;
  22657. this.view = null;
  22658. this.left = ( left !== undefined ) ? left : - 1;
  22659. this.right = ( right !== undefined ) ? right : 1;
  22660. this.top = ( top !== undefined ) ? top : 1;
  22661. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22662. this.near = ( near !== undefined ) ? near : 0.1;
  22663. this.far = ( far !== undefined ) ? far : 2000;
  22664. this.updateProjectionMatrix();
  22665. }
  22666. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22667. constructor: OrthographicCamera,
  22668. isOrthographicCamera: true,
  22669. copy: function ( source, recursive ) {
  22670. Camera.prototype.copy.call( this, source, recursive );
  22671. this.left = source.left;
  22672. this.right = source.right;
  22673. this.top = source.top;
  22674. this.bottom = source.bottom;
  22675. this.near = source.near;
  22676. this.far = source.far;
  22677. this.zoom = source.zoom;
  22678. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22679. return this;
  22680. },
  22681. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22682. if ( this.view === null ) {
  22683. this.view = {
  22684. enabled: true,
  22685. fullWidth: 1,
  22686. fullHeight: 1,
  22687. offsetX: 0,
  22688. offsetY: 0,
  22689. width: 1,
  22690. height: 1
  22691. };
  22692. }
  22693. this.view.enabled = true;
  22694. this.view.fullWidth = fullWidth;
  22695. this.view.fullHeight = fullHeight;
  22696. this.view.offsetX = x;
  22697. this.view.offsetY = y;
  22698. this.view.width = width;
  22699. this.view.height = height;
  22700. this.updateProjectionMatrix();
  22701. },
  22702. clearViewOffset: function () {
  22703. if ( this.view !== null ) {
  22704. this.view.enabled = false;
  22705. }
  22706. this.updateProjectionMatrix();
  22707. },
  22708. updateProjectionMatrix: function () {
  22709. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22710. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22711. var cx = ( this.right + this.left ) / 2;
  22712. var cy = ( this.top + this.bottom ) / 2;
  22713. var left = cx - dx;
  22714. var right = cx + dx;
  22715. var top = cy + dy;
  22716. var bottom = cy - dy;
  22717. if ( this.view !== null && this.view.enabled ) {
  22718. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22719. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22720. var scaleW = ( this.right - this.left ) / this.view.width;
  22721. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22722. left += scaleW * ( this.view.offsetX / zoomW );
  22723. right = left + scaleW * ( this.view.width / zoomW );
  22724. top -= scaleH * ( this.view.offsetY / zoomH );
  22725. bottom = top - scaleH * ( this.view.height / zoomH );
  22726. }
  22727. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22728. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22729. },
  22730. toJSON: function ( meta ) {
  22731. var data = Object3D.prototype.toJSON.call( this, meta );
  22732. data.object.zoom = this.zoom;
  22733. data.object.left = this.left;
  22734. data.object.right = this.right;
  22735. data.object.top = this.top;
  22736. data.object.bottom = this.bottom;
  22737. data.object.near = this.near;
  22738. data.object.far = this.far;
  22739. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22740. return data;
  22741. }
  22742. } );
  22743. /**
  22744. * @author mrdoob / http://mrdoob.com/
  22745. */
  22746. function DirectionalLightShadow( ) {
  22747. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22748. }
  22749. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22750. constructor: DirectionalLightShadow
  22751. } );
  22752. /**
  22753. * @author mrdoob / http://mrdoob.com/
  22754. * @author alteredq / http://alteredqualia.com/
  22755. */
  22756. function DirectionalLight( color, intensity ) {
  22757. Light.call( this, color, intensity );
  22758. this.type = 'DirectionalLight';
  22759. this.position.copy( Object3D.DefaultUp );
  22760. this.updateMatrix();
  22761. this.target = new Object3D();
  22762. this.shadow = new DirectionalLightShadow();
  22763. }
  22764. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22765. constructor: DirectionalLight,
  22766. isDirectionalLight: true,
  22767. copy: function ( source ) {
  22768. Light.prototype.copy.call( this, source );
  22769. this.target = source.target.clone();
  22770. this.shadow = source.shadow.clone();
  22771. return this;
  22772. }
  22773. } );
  22774. /**
  22775. * @author mrdoob / http://mrdoob.com/
  22776. */
  22777. function AmbientLight( color, intensity ) {
  22778. Light.call( this, color, intensity );
  22779. this.type = 'AmbientLight';
  22780. this.castShadow = undefined;
  22781. }
  22782. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22783. constructor: AmbientLight,
  22784. isAmbientLight: true
  22785. } );
  22786. /**
  22787. * @author abelnation / http://github.com/abelnation
  22788. */
  22789. function RectAreaLight( color, intensity, width, height ) {
  22790. Light.call( this, color, intensity );
  22791. this.type = 'RectAreaLight';
  22792. this.width = ( width !== undefined ) ? width : 10;
  22793. this.height = ( height !== undefined ) ? height : 10;
  22794. }
  22795. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22796. constructor: RectAreaLight,
  22797. isRectAreaLight: true,
  22798. copy: function ( source ) {
  22799. Light.prototype.copy.call( this, source );
  22800. this.width = source.width;
  22801. this.height = source.height;
  22802. return this;
  22803. },
  22804. toJSON: function ( meta ) {
  22805. var data = Light.prototype.toJSON.call( this, meta );
  22806. data.object.width = this.width;
  22807. data.object.height = this.height;
  22808. return data;
  22809. }
  22810. } );
  22811. /**
  22812. * @author mrdoob / http://mrdoob.com/
  22813. */
  22814. function MaterialLoader( manager ) {
  22815. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22816. this.textures = {};
  22817. }
  22818. Object.assign( MaterialLoader.prototype, {
  22819. load: function ( url, onLoad, onProgress, onError ) {
  22820. var scope = this;
  22821. var loader = new FileLoader( scope.manager );
  22822. loader.setPath( scope.path );
  22823. loader.load( url, function ( text ) {
  22824. onLoad( scope.parse( JSON.parse( text ) ) );
  22825. }, onProgress, onError );
  22826. },
  22827. parse: function ( json ) {
  22828. var textures = this.textures;
  22829. function getTexture( name ) {
  22830. if ( textures[ name ] === undefined ) {
  22831. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22832. }
  22833. return textures[ name ];
  22834. }
  22835. var material = new Materials[ json.type ]();
  22836. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22837. if ( json.name !== undefined ) material.name = json.name;
  22838. if ( json.color !== undefined ) material.color.setHex( json.color );
  22839. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22840. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22841. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22842. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22843. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22844. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22845. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22846. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22847. if ( json.fog !== undefined ) material.fog = json.fog;
  22848. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22849. if ( json.blending !== undefined ) material.blending = json.blending;
  22850. if ( json.combine !== undefined ) material.combine = json.combine;
  22851. if ( json.side !== undefined ) material.side = json.side;
  22852. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22853. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22854. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22855. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22856. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22857. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22858. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22859. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22860. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22861. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22862. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22863. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22864. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22865. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22866. if ( json.scale !== undefined ) material.scale = json.scale;
  22867. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22868. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22869. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22870. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22871. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22872. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  22873. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22874. if ( json.visible !== undefined ) material.visible = json.visible;
  22875. if ( json.userData !== undefined ) material.userData = json.userData;
  22876. // Shader Material
  22877. if ( json.uniforms !== undefined ) {
  22878. for ( var name in json.uniforms ) {
  22879. var uniform = json.uniforms[ name ];
  22880. material.uniforms[ name ] = {};
  22881. switch ( uniform.type ) {
  22882. case 't':
  22883. material.uniforms[ name ].value = getTexture( uniform.value );
  22884. break;
  22885. case 'c':
  22886. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22887. break;
  22888. case 'v2':
  22889. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22890. break;
  22891. case 'v3':
  22892. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22893. break;
  22894. case 'v4':
  22895. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22896. break;
  22897. case 'm3':
  22898. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22899. case 'm4':
  22900. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22901. break;
  22902. default:
  22903. material.uniforms[ name ].value = uniform.value;
  22904. }
  22905. }
  22906. }
  22907. if ( json.defines !== undefined ) material.defines = json.defines;
  22908. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22909. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22910. if ( json.extensions !== undefined ) {
  22911. for ( var key in json.extensions ) {
  22912. material.extensions[ key ] = json.extensions[ key ];
  22913. }
  22914. }
  22915. // Deprecated
  22916. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22917. // for PointsMaterial
  22918. if ( json.size !== undefined ) material.size = json.size;
  22919. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22920. // maps
  22921. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22922. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22923. if ( json.alphaMap !== undefined ) {
  22924. material.alphaMap = getTexture( json.alphaMap );
  22925. material.transparent = true;
  22926. }
  22927. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22928. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22929. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22930. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22931. if ( json.normalScale !== undefined ) {
  22932. var normalScale = json.normalScale;
  22933. if ( Array.isArray( normalScale ) === false ) {
  22934. // Blender exporter used to export a scalar. See #7459
  22935. normalScale = [ normalScale, normalScale ];
  22936. }
  22937. material.normalScale = new Vector2().fromArray( normalScale );
  22938. }
  22939. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22940. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22941. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22942. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22943. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22944. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22945. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22946. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22947. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22948. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22949. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22950. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  22951. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22952. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22953. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22954. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22955. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22956. return material;
  22957. },
  22958. setPath: function ( value ) {
  22959. this.path = value;
  22960. return this;
  22961. },
  22962. setTextures: function ( value ) {
  22963. this.textures = value;
  22964. return this;
  22965. }
  22966. } );
  22967. /**
  22968. * @author Don McCurdy / https://www.donmccurdy.com
  22969. */
  22970. var LoaderUtils = {
  22971. decodeText: function ( array ) {
  22972. if ( typeof TextDecoder !== 'undefined' ) {
  22973. return new TextDecoder().decode( array );
  22974. }
  22975. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22976. // throws a "maximum call stack size exceeded" error for large arrays.
  22977. var s = '';
  22978. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22979. // Implicitly assumes little-endian.
  22980. s += String.fromCharCode( array[ i ] );
  22981. }
  22982. try {
  22983. // merges multi-byte utf-8 characters.
  22984. return decodeURIComponent( escape( s ) );
  22985. } catch ( e ) { // see #16358
  22986. return s;
  22987. }
  22988. },
  22989. extractUrlBase: function ( url ) {
  22990. var index = url.lastIndexOf( '/' );
  22991. if ( index === - 1 ) return './';
  22992. return url.substr( 0, index + 1 );
  22993. }
  22994. };
  22995. /**
  22996. * @author benaadams / https://twitter.com/ben_a_adams
  22997. */
  22998. function InstancedBufferGeometry() {
  22999. BufferGeometry.call( this );
  23000. this.type = 'InstancedBufferGeometry';
  23001. this.maxInstancedCount = undefined;
  23002. }
  23003. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  23004. constructor: InstancedBufferGeometry,
  23005. isInstancedBufferGeometry: true,
  23006. copy: function ( source ) {
  23007. BufferGeometry.prototype.copy.call( this, source );
  23008. this.maxInstancedCount = source.maxInstancedCount;
  23009. return this;
  23010. },
  23011. clone: function () {
  23012. return new this.constructor().copy( this );
  23013. },
  23014. toJSON: function () {
  23015. var data = BufferGeometry.prototype.toJSON.call( this );
  23016. data.maxInstancedCount = this.maxInstancedCount;
  23017. data.isInstancedBufferGeometry = true;
  23018. return data;
  23019. }
  23020. } );
  23021. /**
  23022. * @author benaadams / https://twitter.com/ben_a_adams
  23023. */
  23024. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  23025. if ( typeof ( normalized ) === 'number' ) {
  23026. meshPerAttribute = normalized;
  23027. normalized = false;
  23028. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  23029. }
  23030. BufferAttribute.call( this, array, itemSize, normalized );
  23031. this.meshPerAttribute = meshPerAttribute || 1;
  23032. }
  23033. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23034. constructor: InstancedBufferAttribute,
  23035. isInstancedBufferAttribute: true,
  23036. copy: function ( source ) {
  23037. BufferAttribute.prototype.copy.call( this, source );
  23038. this.meshPerAttribute = source.meshPerAttribute;
  23039. return this;
  23040. },
  23041. toJSON: function () {
  23042. var data = BufferAttribute.prototype.toJSON.call( this );
  23043. data.meshPerAttribute = this.meshPerAttribute;
  23044. data.isInstancedBufferAttribute = true;
  23045. return data;
  23046. }
  23047. } );
  23048. /**
  23049. * @author mrdoob / http://mrdoob.com/
  23050. */
  23051. function BufferGeometryLoader( manager ) {
  23052. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23053. }
  23054. Object.assign( BufferGeometryLoader.prototype, {
  23055. load: function ( url, onLoad, onProgress, onError ) {
  23056. var scope = this;
  23057. var loader = new FileLoader( scope.manager );
  23058. loader.setPath( scope.path );
  23059. loader.load( url, function ( text ) {
  23060. onLoad( scope.parse( JSON.parse( text ) ) );
  23061. }, onProgress, onError );
  23062. },
  23063. parse: function ( json ) {
  23064. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23065. var index = json.data.index;
  23066. if ( index !== undefined ) {
  23067. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  23068. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  23069. }
  23070. var attributes = json.data.attributes;
  23071. for ( var key in attributes ) {
  23072. var attribute = attributes[ key ];
  23073. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23074. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23075. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  23076. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23077. geometry.addAttribute( key, bufferAttribute );
  23078. }
  23079. var morphAttributes = json.data.morphAttributes;
  23080. if ( morphAttributes ) {
  23081. for ( var key in morphAttributes ) {
  23082. var attributeArray = morphAttributes[ key ];
  23083. var array = [];
  23084. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  23085. var attribute = attributeArray[ i ];
  23086. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23087. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  23088. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23089. array.push( bufferAttribute );
  23090. }
  23091. geometry.morphAttributes[ key ] = array;
  23092. }
  23093. }
  23094. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23095. if ( groups !== undefined ) {
  23096. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  23097. var group = groups[ i ];
  23098. geometry.addGroup( group.start, group.count, group.materialIndex );
  23099. }
  23100. }
  23101. var boundingSphere = json.data.boundingSphere;
  23102. if ( boundingSphere !== undefined ) {
  23103. var center = new Vector3();
  23104. if ( boundingSphere.center !== undefined ) {
  23105. center.fromArray( boundingSphere.center );
  23106. }
  23107. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  23108. }
  23109. if ( json.name ) geometry.name = json.name;
  23110. if ( json.userData ) geometry.userData = json.userData;
  23111. return geometry;
  23112. },
  23113. setPath: function ( value ) {
  23114. this.path = value;
  23115. return this;
  23116. }
  23117. } );
  23118. var TYPED_ARRAYS = {
  23119. Int8Array: Int8Array,
  23120. Uint8Array: Uint8Array,
  23121. // Workaround for IE11 pre KB2929437. See #11440
  23122. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  23123. Int16Array: Int16Array,
  23124. Uint16Array: Uint16Array,
  23125. Int32Array: Int32Array,
  23126. Uint32Array: Uint32Array,
  23127. Float32Array: Float32Array,
  23128. Float64Array: Float64Array
  23129. };
  23130. /**
  23131. * @author mrdoob / http://mrdoob.com/
  23132. */
  23133. function ObjectLoader( manager ) {
  23134. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23135. this.resourcePath = '';
  23136. }
  23137. Object.assign( ObjectLoader.prototype, {
  23138. crossOrigin: 'anonymous',
  23139. load: function ( url, onLoad, onProgress, onError ) {
  23140. var scope = this;
  23141. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  23142. this.resourcePath = this.resourcePath || path;
  23143. var loader = new FileLoader( scope.manager );
  23144. loader.setPath( this.path );
  23145. loader.load( url, function ( text ) {
  23146. var json = null;
  23147. try {
  23148. json = JSON.parse( text );
  23149. } catch ( error ) {
  23150. if ( onError !== undefined ) onError( error );
  23151. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  23152. return;
  23153. }
  23154. var metadata = json.metadata;
  23155. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  23156. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  23157. return;
  23158. }
  23159. scope.parse( json, onLoad );
  23160. }, onProgress, onError );
  23161. },
  23162. setPath: function ( value ) {
  23163. this.path = value;
  23164. return this;
  23165. },
  23166. setResourcePath: function ( value ) {
  23167. this.resourcePath = value;
  23168. return this;
  23169. },
  23170. setCrossOrigin: function ( value ) {
  23171. this.crossOrigin = value;
  23172. return this;
  23173. },
  23174. parse: function ( json, onLoad ) {
  23175. var shapes = this.parseShape( json.shapes );
  23176. var geometries = this.parseGeometries( json.geometries, shapes );
  23177. var images = this.parseImages( json.images, function () {
  23178. if ( onLoad !== undefined ) onLoad( object );
  23179. } );
  23180. var textures = this.parseTextures( json.textures, images );
  23181. var materials = this.parseMaterials( json.materials, textures );
  23182. var object = this.parseObject( json.object, geometries, materials );
  23183. if ( json.animations ) {
  23184. object.animations = this.parseAnimations( json.animations );
  23185. }
  23186. if ( json.images === undefined || json.images.length === 0 ) {
  23187. if ( onLoad !== undefined ) onLoad( object );
  23188. }
  23189. return object;
  23190. },
  23191. parseShape: function ( json ) {
  23192. var shapes = {};
  23193. if ( json !== undefined ) {
  23194. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23195. var shape = new Shape().fromJSON( json[ i ] );
  23196. shapes[ shape.uuid ] = shape;
  23197. }
  23198. }
  23199. return shapes;
  23200. },
  23201. parseGeometries: function ( json, shapes ) {
  23202. var geometries = {};
  23203. if ( json !== undefined ) {
  23204. var bufferGeometryLoader = new BufferGeometryLoader();
  23205. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23206. var geometry;
  23207. var data = json[ i ];
  23208. switch ( data.type ) {
  23209. case 'PlaneGeometry':
  23210. case 'PlaneBufferGeometry':
  23211. geometry = new Geometries[ data.type ](
  23212. data.width,
  23213. data.height,
  23214. data.widthSegments,
  23215. data.heightSegments
  23216. );
  23217. break;
  23218. case 'BoxGeometry':
  23219. case 'BoxBufferGeometry':
  23220. case 'CubeGeometry': // backwards compatible
  23221. geometry = new Geometries[ data.type ](
  23222. data.width,
  23223. data.height,
  23224. data.depth,
  23225. data.widthSegments,
  23226. data.heightSegments,
  23227. data.depthSegments
  23228. );
  23229. break;
  23230. case 'CircleGeometry':
  23231. case 'CircleBufferGeometry':
  23232. geometry = new Geometries[ data.type ](
  23233. data.radius,
  23234. data.segments,
  23235. data.thetaStart,
  23236. data.thetaLength
  23237. );
  23238. break;
  23239. case 'CylinderGeometry':
  23240. case 'CylinderBufferGeometry':
  23241. geometry = new Geometries[ data.type ](
  23242. data.radiusTop,
  23243. data.radiusBottom,
  23244. data.height,
  23245. data.radialSegments,
  23246. data.heightSegments,
  23247. data.openEnded,
  23248. data.thetaStart,
  23249. data.thetaLength
  23250. );
  23251. break;
  23252. case 'ConeGeometry':
  23253. case 'ConeBufferGeometry':
  23254. geometry = new Geometries[ data.type ](
  23255. data.radius,
  23256. data.height,
  23257. data.radialSegments,
  23258. data.heightSegments,
  23259. data.openEnded,
  23260. data.thetaStart,
  23261. data.thetaLength
  23262. );
  23263. break;
  23264. case 'SphereGeometry':
  23265. case 'SphereBufferGeometry':
  23266. geometry = new Geometries[ data.type ](
  23267. data.radius,
  23268. data.widthSegments,
  23269. data.heightSegments,
  23270. data.phiStart,
  23271. data.phiLength,
  23272. data.thetaStart,
  23273. data.thetaLength
  23274. );
  23275. break;
  23276. case 'DodecahedronGeometry':
  23277. case 'DodecahedronBufferGeometry':
  23278. case 'IcosahedronGeometry':
  23279. case 'IcosahedronBufferGeometry':
  23280. case 'OctahedronGeometry':
  23281. case 'OctahedronBufferGeometry':
  23282. case 'TetrahedronGeometry':
  23283. case 'TetrahedronBufferGeometry':
  23284. geometry = new Geometries[ data.type ](
  23285. data.radius,
  23286. data.detail
  23287. );
  23288. break;
  23289. case 'RingGeometry':
  23290. case 'RingBufferGeometry':
  23291. geometry = new Geometries[ data.type ](
  23292. data.innerRadius,
  23293. data.outerRadius,
  23294. data.thetaSegments,
  23295. data.phiSegments,
  23296. data.thetaStart,
  23297. data.thetaLength
  23298. );
  23299. break;
  23300. case 'TorusGeometry':
  23301. case 'TorusBufferGeometry':
  23302. geometry = new Geometries[ data.type ](
  23303. data.radius,
  23304. data.tube,
  23305. data.radialSegments,
  23306. data.tubularSegments,
  23307. data.arc
  23308. );
  23309. break;
  23310. case 'TorusKnotGeometry':
  23311. case 'TorusKnotBufferGeometry':
  23312. geometry = new Geometries[ data.type ](
  23313. data.radius,
  23314. data.tube,
  23315. data.tubularSegments,
  23316. data.radialSegments,
  23317. data.p,
  23318. data.q
  23319. );
  23320. break;
  23321. case 'TubeGeometry':
  23322. case 'TubeBufferGeometry':
  23323. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23324. // User defined curves or instances of CurvePath will not be deserialized.
  23325. geometry = new Geometries[ data.type ](
  23326. new Curves[ data.path.type ]().fromJSON( data.path ),
  23327. data.tubularSegments,
  23328. data.radius,
  23329. data.radialSegments,
  23330. data.closed
  23331. );
  23332. break;
  23333. case 'LatheGeometry':
  23334. case 'LatheBufferGeometry':
  23335. geometry = new Geometries[ data.type ](
  23336. data.points,
  23337. data.segments,
  23338. data.phiStart,
  23339. data.phiLength
  23340. );
  23341. break;
  23342. case 'PolyhedronGeometry':
  23343. case 'PolyhedronBufferGeometry':
  23344. geometry = new Geometries[ data.type ](
  23345. data.vertices,
  23346. data.indices,
  23347. data.radius,
  23348. data.details
  23349. );
  23350. break;
  23351. case 'ShapeGeometry':
  23352. case 'ShapeBufferGeometry':
  23353. var geometryShapes = [];
  23354. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23355. var shape = shapes[ data.shapes[ j ] ];
  23356. geometryShapes.push( shape );
  23357. }
  23358. geometry = new Geometries[ data.type ](
  23359. geometryShapes,
  23360. data.curveSegments
  23361. );
  23362. break;
  23363. case 'ExtrudeGeometry':
  23364. case 'ExtrudeBufferGeometry':
  23365. var geometryShapes = [];
  23366. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23367. var shape = shapes[ data.shapes[ j ] ];
  23368. geometryShapes.push( shape );
  23369. }
  23370. var extrudePath = data.options.extrudePath;
  23371. if ( extrudePath !== undefined ) {
  23372. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23373. }
  23374. geometry = new Geometries[ data.type ](
  23375. geometryShapes,
  23376. data.options
  23377. );
  23378. break;
  23379. case 'BufferGeometry':
  23380. case 'InstancedBufferGeometry':
  23381. geometry = bufferGeometryLoader.parse( data );
  23382. break;
  23383. case 'Geometry':
  23384. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23385. var geometryLoader = new THREE.LegacyJSONLoader();
  23386. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23387. } else {
  23388. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23389. }
  23390. break;
  23391. default:
  23392. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23393. continue;
  23394. }
  23395. geometry.uuid = data.uuid;
  23396. if ( data.name !== undefined ) geometry.name = data.name;
  23397. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23398. geometries[ data.uuid ] = geometry;
  23399. }
  23400. }
  23401. return geometries;
  23402. },
  23403. parseMaterials: function ( json, textures ) {
  23404. var cache = {}; // MultiMaterial
  23405. var materials = {};
  23406. if ( json !== undefined ) {
  23407. var loader = new MaterialLoader();
  23408. loader.setTextures( textures );
  23409. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23410. var data = json[ i ];
  23411. if ( data.type === 'MultiMaterial' ) {
  23412. // Deprecated
  23413. var array = [];
  23414. for ( var j = 0; j < data.materials.length; j ++ ) {
  23415. var material = data.materials[ j ];
  23416. if ( cache[ material.uuid ] === undefined ) {
  23417. cache[ material.uuid ] = loader.parse( material );
  23418. }
  23419. array.push( cache[ material.uuid ] );
  23420. }
  23421. materials[ data.uuid ] = array;
  23422. } else {
  23423. if ( cache[ data.uuid ] === undefined ) {
  23424. cache[ data.uuid ] = loader.parse( data );
  23425. }
  23426. materials[ data.uuid ] = cache[ data.uuid ];
  23427. }
  23428. }
  23429. }
  23430. return materials;
  23431. },
  23432. parseAnimations: function ( json ) {
  23433. var animations = [];
  23434. for ( var i = 0; i < json.length; i ++ ) {
  23435. var data = json[ i ];
  23436. var clip = AnimationClip.parse( data );
  23437. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23438. animations.push( clip );
  23439. }
  23440. return animations;
  23441. },
  23442. parseImages: function ( json, onLoad ) {
  23443. var scope = this;
  23444. var images = {};
  23445. function loadImage( url ) {
  23446. scope.manager.itemStart( url );
  23447. return loader.load( url, function () {
  23448. scope.manager.itemEnd( url );
  23449. }, undefined, function () {
  23450. scope.manager.itemError( url );
  23451. scope.manager.itemEnd( url );
  23452. } );
  23453. }
  23454. if ( json !== undefined && json.length > 0 ) {
  23455. var manager = new LoadingManager( onLoad );
  23456. var loader = new ImageLoader( manager );
  23457. loader.setCrossOrigin( this.crossOrigin );
  23458. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23459. var image = json[ i ];
  23460. var url = image.url;
  23461. if ( Array.isArray( url ) ) {
  23462. // load array of images e.g CubeTexture
  23463. images[ image.uuid ] = [];
  23464. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23465. var currentUrl = url[ j ];
  23466. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23467. images[ image.uuid ].push( loadImage( path ) );
  23468. }
  23469. } else {
  23470. // load single image
  23471. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23472. images[ image.uuid ] = loadImage( path );
  23473. }
  23474. }
  23475. }
  23476. return images;
  23477. },
  23478. parseTextures: function ( json, images ) {
  23479. function parseConstant( value, type ) {
  23480. if ( typeof value === 'number' ) return value;
  23481. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23482. return type[ value ];
  23483. }
  23484. var textures = {};
  23485. if ( json !== undefined ) {
  23486. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23487. var data = json[ i ];
  23488. if ( data.image === undefined ) {
  23489. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23490. }
  23491. if ( images[ data.image ] === undefined ) {
  23492. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23493. }
  23494. var texture;
  23495. if ( Array.isArray( images[ data.image ] ) ) {
  23496. texture = new CubeTexture( images[ data.image ] );
  23497. } else {
  23498. texture = new Texture( images[ data.image ] );
  23499. }
  23500. texture.needsUpdate = true;
  23501. texture.uuid = data.uuid;
  23502. if ( data.name !== undefined ) texture.name = data.name;
  23503. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23504. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23505. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23506. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23507. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23508. if ( data.wrap !== undefined ) {
  23509. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23510. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23511. }
  23512. if ( data.format !== undefined ) texture.format = data.format;
  23513. if ( data.type !== undefined ) texture.type = data.type;
  23514. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23515. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23516. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23517. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23518. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23519. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23520. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23521. textures[ data.uuid ] = texture;
  23522. }
  23523. }
  23524. return textures;
  23525. },
  23526. parseObject: function ( data, geometries, materials ) {
  23527. var object;
  23528. function getGeometry( name ) {
  23529. if ( geometries[ name ] === undefined ) {
  23530. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23531. }
  23532. return geometries[ name ];
  23533. }
  23534. function getMaterial( name ) {
  23535. if ( name === undefined ) return undefined;
  23536. if ( Array.isArray( name ) ) {
  23537. var array = [];
  23538. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23539. var uuid = name[ i ];
  23540. if ( materials[ uuid ] === undefined ) {
  23541. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23542. }
  23543. array.push( materials[ uuid ] );
  23544. }
  23545. return array;
  23546. }
  23547. if ( materials[ name ] === undefined ) {
  23548. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23549. }
  23550. return materials[ name ];
  23551. }
  23552. switch ( data.type ) {
  23553. case 'Scene':
  23554. object = new Scene();
  23555. if ( data.background !== undefined ) {
  23556. if ( Number.isInteger( data.background ) ) {
  23557. object.background = new Color( data.background );
  23558. }
  23559. }
  23560. if ( data.fog !== undefined ) {
  23561. if ( data.fog.type === 'Fog' ) {
  23562. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23563. } else if ( data.fog.type === 'FogExp2' ) {
  23564. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23565. }
  23566. }
  23567. break;
  23568. case 'PerspectiveCamera':
  23569. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23570. if ( data.focus !== undefined ) object.focus = data.focus;
  23571. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23572. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23573. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23574. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23575. break;
  23576. case 'OrthographicCamera':
  23577. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23578. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23579. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23580. break;
  23581. case 'AmbientLight':
  23582. object = new AmbientLight( data.color, data.intensity );
  23583. break;
  23584. case 'DirectionalLight':
  23585. object = new DirectionalLight( data.color, data.intensity );
  23586. break;
  23587. case 'PointLight':
  23588. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23589. break;
  23590. case 'RectAreaLight':
  23591. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23592. break;
  23593. case 'SpotLight':
  23594. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23595. break;
  23596. case 'HemisphereLight':
  23597. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23598. break;
  23599. case 'SkinnedMesh':
  23600. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23601. case 'Mesh':
  23602. var geometry = getGeometry( data.geometry );
  23603. var material = getMaterial( data.material );
  23604. if ( geometry.bones && geometry.bones.length > 0 ) {
  23605. object = new SkinnedMesh( geometry, material );
  23606. } else {
  23607. object = new Mesh( geometry, material );
  23608. }
  23609. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23610. break;
  23611. case 'LOD':
  23612. object = new LOD();
  23613. break;
  23614. case 'Line':
  23615. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23616. break;
  23617. case 'LineLoop':
  23618. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23619. break;
  23620. case 'LineSegments':
  23621. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23622. break;
  23623. case 'PointCloud':
  23624. case 'Points':
  23625. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23626. break;
  23627. case 'Sprite':
  23628. object = new Sprite( getMaterial( data.material ) );
  23629. break;
  23630. case 'Group':
  23631. object = new Group();
  23632. break;
  23633. default:
  23634. object = new Object3D();
  23635. }
  23636. object.uuid = data.uuid;
  23637. if ( data.name !== undefined ) object.name = data.name;
  23638. if ( data.matrix !== undefined ) {
  23639. object.matrix.fromArray( data.matrix );
  23640. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23641. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23642. } else {
  23643. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23644. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23645. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23646. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23647. }
  23648. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23649. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23650. if ( data.shadow ) {
  23651. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23652. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23653. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23654. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23655. }
  23656. if ( data.visible !== undefined ) object.visible = data.visible;
  23657. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23658. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23659. if ( data.userData !== undefined ) object.userData = data.userData;
  23660. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23661. if ( data.children !== undefined ) {
  23662. var children = data.children;
  23663. for ( var i = 0; i < children.length; i ++ ) {
  23664. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23665. }
  23666. }
  23667. if ( data.type === 'LOD' ) {
  23668. var levels = data.levels;
  23669. for ( var l = 0; l < levels.length; l ++ ) {
  23670. var level = levels[ l ];
  23671. var child = object.getObjectByProperty( 'uuid', level.object );
  23672. if ( child !== undefined ) {
  23673. object.addLevel( child, level.distance );
  23674. }
  23675. }
  23676. }
  23677. return object;
  23678. }
  23679. } );
  23680. var TEXTURE_MAPPING = {
  23681. UVMapping: UVMapping,
  23682. CubeReflectionMapping: CubeReflectionMapping,
  23683. CubeRefractionMapping: CubeRefractionMapping,
  23684. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23685. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23686. SphericalReflectionMapping: SphericalReflectionMapping,
  23687. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23688. CubeUVRefractionMapping: CubeUVRefractionMapping
  23689. };
  23690. var TEXTURE_WRAPPING = {
  23691. RepeatWrapping: RepeatWrapping,
  23692. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23693. MirroredRepeatWrapping: MirroredRepeatWrapping
  23694. };
  23695. var TEXTURE_FILTER = {
  23696. NearestFilter: NearestFilter,
  23697. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  23698. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  23699. LinearFilter: LinearFilter,
  23700. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  23701. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  23702. };
  23703. /**
  23704. * @author thespite / http://clicktorelease.com/
  23705. */
  23706. function ImageBitmapLoader( manager ) {
  23707. if ( typeof createImageBitmap === 'undefined' ) {
  23708. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23709. }
  23710. if ( typeof fetch === 'undefined' ) {
  23711. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23712. }
  23713. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23714. this.options = undefined;
  23715. }
  23716. ImageBitmapLoader.prototype = {
  23717. constructor: ImageBitmapLoader,
  23718. setOptions: function setOptions( options ) {
  23719. this.options = options;
  23720. return this;
  23721. },
  23722. load: function ( url, onLoad, onProgress, onError ) {
  23723. if ( url === undefined ) url = '';
  23724. if ( this.path !== undefined ) url = this.path + url;
  23725. url = this.manager.resolveURL( url );
  23726. var scope = this;
  23727. var cached = Cache.get( url );
  23728. if ( cached !== undefined ) {
  23729. scope.manager.itemStart( url );
  23730. setTimeout( function () {
  23731. if ( onLoad ) onLoad( cached );
  23732. scope.manager.itemEnd( url );
  23733. }, 0 );
  23734. return cached;
  23735. }
  23736. fetch( url ).then( function ( res ) {
  23737. return res.blob();
  23738. } ).then( function ( blob ) {
  23739. if ( scope.options === undefined ) {
  23740. // Workaround for FireFox. It causes an error if you pass options.
  23741. return createImageBitmap( blob );
  23742. } else {
  23743. return createImageBitmap( blob, scope.options );
  23744. }
  23745. } ).then( function ( imageBitmap ) {
  23746. Cache.add( url, imageBitmap );
  23747. if ( onLoad ) onLoad( imageBitmap );
  23748. scope.manager.itemEnd( url );
  23749. } ).catch( function ( e ) {
  23750. if ( onError ) onError( e );
  23751. scope.manager.itemError( url );
  23752. scope.manager.itemEnd( url );
  23753. } );
  23754. scope.manager.itemStart( url );
  23755. },
  23756. setCrossOrigin: function ( /* value */ ) {
  23757. return this;
  23758. },
  23759. setPath: function ( value ) {
  23760. this.path = value;
  23761. return this;
  23762. }
  23763. };
  23764. /**
  23765. * @author zz85 / http://www.lab4games.net/zz85/blog
  23766. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23767. **/
  23768. function ShapePath() {
  23769. this.type = 'ShapePath';
  23770. this.color = new Color();
  23771. this.subPaths = [];
  23772. this.currentPath = null;
  23773. }
  23774. Object.assign( ShapePath.prototype, {
  23775. moveTo: function ( x, y ) {
  23776. this.currentPath = new Path();
  23777. this.subPaths.push( this.currentPath );
  23778. this.currentPath.moveTo( x, y );
  23779. },
  23780. lineTo: function ( x, y ) {
  23781. this.currentPath.lineTo( x, y );
  23782. },
  23783. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23784. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23785. },
  23786. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23787. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23788. },
  23789. splineThru: function ( pts ) {
  23790. this.currentPath.splineThru( pts );
  23791. },
  23792. toShapes: function ( isCCW, noHoles ) {
  23793. function toShapesNoHoles( inSubpaths ) {
  23794. var shapes = [];
  23795. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23796. var tmpPath = inSubpaths[ i ];
  23797. var tmpShape = new Shape();
  23798. tmpShape.curves = tmpPath.curves;
  23799. shapes.push( tmpShape );
  23800. }
  23801. return shapes;
  23802. }
  23803. function isPointInsidePolygon( inPt, inPolygon ) {
  23804. var polyLen = inPolygon.length;
  23805. // inPt on polygon contour => immediate success or
  23806. // toggling of inside/outside at every single! intersection point of an edge
  23807. // with the horizontal line through inPt, left of inPt
  23808. // not counting lowerY endpoints of edges and whole edges on that line
  23809. var inside = false;
  23810. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23811. var edgeLowPt = inPolygon[ p ];
  23812. var edgeHighPt = inPolygon[ q ];
  23813. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23814. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23815. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23816. // not parallel
  23817. if ( edgeDy < 0 ) {
  23818. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23819. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23820. }
  23821. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23822. if ( inPt.y === edgeLowPt.y ) {
  23823. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23824. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23825. } else {
  23826. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23827. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23828. if ( perpEdge < 0 ) continue;
  23829. inside = ! inside; // true intersection left of inPt
  23830. }
  23831. } else {
  23832. // parallel or collinear
  23833. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23834. // edge lies on the same horizontal line as inPt
  23835. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23836. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23837. // continue;
  23838. }
  23839. }
  23840. return inside;
  23841. }
  23842. var isClockWise = ShapeUtils.isClockWise;
  23843. var subPaths = this.subPaths;
  23844. if ( subPaths.length === 0 ) return [];
  23845. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23846. var solid, tmpPath, tmpShape, shapes = [];
  23847. if ( subPaths.length === 1 ) {
  23848. tmpPath = subPaths[ 0 ];
  23849. tmpShape = new Shape();
  23850. tmpShape.curves = tmpPath.curves;
  23851. shapes.push( tmpShape );
  23852. return shapes;
  23853. }
  23854. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23855. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23856. // console.log("Holes first", holesFirst);
  23857. var betterShapeHoles = [];
  23858. var newShapes = [];
  23859. var newShapeHoles = [];
  23860. var mainIdx = 0;
  23861. var tmpPoints;
  23862. newShapes[ mainIdx ] = undefined;
  23863. newShapeHoles[ mainIdx ] = [];
  23864. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23865. tmpPath = subPaths[ i ];
  23866. tmpPoints = tmpPath.getPoints();
  23867. solid = isClockWise( tmpPoints );
  23868. solid = isCCW ? ! solid : solid;
  23869. if ( solid ) {
  23870. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23871. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23872. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23873. if ( holesFirst ) mainIdx ++;
  23874. newShapeHoles[ mainIdx ] = [];
  23875. //console.log('cw', i);
  23876. } else {
  23877. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23878. //console.log('ccw', i);
  23879. }
  23880. }
  23881. // only Holes? -> probably all Shapes with wrong orientation
  23882. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23883. if ( newShapes.length > 1 ) {
  23884. var ambiguous = false;
  23885. var toChange = [];
  23886. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23887. betterShapeHoles[ sIdx ] = [];
  23888. }
  23889. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23890. var sho = newShapeHoles[ sIdx ];
  23891. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23892. var ho = sho[ hIdx ];
  23893. var hole_unassigned = true;
  23894. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23895. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23896. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23897. if ( hole_unassigned ) {
  23898. hole_unassigned = false;
  23899. betterShapeHoles[ s2Idx ].push( ho );
  23900. } else {
  23901. ambiguous = true;
  23902. }
  23903. }
  23904. }
  23905. if ( hole_unassigned ) {
  23906. betterShapeHoles[ sIdx ].push( ho );
  23907. }
  23908. }
  23909. }
  23910. // console.log("ambiguous: ", ambiguous);
  23911. if ( toChange.length > 0 ) {
  23912. // console.log("to change: ", toChange);
  23913. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23914. }
  23915. }
  23916. var tmpHoles;
  23917. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23918. tmpShape = newShapes[ i ].s;
  23919. shapes.push( tmpShape );
  23920. tmpHoles = newShapeHoles[ i ];
  23921. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23922. tmpShape.holes.push( tmpHoles[ j ].h );
  23923. }
  23924. }
  23925. //console.log("shape", shapes);
  23926. return shapes;
  23927. }
  23928. } );
  23929. /**
  23930. * @author zz85 / http://www.lab4games.net/zz85/blog
  23931. * @author mrdoob / http://mrdoob.com/
  23932. */
  23933. function Font( data ) {
  23934. this.type = 'Font';
  23935. this.data = data;
  23936. }
  23937. Object.assign( Font.prototype, {
  23938. isFont: true,
  23939. generateShapes: function ( text, size ) {
  23940. if ( size === undefined ) size = 100;
  23941. var shapes = [];
  23942. var paths = createPaths( text, size, this.data );
  23943. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23944. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23945. }
  23946. return shapes;
  23947. }
  23948. } );
  23949. function createPaths( text, size, data ) {
  23950. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23951. var scale = size / data.resolution;
  23952. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23953. var paths = [];
  23954. var offsetX = 0, offsetY = 0;
  23955. for ( var i = 0; i < chars.length; i ++ ) {
  23956. var char = chars[ i ];
  23957. if ( char === '\n' ) {
  23958. offsetX = 0;
  23959. offsetY -= line_height;
  23960. } else {
  23961. var ret = createPath( char, scale, offsetX, offsetY, data );
  23962. offsetX += ret.offsetX;
  23963. paths.push( ret.path );
  23964. }
  23965. }
  23966. return paths;
  23967. }
  23968. function createPath( char, scale, offsetX, offsetY, data ) {
  23969. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23970. if ( ! glyph ) {
  23971. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  23972. return;
  23973. }
  23974. var path = new ShapePath();
  23975. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23976. if ( glyph.o ) {
  23977. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23978. for ( var i = 0, l = outline.length; i < l; ) {
  23979. var action = outline[ i ++ ];
  23980. switch ( action ) {
  23981. case 'm': // moveTo
  23982. x = outline[ i ++ ] * scale + offsetX;
  23983. y = outline[ i ++ ] * scale + offsetY;
  23984. path.moveTo( x, y );
  23985. break;
  23986. case 'l': // lineTo
  23987. x = outline[ i ++ ] * scale + offsetX;
  23988. y = outline[ i ++ ] * scale + offsetY;
  23989. path.lineTo( x, y );
  23990. break;
  23991. case 'q': // quadraticCurveTo
  23992. cpx = outline[ i ++ ] * scale + offsetX;
  23993. cpy = outline[ i ++ ] * scale + offsetY;
  23994. cpx1 = outline[ i ++ ] * scale + offsetX;
  23995. cpy1 = outline[ i ++ ] * scale + offsetY;
  23996. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23997. break;
  23998. case 'b': // bezierCurveTo
  23999. cpx = outline[ i ++ ] * scale + offsetX;
  24000. cpy = outline[ i ++ ] * scale + offsetY;
  24001. cpx1 = outline[ i ++ ] * scale + offsetX;
  24002. cpy1 = outline[ i ++ ] * scale + offsetY;
  24003. cpx2 = outline[ i ++ ] * scale + offsetX;
  24004. cpy2 = outline[ i ++ ] * scale + offsetY;
  24005. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  24006. break;
  24007. }
  24008. }
  24009. }
  24010. return { offsetX: glyph.ha * scale, path: path };
  24011. }
  24012. /**
  24013. * @author mrdoob / http://mrdoob.com/
  24014. */
  24015. function FontLoader( manager ) {
  24016. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  24017. }
  24018. Object.assign( FontLoader.prototype, {
  24019. load: function ( url, onLoad, onProgress, onError ) {
  24020. var scope = this;
  24021. var loader = new FileLoader( this.manager );
  24022. loader.setPath( this.path );
  24023. loader.load( url, function ( text ) {
  24024. var json;
  24025. try {
  24026. json = JSON.parse( text );
  24027. } catch ( e ) {
  24028. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  24029. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  24030. }
  24031. var font = scope.parse( json );
  24032. if ( onLoad ) onLoad( font );
  24033. }, onProgress, onError );
  24034. },
  24035. parse: function ( json ) {
  24036. return new Font( json );
  24037. },
  24038. setPath: function ( value ) {
  24039. this.path = value;
  24040. return this;
  24041. }
  24042. } );
  24043. /**
  24044. * @author alteredq / http://alteredqualia.com/
  24045. */
  24046. function Loader() {}
  24047. Loader.Handlers = {
  24048. handlers: [],
  24049. add: function ( regex, loader ) {
  24050. this.handlers.push( regex, loader );
  24051. },
  24052. get: function ( file ) {
  24053. var handlers = this.handlers;
  24054. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  24055. var regex = handlers[ i ];
  24056. var loader = handlers[ i + 1 ];
  24057. if ( regex.test( file ) ) {
  24058. return loader;
  24059. }
  24060. }
  24061. return null;
  24062. }
  24063. };
  24064. Object.assign( Loader.prototype, {
  24065. crossOrigin: 'anonymous',
  24066. onLoadStart: function () {},
  24067. onLoadProgress: function () {},
  24068. onLoadComplete: function () {},
  24069. initMaterials: function ( materials, texturePath, crossOrigin ) {
  24070. var array = [];
  24071. for ( var i = 0; i < materials.length; ++ i ) {
  24072. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  24073. }
  24074. return array;
  24075. },
  24076. createMaterial: ( function () {
  24077. var BlendingMode = {
  24078. NoBlending: NoBlending,
  24079. NormalBlending: NormalBlending,
  24080. AdditiveBlending: AdditiveBlending,
  24081. SubtractiveBlending: SubtractiveBlending,
  24082. MultiplyBlending: MultiplyBlending,
  24083. CustomBlending: CustomBlending
  24084. };
  24085. var color = new Color();
  24086. var textureLoader = new TextureLoader();
  24087. var materialLoader = new MaterialLoader();
  24088. return function createMaterial( m, texturePath, crossOrigin ) {
  24089. // convert from old material format
  24090. var textures = {};
  24091. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  24092. var fullPath = texturePath + path;
  24093. var loader = Loader.Handlers.get( fullPath );
  24094. var texture;
  24095. if ( loader !== null ) {
  24096. texture = loader.load( fullPath );
  24097. } else {
  24098. textureLoader.setCrossOrigin( crossOrigin );
  24099. texture = textureLoader.load( fullPath );
  24100. }
  24101. if ( repeat !== undefined ) {
  24102. texture.repeat.fromArray( repeat );
  24103. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  24104. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  24105. }
  24106. if ( offset !== undefined ) {
  24107. texture.offset.fromArray( offset );
  24108. }
  24109. if ( wrap !== undefined ) {
  24110. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  24111. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  24112. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  24113. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  24114. }
  24115. if ( anisotropy !== undefined ) {
  24116. texture.anisotropy = anisotropy;
  24117. }
  24118. var uuid = _Math.generateUUID();
  24119. textures[ uuid ] = texture;
  24120. return uuid;
  24121. }
  24122. //
  24123. var json = {
  24124. uuid: _Math.generateUUID(),
  24125. type: 'MeshLambertMaterial'
  24126. };
  24127. for ( var name in m ) {
  24128. var value = m[ name ];
  24129. switch ( name ) {
  24130. case 'DbgColor':
  24131. case 'DbgIndex':
  24132. case 'opticalDensity':
  24133. case 'illumination':
  24134. break;
  24135. case 'DbgName':
  24136. json.name = value;
  24137. break;
  24138. case 'blending':
  24139. json.blending = BlendingMode[ value ];
  24140. break;
  24141. case 'colorAmbient':
  24142. case 'mapAmbient':
  24143. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  24144. break;
  24145. case 'colorDiffuse':
  24146. json.color = color.fromArray( value ).getHex();
  24147. break;
  24148. case 'colorSpecular':
  24149. json.specular = color.fromArray( value ).getHex();
  24150. break;
  24151. case 'colorEmissive':
  24152. json.emissive = color.fromArray( value ).getHex();
  24153. break;
  24154. case 'specularCoef':
  24155. json.shininess = value;
  24156. break;
  24157. case 'shading':
  24158. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  24159. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  24160. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  24161. break;
  24162. case 'mapDiffuse':
  24163. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  24164. break;
  24165. case 'mapDiffuseRepeat':
  24166. case 'mapDiffuseOffset':
  24167. case 'mapDiffuseWrap':
  24168. case 'mapDiffuseAnisotropy':
  24169. break;
  24170. case 'mapEmissive':
  24171. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  24172. break;
  24173. case 'mapEmissiveRepeat':
  24174. case 'mapEmissiveOffset':
  24175. case 'mapEmissiveWrap':
  24176. case 'mapEmissiveAnisotropy':
  24177. break;
  24178. case 'mapLight':
  24179. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  24180. break;
  24181. case 'mapLightRepeat':
  24182. case 'mapLightOffset':
  24183. case 'mapLightWrap':
  24184. case 'mapLightAnisotropy':
  24185. break;
  24186. case 'mapAO':
  24187. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  24188. break;
  24189. case 'mapAORepeat':
  24190. case 'mapAOOffset':
  24191. case 'mapAOWrap':
  24192. case 'mapAOAnisotropy':
  24193. break;
  24194. case 'mapBump':
  24195. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  24196. break;
  24197. case 'mapBumpScale':
  24198. json.bumpScale = value;
  24199. break;
  24200. case 'mapBumpRepeat':
  24201. case 'mapBumpOffset':
  24202. case 'mapBumpWrap':
  24203. case 'mapBumpAnisotropy':
  24204. break;
  24205. case 'mapNormal':
  24206. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  24207. break;
  24208. case 'mapNormalFactor':
  24209. json.normalScale = value;
  24210. break;
  24211. case 'mapNormalRepeat':
  24212. case 'mapNormalOffset':
  24213. case 'mapNormalWrap':
  24214. case 'mapNormalAnisotropy':
  24215. break;
  24216. case 'mapSpecular':
  24217. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  24218. break;
  24219. case 'mapSpecularRepeat':
  24220. case 'mapSpecularOffset':
  24221. case 'mapSpecularWrap':
  24222. case 'mapSpecularAnisotropy':
  24223. break;
  24224. case 'mapMetalness':
  24225. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  24226. break;
  24227. case 'mapMetalnessRepeat':
  24228. case 'mapMetalnessOffset':
  24229. case 'mapMetalnessWrap':
  24230. case 'mapMetalnessAnisotropy':
  24231. break;
  24232. case 'mapRoughness':
  24233. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  24234. break;
  24235. case 'mapRoughnessRepeat':
  24236. case 'mapRoughnessOffset':
  24237. case 'mapRoughnessWrap':
  24238. case 'mapRoughnessAnisotropy':
  24239. break;
  24240. case 'mapAlpha':
  24241. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  24242. break;
  24243. case 'mapAlphaRepeat':
  24244. case 'mapAlphaOffset':
  24245. case 'mapAlphaWrap':
  24246. case 'mapAlphaAnisotropy':
  24247. break;
  24248. case 'flipSided':
  24249. json.side = BackSide;
  24250. break;
  24251. case 'doubleSided':
  24252. json.side = DoubleSide;
  24253. break;
  24254. case 'transparency':
  24255. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  24256. json.opacity = value;
  24257. break;
  24258. case 'depthTest':
  24259. case 'depthWrite':
  24260. case 'colorWrite':
  24261. case 'opacity':
  24262. case 'reflectivity':
  24263. case 'transparent':
  24264. case 'visible':
  24265. case 'wireframe':
  24266. json[ name ] = value;
  24267. break;
  24268. case 'vertexColors':
  24269. if ( value === true ) json.vertexColors = VertexColors;
  24270. if ( value === 'face' ) json.vertexColors = FaceColors;
  24271. break;
  24272. default:
  24273. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  24274. break;
  24275. }
  24276. }
  24277. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  24278. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  24279. if ( json.opacity < 1 ) json.transparent = true;
  24280. materialLoader.setTextures( textures );
  24281. return materialLoader.parse( json );
  24282. };
  24283. } )()
  24284. } );
  24285. /**
  24286. * @author mrdoob / http://mrdoob.com/
  24287. */
  24288. var _context;
  24289. var AudioContext = {
  24290. getContext: function () {
  24291. if ( _context === undefined ) {
  24292. _context = new ( window.AudioContext || window.webkitAudioContext )();
  24293. }
  24294. return _context;
  24295. },
  24296. setContext: function ( value ) {
  24297. _context = value;
  24298. }
  24299. };
  24300. /**
  24301. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24302. */
  24303. function AudioLoader( manager ) {
  24304. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  24305. }
  24306. Object.assign( AudioLoader.prototype, {
  24307. load: function ( url, onLoad, onProgress, onError ) {
  24308. var loader = new FileLoader( this.manager );
  24309. loader.setResponseType( 'arraybuffer' );
  24310. loader.setPath( this.path );
  24311. loader.load( url, function ( buffer ) {
  24312. // Create a copy of the buffer. The `decodeAudioData` method
  24313. // detaches the buffer when complete, preventing reuse.
  24314. var bufferCopy = buffer.slice( 0 );
  24315. var context = AudioContext.getContext();
  24316. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  24317. onLoad( audioBuffer );
  24318. } );
  24319. }, onProgress, onError );
  24320. },
  24321. setPath: function ( value ) {
  24322. this.path = value;
  24323. return this;
  24324. }
  24325. } );
  24326. /**
  24327. * @author bhouston / http://clara.io
  24328. * @author WestLangley / http://github.com/WestLangley
  24329. *
  24330. * Primary reference:
  24331. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24332. *
  24333. * Secondary reference:
  24334. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24335. */
  24336. // 3-band SH defined by 9 coefficients
  24337. function SphericalHarmonics3() {
  24338. this.coefficients = [];
  24339. for ( var i = 0; i < 9; i ++ ) {
  24340. this.coefficients.push( new Vector3() );
  24341. }
  24342. }
  24343. Object.assign( SphericalHarmonics3.prototype, {
  24344. isSphericalHarmonics3: true,
  24345. set: function ( coefficients ) {
  24346. for ( var i = 0; i < 9; i ++ ) {
  24347. this.coefficients[ i ].copy( coefficients[ i ] );
  24348. }
  24349. return this;
  24350. },
  24351. zero: function () {
  24352. for ( var i = 0; i < 9; i ++ ) {
  24353. this.coefficients[ i ].set( 0, 0, 0 );
  24354. }
  24355. return this;
  24356. },
  24357. // get the radiance in the direction of the normal
  24358. // target is a Vector3
  24359. getAt: function ( normal, target ) {
  24360. // normal is assumed to be unit length
  24361. var x = normal.x, y = normal.y, z = normal.z;
  24362. var coeff = this.coefficients;
  24363. // band 0
  24364. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  24365. // band 1
  24366. target.addScale( coeff[ 1 ], 0.488603 * y );
  24367. target.addScale( coeff[ 2 ], 0.488603 * z );
  24368. target.addScale( coeff[ 3 ], 0.488603 * x );
  24369. // band 2
  24370. target.addScale( coeff[ 4 ], 1.092548 * ( x * y ) );
  24371. target.addScale( coeff[ 5 ], 1.092548 * ( y * z ) );
  24372. target.addScale( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  24373. target.addScale( coeff[ 7 ], 1.092548 * ( x * z ) );
  24374. target.addScale( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  24375. return target;
  24376. },
  24377. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24378. // target is a Vector3
  24379. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24380. getIrradianceAt: function ( normal, target ) {
  24381. // normal is assumed to be unit length
  24382. var x = normal.x, y = normal.y, z = normal.z;
  24383. var coeff = this.coefficients;
  24384. // band 0
  24385. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  24386. // band 1
  24387. target.addScale( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  24388. target.addScale( coeff[ 2 ], 2.0 * 0.511664 * z );
  24389. target.addScale( coeff[ 3 ], 2.0 * 0.511664 * x );
  24390. // band 2
  24391. target.addScale( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  24392. target.addScale( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  24393. target.addScale( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24394. target.addScale( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  24395. target.addScale( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  24396. return target;
  24397. },
  24398. add: function ( sh ) {
  24399. for ( var i = 0; i < 9; i ++ ) {
  24400. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24401. }
  24402. return this;
  24403. },
  24404. scale: function ( s ) {
  24405. for ( var i = 0; i < 9; i ++ ) {
  24406. this.coefficients[ i ].multiplyScalar( s );
  24407. }
  24408. return this;
  24409. },
  24410. lerp: function ( sh, alpha ) {
  24411. for ( var i = 0; i < 9; i ++ ) {
  24412. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24413. }
  24414. return this;
  24415. },
  24416. equals: function ( sh ) {
  24417. for ( var i = 0; i < 9; i ++ ) {
  24418. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24419. return false;
  24420. }
  24421. }
  24422. return true;
  24423. },
  24424. copy: function ( sh ) {
  24425. return this.set( sh.coefficients );
  24426. },
  24427. clone: function () {
  24428. return new this.constructor().copy( this );
  24429. },
  24430. fromArray: function ( array ) {
  24431. var coefficients = this.coefficients;
  24432. for ( var i = 0; i < 9; i ++ ) {
  24433. coefficients[ i ].fromArray( array, i * 3 );
  24434. }
  24435. return this;
  24436. },
  24437. toArray: function () {
  24438. var array = [];
  24439. var coefficients = this.coefficients;
  24440. for ( var i = 0; i < 9; i ++ ) {
  24441. coefficients[ i ].toArray( array, i * 3 );
  24442. }
  24443. return array;
  24444. }
  24445. } );
  24446. Object.assign( SphericalHarmonics3, {
  24447. // evaluate the basis functions
  24448. // shBasis is an Array[ 9 ]
  24449. getBasisAt: function ( normal, shBasis ) {
  24450. // normal is assumed to be unit length
  24451. var x = normal.x, y = normal.y, z = normal.z;
  24452. // band 0
  24453. shBasis[ 0 ] = 0.282095;
  24454. // band 1
  24455. shBasis[ 1 ] = 0.488603 * y;
  24456. shBasis[ 2 ] = 0.488603 * z;
  24457. shBasis[ 3 ] = 0.488603 * x;
  24458. // band 2
  24459. shBasis[ 4 ] = 1.092548 * x * y;
  24460. shBasis[ 5 ] = 1.092548 * y * z;
  24461. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24462. shBasis[ 7 ] = 1.092548 * x * z;
  24463. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24464. }
  24465. } );
  24466. /**
  24467. * @author WestLangley / http://github.com/WestLangley
  24468. *
  24469. * A LightProbe is a source of indirect-diffuse light
  24470. */
  24471. function LightProbe( sh, intensity ) {
  24472. Light.call( this, undefined, intensity );
  24473. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24474. }
  24475. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24476. constructor: LightProbe,
  24477. isLightProbe: true,
  24478. copy: function ( source ) {
  24479. Light.prototype.copy.call( this, source );
  24480. this.sh.copy( source.sh );
  24481. this.intensity = source.intensity;
  24482. return this;
  24483. },
  24484. toJSON: function ( meta ) {
  24485. var data = Light.prototype.toJSON.call( this, meta );
  24486. // data.sh = this.sh.toArray(); // todo
  24487. return data;
  24488. }
  24489. } );
  24490. /**
  24491. * @author WestLangley / http://github.com/WestLangley
  24492. */
  24493. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24494. LightProbe.call( this, undefined, intensity );
  24495. var color1 = new Color().set( skyColor );
  24496. var color2 = new Color().set( groundColor );
  24497. var sky = new Vector3( color1.r, color1.g, color1.b );
  24498. var ground = new Vector3( color2.r, color2.g, color2.b );
  24499. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24500. var c0 = Math.sqrt( Math.PI );
  24501. var c1 = c0 * Math.sqrt( 0.75 );
  24502. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24503. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24504. }
  24505. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24506. constructor: HemisphereLightProbe,
  24507. isHemisphereLightProbe: true,
  24508. copy: function ( source ) { // modifying colors not currently supported
  24509. LightProbe.prototype.copy.call( this, source );
  24510. return this;
  24511. },
  24512. toJSON: function ( meta ) {
  24513. var data = LightProbe.prototype.toJSON.call( this, meta );
  24514. // data.sh = this.sh.toArray(); // todo
  24515. return data;
  24516. }
  24517. } );
  24518. /**
  24519. * @author WestLangley / http://github.com/WestLangley
  24520. */
  24521. function AmbientLightProbe( color, intensity ) {
  24522. LightProbe.call( this, undefined, intensity );
  24523. var color1 = new Color().set( color );
  24524. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24525. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24526. }
  24527. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24528. constructor: AmbientLightProbe,
  24529. isAmbientLightProbe: true,
  24530. copy: function ( source ) { // modifying color not currently supported
  24531. LightProbe.prototype.copy.call( this, source );
  24532. return this;
  24533. },
  24534. toJSON: function ( meta ) {
  24535. var data = LightProbe.prototype.toJSON.call( this, meta );
  24536. // data.sh = this.sh.toArray(); // todo
  24537. return data;
  24538. }
  24539. } );
  24540. var _eyeRight, _eyeLeft;
  24541. /**
  24542. * @author mrdoob / http://mrdoob.com/
  24543. */
  24544. function StereoCamera() {
  24545. this.type = 'StereoCamera';
  24546. this.aspect = 1;
  24547. this.eyeSep = 0.064;
  24548. this.cameraL = new PerspectiveCamera();
  24549. this.cameraL.layers.enable( 1 );
  24550. this.cameraL.matrixAutoUpdate = false;
  24551. this.cameraR = new PerspectiveCamera();
  24552. this.cameraR.layers.enable( 2 );
  24553. this.cameraR.matrixAutoUpdate = false;
  24554. this._cache = {
  24555. focus: null,
  24556. fov: null,
  24557. aspect: null,
  24558. near: null,
  24559. far: null,
  24560. zoom: null,
  24561. eyeSep: null
  24562. };
  24563. }
  24564. Object.assign( StereoCamera.prototype, {
  24565. update: function ( camera ) {
  24566. if ( _eyeRight === undefined ) {
  24567. _eyeRight = new Matrix4();
  24568. _eyeLeft = new Matrix4();
  24569. }
  24570. var cache = this._cache;
  24571. var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  24572. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  24573. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  24574. if ( needsUpdate ) {
  24575. cache.focus = camera.focus;
  24576. cache.fov = camera.fov;
  24577. cache.aspect = camera.aspect * this.aspect;
  24578. cache.near = camera.near;
  24579. cache.far = camera.far;
  24580. cache.zoom = camera.zoom;
  24581. cache.eyeSep = this.eyeSep;
  24582. // Off-axis stereoscopic effect based on
  24583. // http://paulbourke.net/stereographics/stereorender/
  24584. var projectionMatrix = camera.projectionMatrix.clone();
  24585. var eyeSepHalf = cache.eyeSep / 2;
  24586. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  24587. var ymax = ( cache.near * Math.tan( _Math.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  24588. var xmin, xmax;
  24589. // translate xOffset
  24590. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  24591. _eyeRight.elements[ 12 ] = eyeSepHalf;
  24592. // for left eye
  24593. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  24594. xmax = ymax * cache.aspect + eyeSepOnProjection;
  24595. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24596. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24597. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24598. // for right eye
  24599. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  24600. xmax = ymax * cache.aspect - eyeSepOnProjection;
  24601. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24602. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24603. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24604. }
  24605. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  24606. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  24607. }
  24608. } );
  24609. /**
  24610. * @author alteredq / http://alteredqualia.com/
  24611. */
  24612. function Clock( autoStart ) {
  24613. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24614. this.startTime = 0;
  24615. this.oldTime = 0;
  24616. this.elapsedTime = 0;
  24617. this.running = false;
  24618. }
  24619. Object.assign( Clock.prototype, {
  24620. start: function () {
  24621. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24622. this.oldTime = this.startTime;
  24623. this.elapsedTime = 0;
  24624. this.running = true;
  24625. },
  24626. stop: function () {
  24627. this.getElapsedTime();
  24628. this.running = false;
  24629. this.autoStart = false;
  24630. },
  24631. getElapsedTime: function () {
  24632. this.getDelta();
  24633. return this.elapsedTime;
  24634. },
  24635. getDelta: function () {
  24636. var diff = 0;
  24637. if ( this.autoStart && ! this.running ) {
  24638. this.start();
  24639. return 0;
  24640. }
  24641. if ( this.running ) {
  24642. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24643. diff = ( newTime - this.oldTime ) / 1000;
  24644. this.oldTime = newTime;
  24645. this.elapsedTime += diff;
  24646. }
  24647. return diff;
  24648. }
  24649. } );
  24650. /**
  24651. * @author mrdoob / http://mrdoob.com/
  24652. */
  24653. var _position, _quaternion$2, _scale;
  24654. var _orientation;
  24655. function AudioListener() {
  24656. Object3D.call( this );
  24657. this.type = 'AudioListener';
  24658. this.context = AudioContext.getContext();
  24659. this.gain = this.context.createGain();
  24660. this.gain.connect( this.context.destination );
  24661. this.filter = null;
  24662. this.timeDelta = 0;
  24663. // private
  24664. this._clock = new Clock();
  24665. }
  24666. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24667. constructor: AudioListener,
  24668. getInput: function () {
  24669. return this.gain;
  24670. },
  24671. removeFilter: function ( ) {
  24672. if ( this.filter !== null ) {
  24673. this.gain.disconnect( this.filter );
  24674. this.filter.disconnect( this.context.destination );
  24675. this.gain.connect( this.context.destination );
  24676. this.filter = null;
  24677. }
  24678. return this;
  24679. },
  24680. getFilter: function () {
  24681. return this.filter;
  24682. },
  24683. setFilter: function ( value ) {
  24684. if ( this.filter !== null ) {
  24685. this.gain.disconnect( this.filter );
  24686. this.filter.disconnect( this.context.destination );
  24687. } else {
  24688. this.gain.disconnect( this.context.destination );
  24689. }
  24690. this.filter = value;
  24691. this.gain.connect( this.filter );
  24692. this.filter.connect( this.context.destination );
  24693. return this;
  24694. },
  24695. getMasterVolume: function () {
  24696. return this.gain.gain.value;
  24697. },
  24698. setMasterVolume: function ( value ) {
  24699. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24700. return this;
  24701. },
  24702. updateMatrixWorld: function ( force ) {
  24703. Object3D.prototype.updateMatrixWorld.call( this, force );
  24704. if ( _position === undefined ) {
  24705. _position = new Vector3();
  24706. _quaternion$2 = new Quaternion();
  24707. _scale = new Vector3();
  24708. _orientation = new Vector3();
  24709. }
  24710. var listener = this.context.listener;
  24711. var up = this.up;
  24712. this.timeDelta = this._clock.getDelta();
  24713. this.matrixWorld.decompose( _position, _quaternion$2, _scale );
  24714. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$2 );
  24715. if ( listener.positionX ) {
  24716. // code path for Chrome (see #14393)
  24717. var endTime = this.context.currentTime + this.timeDelta;
  24718. listener.positionX.linearRampToValueAtTime( _position.x, endTime );
  24719. listener.positionY.linearRampToValueAtTime( _position.y, endTime );
  24720. listener.positionZ.linearRampToValueAtTime( _position.z, endTime );
  24721. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  24722. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  24723. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  24724. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24725. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24726. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24727. } else {
  24728. listener.setPosition( _position.x, _position.y, _position.z );
  24729. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  24730. }
  24731. }
  24732. } );
  24733. /**
  24734. * @author mrdoob / http://mrdoob.com/
  24735. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24736. */
  24737. function Audio( listener ) {
  24738. Object3D.call( this );
  24739. this.type = 'Audio';
  24740. this.listener = listener;
  24741. this.context = listener.context;
  24742. this.gain = this.context.createGain();
  24743. this.gain.connect( listener.getInput() );
  24744. this.autoplay = false;
  24745. this.buffer = null;
  24746. this.detune = 0;
  24747. this.loop = false;
  24748. this.startTime = 0;
  24749. this.offset = 0;
  24750. this.playbackRate = 1;
  24751. this.isPlaying = false;
  24752. this.hasPlaybackControl = true;
  24753. this.sourceType = 'empty';
  24754. this.filters = [];
  24755. }
  24756. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24757. constructor: Audio,
  24758. getOutput: function () {
  24759. return this.gain;
  24760. },
  24761. setNodeSource: function ( audioNode ) {
  24762. this.hasPlaybackControl = false;
  24763. this.sourceType = 'audioNode';
  24764. this.source = audioNode;
  24765. this.connect();
  24766. return this;
  24767. },
  24768. setMediaElementSource: function ( mediaElement ) {
  24769. this.hasPlaybackControl = false;
  24770. this.sourceType = 'mediaNode';
  24771. this.source = this.context.createMediaElementSource( mediaElement );
  24772. this.connect();
  24773. return this;
  24774. },
  24775. setBuffer: function ( audioBuffer ) {
  24776. this.buffer = audioBuffer;
  24777. this.sourceType = 'buffer';
  24778. if ( this.autoplay ) this.play();
  24779. return this;
  24780. },
  24781. play: function () {
  24782. if ( this.isPlaying === true ) {
  24783. console.warn( 'THREE.Audio: Audio is already playing.' );
  24784. return;
  24785. }
  24786. if ( this.hasPlaybackControl === false ) {
  24787. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24788. return;
  24789. }
  24790. var source = this.context.createBufferSource();
  24791. source.buffer = this.buffer;
  24792. source.loop = this.loop;
  24793. source.onended = this.onEnded.bind( this );
  24794. this.startTime = this.context.currentTime;
  24795. source.start( this.startTime, this.offset );
  24796. this.isPlaying = true;
  24797. this.source = source;
  24798. this.setDetune( this.detune );
  24799. this.setPlaybackRate( this.playbackRate );
  24800. return this.connect();
  24801. },
  24802. pause: function () {
  24803. if ( this.hasPlaybackControl === false ) {
  24804. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24805. return;
  24806. }
  24807. if ( this.isPlaying === true ) {
  24808. this.source.stop();
  24809. this.source.onended = null;
  24810. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24811. this.isPlaying = false;
  24812. }
  24813. return this;
  24814. },
  24815. stop: function () {
  24816. if ( this.hasPlaybackControl === false ) {
  24817. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24818. return;
  24819. }
  24820. this.source.stop();
  24821. this.source.onended = null;
  24822. this.offset = 0;
  24823. this.isPlaying = false;
  24824. return this;
  24825. },
  24826. connect: function () {
  24827. if ( this.filters.length > 0 ) {
  24828. this.source.connect( this.filters[ 0 ] );
  24829. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24830. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24831. }
  24832. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24833. } else {
  24834. this.source.connect( this.getOutput() );
  24835. }
  24836. return this;
  24837. },
  24838. disconnect: function () {
  24839. if ( this.filters.length > 0 ) {
  24840. this.source.disconnect( this.filters[ 0 ] );
  24841. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24842. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24843. }
  24844. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24845. } else {
  24846. this.source.disconnect( this.getOutput() );
  24847. }
  24848. return this;
  24849. },
  24850. getFilters: function () {
  24851. return this.filters;
  24852. },
  24853. setFilters: function ( value ) {
  24854. if ( ! value ) value = [];
  24855. if ( this.isPlaying === true ) {
  24856. this.disconnect();
  24857. this.filters = value;
  24858. this.connect();
  24859. } else {
  24860. this.filters = value;
  24861. }
  24862. return this;
  24863. },
  24864. setDetune: function ( value ) {
  24865. this.detune = value;
  24866. if ( this.source.detune === undefined ) return; // only set detune when available
  24867. if ( this.isPlaying === true ) {
  24868. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24869. }
  24870. return this;
  24871. },
  24872. getDetune: function () {
  24873. return this.detune;
  24874. },
  24875. getFilter: function () {
  24876. return this.getFilters()[ 0 ];
  24877. },
  24878. setFilter: function ( filter ) {
  24879. return this.setFilters( filter ? [ filter ] : [] );
  24880. },
  24881. setPlaybackRate: function ( value ) {
  24882. if ( this.hasPlaybackControl === false ) {
  24883. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24884. return;
  24885. }
  24886. this.playbackRate = value;
  24887. if ( this.isPlaying === true ) {
  24888. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24889. }
  24890. return this;
  24891. },
  24892. getPlaybackRate: function () {
  24893. return this.playbackRate;
  24894. },
  24895. onEnded: function () {
  24896. this.isPlaying = false;
  24897. },
  24898. getLoop: function () {
  24899. if ( this.hasPlaybackControl === false ) {
  24900. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24901. return false;
  24902. }
  24903. return this.loop;
  24904. },
  24905. setLoop: function ( value ) {
  24906. if ( this.hasPlaybackControl === false ) {
  24907. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24908. return;
  24909. }
  24910. this.loop = value;
  24911. if ( this.isPlaying === true ) {
  24912. this.source.loop = this.loop;
  24913. }
  24914. return this;
  24915. },
  24916. getVolume: function () {
  24917. return this.gain.gain.value;
  24918. },
  24919. setVolume: function ( value ) {
  24920. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24921. return this;
  24922. }
  24923. } );
  24924. /**
  24925. * @author mrdoob / http://mrdoob.com/
  24926. */
  24927. var _position$1, _quaternion$3, _scale$1;
  24928. var _orientation$1;
  24929. function PositionalAudio( listener ) {
  24930. Audio.call( this, listener );
  24931. this.panner = this.context.createPanner();
  24932. this.panner.panningModel = 'HRTF';
  24933. this.panner.connect( this.gain );
  24934. }
  24935. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24936. constructor: PositionalAudio,
  24937. getOutput: function () {
  24938. return this.panner;
  24939. },
  24940. getRefDistance: function () {
  24941. return this.panner.refDistance;
  24942. },
  24943. setRefDistance: function ( value ) {
  24944. this.panner.refDistance = value;
  24945. return this;
  24946. },
  24947. getRolloffFactor: function () {
  24948. return this.panner.rolloffFactor;
  24949. },
  24950. setRolloffFactor: function ( value ) {
  24951. this.panner.rolloffFactor = value;
  24952. return this;
  24953. },
  24954. getDistanceModel: function () {
  24955. return this.panner.distanceModel;
  24956. },
  24957. setDistanceModel: function ( value ) {
  24958. this.panner.distanceModel = value;
  24959. return this;
  24960. },
  24961. getMaxDistance: function () {
  24962. return this.panner.maxDistance;
  24963. },
  24964. setMaxDistance: function ( value ) {
  24965. this.panner.maxDistance = value;
  24966. return this;
  24967. },
  24968. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24969. this.panner.coneInnerAngle = coneInnerAngle;
  24970. this.panner.coneOuterAngle = coneOuterAngle;
  24971. this.panner.coneOuterGain = coneOuterGain;
  24972. return this;
  24973. },
  24974. updateMatrixWorld: function ( force ) {
  24975. Object3D.prototype.updateMatrixWorld.call( this, force );
  24976. if ( _position$1 === undefined ) {
  24977. _position$1 = new Vector3();
  24978. _quaternion$3 = new Quaternion();
  24979. _scale$1 = new Vector3();
  24980. _orientation$1 = new Vector3();
  24981. }
  24982. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24983. this.matrixWorld.decompose( _position$1, _quaternion$3, _scale$1 );
  24984. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$3 );
  24985. var panner = this.panner;
  24986. if ( panner.positionX ) {
  24987. // code path for Chrome and Firefox (see #14393)
  24988. var endTime = this.context.currentTime + this.listener.timeDelta;
  24989. panner.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  24990. panner.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  24991. panner.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  24992. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  24993. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  24994. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  24995. } else {
  24996. panner.setPosition( _position$1.x, _position$1.y, _position$1.z );
  24997. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  24998. }
  24999. }
  25000. } );
  25001. /**
  25002. * @author mrdoob / http://mrdoob.com/
  25003. */
  25004. function AudioAnalyser( audio, fftSize ) {
  25005. this.analyser = audio.context.createAnalyser();
  25006. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  25007. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  25008. audio.getOutput().connect( this.analyser );
  25009. }
  25010. Object.assign( AudioAnalyser.prototype, {
  25011. getFrequencyData: function () {
  25012. this.analyser.getByteFrequencyData( this.data );
  25013. return this.data;
  25014. },
  25015. getAverageFrequency: function () {
  25016. var value = 0, data = this.getFrequencyData();
  25017. for ( var i = 0; i < data.length; i ++ ) {
  25018. value += data[ i ];
  25019. }
  25020. return value / data.length;
  25021. }
  25022. } );
  25023. /**
  25024. *
  25025. * Buffered scene graph property that allows weighted accumulation.
  25026. *
  25027. *
  25028. * @author Ben Houston / http://clara.io/
  25029. * @author David Sarno / http://lighthaus.us/
  25030. * @author tschw
  25031. */
  25032. function PropertyMixer( binding, typeName, valueSize ) {
  25033. this.binding = binding;
  25034. this.valueSize = valueSize;
  25035. var bufferType = Float64Array,
  25036. mixFunction;
  25037. switch ( typeName ) {
  25038. case 'quaternion':
  25039. mixFunction = this._slerp;
  25040. break;
  25041. case 'string':
  25042. case 'bool':
  25043. bufferType = Array;
  25044. mixFunction = this._select;
  25045. break;
  25046. default:
  25047. mixFunction = this._lerp;
  25048. }
  25049. this.buffer = new bufferType( valueSize * 4 );
  25050. // layout: [ incoming | accu0 | accu1 | orig ]
  25051. //
  25052. // interpolators can use .buffer as their .result
  25053. // the data then goes to 'incoming'
  25054. //
  25055. // 'accu0' and 'accu1' are used frame-interleaved for
  25056. // the cumulative result and are compared to detect
  25057. // changes
  25058. //
  25059. // 'orig' stores the original state of the property
  25060. this._mixBufferRegion = mixFunction;
  25061. this.cumulativeWeight = 0;
  25062. this.useCount = 0;
  25063. this.referenceCount = 0;
  25064. }
  25065. Object.assign( PropertyMixer.prototype, {
  25066. // accumulate data in the 'incoming' region into 'accu<i>'
  25067. accumulate: function ( accuIndex, weight ) {
  25068. // note: happily accumulating nothing when weight = 0, the caller knows
  25069. // the weight and shouldn't have made the call in the first place
  25070. var buffer = this.buffer,
  25071. stride = this.valueSize,
  25072. offset = accuIndex * stride + stride,
  25073. currentWeight = this.cumulativeWeight;
  25074. if ( currentWeight === 0 ) {
  25075. // accuN := incoming * weight
  25076. for ( var i = 0; i !== stride; ++ i ) {
  25077. buffer[ offset + i ] = buffer[ i ];
  25078. }
  25079. currentWeight = weight;
  25080. } else {
  25081. // accuN := accuN + incoming * weight
  25082. currentWeight += weight;
  25083. var mix = weight / currentWeight;
  25084. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25085. }
  25086. this.cumulativeWeight = currentWeight;
  25087. },
  25088. // apply the state of 'accu<i>' to the binding when accus differ
  25089. apply: function ( accuIndex ) {
  25090. var stride = this.valueSize,
  25091. buffer = this.buffer,
  25092. offset = accuIndex * stride + stride,
  25093. weight = this.cumulativeWeight,
  25094. binding = this.binding;
  25095. this.cumulativeWeight = 0;
  25096. if ( weight < 1 ) {
  25097. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25098. var originalValueOffset = stride * 3;
  25099. this._mixBufferRegion(
  25100. buffer, offset, originalValueOffset, 1 - weight, stride );
  25101. }
  25102. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  25103. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25104. // value has changed -> update scene graph
  25105. binding.setValue( buffer, offset );
  25106. break;
  25107. }
  25108. }
  25109. },
  25110. // remember the state of the bound property and copy it to both accus
  25111. saveOriginalState: function () {
  25112. var binding = this.binding;
  25113. var buffer = this.buffer,
  25114. stride = this.valueSize,
  25115. originalValueOffset = stride * 3;
  25116. binding.getValue( buffer, originalValueOffset );
  25117. // accu[0..1] := orig -- initially detect changes against the original
  25118. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25119. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25120. }
  25121. this.cumulativeWeight = 0;
  25122. },
  25123. // apply the state previously taken via 'saveOriginalState' to the binding
  25124. restoreOriginalState: function () {
  25125. var originalValueOffset = this.valueSize * 3;
  25126. this.binding.setValue( this.buffer, originalValueOffset );
  25127. },
  25128. // mix functions
  25129. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25130. if ( t >= 0.5 ) {
  25131. for ( var i = 0; i !== stride; ++ i ) {
  25132. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  25133. }
  25134. }
  25135. },
  25136. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  25137. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  25138. },
  25139. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25140. var s = 1 - t;
  25141. for ( var i = 0; i !== stride; ++ i ) {
  25142. var j = dstOffset + i;
  25143. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  25144. }
  25145. }
  25146. } );
  25147. /**
  25148. *
  25149. * A reference to a real property in the scene graph.
  25150. *
  25151. *
  25152. * @author Ben Houston / http://clara.io/
  25153. * @author David Sarno / http://lighthaus.us/
  25154. * @author tschw
  25155. */
  25156. // Characters [].:/ are reserved for track binding syntax.
  25157. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25158. function Composite( targetGroup, path, optionalParsedPath ) {
  25159. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  25160. this._targetGroup = targetGroup;
  25161. this._bindings = targetGroup.subscribe_( path, parsedPath );
  25162. }
  25163. Object.assign( Composite.prototype, {
  25164. getValue: function ( array, offset ) {
  25165. this.bind(); // bind all binding
  25166. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25167. binding = this._bindings[ firstValidIndex ];
  25168. // and only call .getValue on the first
  25169. if ( binding !== undefined ) binding.getValue( array, offset );
  25170. },
  25171. setValue: function ( array, offset ) {
  25172. var bindings = this._bindings;
  25173. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25174. bindings[ i ].setValue( array, offset );
  25175. }
  25176. },
  25177. bind: function () {
  25178. var bindings = this._bindings;
  25179. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25180. bindings[ i ].bind();
  25181. }
  25182. },
  25183. unbind: function () {
  25184. var bindings = this._bindings;
  25185. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25186. bindings[ i ].unbind();
  25187. }
  25188. }
  25189. } );
  25190. function PropertyBinding( rootNode, path, parsedPath ) {
  25191. this.path = path;
  25192. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  25193. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  25194. this.rootNode = rootNode;
  25195. }
  25196. Object.assign( PropertyBinding, {
  25197. Composite: Composite,
  25198. create: function ( root, path, parsedPath ) {
  25199. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  25200. return new PropertyBinding( root, path, parsedPath );
  25201. } else {
  25202. return new PropertyBinding.Composite( root, path, parsedPath );
  25203. }
  25204. },
  25205. /**
  25206. * Replaces spaces with underscores and removes unsupported characters from
  25207. * node names, to ensure compatibility with parseTrackName().
  25208. *
  25209. * @param {string} name Node name to be sanitized.
  25210. * @return {string}
  25211. */
  25212. sanitizeNodeName: ( function () {
  25213. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  25214. return function sanitizeNodeName( name ) {
  25215. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  25216. };
  25217. }() ),
  25218. parseTrackName: function () {
  25219. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25220. // only latin characters, and the unicode \p{L} is not yet supported. So
  25221. // instead, we exclude reserved characters and match everything else.
  25222. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  25223. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  25224. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25225. // be matched to parse the rest of the track name.
  25226. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  25227. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25228. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  25229. // Object on target node, and accessor. May not contain reserved
  25230. // characters. Accessor may contain any character except closing bracket.
  25231. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  25232. // Property and accessor. May not contain reserved characters. Accessor may
  25233. // contain any non-bracket characters.
  25234. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  25235. var trackRe = new RegExp( ''
  25236. + '^'
  25237. + directoryRe
  25238. + nodeRe
  25239. + objectRe
  25240. + propertyRe
  25241. + '$'
  25242. );
  25243. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  25244. return function parseTrackName( trackName ) {
  25245. var matches = trackRe.exec( trackName );
  25246. if ( ! matches ) {
  25247. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  25248. }
  25249. var results = {
  25250. // directoryName: matches[ 1 ], // (tschw) currently unused
  25251. nodeName: matches[ 2 ],
  25252. objectName: matches[ 3 ],
  25253. objectIndex: matches[ 4 ],
  25254. propertyName: matches[ 5 ], // required
  25255. propertyIndex: matches[ 6 ]
  25256. };
  25257. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  25258. if ( lastDot !== undefined && lastDot !== - 1 ) {
  25259. var objectName = results.nodeName.substring( lastDot + 1 );
  25260. // Object names must be checked against a whitelist. Otherwise, there
  25261. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25262. // 'bar' could be the objectName, or part of a nodeName (which can
  25263. // include '.' characters).
  25264. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  25265. results.nodeName = results.nodeName.substring( 0, lastDot );
  25266. results.objectName = objectName;
  25267. }
  25268. }
  25269. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  25270. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  25271. }
  25272. return results;
  25273. };
  25274. }(),
  25275. findNode: function ( root, nodeName ) {
  25276. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  25277. return root;
  25278. }
  25279. // search into skeleton bones.
  25280. if ( root.skeleton ) {
  25281. var bone = root.skeleton.getBoneByName( nodeName );
  25282. if ( bone !== undefined ) {
  25283. return bone;
  25284. }
  25285. }
  25286. // search into node subtree.
  25287. if ( root.children ) {
  25288. var searchNodeSubtree = function ( children ) {
  25289. for ( var i = 0; i < children.length; i ++ ) {
  25290. var childNode = children[ i ];
  25291. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  25292. return childNode;
  25293. }
  25294. var result = searchNodeSubtree( childNode.children );
  25295. if ( result ) return result;
  25296. }
  25297. return null;
  25298. };
  25299. var subTreeNode = searchNodeSubtree( root.children );
  25300. if ( subTreeNode ) {
  25301. return subTreeNode;
  25302. }
  25303. }
  25304. return null;
  25305. }
  25306. } );
  25307. Object.assign( PropertyBinding.prototype, { // prototype, continued
  25308. // these are used to "bind" a nonexistent property
  25309. _getValue_unavailable: function () {},
  25310. _setValue_unavailable: function () {},
  25311. BindingType: {
  25312. Direct: 0,
  25313. EntireArray: 1,
  25314. ArrayElement: 2,
  25315. HasFromToArray: 3
  25316. },
  25317. Versioning: {
  25318. None: 0,
  25319. NeedsUpdate: 1,
  25320. MatrixWorldNeedsUpdate: 2
  25321. },
  25322. GetterByBindingType: [
  25323. function getValue_direct( buffer, offset ) {
  25324. buffer[ offset ] = this.node[ this.propertyName ];
  25325. },
  25326. function getValue_array( buffer, offset ) {
  25327. var source = this.resolvedProperty;
  25328. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25329. buffer[ offset ++ ] = source[ i ];
  25330. }
  25331. },
  25332. function getValue_arrayElement( buffer, offset ) {
  25333. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25334. },
  25335. function getValue_toArray( buffer, offset ) {
  25336. this.resolvedProperty.toArray( buffer, offset );
  25337. }
  25338. ],
  25339. SetterByBindingTypeAndVersioning: [
  25340. [
  25341. // Direct
  25342. function setValue_direct( buffer, offset ) {
  25343. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25344. },
  25345. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25346. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25347. this.targetObject.needsUpdate = true;
  25348. },
  25349. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25350. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25351. this.targetObject.matrixWorldNeedsUpdate = true;
  25352. }
  25353. ], [
  25354. // EntireArray
  25355. function setValue_array( buffer, offset ) {
  25356. var dest = this.resolvedProperty;
  25357. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25358. dest[ i ] = buffer[ offset ++ ];
  25359. }
  25360. },
  25361. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25362. var dest = this.resolvedProperty;
  25363. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25364. dest[ i ] = buffer[ offset ++ ];
  25365. }
  25366. this.targetObject.needsUpdate = true;
  25367. },
  25368. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25369. var dest = this.resolvedProperty;
  25370. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25371. dest[ i ] = buffer[ offset ++ ];
  25372. }
  25373. this.targetObject.matrixWorldNeedsUpdate = true;
  25374. }
  25375. ], [
  25376. // ArrayElement
  25377. function setValue_arrayElement( buffer, offset ) {
  25378. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25379. },
  25380. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25381. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25382. this.targetObject.needsUpdate = true;
  25383. },
  25384. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25385. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25386. this.targetObject.matrixWorldNeedsUpdate = true;
  25387. }
  25388. ], [
  25389. // HasToFromArray
  25390. function setValue_fromArray( buffer, offset ) {
  25391. this.resolvedProperty.fromArray( buffer, offset );
  25392. },
  25393. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25394. this.resolvedProperty.fromArray( buffer, offset );
  25395. this.targetObject.needsUpdate = true;
  25396. },
  25397. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25398. this.resolvedProperty.fromArray( buffer, offset );
  25399. this.targetObject.matrixWorldNeedsUpdate = true;
  25400. }
  25401. ]
  25402. ],
  25403. getValue: function getValue_unbound( targetArray, offset ) {
  25404. this.bind();
  25405. this.getValue( targetArray, offset );
  25406. // Note: This class uses a State pattern on a per-method basis:
  25407. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25408. // prototype version of these methods with one that represents
  25409. // the bound state. When the property is not found, the methods
  25410. // become no-ops.
  25411. },
  25412. setValue: function getValue_unbound( sourceArray, offset ) {
  25413. this.bind();
  25414. this.setValue( sourceArray, offset );
  25415. },
  25416. // create getter / setter pair for a property in the scene graph
  25417. bind: function () {
  25418. var targetObject = this.node,
  25419. parsedPath = this.parsedPath,
  25420. objectName = parsedPath.objectName,
  25421. propertyName = parsedPath.propertyName,
  25422. propertyIndex = parsedPath.propertyIndex;
  25423. if ( ! targetObject ) {
  25424. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25425. this.node = targetObject;
  25426. }
  25427. // set fail state so we can just 'return' on error
  25428. this.getValue = this._getValue_unavailable;
  25429. this.setValue = this._setValue_unavailable;
  25430. // ensure there is a value node
  25431. if ( ! targetObject ) {
  25432. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25433. return;
  25434. }
  25435. if ( objectName ) {
  25436. var objectIndex = parsedPath.objectIndex;
  25437. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25438. switch ( objectName ) {
  25439. case 'materials':
  25440. if ( ! targetObject.material ) {
  25441. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25442. return;
  25443. }
  25444. if ( ! targetObject.material.materials ) {
  25445. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25446. return;
  25447. }
  25448. targetObject = targetObject.material.materials;
  25449. break;
  25450. case 'bones':
  25451. if ( ! targetObject.skeleton ) {
  25452. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25453. return;
  25454. }
  25455. // potential future optimization: skip this if propertyIndex is already an integer
  25456. // and convert the integer string to a true integer.
  25457. targetObject = targetObject.skeleton.bones;
  25458. // support resolving morphTarget names into indices.
  25459. for ( var i = 0; i < targetObject.length; i ++ ) {
  25460. if ( targetObject[ i ].name === objectIndex ) {
  25461. objectIndex = i;
  25462. break;
  25463. }
  25464. }
  25465. break;
  25466. default:
  25467. if ( targetObject[ objectName ] === undefined ) {
  25468. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25469. return;
  25470. }
  25471. targetObject = targetObject[ objectName ];
  25472. }
  25473. if ( objectIndex !== undefined ) {
  25474. if ( targetObject[ objectIndex ] === undefined ) {
  25475. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25476. return;
  25477. }
  25478. targetObject = targetObject[ objectIndex ];
  25479. }
  25480. }
  25481. // resolve property
  25482. var nodeProperty = targetObject[ propertyName ];
  25483. if ( nodeProperty === undefined ) {
  25484. var nodeName = parsedPath.nodeName;
  25485. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25486. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25487. return;
  25488. }
  25489. // determine versioning scheme
  25490. var versioning = this.Versioning.None;
  25491. this.targetObject = targetObject;
  25492. if ( targetObject.needsUpdate !== undefined ) { // material
  25493. versioning = this.Versioning.NeedsUpdate;
  25494. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25495. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25496. }
  25497. // determine how the property gets bound
  25498. var bindingType = this.BindingType.Direct;
  25499. if ( propertyIndex !== undefined ) {
  25500. // access a sub element of the property array (only primitives are supported right now)
  25501. if ( propertyName === "morphTargetInfluences" ) {
  25502. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25503. // support resolving morphTarget names into indices.
  25504. if ( ! targetObject.geometry ) {
  25505. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25506. return;
  25507. }
  25508. if ( targetObject.geometry.isBufferGeometry ) {
  25509. if ( ! targetObject.geometry.morphAttributes ) {
  25510. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25511. return;
  25512. }
  25513. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25514. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25515. propertyIndex = i;
  25516. break;
  25517. }
  25518. }
  25519. } else {
  25520. if ( ! targetObject.geometry.morphTargets ) {
  25521. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25522. return;
  25523. }
  25524. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25525. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25526. propertyIndex = i;
  25527. break;
  25528. }
  25529. }
  25530. }
  25531. }
  25532. bindingType = this.BindingType.ArrayElement;
  25533. this.resolvedProperty = nodeProperty;
  25534. this.propertyIndex = propertyIndex;
  25535. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25536. // must use copy for Object3D.Euler/Quaternion
  25537. bindingType = this.BindingType.HasFromToArray;
  25538. this.resolvedProperty = nodeProperty;
  25539. } else if ( Array.isArray( nodeProperty ) ) {
  25540. bindingType = this.BindingType.EntireArray;
  25541. this.resolvedProperty = nodeProperty;
  25542. } else {
  25543. this.propertyName = propertyName;
  25544. }
  25545. // select getter / setter
  25546. this.getValue = this.GetterByBindingType[ bindingType ];
  25547. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25548. },
  25549. unbind: function () {
  25550. this.node = null;
  25551. // back to the prototype version of getValue / setValue
  25552. // note: avoiding to mutate the shape of 'this' via 'delete'
  25553. this.getValue = this._getValue_unbound;
  25554. this.setValue = this._setValue_unbound;
  25555. }
  25556. } );
  25557. //!\ DECLARE ALIAS AFTER assign prototype !
  25558. Object.assign( PropertyBinding.prototype, {
  25559. // initial state of these methods that calls 'bind'
  25560. _getValue_unbound: PropertyBinding.prototype.getValue,
  25561. _setValue_unbound: PropertyBinding.prototype.setValue,
  25562. } );
  25563. /**
  25564. *
  25565. * A group of objects that receives a shared animation state.
  25566. *
  25567. * Usage:
  25568. *
  25569. * - Add objects you would otherwise pass as 'root' to the
  25570. * constructor or the .clipAction method of AnimationMixer.
  25571. *
  25572. * - Instead pass this object as 'root'.
  25573. *
  25574. * - You can also add and remove objects later when the mixer
  25575. * is running.
  25576. *
  25577. * Note:
  25578. *
  25579. * Objects of this class appear as one object to the mixer,
  25580. * so cache control of the individual objects must be done
  25581. * on the group.
  25582. *
  25583. * Limitation:
  25584. *
  25585. * - The animated properties must be compatible among the
  25586. * all objects in the group.
  25587. *
  25588. * - A single property can either be controlled through a
  25589. * target group or directly, but not both.
  25590. *
  25591. * @author tschw
  25592. */
  25593. function AnimationObjectGroup() {
  25594. this.uuid = _Math.generateUUID();
  25595. // cached objects followed by the active ones
  25596. this._objects = Array.prototype.slice.call( arguments );
  25597. this.nCachedObjects_ = 0; // threshold
  25598. // note: read by PropertyBinding.Composite
  25599. var indices = {};
  25600. this._indicesByUUID = indices; // for bookkeeping
  25601. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25602. indices[ arguments[ i ].uuid ] = i;
  25603. }
  25604. this._paths = []; // inside: string
  25605. this._parsedPaths = []; // inside: { we don't care, here }
  25606. this._bindings = []; // inside: Array< PropertyBinding >
  25607. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25608. var scope = this;
  25609. this.stats = {
  25610. objects: {
  25611. get total() {
  25612. return scope._objects.length;
  25613. },
  25614. get inUse() {
  25615. return this.total - scope.nCachedObjects_;
  25616. }
  25617. },
  25618. get bindingsPerObject() {
  25619. return scope._bindings.length;
  25620. }
  25621. };
  25622. }
  25623. Object.assign( AnimationObjectGroup.prototype, {
  25624. isAnimationObjectGroup: true,
  25625. add: function () {
  25626. var objects = this._objects,
  25627. nObjects = objects.length,
  25628. nCachedObjects = this.nCachedObjects_,
  25629. indicesByUUID = this._indicesByUUID,
  25630. paths = this._paths,
  25631. parsedPaths = this._parsedPaths,
  25632. bindings = this._bindings,
  25633. nBindings = bindings.length,
  25634. knownObject = undefined;
  25635. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25636. var object = arguments[ i ],
  25637. uuid = object.uuid,
  25638. index = indicesByUUID[ uuid ];
  25639. if ( index === undefined ) {
  25640. // unknown object -> add it to the ACTIVE region
  25641. index = nObjects ++;
  25642. indicesByUUID[ uuid ] = index;
  25643. objects.push( object );
  25644. // accounting is done, now do the same for all bindings
  25645. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25646. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25647. }
  25648. } else if ( index < nCachedObjects ) {
  25649. knownObject = objects[ index ];
  25650. // move existing object to the ACTIVE region
  25651. var firstActiveIndex = -- nCachedObjects,
  25652. lastCachedObject = objects[ firstActiveIndex ];
  25653. indicesByUUID[ lastCachedObject.uuid ] = index;
  25654. objects[ index ] = lastCachedObject;
  25655. indicesByUUID[ uuid ] = firstActiveIndex;
  25656. objects[ firstActiveIndex ] = object;
  25657. // accounting is done, now do the same for all bindings
  25658. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25659. var bindingsForPath = bindings[ j ],
  25660. lastCached = bindingsForPath[ firstActiveIndex ],
  25661. binding = bindingsForPath[ index ];
  25662. bindingsForPath[ index ] = lastCached;
  25663. if ( binding === undefined ) {
  25664. // since we do not bother to create new bindings
  25665. // for objects that are cached, the binding may
  25666. // or may not exist
  25667. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25668. }
  25669. bindingsForPath[ firstActiveIndex ] = binding;
  25670. }
  25671. } else if ( objects[ index ] !== knownObject ) {
  25672. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25673. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25674. } // else the object is already where we want it to be
  25675. } // for arguments
  25676. this.nCachedObjects_ = nCachedObjects;
  25677. },
  25678. remove: function () {
  25679. var objects = this._objects,
  25680. nCachedObjects = this.nCachedObjects_,
  25681. indicesByUUID = this._indicesByUUID,
  25682. bindings = this._bindings,
  25683. nBindings = bindings.length;
  25684. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25685. var object = arguments[ i ],
  25686. uuid = object.uuid,
  25687. index = indicesByUUID[ uuid ];
  25688. if ( index !== undefined && index >= nCachedObjects ) {
  25689. // move existing object into the CACHED region
  25690. var lastCachedIndex = nCachedObjects ++,
  25691. firstActiveObject = objects[ lastCachedIndex ];
  25692. indicesByUUID[ firstActiveObject.uuid ] = index;
  25693. objects[ index ] = firstActiveObject;
  25694. indicesByUUID[ uuid ] = lastCachedIndex;
  25695. objects[ lastCachedIndex ] = object;
  25696. // accounting is done, now do the same for all bindings
  25697. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25698. var bindingsForPath = bindings[ j ],
  25699. firstActive = bindingsForPath[ lastCachedIndex ],
  25700. binding = bindingsForPath[ index ];
  25701. bindingsForPath[ index ] = firstActive;
  25702. bindingsForPath[ lastCachedIndex ] = binding;
  25703. }
  25704. }
  25705. } // for arguments
  25706. this.nCachedObjects_ = nCachedObjects;
  25707. },
  25708. // remove & forget
  25709. uncache: function () {
  25710. var objects = this._objects,
  25711. nObjects = objects.length,
  25712. nCachedObjects = this.nCachedObjects_,
  25713. indicesByUUID = this._indicesByUUID,
  25714. bindings = this._bindings,
  25715. nBindings = bindings.length;
  25716. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25717. var object = arguments[ i ],
  25718. uuid = object.uuid,
  25719. index = indicesByUUID[ uuid ];
  25720. if ( index !== undefined ) {
  25721. delete indicesByUUID[ uuid ];
  25722. if ( index < nCachedObjects ) {
  25723. // object is cached, shrink the CACHED region
  25724. var firstActiveIndex = -- nCachedObjects,
  25725. lastCachedObject = objects[ firstActiveIndex ],
  25726. lastIndex = -- nObjects,
  25727. lastObject = objects[ lastIndex ];
  25728. // last cached object takes this object's place
  25729. indicesByUUID[ lastCachedObject.uuid ] = index;
  25730. objects[ index ] = lastCachedObject;
  25731. // last object goes to the activated slot and pop
  25732. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25733. objects[ firstActiveIndex ] = lastObject;
  25734. objects.pop();
  25735. // accounting is done, now do the same for all bindings
  25736. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25737. var bindingsForPath = bindings[ j ],
  25738. lastCached = bindingsForPath[ firstActiveIndex ],
  25739. last = bindingsForPath[ lastIndex ];
  25740. bindingsForPath[ index ] = lastCached;
  25741. bindingsForPath[ firstActiveIndex ] = last;
  25742. bindingsForPath.pop();
  25743. }
  25744. } else {
  25745. // object is active, just swap with the last and pop
  25746. var lastIndex = -- nObjects,
  25747. lastObject = objects[ lastIndex ];
  25748. indicesByUUID[ lastObject.uuid ] = index;
  25749. objects[ index ] = lastObject;
  25750. objects.pop();
  25751. // accounting is done, now do the same for all bindings
  25752. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25753. var bindingsForPath = bindings[ j ];
  25754. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25755. bindingsForPath.pop();
  25756. }
  25757. } // cached or active
  25758. } // if object is known
  25759. } // for arguments
  25760. this.nCachedObjects_ = nCachedObjects;
  25761. },
  25762. // Internal interface used by befriended PropertyBinding.Composite:
  25763. subscribe_: function ( path, parsedPath ) {
  25764. // returns an array of bindings for the given path that is changed
  25765. // according to the contained objects in the group
  25766. var indicesByPath = this._bindingsIndicesByPath,
  25767. index = indicesByPath[ path ],
  25768. bindings = this._bindings;
  25769. if ( index !== undefined ) return bindings[ index ];
  25770. var paths = this._paths,
  25771. parsedPaths = this._parsedPaths,
  25772. objects = this._objects,
  25773. nObjects = objects.length,
  25774. nCachedObjects = this.nCachedObjects_,
  25775. bindingsForPath = new Array( nObjects );
  25776. index = bindings.length;
  25777. indicesByPath[ path ] = index;
  25778. paths.push( path );
  25779. parsedPaths.push( parsedPath );
  25780. bindings.push( bindingsForPath );
  25781. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25782. var object = objects[ i ];
  25783. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25784. }
  25785. return bindingsForPath;
  25786. },
  25787. unsubscribe_: function ( path ) {
  25788. // tells the group to forget about a property path and no longer
  25789. // update the array previously obtained with 'subscribe_'
  25790. var indicesByPath = this._bindingsIndicesByPath,
  25791. index = indicesByPath[ path ];
  25792. if ( index !== undefined ) {
  25793. var paths = this._paths,
  25794. parsedPaths = this._parsedPaths,
  25795. bindings = this._bindings,
  25796. lastBindingsIndex = bindings.length - 1,
  25797. lastBindings = bindings[ lastBindingsIndex ],
  25798. lastBindingsPath = path[ lastBindingsIndex ];
  25799. indicesByPath[ lastBindingsPath ] = index;
  25800. bindings[ index ] = lastBindings;
  25801. bindings.pop();
  25802. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25803. parsedPaths.pop();
  25804. paths[ index ] = paths[ lastBindingsIndex ];
  25805. paths.pop();
  25806. }
  25807. }
  25808. } );
  25809. /**
  25810. *
  25811. * Action provided by AnimationMixer for scheduling clip playback on specific
  25812. * objects.
  25813. *
  25814. * @author Ben Houston / http://clara.io/
  25815. * @author David Sarno / http://lighthaus.us/
  25816. * @author tschw
  25817. *
  25818. */
  25819. function AnimationAction( mixer, clip, localRoot ) {
  25820. this._mixer = mixer;
  25821. this._clip = clip;
  25822. this._localRoot = localRoot || null;
  25823. var tracks = clip.tracks,
  25824. nTracks = tracks.length,
  25825. interpolants = new Array( nTracks );
  25826. var interpolantSettings = {
  25827. endingStart: ZeroCurvatureEnding,
  25828. endingEnd: ZeroCurvatureEnding
  25829. };
  25830. for ( var i = 0; i !== nTracks; ++ i ) {
  25831. var interpolant = tracks[ i ].createInterpolant( null );
  25832. interpolants[ i ] = interpolant;
  25833. interpolant.settings = interpolantSettings;
  25834. }
  25835. this._interpolantSettings = interpolantSettings;
  25836. this._interpolants = interpolants; // bound by the mixer
  25837. // inside: PropertyMixer (managed by the mixer)
  25838. this._propertyBindings = new Array( nTracks );
  25839. this._cacheIndex = null; // for the memory manager
  25840. this._byClipCacheIndex = null; // for the memory manager
  25841. this._timeScaleInterpolant = null;
  25842. this._weightInterpolant = null;
  25843. this.loop = LoopRepeat;
  25844. this._loopCount = - 1;
  25845. // global mixer time when the action is to be started
  25846. // it's set back to 'null' upon start of the action
  25847. this._startTime = null;
  25848. // scaled local time of the action
  25849. // gets clamped or wrapped to 0..clip.duration according to loop
  25850. this.time = 0;
  25851. this.timeScale = 1;
  25852. this._effectiveTimeScale = 1;
  25853. this.weight = 1;
  25854. this._effectiveWeight = 1;
  25855. this.repetitions = Infinity; // no. of repetitions when looping
  25856. this.paused = false; // true -> zero effective time scale
  25857. this.enabled = true; // false -> zero effective weight
  25858. this.clampWhenFinished = false;// keep feeding the last frame?
  25859. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25860. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25861. }
  25862. Object.assign( AnimationAction.prototype, {
  25863. // State & Scheduling
  25864. play: function () {
  25865. this._mixer._activateAction( this );
  25866. return this;
  25867. },
  25868. stop: function () {
  25869. this._mixer._deactivateAction( this );
  25870. return this.reset();
  25871. },
  25872. reset: function () {
  25873. this.paused = false;
  25874. this.enabled = true;
  25875. this.time = 0; // restart clip
  25876. this._loopCount = - 1;// forget previous loops
  25877. this._startTime = null;// forget scheduling
  25878. return this.stopFading().stopWarping();
  25879. },
  25880. isRunning: function () {
  25881. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25882. this._startTime === null && this._mixer._isActiveAction( this );
  25883. },
  25884. // return true when play has been called
  25885. isScheduled: function () {
  25886. return this._mixer._isActiveAction( this );
  25887. },
  25888. startAt: function ( time ) {
  25889. this._startTime = time;
  25890. return this;
  25891. },
  25892. setLoop: function ( mode, repetitions ) {
  25893. this.loop = mode;
  25894. this.repetitions = repetitions;
  25895. return this;
  25896. },
  25897. // Weight
  25898. // set the weight stopping any scheduled fading
  25899. // although .enabled = false yields an effective weight of zero, this
  25900. // method does *not* change .enabled, because it would be confusing
  25901. setEffectiveWeight: function ( weight ) {
  25902. this.weight = weight;
  25903. // note: same logic as when updated at runtime
  25904. this._effectiveWeight = this.enabled ? weight : 0;
  25905. return this.stopFading();
  25906. },
  25907. // return the weight considering fading and .enabled
  25908. getEffectiveWeight: function () {
  25909. return this._effectiveWeight;
  25910. },
  25911. fadeIn: function ( duration ) {
  25912. return this._scheduleFading( duration, 0, 1 );
  25913. },
  25914. fadeOut: function ( duration ) {
  25915. return this._scheduleFading( duration, 1, 0 );
  25916. },
  25917. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25918. fadeOutAction.fadeOut( duration );
  25919. this.fadeIn( duration );
  25920. if ( warp ) {
  25921. var fadeInDuration = this._clip.duration,
  25922. fadeOutDuration = fadeOutAction._clip.duration,
  25923. startEndRatio = fadeOutDuration / fadeInDuration,
  25924. endStartRatio = fadeInDuration / fadeOutDuration;
  25925. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25926. this.warp( endStartRatio, 1.0, duration );
  25927. }
  25928. return this;
  25929. },
  25930. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25931. return fadeInAction.crossFadeFrom( this, duration, warp );
  25932. },
  25933. stopFading: function () {
  25934. var weightInterpolant = this._weightInterpolant;
  25935. if ( weightInterpolant !== null ) {
  25936. this._weightInterpolant = null;
  25937. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25938. }
  25939. return this;
  25940. },
  25941. // Time Scale Control
  25942. // set the time scale stopping any scheduled warping
  25943. // although .paused = true yields an effective time scale of zero, this
  25944. // method does *not* change .paused, because it would be confusing
  25945. setEffectiveTimeScale: function ( timeScale ) {
  25946. this.timeScale = timeScale;
  25947. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25948. return this.stopWarping();
  25949. },
  25950. // return the time scale considering warping and .paused
  25951. getEffectiveTimeScale: function () {
  25952. return this._effectiveTimeScale;
  25953. },
  25954. setDuration: function ( duration ) {
  25955. this.timeScale = this._clip.duration / duration;
  25956. return this.stopWarping();
  25957. },
  25958. syncWith: function ( action ) {
  25959. this.time = action.time;
  25960. this.timeScale = action.timeScale;
  25961. return this.stopWarping();
  25962. },
  25963. halt: function ( duration ) {
  25964. return this.warp( this._effectiveTimeScale, 0, duration );
  25965. },
  25966. warp: function ( startTimeScale, endTimeScale, duration ) {
  25967. var mixer = this._mixer, now = mixer.time,
  25968. interpolant = this._timeScaleInterpolant,
  25969. timeScale = this.timeScale;
  25970. if ( interpolant === null ) {
  25971. interpolant = mixer._lendControlInterpolant();
  25972. this._timeScaleInterpolant = interpolant;
  25973. }
  25974. var times = interpolant.parameterPositions,
  25975. values = interpolant.sampleValues;
  25976. times[ 0 ] = now;
  25977. times[ 1 ] = now + duration;
  25978. values[ 0 ] = startTimeScale / timeScale;
  25979. values[ 1 ] = endTimeScale / timeScale;
  25980. return this;
  25981. },
  25982. stopWarping: function () {
  25983. var timeScaleInterpolant = this._timeScaleInterpolant;
  25984. if ( timeScaleInterpolant !== null ) {
  25985. this._timeScaleInterpolant = null;
  25986. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25987. }
  25988. return this;
  25989. },
  25990. // Object Accessors
  25991. getMixer: function () {
  25992. return this._mixer;
  25993. },
  25994. getClip: function () {
  25995. return this._clip;
  25996. },
  25997. getRoot: function () {
  25998. return this._localRoot || this._mixer._root;
  25999. },
  26000. // Interna
  26001. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  26002. // called by the mixer
  26003. if ( ! this.enabled ) {
  26004. // call ._updateWeight() to update ._effectiveWeight
  26005. this._updateWeight( time );
  26006. return;
  26007. }
  26008. var startTime = this._startTime;
  26009. if ( startTime !== null ) {
  26010. // check for scheduled start of action
  26011. var timeRunning = ( time - startTime ) * timeDirection;
  26012. if ( timeRunning < 0 || timeDirection === 0 ) {
  26013. return; // yet to come / don't decide when delta = 0
  26014. }
  26015. // start
  26016. this._startTime = null; // unschedule
  26017. deltaTime = timeDirection * timeRunning;
  26018. }
  26019. // apply time scale and advance time
  26020. deltaTime *= this._updateTimeScale( time );
  26021. var clipTime = this._updateTime( deltaTime );
  26022. // note: _updateTime may disable the action resulting in
  26023. // an effective weight of 0
  26024. var weight = this._updateWeight( time );
  26025. if ( weight > 0 ) {
  26026. var interpolants = this._interpolants;
  26027. var propertyMixers = this._propertyBindings;
  26028. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  26029. interpolants[ j ].evaluate( clipTime );
  26030. propertyMixers[ j ].accumulate( accuIndex, weight );
  26031. }
  26032. }
  26033. },
  26034. _updateWeight: function ( time ) {
  26035. var weight = 0;
  26036. if ( this.enabled ) {
  26037. weight = this.weight;
  26038. var interpolant = this._weightInterpolant;
  26039. if ( interpolant !== null ) {
  26040. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26041. weight *= interpolantValue;
  26042. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26043. this.stopFading();
  26044. if ( interpolantValue === 0 ) {
  26045. // faded out, disable
  26046. this.enabled = false;
  26047. }
  26048. }
  26049. }
  26050. }
  26051. this._effectiveWeight = weight;
  26052. return weight;
  26053. },
  26054. _updateTimeScale: function ( time ) {
  26055. var timeScale = 0;
  26056. if ( ! this.paused ) {
  26057. timeScale = this.timeScale;
  26058. var interpolant = this._timeScaleInterpolant;
  26059. if ( interpolant !== null ) {
  26060. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26061. timeScale *= interpolantValue;
  26062. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26063. this.stopWarping();
  26064. if ( timeScale === 0 ) {
  26065. // motion has halted, pause
  26066. this.paused = true;
  26067. } else {
  26068. // warp done - apply final time scale
  26069. this.timeScale = timeScale;
  26070. }
  26071. }
  26072. }
  26073. }
  26074. this._effectiveTimeScale = timeScale;
  26075. return timeScale;
  26076. },
  26077. _updateTime: function ( deltaTime ) {
  26078. var time = this.time + deltaTime;
  26079. var duration = this._clip.duration;
  26080. var loop = this.loop;
  26081. var loopCount = this._loopCount;
  26082. var pingPong = ( loop === LoopPingPong );
  26083. if ( deltaTime === 0 ) {
  26084. if ( loopCount === - 1 ) return time;
  26085. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26086. }
  26087. if ( loop === LoopOnce ) {
  26088. if ( loopCount === - 1 ) {
  26089. // just started
  26090. this._loopCount = 0;
  26091. this._setEndings( true, true, false );
  26092. }
  26093. handle_stop: {
  26094. if ( time >= duration ) {
  26095. time = duration;
  26096. } else if ( time < 0 ) {
  26097. time = 0;
  26098. } else {
  26099. this.time = time;
  26100. break handle_stop;
  26101. }
  26102. if ( this.clampWhenFinished ) this.paused = true;
  26103. else this.enabled = false;
  26104. this.time = time;
  26105. this._mixer.dispatchEvent( {
  26106. type: 'finished', action: this,
  26107. direction: deltaTime < 0 ? - 1 : 1
  26108. } );
  26109. }
  26110. } else { // repetitive Repeat or PingPong
  26111. if ( loopCount === - 1 ) {
  26112. // just started
  26113. if ( deltaTime >= 0 ) {
  26114. loopCount = 0;
  26115. this._setEndings( true, this.repetitions === 0, pingPong );
  26116. } else {
  26117. // when looping in reverse direction, the initial
  26118. // transition through zero counts as a repetition,
  26119. // so leave loopCount at -1
  26120. this._setEndings( this.repetitions === 0, true, pingPong );
  26121. }
  26122. }
  26123. if ( time >= duration || time < 0 ) {
  26124. // wrap around
  26125. var loopDelta = Math.floor( time / duration ); // signed
  26126. time -= duration * loopDelta;
  26127. loopCount += Math.abs( loopDelta );
  26128. var pending = this.repetitions - loopCount;
  26129. if ( pending <= 0 ) {
  26130. // have to stop (switch state, clamp time, fire event)
  26131. if ( this.clampWhenFinished ) this.paused = true;
  26132. else this.enabled = false;
  26133. time = deltaTime > 0 ? duration : 0;
  26134. this.time = time;
  26135. this._mixer.dispatchEvent( {
  26136. type: 'finished', action: this,
  26137. direction: deltaTime > 0 ? 1 : - 1
  26138. } );
  26139. } else {
  26140. // keep running
  26141. if ( pending === 1 ) {
  26142. // entering the last round
  26143. var atStart = deltaTime < 0;
  26144. this._setEndings( atStart, ! atStart, pingPong );
  26145. } else {
  26146. this._setEndings( false, false, pingPong );
  26147. }
  26148. this._loopCount = loopCount;
  26149. this.time = time;
  26150. this._mixer.dispatchEvent( {
  26151. type: 'loop', action: this, loopDelta: loopDelta
  26152. } );
  26153. }
  26154. } else {
  26155. this.time = time;
  26156. }
  26157. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  26158. // invert time for the "pong round"
  26159. return duration - time;
  26160. }
  26161. }
  26162. return time;
  26163. },
  26164. _setEndings: function ( atStart, atEnd, pingPong ) {
  26165. var settings = this._interpolantSettings;
  26166. if ( pingPong ) {
  26167. settings.endingStart = ZeroSlopeEnding;
  26168. settings.endingEnd = ZeroSlopeEnding;
  26169. } else {
  26170. // assuming for LoopOnce atStart == atEnd == true
  26171. if ( atStart ) {
  26172. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26173. } else {
  26174. settings.endingStart = WrapAroundEnding;
  26175. }
  26176. if ( atEnd ) {
  26177. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26178. } else {
  26179. settings.endingEnd = WrapAroundEnding;
  26180. }
  26181. }
  26182. },
  26183. _scheduleFading: function ( duration, weightNow, weightThen ) {
  26184. var mixer = this._mixer, now = mixer.time,
  26185. interpolant = this._weightInterpolant;
  26186. if ( interpolant === null ) {
  26187. interpolant = mixer._lendControlInterpolant();
  26188. this._weightInterpolant = interpolant;
  26189. }
  26190. var times = interpolant.parameterPositions,
  26191. values = interpolant.sampleValues;
  26192. times[ 0 ] = now;
  26193. values[ 0 ] = weightNow;
  26194. times[ 1 ] = now + duration;
  26195. values[ 1 ] = weightThen;
  26196. return this;
  26197. }
  26198. } );
  26199. /**
  26200. *
  26201. * Player for AnimationClips.
  26202. *
  26203. *
  26204. * @author Ben Houston / http://clara.io/
  26205. * @author David Sarno / http://lighthaus.us/
  26206. * @author tschw
  26207. */
  26208. function AnimationMixer( root ) {
  26209. this._root = root;
  26210. this._initMemoryManager();
  26211. this._accuIndex = 0;
  26212. this.time = 0;
  26213. this.timeScale = 1.0;
  26214. }
  26215. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  26216. constructor: AnimationMixer,
  26217. _bindAction: function ( action, prototypeAction ) {
  26218. var root = action._localRoot || this._root,
  26219. tracks = action._clip.tracks,
  26220. nTracks = tracks.length,
  26221. bindings = action._propertyBindings,
  26222. interpolants = action._interpolants,
  26223. rootUuid = root.uuid,
  26224. bindingsByRoot = this._bindingsByRootAndName,
  26225. bindingsByName = bindingsByRoot[ rootUuid ];
  26226. if ( bindingsByName === undefined ) {
  26227. bindingsByName = {};
  26228. bindingsByRoot[ rootUuid ] = bindingsByName;
  26229. }
  26230. for ( var i = 0; i !== nTracks; ++ i ) {
  26231. var track = tracks[ i ],
  26232. trackName = track.name,
  26233. binding = bindingsByName[ trackName ];
  26234. if ( binding !== undefined ) {
  26235. bindings[ i ] = binding;
  26236. } else {
  26237. binding = bindings[ i ];
  26238. if ( binding !== undefined ) {
  26239. // existing binding, make sure the cache knows
  26240. if ( binding._cacheIndex === null ) {
  26241. ++ binding.referenceCount;
  26242. this._addInactiveBinding( binding, rootUuid, trackName );
  26243. }
  26244. continue;
  26245. }
  26246. var path = prototypeAction && prototypeAction.
  26247. _propertyBindings[ i ].binding.parsedPath;
  26248. binding = new PropertyMixer(
  26249. PropertyBinding.create( root, trackName, path ),
  26250. track.ValueTypeName, track.getValueSize() );
  26251. ++ binding.referenceCount;
  26252. this._addInactiveBinding( binding, rootUuid, trackName );
  26253. bindings[ i ] = binding;
  26254. }
  26255. interpolants[ i ].resultBuffer = binding.buffer;
  26256. }
  26257. },
  26258. _activateAction: function ( action ) {
  26259. if ( ! this._isActiveAction( action ) ) {
  26260. if ( action._cacheIndex === null ) {
  26261. // this action has been forgotten by the cache, but the user
  26262. // appears to be still using it -> rebind
  26263. var rootUuid = ( action._localRoot || this._root ).uuid,
  26264. clipUuid = action._clip.uuid,
  26265. actionsForClip = this._actionsByClip[ clipUuid ];
  26266. this._bindAction( action,
  26267. actionsForClip && actionsForClip.knownActions[ 0 ] );
  26268. this._addInactiveAction( action, clipUuid, rootUuid );
  26269. }
  26270. var bindings = action._propertyBindings;
  26271. // increment reference counts / sort out state
  26272. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26273. var binding = bindings[ i ];
  26274. if ( binding.useCount ++ === 0 ) {
  26275. this._lendBinding( binding );
  26276. binding.saveOriginalState();
  26277. }
  26278. }
  26279. this._lendAction( action );
  26280. }
  26281. },
  26282. _deactivateAction: function ( action ) {
  26283. if ( this._isActiveAction( action ) ) {
  26284. var bindings = action._propertyBindings;
  26285. // decrement reference counts / sort out state
  26286. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26287. var binding = bindings[ i ];
  26288. if ( -- binding.useCount === 0 ) {
  26289. binding.restoreOriginalState();
  26290. this._takeBackBinding( binding );
  26291. }
  26292. }
  26293. this._takeBackAction( action );
  26294. }
  26295. },
  26296. // Memory manager
  26297. _initMemoryManager: function () {
  26298. this._actions = []; // 'nActiveActions' followed by inactive ones
  26299. this._nActiveActions = 0;
  26300. this._actionsByClip = {};
  26301. // inside:
  26302. // {
  26303. // knownActions: Array< AnimationAction > - used as prototypes
  26304. // actionByRoot: AnimationAction - lookup
  26305. // }
  26306. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26307. this._nActiveBindings = 0;
  26308. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26309. this._controlInterpolants = []; // same game as above
  26310. this._nActiveControlInterpolants = 0;
  26311. var scope = this;
  26312. this.stats = {
  26313. actions: {
  26314. get total() {
  26315. return scope._actions.length;
  26316. },
  26317. get inUse() {
  26318. return scope._nActiveActions;
  26319. }
  26320. },
  26321. bindings: {
  26322. get total() {
  26323. return scope._bindings.length;
  26324. },
  26325. get inUse() {
  26326. return scope._nActiveBindings;
  26327. }
  26328. },
  26329. controlInterpolants: {
  26330. get total() {
  26331. return scope._controlInterpolants.length;
  26332. },
  26333. get inUse() {
  26334. return scope._nActiveControlInterpolants;
  26335. }
  26336. }
  26337. };
  26338. },
  26339. // Memory management for AnimationAction objects
  26340. _isActiveAction: function ( action ) {
  26341. var index = action._cacheIndex;
  26342. return index !== null && index < this._nActiveActions;
  26343. },
  26344. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26345. var actions = this._actions,
  26346. actionsByClip = this._actionsByClip,
  26347. actionsForClip = actionsByClip[ clipUuid ];
  26348. if ( actionsForClip === undefined ) {
  26349. actionsForClip = {
  26350. knownActions: [ action ],
  26351. actionByRoot: {}
  26352. };
  26353. action._byClipCacheIndex = 0;
  26354. actionsByClip[ clipUuid ] = actionsForClip;
  26355. } else {
  26356. var knownActions = actionsForClip.knownActions;
  26357. action._byClipCacheIndex = knownActions.length;
  26358. knownActions.push( action );
  26359. }
  26360. action._cacheIndex = actions.length;
  26361. actions.push( action );
  26362. actionsForClip.actionByRoot[ rootUuid ] = action;
  26363. },
  26364. _removeInactiveAction: function ( action ) {
  26365. var actions = this._actions,
  26366. lastInactiveAction = actions[ actions.length - 1 ],
  26367. cacheIndex = action._cacheIndex;
  26368. lastInactiveAction._cacheIndex = cacheIndex;
  26369. actions[ cacheIndex ] = lastInactiveAction;
  26370. actions.pop();
  26371. action._cacheIndex = null;
  26372. var clipUuid = action._clip.uuid,
  26373. actionsByClip = this._actionsByClip,
  26374. actionsForClip = actionsByClip[ clipUuid ],
  26375. knownActionsForClip = actionsForClip.knownActions,
  26376. lastKnownAction =
  26377. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26378. byClipCacheIndex = action._byClipCacheIndex;
  26379. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26380. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26381. knownActionsForClip.pop();
  26382. action._byClipCacheIndex = null;
  26383. var actionByRoot = actionsForClip.actionByRoot,
  26384. rootUuid = ( action._localRoot || this._root ).uuid;
  26385. delete actionByRoot[ rootUuid ];
  26386. if ( knownActionsForClip.length === 0 ) {
  26387. delete actionsByClip[ clipUuid ];
  26388. }
  26389. this._removeInactiveBindingsForAction( action );
  26390. },
  26391. _removeInactiveBindingsForAction: function ( action ) {
  26392. var bindings = action._propertyBindings;
  26393. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26394. var binding = bindings[ i ];
  26395. if ( -- binding.referenceCount === 0 ) {
  26396. this._removeInactiveBinding( binding );
  26397. }
  26398. }
  26399. },
  26400. _lendAction: function ( action ) {
  26401. // [ active actions | inactive actions ]
  26402. // [ active actions >| inactive actions ]
  26403. // s a
  26404. // <-swap->
  26405. // a s
  26406. var actions = this._actions,
  26407. prevIndex = action._cacheIndex,
  26408. lastActiveIndex = this._nActiveActions ++,
  26409. firstInactiveAction = actions[ lastActiveIndex ];
  26410. action._cacheIndex = lastActiveIndex;
  26411. actions[ lastActiveIndex ] = action;
  26412. firstInactiveAction._cacheIndex = prevIndex;
  26413. actions[ prevIndex ] = firstInactiveAction;
  26414. },
  26415. _takeBackAction: function ( action ) {
  26416. // [ active actions | inactive actions ]
  26417. // [ active actions |< inactive actions ]
  26418. // a s
  26419. // <-swap->
  26420. // s a
  26421. var actions = this._actions,
  26422. prevIndex = action._cacheIndex,
  26423. firstInactiveIndex = -- this._nActiveActions,
  26424. lastActiveAction = actions[ firstInactiveIndex ];
  26425. action._cacheIndex = firstInactiveIndex;
  26426. actions[ firstInactiveIndex ] = action;
  26427. lastActiveAction._cacheIndex = prevIndex;
  26428. actions[ prevIndex ] = lastActiveAction;
  26429. },
  26430. // Memory management for PropertyMixer objects
  26431. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26432. var bindingsByRoot = this._bindingsByRootAndName,
  26433. bindingByName = bindingsByRoot[ rootUuid ],
  26434. bindings = this._bindings;
  26435. if ( bindingByName === undefined ) {
  26436. bindingByName = {};
  26437. bindingsByRoot[ rootUuid ] = bindingByName;
  26438. }
  26439. bindingByName[ trackName ] = binding;
  26440. binding._cacheIndex = bindings.length;
  26441. bindings.push( binding );
  26442. },
  26443. _removeInactiveBinding: function ( binding ) {
  26444. var bindings = this._bindings,
  26445. propBinding = binding.binding,
  26446. rootUuid = propBinding.rootNode.uuid,
  26447. trackName = propBinding.path,
  26448. bindingsByRoot = this._bindingsByRootAndName,
  26449. bindingByName = bindingsByRoot[ rootUuid ],
  26450. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26451. cacheIndex = binding._cacheIndex;
  26452. lastInactiveBinding._cacheIndex = cacheIndex;
  26453. bindings[ cacheIndex ] = lastInactiveBinding;
  26454. bindings.pop();
  26455. delete bindingByName[ trackName ];
  26456. if ( Object.keys( bindingByName ).length === 0 ) {
  26457. delete bindingsByRoot[ rootUuid ];
  26458. }
  26459. },
  26460. _lendBinding: function ( binding ) {
  26461. var bindings = this._bindings,
  26462. prevIndex = binding._cacheIndex,
  26463. lastActiveIndex = this._nActiveBindings ++,
  26464. firstInactiveBinding = bindings[ lastActiveIndex ];
  26465. binding._cacheIndex = lastActiveIndex;
  26466. bindings[ lastActiveIndex ] = binding;
  26467. firstInactiveBinding._cacheIndex = prevIndex;
  26468. bindings[ prevIndex ] = firstInactiveBinding;
  26469. },
  26470. _takeBackBinding: function ( binding ) {
  26471. var bindings = this._bindings,
  26472. prevIndex = binding._cacheIndex,
  26473. firstInactiveIndex = -- this._nActiveBindings,
  26474. lastActiveBinding = bindings[ firstInactiveIndex ];
  26475. binding._cacheIndex = firstInactiveIndex;
  26476. bindings[ firstInactiveIndex ] = binding;
  26477. lastActiveBinding._cacheIndex = prevIndex;
  26478. bindings[ prevIndex ] = lastActiveBinding;
  26479. },
  26480. // Memory management of Interpolants for weight and time scale
  26481. _lendControlInterpolant: function () {
  26482. var interpolants = this._controlInterpolants,
  26483. lastActiveIndex = this._nActiveControlInterpolants ++,
  26484. interpolant = interpolants[ lastActiveIndex ];
  26485. if ( interpolant === undefined ) {
  26486. interpolant = new LinearInterpolant(
  26487. new Float32Array( 2 ), new Float32Array( 2 ),
  26488. 1, this._controlInterpolantsResultBuffer );
  26489. interpolant.__cacheIndex = lastActiveIndex;
  26490. interpolants[ lastActiveIndex ] = interpolant;
  26491. }
  26492. return interpolant;
  26493. },
  26494. _takeBackControlInterpolant: function ( interpolant ) {
  26495. var interpolants = this._controlInterpolants,
  26496. prevIndex = interpolant.__cacheIndex,
  26497. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26498. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26499. interpolant.__cacheIndex = firstInactiveIndex;
  26500. interpolants[ firstInactiveIndex ] = interpolant;
  26501. lastActiveInterpolant.__cacheIndex = prevIndex;
  26502. interpolants[ prevIndex ] = lastActiveInterpolant;
  26503. },
  26504. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26505. // return an action for a clip optionally using a custom root target
  26506. // object (this method allocates a lot of dynamic memory in case a
  26507. // previously unknown clip/root combination is specified)
  26508. clipAction: function ( clip, optionalRoot ) {
  26509. var root = optionalRoot || this._root,
  26510. rootUuid = root.uuid,
  26511. clipObject = typeof clip === 'string' ?
  26512. AnimationClip.findByName( root, clip ) : clip,
  26513. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26514. actionsForClip = this._actionsByClip[ clipUuid ],
  26515. prototypeAction = null;
  26516. if ( actionsForClip !== undefined ) {
  26517. var existingAction =
  26518. actionsForClip.actionByRoot[ rootUuid ];
  26519. if ( existingAction !== undefined ) {
  26520. return existingAction;
  26521. }
  26522. // we know the clip, so we don't have to parse all
  26523. // the bindings again but can just copy
  26524. prototypeAction = actionsForClip.knownActions[ 0 ];
  26525. // also, take the clip from the prototype action
  26526. if ( clipObject === null )
  26527. clipObject = prototypeAction._clip;
  26528. }
  26529. // clip must be known when specified via string
  26530. if ( clipObject === null ) return null;
  26531. // allocate all resources required to run it
  26532. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26533. this._bindAction( newAction, prototypeAction );
  26534. // and make the action known to the memory manager
  26535. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26536. return newAction;
  26537. },
  26538. // get an existing action
  26539. existingAction: function ( clip, optionalRoot ) {
  26540. var root = optionalRoot || this._root,
  26541. rootUuid = root.uuid,
  26542. clipObject = typeof clip === 'string' ?
  26543. AnimationClip.findByName( root, clip ) : clip,
  26544. clipUuid = clipObject ? clipObject.uuid : clip,
  26545. actionsForClip = this._actionsByClip[ clipUuid ];
  26546. if ( actionsForClip !== undefined ) {
  26547. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26548. }
  26549. return null;
  26550. },
  26551. // deactivates all previously scheduled actions
  26552. stopAllAction: function () {
  26553. var actions = this._actions,
  26554. nActions = this._nActiveActions,
  26555. bindings = this._bindings,
  26556. nBindings = this._nActiveBindings;
  26557. this._nActiveActions = 0;
  26558. this._nActiveBindings = 0;
  26559. for ( var i = 0; i !== nActions; ++ i ) {
  26560. actions[ i ].reset();
  26561. }
  26562. for ( var i = 0; i !== nBindings; ++ i ) {
  26563. bindings[ i ].useCount = 0;
  26564. }
  26565. return this;
  26566. },
  26567. // advance the time and update apply the animation
  26568. update: function ( deltaTime ) {
  26569. deltaTime *= this.timeScale;
  26570. var actions = this._actions,
  26571. nActions = this._nActiveActions,
  26572. time = this.time += deltaTime,
  26573. timeDirection = Math.sign( deltaTime ),
  26574. accuIndex = this._accuIndex ^= 1;
  26575. // run active actions
  26576. for ( var i = 0; i !== nActions; ++ i ) {
  26577. var action = actions[ i ];
  26578. action._update( time, deltaTime, timeDirection, accuIndex );
  26579. }
  26580. // update scene graph
  26581. var bindings = this._bindings,
  26582. nBindings = this._nActiveBindings;
  26583. for ( var i = 0; i !== nBindings; ++ i ) {
  26584. bindings[ i ].apply( accuIndex );
  26585. }
  26586. return this;
  26587. },
  26588. // return this mixer's root target object
  26589. getRoot: function () {
  26590. return this._root;
  26591. },
  26592. // free all resources specific to a particular clip
  26593. uncacheClip: function ( clip ) {
  26594. var actions = this._actions,
  26595. clipUuid = clip.uuid,
  26596. actionsByClip = this._actionsByClip,
  26597. actionsForClip = actionsByClip[ clipUuid ];
  26598. if ( actionsForClip !== undefined ) {
  26599. // note: just calling _removeInactiveAction would mess up the
  26600. // iteration state and also require updating the state we can
  26601. // just throw away
  26602. var actionsToRemove = actionsForClip.knownActions;
  26603. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26604. var action = actionsToRemove[ i ];
  26605. this._deactivateAction( action );
  26606. var cacheIndex = action._cacheIndex,
  26607. lastInactiveAction = actions[ actions.length - 1 ];
  26608. action._cacheIndex = null;
  26609. action._byClipCacheIndex = null;
  26610. lastInactiveAction._cacheIndex = cacheIndex;
  26611. actions[ cacheIndex ] = lastInactiveAction;
  26612. actions.pop();
  26613. this._removeInactiveBindingsForAction( action );
  26614. }
  26615. delete actionsByClip[ clipUuid ];
  26616. }
  26617. },
  26618. // free all resources specific to a particular root target object
  26619. uncacheRoot: function ( root ) {
  26620. var rootUuid = root.uuid,
  26621. actionsByClip = this._actionsByClip;
  26622. for ( var clipUuid in actionsByClip ) {
  26623. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26624. action = actionByRoot[ rootUuid ];
  26625. if ( action !== undefined ) {
  26626. this._deactivateAction( action );
  26627. this._removeInactiveAction( action );
  26628. }
  26629. }
  26630. var bindingsByRoot = this._bindingsByRootAndName,
  26631. bindingByName = bindingsByRoot[ rootUuid ];
  26632. if ( bindingByName !== undefined ) {
  26633. for ( var trackName in bindingByName ) {
  26634. var binding = bindingByName[ trackName ];
  26635. binding.restoreOriginalState();
  26636. this._removeInactiveBinding( binding );
  26637. }
  26638. }
  26639. },
  26640. // remove a targeted clip from the cache
  26641. uncacheAction: function ( clip, optionalRoot ) {
  26642. var action = this.existingAction( clip, optionalRoot );
  26643. if ( action !== null ) {
  26644. this._deactivateAction( action );
  26645. this._removeInactiveAction( action );
  26646. }
  26647. }
  26648. } );
  26649. /**
  26650. * @author mrdoob / http://mrdoob.com/
  26651. */
  26652. function Uniform( value ) {
  26653. if ( typeof value === 'string' ) {
  26654. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26655. value = arguments[ 1 ];
  26656. }
  26657. this.value = value;
  26658. }
  26659. Uniform.prototype.clone = function () {
  26660. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26661. };
  26662. /**
  26663. * @author benaadams / https://twitter.com/ben_a_adams
  26664. */
  26665. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26666. InterleavedBuffer.call( this, array, stride );
  26667. this.meshPerAttribute = meshPerAttribute || 1;
  26668. }
  26669. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26670. constructor: InstancedInterleavedBuffer,
  26671. isInstancedInterleavedBuffer: true,
  26672. copy: function ( source ) {
  26673. InterleavedBuffer.prototype.copy.call( this, source );
  26674. this.meshPerAttribute = source.meshPerAttribute;
  26675. return this;
  26676. }
  26677. } );
  26678. /**
  26679. * @author mrdoob / http://mrdoob.com/
  26680. * @author bhouston / http://clara.io/
  26681. * @author stephomi / http://stephaneginier.com/
  26682. */
  26683. function Raycaster( origin, direction, near, far ) {
  26684. this.ray = new Ray( origin, direction );
  26685. // direction is assumed to be normalized (for accurate distance calculations)
  26686. this.near = near || 0;
  26687. this.far = far || Infinity;
  26688. this.params = {
  26689. Mesh: {},
  26690. Line: {},
  26691. LOD: {},
  26692. Points: { threshold: 1 },
  26693. Sprite: {}
  26694. };
  26695. Object.defineProperties( this.params, {
  26696. PointCloud: {
  26697. get: function () {
  26698. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26699. return this.Points;
  26700. }
  26701. }
  26702. } );
  26703. }
  26704. function ascSort( a, b ) {
  26705. return a.distance - b.distance;
  26706. }
  26707. function intersectObject( object, raycaster, intersects, recursive ) {
  26708. if ( object.visible === false ) return;
  26709. object.raycast( raycaster, intersects );
  26710. if ( recursive === true ) {
  26711. var children = object.children;
  26712. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26713. intersectObject( children[ i ], raycaster, intersects, true );
  26714. }
  26715. }
  26716. }
  26717. Object.assign( Raycaster.prototype, {
  26718. linePrecision: 1,
  26719. set: function ( origin, direction ) {
  26720. // direction is assumed to be normalized (for accurate distance calculations)
  26721. this.ray.set( origin, direction );
  26722. },
  26723. setFromCamera: function ( coords, camera ) {
  26724. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26725. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26726. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26727. this._camera = camera;
  26728. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26729. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26730. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26731. this._camera = camera;
  26732. } else {
  26733. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26734. }
  26735. },
  26736. intersectObject: function ( object, recursive, optionalTarget ) {
  26737. var intersects = optionalTarget || [];
  26738. intersectObject( object, this, intersects, recursive );
  26739. intersects.sort( ascSort );
  26740. return intersects;
  26741. },
  26742. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26743. var intersects = optionalTarget || [];
  26744. if ( Array.isArray( objects ) === false ) {
  26745. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26746. return intersects;
  26747. }
  26748. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26749. intersectObject( objects[ i ], this, intersects, recursive );
  26750. }
  26751. intersects.sort( ascSort );
  26752. return intersects;
  26753. }
  26754. } );
  26755. /**
  26756. * @author bhouston / http://clara.io
  26757. * @author WestLangley / http://github.com/WestLangley
  26758. *
  26759. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26760. *
  26761. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26762. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26763. */
  26764. function Spherical( radius, phi, theta ) {
  26765. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26766. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26767. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26768. return this;
  26769. }
  26770. Object.assign( Spherical.prototype, {
  26771. set: function ( radius, phi, theta ) {
  26772. this.radius = radius;
  26773. this.phi = phi;
  26774. this.theta = theta;
  26775. return this;
  26776. },
  26777. clone: function () {
  26778. return new this.constructor().copy( this );
  26779. },
  26780. copy: function ( other ) {
  26781. this.radius = other.radius;
  26782. this.phi = other.phi;
  26783. this.theta = other.theta;
  26784. return this;
  26785. },
  26786. // restrict phi to be betwee EPS and PI-EPS
  26787. makeSafe: function () {
  26788. var EPS = 0.000001;
  26789. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26790. return this;
  26791. },
  26792. setFromVector3: function ( v ) {
  26793. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26794. },
  26795. setFromCartesianCoords: function ( x, y, z ) {
  26796. this.radius = Math.sqrt( x * x + y * y + z * z );
  26797. if ( this.radius === 0 ) {
  26798. this.theta = 0;
  26799. this.phi = 0;
  26800. } else {
  26801. this.theta = Math.atan2( x, z );
  26802. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26803. }
  26804. return this;
  26805. }
  26806. } );
  26807. /**
  26808. * @author Mugen87 / https://github.com/Mugen87
  26809. *
  26810. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26811. *
  26812. */
  26813. function Cylindrical( radius, theta, y ) {
  26814. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26815. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26816. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26817. return this;
  26818. }
  26819. Object.assign( Cylindrical.prototype, {
  26820. set: function ( radius, theta, y ) {
  26821. this.radius = radius;
  26822. this.theta = theta;
  26823. this.y = y;
  26824. return this;
  26825. },
  26826. clone: function () {
  26827. return new this.constructor().copy( this );
  26828. },
  26829. copy: function ( other ) {
  26830. this.radius = other.radius;
  26831. this.theta = other.theta;
  26832. this.y = other.y;
  26833. return this;
  26834. },
  26835. setFromVector3: function ( v ) {
  26836. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26837. },
  26838. setFromCartesianCoords: function ( x, y, z ) {
  26839. this.radius = Math.sqrt( x * x + z * z );
  26840. this.theta = Math.atan2( x, z );
  26841. this.y = y;
  26842. return this;
  26843. }
  26844. } );
  26845. /**
  26846. * @author bhouston / http://clara.io
  26847. */
  26848. var _vector$5;
  26849. function Box2( min, max ) {
  26850. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26851. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26852. }
  26853. Object.assign( Box2.prototype, {
  26854. set: function ( min, max ) {
  26855. this.min.copy( min );
  26856. this.max.copy( max );
  26857. return this;
  26858. },
  26859. setFromPoints: function ( points ) {
  26860. this.makeEmpty();
  26861. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26862. this.expandByPoint( points[ i ] );
  26863. }
  26864. return this;
  26865. },
  26866. setFromCenterAndSize: function ( center, size ) {
  26867. if ( _vector$5 === undefined ) _vector$5 = new Vector2();
  26868. var halfSize = _vector$5.copy( size ).multiplyScalar( 0.5 );
  26869. this.min.copy( center ).sub( halfSize );
  26870. this.max.copy( center ).add( halfSize );
  26871. return this;
  26872. },
  26873. clone: function () {
  26874. return new this.constructor().copy( this );
  26875. },
  26876. copy: function ( box ) {
  26877. this.min.copy( box.min );
  26878. this.max.copy( box.max );
  26879. return this;
  26880. },
  26881. makeEmpty: function () {
  26882. this.min.x = this.min.y = + Infinity;
  26883. this.max.x = this.max.y = - Infinity;
  26884. return this;
  26885. },
  26886. isEmpty: function () {
  26887. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26888. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26889. },
  26890. getCenter: function ( target ) {
  26891. if ( target === undefined ) {
  26892. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26893. target = new Vector2();
  26894. }
  26895. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26896. },
  26897. getSize: function ( target ) {
  26898. if ( target === undefined ) {
  26899. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26900. target = new Vector2();
  26901. }
  26902. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26903. },
  26904. expandByPoint: function ( point ) {
  26905. this.min.min( point );
  26906. this.max.max( point );
  26907. return this;
  26908. },
  26909. expandByVector: function ( vector ) {
  26910. this.min.sub( vector );
  26911. this.max.add( vector );
  26912. return this;
  26913. },
  26914. expandByScalar: function ( scalar ) {
  26915. this.min.addScalar( - scalar );
  26916. this.max.addScalar( scalar );
  26917. return this;
  26918. },
  26919. containsPoint: function ( point ) {
  26920. return point.x < this.min.x || point.x > this.max.x ||
  26921. point.y < this.min.y || point.y > this.max.y ? false : true;
  26922. },
  26923. containsBox: function ( box ) {
  26924. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26925. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26926. },
  26927. getParameter: function ( point, target ) {
  26928. // This can potentially have a divide by zero if the box
  26929. // has a size dimension of 0.
  26930. if ( target === undefined ) {
  26931. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26932. target = new Vector2();
  26933. }
  26934. return target.set(
  26935. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26936. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26937. );
  26938. },
  26939. intersectsBox: function ( box ) {
  26940. // using 4 splitting planes to rule out intersections
  26941. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26942. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26943. },
  26944. clampPoint: function ( point, target ) {
  26945. if ( target === undefined ) {
  26946. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26947. target = new Vector2();
  26948. }
  26949. return target.copy( point ).clamp( this.min, this.max );
  26950. },
  26951. distanceToPoint: function ( point ) {
  26952. if ( _vector$5 === undefined ) _vector$5 = new Vector2();
  26953. var clampedPoint = _vector$5.copy( point ).clamp( this.min, this.max );
  26954. return clampedPoint.sub( point ).length();
  26955. },
  26956. intersect: function ( box ) {
  26957. this.min.max( box.min );
  26958. this.max.min( box.max );
  26959. return this;
  26960. },
  26961. union: function ( box ) {
  26962. this.min.min( box.min );
  26963. this.max.max( box.max );
  26964. return this;
  26965. },
  26966. translate: function ( offset ) {
  26967. this.min.add( offset );
  26968. this.max.add( offset );
  26969. return this;
  26970. },
  26971. equals: function ( box ) {
  26972. return box.min.equals( this.min ) && box.max.equals( this.max );
  26973. }
  26974. } );
  26975. /**
  26976. * @author bhouston / http://clara.io
  26977. */
  26978. var _startP, _startEnd;
  26979. function Line3( start, end ) {
  26980. this.start = ( start !== undefined ) ? start : new Vector3();
  26981. this.end = ( end !== undefined ) ? end : new Vector3();
  26982. }
  26983. Object.assign( Line3.prototype, {
  26984. set: function ( start, end ) {
  26985. this.start.copy( start );
  26986. this.end.copy( end );
  26987. return this;
  26988. },
  26989. clone: function () {
  26990. return new this.constructor().copy( this );
  26991. },
  26992. copy: function ( line ) {
  26993. this.start.copy( line.start );
  26994. this.end.copy( line.end );
  26995. return this;
  26996. },
  26997. getCenter: function ( target ) {
  26998. if ( target === undefined ) {
  26999. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  27000. target = new Vector3();
  27001. }
  27002. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  27003. },
  27004. delta: function ( target ) {
  27005. if ( target === undefined ) {
  27006. console.warn( 'THREE.Line3: .delta() target is now required' );
  27007. target = new Vector3();
  27008. }
  27009. return target.subVectors( this.end, this.start );
  27010. },
  27011. distanceSq: function () {
  27012. return this.start.distanceToSquared( this.end );
  27013. },
  27014. distance: function () {
  27015. return this.start.distanceTo( this.end );
  27016. },
  27017. at: function ( t, target ) {
  27018. if ( target === undefined ) {
  27019. console.warn( 'THREE.Line3: .at() target is now required' );
  27020. target = new Vector3();
  27021. }
  27022. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27023. },
  27024. closestPointToPointParameter: function ( point, clampToLine ) {
  27025. if ( _startP === undefined ) {
  27026. _startP = new Vector3();
  27027. _startEnd = new Vector3();
  27028. }
  27029. _startP.subVectors( point, this.start );
  27030. _startEnd.subVectors( this.end, this.start );
  27031. var startEnd2 = _startEnd.dot( _startEnd );
  27032. var startEnd_startP = _startEnd.dot( _startP );
  27033. var t = startEnd_startP / startEnd2;
  27034. if ( clampToLine ) {
  27035. t = _Math.clamp( t, 0, 1 );
  27036. }
  27037. return t;
  27038. },
  27039. closestPointToPoint: function ( point, clampToLine, target ) {
  27040. var t = this.closestPointToPointParameter( point, clampToLine );
  27041. if ( target === undefined ) {
  27042. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27043. target = new Vector3();
  27044. }
  27045. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27046. },
  27047. applyMatrix4: function ( matrix ) {
  27048. this.start.applyMatrix4( matrix );
  27049. this.end.applyMatrix4( matrix );
  27050. return this;
  27051. },
  27052. equals: function ( line ) {
  27053. return line.start.equals( this.start ) && line.end.equals( this.end );
  27054. }
  27055. } );
  27056. /**
  27057. * @author alteredq / http://alteredqualia.com/
  27058. */
  27059. function ImmediateRenderObject( material ) {
  27060. Object3D.call( this );
  27061. this.material = material;
  27062. this.render = function ( /* renderCallback */ ) {};
  27063. }
  27064. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27065. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27066. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27067. /**
  27068. * @author mrdoob / http://mrdoob.com/
  27069. * @author WestLangley / http://github.com/WestLangley
  27070. */
  27071. var _v1$3, _v2$2, _normalMatrix$1, _keys;
  27072. function VertexNormalsHelper( object, size, hex, linewidth ) {
  27073. this.object = object;
  27074. this.size = ( size !== undefined ) ? size : 1;
  27075. var color = ( hex !== undefined ) ? hex : 0xff0000;
  27076. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27077. //
  27078. var nNormals = 0;
  27079. var objGeometry = this.object.geometry;
  27080. if ( objGeometry && objGeometry.isGeometry ) {
  27081. nNormals = objGeometry.faces.length * 3;
  27082. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27083. nNormals = objGeometry.attributes.normal.count;
  27084. }
  27085. //
  27086. var geometry = new BufferGeometry();
  27087. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27088. geometry.addAttribute( 'position', positions );
  27089. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27090. //
  27091. this.matrixAutoUpdate = false;
  27092. this.update();
  27093. }
  27094. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27095. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  27096. VertexNormalsHelper.prototype.update = function () {
  27097. if ( _normalMatrix$1 === undefined ) {
  27098. _v1$3 = new Vector3();
  27099. _v2$2 = new Vector3();
  27100. _normalMatrix$1 = new Matrix3();
  27101. _keys = [ 'a', 'b', 'c' ];
  27102. }
  27103. this.object.updateMatrixWorld( true );
  27104. _normalMatrix$1.getNormalMatrix( this.object.matrixWorld );
  27105. var matrixWorld = this.object.matrixWorld;
  27106. var position = this.geometry.attributes.position;
  27107. //
  27108. var objGeometry = this.object.geometry;
  27109. if ( objGeometry && objGeometry.isGeometry ) {
  27110. var vertices = objGeometry.vertices;
  27111. var faces = objGeometry.faces;
  27112. var idx = 0;
  27113. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27114. var face = faces[ i ];
  27115. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  27116. var vertex = vertices[ face[ _keys[ j ] ] ];
  27117. var normal = face.vertexNormals[ j ];
  27118. _v1$3.copy( vertex ).applyMatrix4( matrixWorld );
  27119. _v2$2.copy( normal ).applyMatrix3( _normalMatrix$1 ).normalize().multiplyScalar( this.size ).add( _v1$3 );
  27120. position.setXYZ( idx, _v1$3.x, _v1$3.y, _v1$3.z );
  27121. idx = idx + 1;
  27122. position.setXYZ( idx, _v2$2.x, _v2$2.y, _v2$2.z );
  27123. idx = idx + 1;
  27124. }
  27125. }
  27126. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27127. var objPos = objGeometry.attributes.position;
  27128. var objNorm = objGeometry.attributes.normal;
  27129. var idx = 0;
  27130. // for simplicity, ignore index and drawcalls, and render every normal
  27131. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  27132. _v1$3.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  27133. _v2$2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  27134. _v2$2.applyMatrix3( _normalMatrix$1 ).normalize().multiplyScalar( this.size ).add( _v1$3 );
  27135. position.setXYZ( idx, _v1$3.x, _v1$3.y, _v1$3.z );
  27136. idx = idx + 1;
  27137. position.setXYZ( idx, _v2$2.x, _v2$2.y, _v2$2.z );
  27138. idx = idx + 1;
  27139. }
  27140. }
  27141. position.needsUpdate = true;
  27142. };
  27143. /**
  27144. * @author alteredq / http://alteredqualia.com/
  27145. * @author mrdoob / http://mrdoob.com/
  27146. * @author WestLangley / http://github.com/WestLangley
  27147. */
  27148. var _vector$6;
  27149. function SpotLightHelper( light, color ) {
  27150. Object3D.call( this );
  27151. this.light = light;
  27152. this.light.updateMatrixWorld();
  27153. this.matrix = light.matrixWorld;
  27154. this.matrixAutoUpdate = false;
  27155. this.color = color;
  27156. var geometry = new BufferGeometry();
  27157. var positions = [
  27158. 0, 0, 0, 0, 0, 1,
  27159. 0, 0, 0, 1, 0, 1,
  27160. 0, 0, 0, - 1, 0, 1,
  27161. 0, 0, 0, 0, 1, 1,
  27162. 0, 0, 0, 0, - 1, 1
  27163. ];
  27164. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27165. var p1 = ( i / l ) * Math.PI * 2;
  27166. var p2 = ( j / l ) * Math.PI * 2;
  27167. positions.push(
  27168. Math.cos( p1 ), Math.sin( p1 ), 1,
  27169. Math.cos( p2 ), Math.sin( p2 ), 1
  27170. );
  27171. }
  27172. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27173. var material = new LineBasicMaterial( { fog: false } );
  27174. this.cone = new LineSegments( geometry, material );
  27175. this.add( this.cone );
  27176. this.update();
  27177. }
  27178. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  27179. SpotLightHelper.prototype.constructor = SpotLightHelper;
  27180. SpotLightHelper.prototype.dispose = function () {
  27181. this.cone.geometry.dispose();
  27182. this.cone.material.dispose();
  27183. };
  27184. SpotLightHelper.prototype.update = function () {
  27185. if ( _vector$6 === undefined ) _vector$6 = new Vector3();
  27186. this.light.updateMatrixWorld();
  27187. var coneLength = this.light.distance ? this.light.distance : 1000;
  27188. var coneWidth = coneLength * Math.tan( this.light.angle );
  27189. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  27190. _vector$6.setFromMatrixPosition( this.light.target.matrixWorld );
  27191. this.cone.lookAt( _vector$6 );
  27192. if ( this.color !== undefined ) {
  27193. this.cone.material.color.set( this.color );
  27194. } else {
  27195. this.cone.material.color.copy( this.light.color );
  27196. }
  27197. };
  27198. /**
  27199. * @author Sean Griffin / http://twitter.com/sgrif
  27200. * @author Michael Guerrero / http://realitymeltdown.com
  27201. * @author mrdoob / http://mrdoob.com/
  27202. * @author ikerr / http://verold.com
  27203. * @author Mugen87 / https://github.com/Mugen87
  27204. */
  27205. var _vector$7, _boneMatrix, _matrixWorldInv;
  27206. function getBoneList( object ) {
  27207. var boneList = [];
  27208. if ( object && object.isBone ) {
  27209. boneList.push( object );
  27210. }
  27211. for ( var i = 0; i < object.children.length; i ++ ) {
  27212. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  27213. }
  27214. return boneList;
  27215. }
  27216. function SkeletonHelper( object ) {
  27217. var bones = getBoneList( object );
  27218. var geometry = new BufferGeometry();
  27219. var vertices = [];
  27220. var colors = [];
  27221. var color1 = new Color( 0, 0, 1 );
  27222. var color2 = new Color( 0, 1, 0 );
  27223. for ( var i = 0; i < bones.length; i ++ ) {
  27224. var bone = bones[ i ];
  27225. if ( bone.parent && bone.parent.isBone ) {
  27226. vertices.push( 0, 0, 0 );
  27227. vertices.push( 0, 0, 0 );
  27228. colors.push( color1.r, color1.g, color1.b );
  27229. colors.push( color2.r, color2.g, color2.b );
  27230. }
  27231. }
  27232. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27233. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27234. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  27235. LineSegments.call( this, geometry, material );
  27236. this.root = object;
  27237. this.bones = bones;
  27238. this.matrix = object.matrixWorld;
  27239. this.matrixAutoUpdate = false;
  27240. }
  27241. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  27242. SkeletonHelper.prototype.constructor = SkeletonHelper;
  27243. SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
  27244. if ( _matrixWorldInv === undefined ) {
  27245. _vector$7 = new Vector3();
  27246. _boneMatrix = new Matrix4();
  27247. _matrixWorldInv = new Matrix4();
  27248. }
  27249. var bones = this.bones;
  27250. var geometry = this.geometry;
  27251. var position = geometry.getAttribute( 'position' );
  27252. _matrixWorldInv.getInverse( this.root.matrixWorld );
  27253. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  27254. var bone = bones[ i ];
  27255. if ( bone.parent && bone.parent.isBone ) {
  27256. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  27257. _vector$7.setFromMatrixPosition( _boneMatrix );
  27258. position.setXYZ( j, _vector$7.x, _vector$7.y, _vector$7.z );
  27259. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  27260. _vector$7.setFromMatrixPosition( _boneMatrix );
  27261. position.setXYZ( j + 1, _vector$7.x, _vector$7.y, _vector$7.z );
  27262. j += 2;
  27263. }
  27264. }
  27265. geometry.getAttribute( 'position' ).needsUpdate = true;
  27266. Object3D.prototype.updateMatrixWorld.call( this, force );
  27267. };
  27268. /**
  27269. * @author alteredq / http://alteredqualia.com/
  27270. * @author mrdoob / http://mrdoob.com/
  27271. */
  27272. function PointLightHelper( light, sphereSize, color ) {
  27273. this.light = light;
  27274. this.light.updateMatrixWorld();
  27275. this.color = color;
  27276. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  27277. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27278. Mesh.call( this, geometry, material );
  27279. this.matrix = this.light.matrixWorld;
  27280. this.matrixAutoUpdate = false;
  27281. this.update();
  27282. /*
  27283. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27284. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27285. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27286. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27287. var d = light.distance;
  27288. if ( d === 0.0 ) {
  27289. this.lightDistance.visible = false;
  27290. } else {
  27291. this.lightDistance.scale.set( d, d, d );
  27292. }
  27293. this.add( this.lightDistance );
  27294. */
  27295. }
  27296. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27297. PointLightHelper.prototype.constructor = PointLightHelper;
  27298. PointLightHelper.prototype.dispose = function () {
  27299. this.geometry.dispose();
  27300. this.material.dispose();
  27301. };
  27302. PointLightHelper.prototype.update = function () {
  27303. if ( this.color !== undefined ) {
  27304. this.material.color.set( this.color );
  27305. } else {
  27306. this.material.color.copy( this.light.color );
  27307. }
  27308. /*
  27309. var d = this.light.distance;
  27310. if ( d === 0.0 ) {
  27311. this.lightDistance.visible = false;
  27312. } else {
  27313. this.lightDistance.visible = true;
  27314. this.lightDistance.scale.set( d, d, d );
  27315. }
  27316. */
  27317. };
  27318. /**
  27319. * @author abelnation / http://github.com/abelnation
  27320. * @author Mugen87 / http://github.com/Mugen87
  27321. * @author WestLangley / http://github.com/WestLangley
  27322. *
  27323. * This helper must be added as a child of the light
  27324. */
  27325. function RectAreaLightHelper( light, color ) {
  27326. this.type = 'RectAreaLightHelper';
  27327. this.light = light;
  27328. this.color = color; // optional hardwired color for the helper
  27329. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27330. var geometry = new BufferGeometry();
  27331. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27332. geometry.computeBoundingSphere();
  27333. var material = new LineBasicMaterial( { fog: false } );
  27334. Line.call( this, geometry, material );
  27335. //
  27336. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27337. var geometry2 = new BufferGeometry();
  27338. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27339. geometry2.computeBoundingSphere();
  27340. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27341. this.update();
  27342. }
  27343. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27344. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27345. RectAreaLightHelper.prototype.update = function () {
  27346. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27347. if ( this.color !== undefined ) {
  27348. this.material.color.set( this.color );
  27349. this.children[ 0 ].material.color.set( this.color );
  27350. } else {
  27351. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27352. // prevent hue shift
  27353. var c = this.material.color;
  27354. var max = Math.max( c.r, c.g, c.b );
  27355. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27356. this.children[ 0 ].material.color.copy( this.material.color );
  27357. }
  27358. };
  27359. RectAreaLightHelper.prototype.dispose = function () {
  27360. this.geometry.dispose();
  27361. this.material.dispose();
  27362. this.children[ 0 ].geometry.dispose();
  27363. this.children[ 0 ].material.dispose();
  27364. };
  27365. /**
  27366. * @author alteredq / http://alteredqualia.com/
  27367. * @author mrdoob / http://mrdoob.com/
  27368. * @author Mugen87 / https://github.com/Mugen87
  27369. */
  27370. var _vector$8, _color1, _color2;
  27371. function HemisphereLightHelper( light, size, color ) {
  27372. Object3D.call( this );
  27373. this.light = light;
  27374. this.light.updateMatrixWorld();
  27375. this.matrix = light.matrixWorld;
  27376. this.matrixAutoUpdate = false;
  27377. this.color = color;
  27378. var geometry = new OctahedronBufferGeometry( size );
  27379. geometry.rotateY( Math.PI * 0.5 );
  27380. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27381. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27382. var position = geometry.getAttribute( 'position' );
  27383. var colors = new Float32Array( position.count * 3 );
  27384. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27385. this.add( new Mesh( geometry, this.material ) );
  27386. this.update();
  27387. }
  27388. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27389. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27390. HemisphereLightHelper.prototype.dispose = function () {
  27391. this.children[ 0 ].geometry.dispose();
  27392. this.children[ 0 ].material.dispose();
  27393. };
  27394. HemisphereLightHelper.prototype.update = function () {
  27395. if ( _color2 === undefined ) {
  27396. _vector$8 = new Vector3();
  27397. _color1 = new Color();
  27398. _color2 = new Color();
  27399. }
  27400. var mesh = this.children[ 0 ];
  27401. if ( this.color !== undefined ) {
  27402. this.material.color.set( this.color );
  27403. } else {
  27404. var colors = mesh.geometry.getAttribute( 'color' );
  27405. _color1.copy( this.light.color );
  27406. _color2.copy( this.light.groundColor );
  27407. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27408. var color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  27409. colors.setXYZ( i, color.r, color.g, color.b );
  27410. }
  27411. colors.needsUpdate = true;
  27412. }
  27413. mesh.lookAt( _vector$8.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27414. };
  27415. /**
  27416. * @author WestLangley / http://github.com/WestLangley
  27417. */
  27418. function LightProbeHelper( lightProbe, size ) {
  27419. this.lightProbe = lightProbe;
  27420. this.size = size;
  27421. var defines = {};
  27422. defines[ 'GAMMA_OUTPUT' ] = "";
  27423. // material
  27424. var material = new ShaderMaterial( {
  27425. defines: defines,
  27426. uniforms: {
  27427. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  27428. intensity: { value: this.lightProbe.intensity }
  27429. },
  27430. vertexShader: [
  27431. 'varying vec3 vNormal;',
  27432. 'void main() {',
  27433. ' vNormal = normalize( normalMatrix * normal );',
  27434. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  27435. '}',
  27436. ].join( '\n' ),
  27437. fragmentShader: [
  27438. '#define RECIPROCAL_PI 0.318309886',
  27439. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  27440. ' // matrix is assumed to be orthogonal',
  27441. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  27442. '}',
  27443. 'vec3 linearToOutput( in vec3 a ) {',
  27444. ' #ifdef GAMMA_OUTPUT',
  27445. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  27446. ' #else',
  27447. ' return a;',
  27448. ' #endif',
  27449. '}',
  27450. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  27451. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  27452. ' // normal is assumed to have unit length',
  27453. ' float x = normal.x, y = normal.y, z = normal.z;',
  27454. ' // band 0',
  27455. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  27456. ' // band 1',
  27457. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  27458. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  27459. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  27460. ' // band 2',
  27461. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  27462. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  27463. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  27464. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  27465. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  27466. ' return result;',
  27467. '}',
  27468. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  27469. 'uniform float intensity; // light probe intensity',
  27470. 'varying vec3 vNormal;',
  27471. 'void main() {',
  27472. ' vec3 normal = normalize( vNormal );',
  27473. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  27474. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  27475. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  27476. ' outgoingLight = linearToOutput( outgoingLight );',
  27477. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  27478. '}'
  27479. ].join( '\n' )
  27480. } );
  27481. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  27482. Mesh.call( this, geometry, material );
  27483. this.onBeforeRender();
  27484. }
  27485. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  27486. LightProbeHelper.prototype.constructor = LightProbeHelper;
  27487. LightProbeHelper.prototype.dispose = function () {
  27488. this.geometry.dispose();
  27489. this.material.dispose();
  27490. };
  27491. LightProbeHelper.prototype.onBeforeRender = function () {
  27492. this.position.copy( this.lightProbe.position );
  27493. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  27494. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  27495. };
  27496. /**
  27497. * @author mrdoob / http://mrdoob.com/
  27498. */
  27499. function GridHelper( size, divisions, color1, color2 ) {
  27500. size = size || 10;
  27501. divisions = divisions || 10;
  27502. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27503. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27504. var center = divisions / 2;
  27505. var step = size / divisions;
  27506. var halfSize = size / 2;
  27507. var vertices = [], colors = [];
  27508. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27509. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27510. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27511. var color = i === center ? color1 : color2;
  27512. color.toArray( colors, j ); j += 3;
  27513. color.toArray( colors, j ); j += 3;
  27514. color.toArray( colors, j ); j += 3;
  27515. color.toArray( colors, j ); j += 3;
  27516. }
  27517. var geometry = new BufferGeometry();
  27518. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27519. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27520. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27521. LineSegments.call( this, geometry, material );
  27522. }
  27523. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27524. constructor: GridHelper,
  27525. copy: function ( source ) {
  27526. LineSegments.prototype.copy.call( this, source );
  27527. this.geometry.copy( source.geometry );
  27528. this.material.copy( source.material );
  27529. return this;
  27530. },
  27531. clone: function () {
  27532. return new this.constructor().copy( this );
  27533. }
  27534. } );
  27535. /**
  27536. * @author mrdoob / http://mrdoob.com/
  27537. * @author Mugen87 / http://github.com/Mugen87
  27538. * @author Hectate / http://www.github.com/Hectate
  27539. */
  27540. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27541. radius = radius || 10;
  27542. radials = radials || 16;
  27543. circles = circles || 8;
  27544. divisions = divisions || 64;
  27545. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27546. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27547. var vertices = [];
  27548. var colors = [];
  27549. var x, z;
  27550. var v, i, j, r, color;
  27551. // create the radials
  27552. for ( i = 0; i <= radials; i ++ ) {
  27553. v = ( i / radials ) * ( Math.PI * 2 );
  27554. x = Math.sin( v ) * radius;
  27555. z = Math.cos( v ) * radius;
  27556. vertices.push( 0, 0, 0 );
  27557. vertices.push( x, 0, z );
  27558. color = ( i & 1 ) ? color1 : color2;
  27559. colors.push( color.r, color.g, color.b );
  27560. colors.push( color.r, color.g, color.b );
  27561. }
  27562. // create the circles
  27563. for ( i = 0; i <= circles; i ++ ) {
  27564. color = ( i & 1 ) ? color1 : color2;
  27565. r = radius - ( radius / circles * i );
  27566. for ( j = 0; j < divisions; j ++ ) {
  27567. // first vertex
  27568. v = ( j / divisions ) * ( Math.PI * 2 );
  27569. x = Math.sin( v ) * r;
  27570. z = Math.cos( v ) * r;
  27571. vertices.push( x, 0, z );
  27572. colors.push( color.r, color.g, color.b );
  27573. // second vertex
  27574. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27575. x = Math.sin( v ) * r;
  27576. z = Math.cos( v ) * r;
  27577. vertices.push( x, 0, z );
  27578. colors.push( color.r, color.g, color.b );
  27579. }
  27580. }
  27581. var geometry = new BufferGeometry();
  27582. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27583. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27584. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27585. LineSegments.call( this, geometry, material );
  27586. }
  27587. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27588. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27589. /**
  27590. * @author Mugen87 / http://github.com/Mugen87
  27591. */
  27592. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27593. this.audio = audio;
  27594. this.range = range || 1;
  27595. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27596. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27597. var geometry = new BufferGeometry();
  27598. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27599. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27600. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27601. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27602. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27603. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27604. this.update();
  27605. }
  27606. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27607. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27608. PositionalAudioHelper.prototype.update = function () {
  27609. var audio = this.audio;
  27610. var range = this.range;
  27611. var divisionsInnerAngle = this.divisionsInnerAngle;
  27612. var divisionsOuterAngle = this.divisionsOuterAngle;
  27613. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27614. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27615. var halfConeInnerAngle = coneInnerAngle / 2;
  27616. var halfConeOuterAngle = coneOuterAngle / 2;
  27617. var start = 0;
  27618. var count = 0;
  27619. var i, stride;
  27620. var geometry = this.geometry;
  27621. var positionAttribute = geometry.attributes.position;
  27622. geometry.clearGroups();
  27623. //
  27624. function generateSegment( from, to, divisions, materialIndex ) {
  27625. var step = ( to - from ) / divisions;
  27626. positionAttribute.setXYZ( start, 0, 0, 0 );
  27627. count ++;
  27628. for ( i = from; i < to; i += step ) {
  27629. stride = start + count;
  27630. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27631. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27632. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27633. count += 3;
  27634. }
  27635. geometry.addGroup( start, count, materialIndex );
  27636. start += count;
  27637. count = 0;
  27638. }
  27639. //
  27640. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27641. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27642. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27643. //
  27644. positionAttribute.needsUpdate = true;
  27645. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27646. };
  27647. PositionalAudioHelper.prototype.dispose = function () {
  27648. this.geometry.dispose();
  27649. this.material[ 0 ].dispose();
  27650. this.material[ 1 ].dispose();
  27651. };
  27652. /**
  27653. * @author mrdoob / http://mrdoob.com/
  27654. * @author WestLangley / http://github.com/WestLangley
  27655. */
  27656. var _v1$4, _v2$3, _normalMatrix$2;
  27657. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27658. // FaceNormalsHelper only supports THREE.Geometry
  27659. this.object = object;
  27660. this.size = ( size !== undefined ) ? size : 1;
  27661. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27662. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27663. //
  27664. var nNormals = 0;
  27665. var objGeometry = this.object.geometry;
  27666. if ( objGeometry && objGeometry.isGeometry ) {
  27667. nNormals = objGeometry.faces.length;
  27668. } else {
  27669. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27670. }
  27671. //
  27672. var geometry = new BufferGeometry();
  27673. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27674. geometry.addAttribute( 'position', positions );
  27675. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27676. //
  27677. this.matrixAutoUpdate = false;
  27678. this.update();
  27679. }
  27680. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27681. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27682. FaceNormalsHelper.prototype.update = function () {
  27683. if ( _normalMatrix$2 === undefined ) {
  27684. _v1$4 = new Vector3();
  27685. _v2$3 = new Vector3();
  27686. _normalMatrix$2 = new Matrix3();
  27687. }
  27688. this.object.updateMatrixWorld( true );
  27689. _normalMatrix$2.getNormalMatrix( this.object.matrixWorld );
  27690. var matrixWorld = this.object.matrixWorld;
  27691. var position = this.geometry.attributes.position;
  27692. //
  27693. var objGeometry = this.object.geometry;
  27694. var vertices = objGeometry.vertices;
  27695. var faces = objGeometry.faces;
  27696. var idx = 0;
  27697. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27698. var face = faces[ i ];
  27699. var normal = face.normal;
  27700. _v1$4.copy( vertices[ face.a ] )
  27701. .add( vertices[ face.b ] )
  27702. .add( vertices[ face.c ] )
  27703. .divideScalar( 3 )
  27704. .applyMatrix4( matrixWorld );
  27705. _v2$3.copy( normal ).applyMatrix3( _normalMatrix$2 ).normalize().multiplyScalar( this.size ).add( _v1$4 );
  27706. position.setXYZ( idx, _v1$4.x, _v1$4.y, _v1$4.z );
  27707. idx = idx + 1;
  27708. position.setXYZ( idx, _v2$3.x, _v2$3.y, _v2$3.z );
  27709. idx = idx + 1;
  27710. }
  27711. position.needsUpdate = true;
  27712. };
  27713. /**
  27714. * @author alteredq / http://alteredqualia.com/
  27715. * @author mrdoob / http://mrdoob.com/
  27716. * @author WestLangley / http://github.com/WestLangley
  27717. */
  27718. var _v1$5, _v2$4, _v3$1;
  27719. function DirectionalLightHelper( light, size, color ) {
  27720. Object3D.call( this );
  27721. this.light = light;
  27722. this.light.updateMatrixWorld();
  27723. this.matrix = light.matrixWorld;
  27724. this.matrixAutoUpdate = false;
  27725. this.color = color;
  27726. if ( size === undefined ) size = 1;
  27727. var geometry = new BufferGeometry();
  27728. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27729. - size, size, 0,
  27730. size, size, 0,
  27731. size, - size, 0,
  27732. - size, - size, 0,
  27733. - size, size, 0
  27734. ], 3 ) );
  27735. var material = new LineBasicMaterial( { fog: false } );
  27736. this.lightPlane = new Line( geometry, material );
  27737. this.add( this.lightPlane );
  27738. geometry = new BufferGeometry();
  27739. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27740. this.targetLine = new Line( geometry, material );
  27741. this.add( this.targetLine );
  27742. this.update();
  27743. }
  27744. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27745. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27746. DirectionalLightHelper.prototype.dispose = function () {
  27747. this.lightPlane.geometry.dispose();
  27748. this.lightPlane.material.dispose();
  27749. this.targetLine.geometry.dispose();
  27750. this.targetLine.material.dispose();
  27751. };
  27752. DirectionalLightHelper.prototype.update = function () {
  27753. if ( _v3$1 === undefined ) {
  27754. _v1$5 = new Vector3();
  27755. _v2$4 = new Vector3();
  27756. _v3$1 = new Vector3();
  27757. }
  27758. _v1$5.setFromMatrixPosition( this.light.matrixWorld );
  27759. _v2$4.setFromMatrixPosition( this.light.target.matrixWorld );
  27760. _v3$1.subVectors( _v2$4, _v1$5 );
  27761. this.lightPlane.lookAt( _v2$4 );
  27762. if ( this.color !== undefined ) {
  27763. this.lightPlane.material.color.set( this.color );
  27764. this.targetLine.material.color.set( this.color );
  27765. } else {
  27766. this.lightPlane.material.color.copy( this.light.color );
  27767. this.targetLine.material.color.copy( this.light.color );
  27768. }
  27769. this.targetLine.lookAt( _v2$4 );
  27770. this.targetLine.scale.z = _v3$1.length();
  27771. };
  27772. /**
  27773. * @author alteredq / http://alteredqualia.com/
  27774. * @author Mugen87 / https://github.com/Mugen87
  27775. *
  27776. * - shows frustum, line of sight and up of the camera
  27777. * - suitable for fast updates
  27778. * - based on frustum visualization in lightgl.js shadowmap example
  27779. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27780. */
  27781. function CameraHelper( camera ) {
  27782. var geometry = new BufferGeometry();
  27783. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27784. var vertices = [];
  27785. var colors = [];
  27786. var pointMap = {};
  27787. // colors
  27788. var colorFrustum = new Color( 0xffaa00 );
  27789. var colorCone = new Color( 0xff0000 );
  27790. var colorUp = new Color( 0x00aaff );
  27791. var colorTarget = new Color( 0xffffff );
  27792. var colorCross = new Color( 0x333333 );
  27793. // near
  27794. addLine( 'n1', 'n2', colorFrustum );
  27795. addLine( 'n2', 'n4', colorFrustum );
  27796. addLine( 'n4', 'n3', colorFrustum );
  27797. addLine( 'n3', 'n1', colorFrustum );
  27798. // far
  27799. addLine( 'f1', 'f2', colorFrustum );
  27800. addLine( 'f2', 'f4', colorFrustum );
  27801. addLine( 'f4', 'f3', colorFrustum );
  27802. addLine( 'f3', 'f1', colorFrustum );
  27803. // sides
  27804. addLine( 'n1', 'f1', colorFrustum );
  27805. addLine( 'n2', 'f2', colorFrustum );
  27806. addLine( 'n3', 'f3', colorFrustum );
  27807. addLine( 'n4', 'f4', colorFrustum );
  27808. // cone
  27809. addLine( 'p', 'n1', colorCone );
  27810. addLine( 'p', 'n2', colorCone );
  27811. addLine( 'p', 'n3', colorCone );
  27812. addLine( 'p', 'n4', colorCone );
  27813. // up
  27814. addLine( 'u1', 'u2', colorUp );
  27815. addLine( 'u2', 'u3', colorUp );
  27816. addLine( 'u3', 'u1', colorUp );
  27817. // target
  27818. addLine( 'c', 't', colorTarget );
  27819. addLine( 'p', 'c', colorCross );
  27820. // cross
  27821. addLine( 'cn1', 'cn2', colorCross );
  27822. addLine( 'cn3', 'cn4', colorCross );
  27823. addLine( 'cf1', 'cf2', colorCross );
  27824. addLine( 'cf3', 'cf4', colorCross );
  27825. function addLine( a, b, color ) {
  27826. addPoint( a, color );
  27827. addPoint( b, color );
  27828. }
  27829. function addPoint( id, color ) {
  27830. vertices.push( 0, 0, 0 );
  27831. colors.push( color.r, color.g, color.b );
  27832. if ( pointMap[ id ] === undefined ) {
  27833. pointMap[ id ] = [];
  27834. }
  27835. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27836. }
  27837. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27838. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27839. LineSegments.call( this, geometry, material );
  27840. this.camera = camera;
  27841. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27842. this.matrix = camera.matrixWorld;
  27843. this.matrixAutoUpdate = false;
  27844. this.pointMap = pointMap;
  27845. this.update();
  27846. }
  27847. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27848. CameraHelper.prototype.constructor = CameraHelper;
  27849. CameraHelper.prototype.update = function () {
  27850. var geometry, pointMap;
  27851. var vector = new Vector3();
  27852. var camera = new Camera();
  27853. function setPoint( point, x, y, z ) {
  27854. vector.set( x, y, z ).unproject( camera );
  27855. var points = pointMap[ point ];
  27856. if ( points !== undefined ) {
  27857. var position = geometry.getAttribute( 'position' );
  27858. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27859. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27860. }
  27861. }
  27862. }
  27863. return function update() {
  27864. geometry = this.geometry;
  27865. pointMap = this.pointMap;
  27866. var w = 1, h = 1;
  27867. // we need just camera projection matrix inverse
  27868. // world matrix must be identity
  27869. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27870. // center / target
  27871. setPoint( 'c', 0, 0, - 1 );
  27872. setPoint( 't', 0, 0, 1 );
  27873. // near
  27874. setPoint( 'n1', - w, - h, - 1 );
  27875. setPoint( 'n2', w, - h, - 1 );
  27876. setPoint( 'n3', - w, h, - 1 );
  27877. setPoint( 'n4', w, h, - 1 );
  27878. // far
  27879. setPoint( 'f1', - w, - h, 1 );
  27880. setPoint( 'f2', w, - h, 1 );
  27881. setPoint( 'f3', - w, h, 1 );
  27882. setPoint( 'f4', w, h, 1 );
  27883. // up
  27884. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27885. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27886. setPoint( 'u3', 0, h * 2, - 1 );
  27887. // cross
  27888. setPoint( 'cf1', - w, 0, 1 );
  27889. setPoint( 'cf2', w, 0, 1 );
  27890. setPoint( 'cf3', 0, - h, 1 );
  27891. setPoint( 'cf4', 0, h, 1 );
  27892. setPoint( 'cn1', - w, 0, - 1 );
  27893. setPoint( 'cn2', w, 0, - 1 );
  27894. setPoint( 'cn3', 0, - h, - 1 );
  27895. setPoint( 'cn4', 0, h, - 1 );
  27896. geometry.getAttribute( 'position' ).needsUpdate = true;
  27897. };
  27898. }();
  27899. /**
  27900. * @author mrdoob / http://mrdoob.com/
  27901. * @author Mugen87 / http://github.com/Mugen87
  27902. */
  27903. var _box$1;
  27904. function BoxHelper( object, color ) {
  27905. this.object = object;
  27906. if ( color === undefined ) color = 0xffff00;
  27907. 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 ] );
  27908. var positions = new Float32Array( 8 * 3 );
  27909. var geometry = new BufferGeometry();
  27910. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27911. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27912. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27913. this.matrixAutoUpdate = false;
  27914. this.update();
  27915. }
  27916. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27917. BoxHelper.prototype.constructor = BoxHelper;
  27918. BoxHelper.prototype.update = function ( object ) {
  27919. if ( _box$1 === undefined ) _box$1 = new Box3();
  27920. if ( object !== undefined ) {
  27921. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27922. }
  27923. if ( this.object !== undefined ) {
  27924. _box$1.setFromObject( this.object );
  27925. }
  27926. if ( _box$1.isEmpty() ) return;
  27927. var min = _box$1.min;
  27928. var max = _box$1.max;
  27929. /*
  27930. 5____4
  27931. 1/___0/|
  27932. | 6__|_7
  27933. 2/___3/
  27934. 0: max.x, max.y, max.z
  27935. 1: min.x, max.y, max.z
  27936. 2: min.x, min.y, max.z
  27937. 3: max.x, min.y, max.z
  27938. 4: max.x, max.y, min.z
  27939. 5: min.x, max.y, min.z
  27940. 6: min.x, min.y, min.z
  27941. 7: max.x, min.y, min.z
  27942. */
  27943. var position = this.geometry.attributes.position;
  27944. var array = position.array;
  27945. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27946. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27947. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27948. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27949. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27950. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27951. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27952. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27953. position.needsUpdate = true;
  27954. this.geometry.computeBoundingSphere();
  27955. };
  27956. BoxHelper.prototype.setFromObject = function ( object ) {
  27957. this.object = object;
  27958. this.update();
  27959. return this;
  27960. };
  27961. BoxHelper.prototype.copy = function ( source ) {
  27962. LineSegments.prototype.copy.call( this, source );
  27963. this.object = source.object;
  27964. return this;
  27965. };
  27966. BoxHelper.prototype.clone = function () {
  27967. return new this.constructor().copy( this );
  27968. };
  27969. /**
  27970. * @author WestLangley / http://github.com/WestLangley
  27971. */
  27972. function Box3Helper( box, color ) {
  27973. this.type = 'Box3Helper';
  27974. this.box = box;
  27975. color = color || 0xffff00;
  27976. 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 ] );
  27977. 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 ];
  27978. var geometry = new BufferGeometry();
  27979. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27980. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27981. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27982. this.geometry.computeBoundingSphere();
  27983. }
  27984. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27985. Box3Helper.prototype.constructor = Box3Helper;
  27986. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27987. var box = this.box;
  27988. if ( box.isEmpty() ) return;
  27989. box.getCenter( this.position );
  27990. box.getSize( this.scale );
  27991. this.scale.multiplyScalar( 0.5 );
  27992. Object3D.prototype.updateMatrixWorld.call( this, force );
  27993. };
  27994. /**
  27995. * @author WestLangley / http://github.com/WestLangley
  27996. */
  27997. function PlaneHelper( plane, size, hex ) {
  27998. this.type = 'PlaneHelper';
  27999. this.plane = plane;
  28000. this.size = ( size === undefined ) ? 1 : size;
  28001. var color = ( hex !== undefined ) ? hex : 0xffff00;
  28002. 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 ];
  28003. var geometry = new BufferGeometry();
  28004. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28005. geometry.computeBoundingSphere();
  28006. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  28007. //
  28008. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28009. var geometry2 = new BufferGeometry();
  28010. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28011. geometry2.computeBoundingSphere();
  28012. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  28013. }
  28014. PlaneHelper.prototype = Object.create( Line.prototype );
  28015. PlaneHelper.prototype.constructor = PlaneHelper;
  28016. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  28017. var scale = - this.plane.constant;
  28018. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28019. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28020. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28021. this.lookAt( this.plane.normal );
  28022. Object3D.prototype.updateMatrixWorld.call( this, force );
  28023. };
  28024. /**
  28025. * @author WestLangley / http://github.com/WestLangley
  28026. * @author zz85 / http://github.com/zz85
  28027. * @author bhouston / http://clara.io
  28028. *
  28029. * Creates an arrow for visualizing directions
  28030. *
  28031. * Parameters:
  28032. * dir - Vector3
  28033. * origin - Vector3
  28034. * length - Number
  28035. * color - color in hex value
  28036. * headLength - Number
  28037. * headWidth - Number
  28038. */
  28039. var _axis;
  28040. var _lineGeometry, _coneGeometry;
  28041. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  28042. // dir is assumed to be normalized
  28043. Object3D.call( this );
  28044. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28045. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28046. if ( length === undefined ) length = 1;
  28047. if ( color === undefined ) color = 0xffff00;
  28048. if ( headLength === undefined ) headLength = 0.2 * length;
  28049. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28050. if ( _lineGeometry === undefined ) {
  28051. _lineGeometry = new BufferGeometry();
  28052. _lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28053. _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28054. _coneGeometry.translate( 0, - 0.5, 0 );
  28055. }
  28056. this.position.copy( origin );
  28057. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color } ) );
  28058. this.line.matrixAutoUpdate = false;
  28059. this.add( this.line );
  28060. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color } ) );
  28061. this.cone.matrixAutoUpdate = false;
  28062. this.add( this.cone );
  28063. this.setDirection( dir );
  28064. this.setLength( length, headLength, headWidth );
  28065. }
  28066. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28067. ArrowHelper.prototype.constructor = ArrowHelper;
  28068. ArrowHelper.prototype.setDirection = function ( dir ) {
  28069. if ( _axis === undefined ) _axis = new Vector3();
  28070. // dir is assumed to be normalized
  28071. if ( dir.y > 0.99999 ) {
  28072. this.quaternion.set( 0, 0, 0, 1 );
  28073. } else if ( dir.y < - 0.99999 ) {
  28074. this.quaternion.set( 1, 0, 0, 0 );
  28075. } else {
  28076. _axis.set( dir.z, 0, - dir.x ).normalize();
  28077. var radians = Math.acos( dir.y );
  28078. this.quaternion.setFromAxisAngle( _axis, radians );
  28079. }
  28080. };
  28081. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28082. if ( headLength === undefined ) headLength = 0.2 * length;
  28083. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28084. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  28085. this.line.updateMatrix();
  28086. this.cone.scale.set( headWidth, headLength, headWidth );
  28087. this.cone.position.y = length;
  28088. this.cone.updateMatrix();
  28089. };
  28090. ArrowHelper.prototype.setColor = function ( color ) {
  28091. this.line.material.color.set( color );
  28092. this.cone.material.color.set( color );
  28093. };
  28094. ArrowHelper.prototype.copy = function ( source ) {
  28095. Object3D.prototype.copy.call( this, source, false );
  28096. this.line.copy( source.line );
  28097. this.cone.copy( source.cone );
  28098. return this;
  28099. };
  28100. ArrowHelper.prototype.clone = function () {
  28101. return new this.constructor().copy( this );
  28102. };
  28103. /**
  28104. * @author sroucheray / http://sroucheray.org/
  28105. * @author mrdoob / http://mrdoob.com/
  28106. */
  28107. function AxesHelper( size ) {
  28108. size = size || 1;
  28109. var vertices = [
  28110. 0, 0, 0, size, 0, 0,
  28111. 0, 0, 0, 0, size, 0,
  28112. 0, 0, 0, 0, 0, size
  28113. ];
  28114. var colors = [
  28115. 1, 0, 0, 1, 0.6, 0,
  28116. 0, 1, 0, 0.6, 1, 0,
  28117. 0, 0, 1, 0, 0.6, 1
  28118. ];
  28119. var geometry = new BufferGeometry();
  28120. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28121. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28122. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28123. LineSegments.call( this, geometry, material );
  28124. }
  28125. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28126. AxesHelper.prototype.constructor = AxesHelper;
  28127. /**
  28128. * @author mrdoob / http://mrdoob.com/
  28129. */
  28130. function Face4( a, b, c, d, normal, color, materialIndex ) {
  28131. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  28132. return new Face3( a, b, c, normal, color, materialIndex );
  28133. }
  28134. var LineStrip = 0;
  28135. var LinePieces = 1;
  28136. function MeshFaceMaterial( materials ) {
  28137. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28138. return materials;
  28139. }
  28140. function MultiMaterial( materials ) {
  28141. if ( materials === undefined ) materials = [];
  28142. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28143. materials.isMultiMaterial = true;
  28144. materials.materials = materials;
  28145. materials.clone = function () {
  28146. return materials.slice();
  28147. };
  28148. return materials;
  28149. }
  28150. function PointCloud( geometry, material ) {
  28151. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28152. return new Points( geometry, material );
  28153. }
  28154. function Particle( material ) {
  28155. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28156. return new Sprite( material );
  28157. }
  28158. function ParticleSystem( geometry, material ) {
  28159. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28160. return new Points( geometry, material );
  28161. }
  28162. function PointCloudMaterial( parameters ) {
  28163. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28164. return new PointsMaterial( parameters );
  28165. }
  28166. function ParticleBasicMaterial( parameters ) {
  28167. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28168. return new PointsMaterial( parameters );
  28169. }
  28170. function ParticleSystemMaterial( parameters ) {
  28171. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  28172. return new PointsMaterial( parameters );
  28173. }
  28174. function Vertex( x, y, z ) {
  28175. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  28176. return new Vector3( x, y, z );
  28177. }
  28178. //
  28179. function DynamicBufferAttribute( array, itemSize ) {
  28180. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  28181. return new BufferAttribute( array, itemSize ).setDynamic( true );
  28182. }
  28183. function Int8Attribute( array, itemSize ) {
  28184. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  28185. return new Int8BufferAttribute( array, itemSize );
  28186. }
  28187. function Uint8Attribute( array, itemSize ) {
  28188. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  28189. return new Uint8BufferAttribute( array, itemSize );
  28190. }
  28191. function Uint8ClampedAttribute( array, itemSize ) {
  28192. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  28193. return new Uint8ClampedBufferAttribute( array, itemSize );
  28194. }
  28195. function Int16Attribute( array, itemSize ) {
  28196. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  28197. return new Int16BufferAttribute( array, itemSize );
  28198. }
  28199. function Uint16Attribute( array, itemSize ) {
  28200. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  28201. return new Uint16BufferAttribute( array, itemSize );
  28202. }
  28203. function Int32Attribute( array, itemSize ) {
  28204. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28205. return new Int32BufferAttribute( array, itemSize );
  28206. }
  28207. function Uint32Attribute( array, itemSize ) {
  28208. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28209. return new Uint32BufferAttribute( array, itemSize );
  28210. }
  28211. function Float32Attribute( array, itemSize ) {
  28212. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28213. return new Float32BufferAttribute( array, itemSize );
  28214. }
  28215. function Float64Attribute( array, itemSize ) {
  28216. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28217. return new Float64BufferAttribute( array, itemSize );
  28218. }
  28219. //
  28220. Curve.create = function ( construct, getPoint ) {
  28221. console.log( 'THREE.Curve.create() has been deprecated' );
  28222. construct.prototype = Object.create( Curve.prototype );
  28223. construct.prototype.constructor = construct;
  28224. construct.prototype.getPoint = getPoint;
  28225. return construct;
  28226. };
  28227. //
  28228. Object.assign( CurvePath.prototype, {
  28229. createPointsGeometry: function ( divisions ) {
  28230. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28231. // generate geometry from path points (for Line or Points objects)
  28232. var pts = this.getPoints( divisions );
  28233. return this.createGeometry( pts );
  28234. },
  28235. createSpacedPointsGeometry: function ( divisions ) {
  28236. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28237. // generate geometry from equidistant sampling along the path
  28238. var pts = this.getSpacedPoints( divisions );
  28239. return this.createGeometry( pts );
  28240. },
  28241. createGeometry: function ( points ) {
  28242. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28243. var geometry = new Geometry();
  28244. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28245. var point = points[ i ];
  28246. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  28247. }
  28248. return geometry;
  28249. }
  28250. } );
  28251. //
  28252. Object.assign( Path.prototype, {
  28253. fromPoints: function ( points ) {
  28254. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28255. this.setFromPoints( points );
  28256. }
  28257. } );
  28258. //
  28259. function ClosedSplineCurve3( points ) {
  28260. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28261. CatmullRomCurve3.call( this, points );
  28262. this.type = 'catmullrom';
  28263. this.closed = true;
  28264. }
  28265. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28266. //
  28267. function SplineCurve3( points ) {
  28268. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28269. CatmullRomCurve3.call( this, points );
  28270. this.type = 'catmullrom';
  28271. }
  28272. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28273. //
  28274. function Spline( points ) {
  28275. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28276. CatmullRomCurve3.call( this, points );
  28277. this.type = 'catmullrom';
  28278. }
  28279. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28280. Object.assign( Spline.prototype, {
  28281. initFromArray: function ( /* a */ ) {
  28282. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28283. },
  28284. getControlPointsArray: function ( /* optionalTarget */ ) {
  28285. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28286. },
  28287. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  28288. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  28289. }
  28290. } );
  28291. //
  28292. function AxisHelper( size ) {
  28293. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28294. return new AxesHelper( size );
  28295. }
  28296. function BoundingBoxHelper( object, color ) {
  28297. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28298. return new BoxHelper( object, color );
  28299. }
  28300. function EdgesHelper( object, hex ) {
  28301. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28302. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28303. }
  28304. GridHelper.prototype.setColors = function () {
  28305. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28306. };
  28307. SkeletonHelper.prototype.update = function () {
  28308. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28309. };
  28310. function WireframeHelper( object, hex ) {
  28311. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28312. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28313. }
  28314. //
  28315. Object.assign( Loader.prototype, {
  28316. extractUrlBase: function ( url ) {
  28317. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28318. return LoaderUtils.extractUrlBase( url );
  28319. }
  28320. } );
  28321. function XHRLoader( manager ) {
  28322. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28323. return new FileLoader( manager );
  28324. }
  28325. function BinaryTextureLoader( manager ) {
  28326. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28327. return new DataTextureLoader( manager );
  28328. }
  28329. Object.assign( ObjectLoader.prototype, {
  28330. setTexturePath: function ( value ) {
  28331. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  28332. return this.setResourcePath( value );
  28333. }
  28334. } );
  28335. //
  28336. Object.assign( Box2.prototype, {
  28337. center: function ( optionalTarget ) {
  28338. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28339. return this.getCenter( optionalTarget );
  28340. },
  28341. empty: function () {
  28342. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28343. return this.isEmpty();
  28344. },
  28345. isIntersectionBox: function ( box ) {
  28346. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28347. return this.intersectsBox( box );
  28348. },
  28349. size: function ( optionalTarget ) {
  28350. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28351. return this.getSize( optionalTarget );
  28352. }
  28353. } );
  28354. Object.assign( Box3.prototype, {
  28355. center: function ( optionalTarget ) {
  28356. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28357. return this.getCenter( optionalTarget );
  28358. },
  28359. empty: function () {
  28360. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28361. return this.isEmpty();
  28362. },
  28363. isIntersectionBox: function ( box ) {
  28364. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28365. return this.intersectsBox( box );
  28366. },
  28367. isIntersectionSphere: function ( sphere ) {
  28368. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28369. return this.intersectsSphere( sphere );
  28370. },
  28371. size: function ( optionalTarget ) {
  28372. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28373. return this.getSize( optionalTarget );
  28374. }
  28375. } );
  28376. Line3.prototype.center = function ( optionalTarget ) {
  28377. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28378. return this.getCenter( optionalTarget );
  28379. };
  28380. Object.assign( _Math, {
  28381. random16: function () {
  28382. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28383. return Math.random();
  28384. },
  28385. nearestPowerOfTwo: function ( value ) {
  28386. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28387. return _Math.floorPowerOfTwo( value );
  28388. },
  28389. nextPowerOfTwo: function ( value ) {
  28390. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28391. return _Math.ceilPowerOfTwo( value );
  28392. }
  28393. } );
  28394. Object.assign( Matrix3.prototype, {
  28395. flattenToArrayOffset: function ( array, offset ) {
  28396. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28397. return this.toArray( array, offset );
  28398. },
  28399. multiplyVector3: function ( vector ) {
  28400. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28401. return vector.applyMatrix3( this );
  28402. },
  28403. multiplyVector3Array: function ( /* a */ ) {
  28404. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28405. },
  28406. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28407. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28408. return this.applyToBufferAttribute( buffer );
  28409. },
  28410. applyToVector3Array: function ( /* array, offset, length */ ) {
  28411. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28412. }
  28413. } );
  28414. Object.assign( Matrix4.prototype, {
  28415. extractPosition: function ( m ) {
  28416. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28417. return this.copyPosition( m );
  28418. },
  28419. flattenToArrayOffset: function ( array, offset ) {
  28420. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28421. return this.toArray( array, offset );
  28422. },
  28423. getPosition: function () {
  28424. var v1;
  28425. return function getPosition() {
  28426. if ( v1 === undefined ) v1 = new Vector3();
  28427. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28428. return v1.setFromMatrixColumn( this, 3 );
  28429. };
  28430. }(),
  28431. setRotationFromQuaternion: function ( q ) {
  28432. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28433. return this.makeRotationFromQuaternion( q );
  28434. },
  28435. multiplyToArray: function () {
  28436. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28437. },
  28438. multiplyVector3: function ( vector ) {
  28439. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28440. return vector.applyMatrix4( this );
  28441. },
  28442. multiplyVector4: function ( vector ) {
  28443. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28444. return vector.applyMatrix4( this );
  28445. },
  28446. multiplyVector3Array: function ( /* a */ ) {
  28447. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28448. },
  28449. rotateAxis: function ( v ) {
  28450. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28451. v.transformDirection( this );
  28452. },
  28453. crossVector: function ( vector ) {
  28454. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28455. return vector.applyMatrix4( this );
  28456. },
  28457. translate: function () {
  28458. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28459. },
  28460. rotateX: function () {
  28461. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28462. },
  28463. rotateY: function () {
  28464. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28465. },
  28466. rotateZ: function () {
  28467. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28468. },
  28469. rotateByAxis: function () {
  28470. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28471. },
  28472. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28473. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28474. return this.applyToBufferAttribute( buffer );
  28475. },
  28476. applyToVector3Array: function ( /* array, offset, length */ ) {
  28477. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28478. },
  28479. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28480. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28481. return this.makePerspective( left, right, top, bottom, near, far );
  28482. }
  28483. } );
  28484. Plane.prototype.isIntersectionLine = function ( line ) {
  28485. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28486. return this.intersectsLine( line );
  28487. };
  28488. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28489. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28490. return vector.applyQuaternion( this );
  28491. };
  28492. Object.assign( Ray.prototype, {
  28493. isIntersectionBox: function ( box ) {
  28494. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28495. return this.intersectsBox( box );
  28496. },
  28497. isIntersectionPlane: function ( plane ) {
  28498. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28499. return this.intersectsPlane( plane );
  28500. },
  28501. isIntersectionSphere: function ( sphere ) {
  28502. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28503. return this.intersectsSphere( sphere );
  28504. }
  28505. } );
  28506. Object.assign( Triangle.prototype, {
  28507. area: function () {
  28508. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28509. return this.getArea();
  28510. },
  28511. barycoordFromPoint: function ( point, target ) {
  28512. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28513. return this.getBarycoord( point, target );
  28514. },
  28515. midpoint: function ( target ) {
  28516. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28517. return this.getMidpoint( target );
  28518. },
  28519. normal: function ( target ) {
  28520. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28521. return this.getNormal( target );
  28522. },
  28523. plane: function ( target ) {
  28524. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28525. return this.getPlane( target );
  28526. }
  28527. } );
  28528. Object.assign( Triangle, {
  28529. barycoordFromPoint: function ( point, a, b, c, target ) {
  28530. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28531. return Triangle.getBarycoord( point, a, b, c, target );
  28532. },
  28533. normal: function ( a, b, c, target ) {
  28534. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28535. return Triangle.getNormal( a, b, c, target );
  28536. }
  28537. } );
  28538. Object.assign( Shape.prototype, {
  28539. extractAllPoints: function ( divisions ) {
  28540. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28541. return this.extractPoints( divisions );
  28542. },
  28543. extrude: function ( options ) {
  28544. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28545. return new ExtrudeGeometry( this, options );
  28546. },
  28547. makeGeometry: function ( options ) {
  28548. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28549. return new ShapeGeometry( this, options );
  28550. }
  28551. } );
  28552. Object.assign( Vector2.prototype, {
  28553. fromAttribute: function ( attribute, index, offset ) {
  28554. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28555. return this.fromBufferAttribute( attribute, index, offset );
  28556. },
  28557. distanceToManhattan: function ( v ) {
  28558. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28559. return this.manhattanDistanceTo( v );
  28560. },
  28561. lengthManhattan: function () {
  28562. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28563. return this.manhattanLength();
  28564. }
  28565. } );
  28566. Object.assign( Vector3.prototype, {
  28567. setEulerFromRotationMatrix: function () {
  28568. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28569. },
  28570. setEulerFromQuaternion: function () {
  28571. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28572. },
  28573. getPositionFromMatrix: function ( m ) {
  28574. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28575. return this.setFromMatrixPosition( m );
  28576. },
  28577. getScaleFromMatrix: function ( m ) {
  28578. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28579. return this.setFromMatrixScale( m );
  28580. },
  28581. getColumnFromMatrix: function ( index, matrix ) {
  28582. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28583. return this.setFromMatrixColumn( matrix, index );
  28584. },
  28585. applyProjection: function ( m ) {
  28586. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28587. return this.applyMatrix4( m );
  28588. },
  28589. fromAttribute: function ( attribute, index, offset ) {
  28590. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28591. return this.fromBufferAttribute( attribute, index, offset );
  28592. },
  28593. distanceToManhattan: function ( v ) {
  28594. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28595. return this.manhattanDistanceTo( v );
  28596. },
  28597. lengthManhattan: function () {
  28598. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28599. return this.manhattanLength();
  28600. }
  28601. } );
  28602. Object.assign( Vector4.prototype, {
  28603. fromAttribute: function ( attribute, index, offset ) {
  28604. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28605. return this.fromBufferAttribute( attribute, index, offset );
  28606. },
  28607. lengthManhattan: function () {
  28608. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28609. return this.manhattanLength();
  28610. }
  28611. } );
  28612. //
  28613. Object.assign( Geometry.prototype, {
  28614. computeTangents: function () {
  28615. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28616. },
  28617. computeLineDistances: function () {
  28618. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28619. }
  28620. } );
  28621. Object.assign( Object3D.prototype, {
  28622. getChildByName: function ( name ) {
  28623. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28624. return this.getObjectByName( name );
  28625. },
  28626. renderDepth: function () {
  28627. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28628. },
  28629. translate: function ( distance, axis ) {
  28630. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28631. return this.translateOnAxis( axis, distance );
  28632. },
  28633. getWorldRotation: function () {
  28634. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28635. }
  28636. } );
  28637. Object.defineProperties( Object3D.prototype, {
  28638. eulerOrder: {
  28639. get: function () {
  28640. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28641. return this.rotation.order;
  28642. },
  28643. set: function ( value ) {
  28644. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28645. this.rotation.order = value;
  28646. }
  28647. },
  28648. useQuaternion: {
  28649. get: function () {
  28650. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28651. },
  28652. set: function () {
  28653. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28654. }
  28655. }
  28656. } );
  28657. Object.defineProperties( LOD.prototype, {
  28658. objects: {
  28659. get: function () {
  28660. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28661. return this.levels;
  28662. }
  28663. }
  28664. } );
  28665. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28666. get: function () {
  28667. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28668. },
  28669. set: function () {
  28670. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28671. }
  28672. } );
  28673. SkinnedMesh.prototype.initBones = function () {
  28674. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28675. };
  28676. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28677. get: function () {
  28678. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28679. return this.arcLengthDivisions;
  28680. },
  28681. set: function ( value ) {
  28682. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28683. this.arcLengthDivisions = value;
  28684. }
  28685. } );
  28686. //
  28687. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28688. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28689. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28690. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28691. this.setFocalLength( focalLength );
  28692. };
  28693. //
  28694. Object.defineProperties( Light.prototype, {
  28695. onlyShadow: {
  28696. set: function () {
  28697. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28698. }
  28699. },
  28700. shadowCameraFov: {
  28701. set: function ( value ) {
  28702. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28703. this.shadow.camera.fov = value;
  28704. }
  28705. },
  28706. shadowCameraLeft: {
  28707. set: function ( value ) {
  28708. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28709. this.shadow.camera.left = value;
  28710. }
  28711. },
  28712. shadowCameraRight: {
  28713. set: function ( value ) {
  28714. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28715. this.shadow.camera.right = value;
  28716. }
  28717. },
  28718. shadowCameraTop: {
  28719. set: function ( value ) {
  28720. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28721. this.shadow.camera.top = value;
  28722. }
  28723. },
  28724. shadowCameraBottom: {
  28725. set: function ( value ) {
  28726. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28727. this.shadow.camera.bottom = value;
  28728. }
  28729. },
  28730. shadowCameraNear: {
  28731. set: function ( value ) {
  28732. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28733. this.shadow.camera.near = value;
  28734. }
  28735. },
  28736. shadowCameraFar: {
  28737. set: function ( value ) {
  28738. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28739. this.shadow.camera.far = value;
  28740. }
  28741. },
  28742. shadowCameraVisible: {
  28743. set: function () {
  28744. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28745. }
  28746. },
  28747. shadowBias: {
  28748. set: function ( value ) {
  28749. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28750. this.shadow.bias = value;
  28751. }
  28752. },
  28753. shadowDarkness: {
  28754. set: function () {
  28755. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28756. }
  28757. },
  28758. shadowMapWidth: {
  28759. set: function ( value ) {
  28760. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28761. this.shadow.mapSize.width = value;
  28762. }
  28763. },
  28764. shadowMapHeight: {
  28765. set: function ( value ) {
  28766. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28767. this.shadow.mapSize.height = value;
  28768. }
  28769. }
  28770. } );
  28771. //
  28772. Object.defineProperties( BufferAttribute.prototype, {
  28773. length: {
  28774. get: function () {
  28775. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28776. return this.array.length;
  28777. }
  28778. },
  28779. copyIndicesArray: function ( /* indices */ ) {
  28780. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28781. }
  28782. } );
  28783. Object.assign( BufferGeometry.prototype, {
  28784. addIndex: function ( index ) {
  28785. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28786. this.setIndex( index );
  28787. },
  28788. addDrawCall: function ( start, count, indexOffset ) {
  28789. if ( indexOffset !== undefined ) {
  28790. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28791. }
  28792. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28793. this.addGroup( start, count );
  28794. },
  28795. clearDrawCalls: function () {
  28796. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28797. this.clearGroups();
  28798. },
  28799. computeTangents: function () {
  28800. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28801. },
  28802. computeOffsets: function () {
  28803. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28804. }
  28805. } );
  28806. Object.defineProperties( BufferGeometry.prototype, {
  28807. drawcalls: {
  28808. get: function () {
  28809. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28810. return this.groups;
  28811. }
  28812. },
  28813. offsets: {
  28814. get: function () {
  28815. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28816. return this.groups;
  28817. }
  28818. }
  28819. } );
  28820. //
  28821. Object.assign( ExtrudeBufferGeometry.prototype, {
  28822. getArrays: function () {
  28823. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28824. },
  28825. addShapeList: function () {
  28826. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28827. },
  28828. addShape: function () {
  28829. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28830. }
  28831. } );
  28832. //
  28833. Object.defineProperties( Uniform.prototype, {
  28834. dynamic: {
  28835. set: function () {
  28836. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28837. }
  28838. },
  28839. onUpdate: {
  28840. value: function () {
  28841. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28842. return this;
  28843. }
  28844. }
  28845. } );
  28846. //
  28847. Object.defineProperties( Material.prototype, {
  28848. wrapAround: {
  28849. get: function () {
  28850. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28851. },
  28852. set: function () {
  28853. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28854. }
  28855. },
  28856. overdraw: {
  28857. get: function () {
  28858. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28859. },
  28860. set: function () {
  28861. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28862. }
  28863. },
  28864. wrapRGB: {
  28865. get: function () {
  28866. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28867. return new Color();
  28868. }
  28869. },
  28870. shading: {
  28871. get: function () {
  28872. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28873. },
  28874. set: function ( value ) {
  28875. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28876. this.flatShading = ( value === FlatShading );
  28877. }
  28878. }
  28879. } );
  28880. Object.defineProperties( MeshPhongMaterial.prototype, {
  28881. metal: {
  28882. get: function () {
  28883. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28884. return false;
  28885. },
  28886. set: function () {
  28887. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28888. }
  28889. }
  28890. } );
  28891. Object.defineProperties( ShaderMaterial.prototype, {
  28892. derivatives: {
  28893. get: function () {
  28894. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28895. return this.extensions.derivatives;
  28896. },
  28897. set: function ( value ) {
  28898. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28899. this.extensions.derivatives = value;
  28900. }
  28901. }
  28902. } );
  28903. //
  28904. Object.assign( WebGLRenderer.prototype, {
  28905. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28906. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28907. this.setRenderTarget( renderTarget );
  28908. this.clear( color, depth, stencil );
  28909. },
  28910. animate: function ( callback ) {
  28911. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28912. this.setAnimationLoop( callback );
  28913. },
  28914. getCurrentRenderTarget: function () {
  28915. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28916. return this.getRenderTarget();
  28917. },
  28918. getMaxAnisotropy: function () {
  28919. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28920. return this.capabilities.getMaxAnisotropy();
  28921. },
  28922. getPrecision: function () {
  28923. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28924. return this.capabilities.precision;
  28925. },
  28926. resetGLState: function () {
  28927. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28928. return this.state.reset();
  28929. },
  28930. supportsFloatTextures: function () {
  28931. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28932. return this.extensions.get( 'OES_texture_float' );
  28933. },
  28934. supportsHalfFloatTextures: function () {
  28935. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28936. return this.extensions.get( 'OES_texture_half_float' );
  28937. },
  28938. supportsStandardDerivatives: function () {
  28939. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28940. return this.extensions.get( 'OES_standard_derivatives' );
  28941. },
  28942. supportsCompressedTextureS3TC: function () {
  28943. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28944. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28945. },
  28946. supportsCompressedTexturePVRTC: function () {
  28947. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28948. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28949. },
  28950. supportsBlendMinMax: function () {
  28951. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28952. return this.extensions.get( 'EXT_blend_minmax' );
  28953. },
  28954. supportsVertexTextures: function () {
  28955. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28956. return this.capabilities.vertexTextures;
  28957. },
  28958. supportsInstancedArrays: function () {
  28959. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28960. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28961. },
  28962. enableScissorTest: function ( boolean ) {
  28963. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28964. this.setScissorTest( boolean );
  28965. },
  28966. initMaterial: function () {
  28967. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28968. },
  28969. addPrePlugin: function () {
  28970. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28971. },
  28972. addPostPlugin: function () {
  28973. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28974. },
  28975. updateShadowMap: function () {
  28976. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28977. },
  28978. setFaceCulling: function () {
  28979. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28980. },
  28981. allocTextureUnit: function () {
  28982. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28983. },
  28984. setTexture: function () {
  28985. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28986. },
  28987. setTexture2D: function () {
  28988. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28989. },
  28990. setTextureCube: function () {
  28991. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28992. },
  28993. getActiveMipMapLevel: function () {
  28994. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  28995. return this.getActiveMipmapLevel();
  28996. }
  28997. } );
  28998. Object.defineProperties( WebGLRenderer.prototype, {
  28999. shadowMapEnabled: {
  29000. get: function () {
  29001. return this.shadowMap.enabled;
  29002. },
  29003. set: function ( value ) {
  29004. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  29005. this.shadowMap.enabled = value;
  29006. }
  29007. },
  29008. shadowMapType: {
  29009. get: function () {
  29010. return this.shadowMap.type;
  29011. },
  29012. set: function ( value ) {
  29013. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  29014. this.shadowMap.type = value;
  29015. }
  29016. },
  29017. shadowMapCullFace: {
  29018. get: function () {
  29019. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29020. return undefined;
  29021. },
  29022. set: function ( /* value */ ) {
  29023. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29024. }
  29025. },
  29026. context: {
  29027. get: function () {
  29028. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  29029. return this.getContext();
  29030. }
  29031. }
  29032. } );
  29033. Object.defineProperties( WebGLShadowMap.prototype, {
  29034. cullFace: {
  29035. get: function () {
  29036. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29037. return undefined;
  29038. },
  29039. set: function ( /* cullFace */ ) {
  29040. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29041. }
  29042. },
  29043. renderReverseSided: {
  29044. get: function () {
  29045. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29046. return undefined;
  29047. },
  29048. set: function () {
  29049. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29050. }
  29051. },
  29052. renderSingleSided: {
  29053. get: function () {
  29054. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29055. return undefined;
  29056. },
  29057. set: function () {
  29058. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29059. }
  29060. }
  29061. } );
  29062. //
  29063. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  29064. activeCubeFace: {
  29065. set: function ( /* value */ ) {
  29066. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  29067. }
  29068. },
  29069. activeMipMapLevel: {
  29070. set: function ( /* value */ ) {
  29071. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  29072. }
  29073. }
  29074. } );
  29075. //
  29076. Object.defineProperties( WebGLRenderTarget.prototype, {
  29077. wrapS: {
  29078. get: function () {
  29079. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29080. return this.texture.wrapS;
  29081. },
  29082. set: function ( value ) {
  29083. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29084. this.texture.wrapS = value;
  29085. }
  29086. },
  29087. wrapT: {
  29088. get: function () {
  29089. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29090. return this.texture.wrapT;
  29091. },
  29092. set: function ( value ) {
  29093. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29094. this.texture.wrapT = value;
  29095. }
  29096. },
  29097. magFilter: {
  29098. get: function () {
  29099. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29100. return this.texture.magFilter;
  29101. },
  29102. set: function ( value ) {
  29103. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29104. this.texture.magFilter = value;
  29105. }
  29106. },
  29107. minFilter: {
  29108. get: function () {
  29109. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29110. return this.texture.minFilter;
  29111. },
  29112. set: function ( value ) {
  29113. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29114. this.texture.minFilter = value;
  29115. }
  29116. },
  29117. anisotropy: {
  29118. get: function () {
  29119. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29120. return this.texture.anisotropy;
  29121. },
  29122. set: function ( value ) {
  29123. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29124. this.texture.anisotropy = value;
  29125. }
  29126. },
  29127. offset: {
  29128. get: function () {
  29129. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29130. return this.texture.offset;
  29131. },
  29132. set: function ( value ) {
  29133. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29134. this.texture.offset = value;
  29135. }
  29136. },
  29137. repeat: {
  29138. get: function () {
  29139. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29140. return this.texture.repeat;
  29141. },
  29142. set: function ( value ) {
  29143. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29144. this.texture.repeat = value;
  29145. }
  29146. },
  29147. format: {
  29148. get: function () {
  29149. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29150. return this.texture.format;
  29151. },
  29152. set: function ( value ) {
  29153. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29154. this.texture.format = value;
  29155. }
  29156. },
  29157. type: {
  29158. get: function () {
  29159. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29160. return this.texture.type;
  29161. },
  29162. set: function ( value ) {
  29163. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29164. this.texture.type = value;
  29165. }
  29166. },
  29167. generateMipmaps: {
  29168. get: function () {
  29169. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29170. return this.texture.generateMipmaps;
  29171. },
  29172. set: function ( value ) {
  29173. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29174. this.texture.generateMipmaps = value;
  29175. }
  29176. }
  29177. } );
  29178. //
  29179. Object.defineProperties( WebVRManager.prototype, {
  29180. standing: {
  29181. set: function ( /* value */ ) {
  29182. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  29183. }
  29184. },
  29185. userHeight: {
  29186. set: function ( /* value */ ) {
  29187. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  29188. }
  29189. }
  29190. } );
  29191. //
  29192. Audio.prototype.load = function ( file ) {
  29193. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  29194. var scope = this;
  29195. var audioLoader = new AudioLoader();
  29196. audioLoader.load( file, function ( buffer ) {
  29197. scope.setBuffer( buffer );
  29198. } );
  29199. return this;
  29200. };
  29201. AudioAnalyser.prototype.getData = function () {
  29202. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  29203. return this.getFrequencyData();
  29204. };
  29205. //
  29206. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  29207. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  29208. return this.update( renderer, scene );
  29209. };
  29210. //
  29211. var GeometryUtils = {
  29212. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  29213. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  29214. var matrix;
  29215. if ( geometry2.isMesh ) {
  29216. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  29217. matrix = geometry2.matrix;
  29218. geometry2 = geometry2.geometry;
  29219. }
  29220. geometry1.merge( geometry2, matrix, materialIndexOffset );
  29221. },
  29222. center: function ( geometry ) {
  29223. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  29224. return geometry.center();
  29225. }
  29226. };
  29227. ImageUtils.crossOrigin = undefined;
  29228. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29229. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29230. var loader = new TextureLoader();
  29231. loader.setCrossOrigin( this.crossOrigin );
  29232. var texture = loader.load( url, onLoad, undefined, onError );
  29233. if ( mapping ) texture.mapping = mapping;
  29234. return texture;
  29235. };
  29236. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29237. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29238. var loader = new CubeTextureLoader();
  29239. loader.setCrossOrigin( this.crossOrigin );
  29240. var texture = loader.load( urls, onLoad, undefined, onError );
  29241. if ( mapping ) texture.mapping = mapping;
  29242. return texture;
  29243. };
  29244. ImageUtils.loadCompressedTexture = function () {
  29245. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29246. };
  29247. ImageUtils.loadCompressedTextureCube = function () {
  29248. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29249. };
  29250. //
  29251. function CanvasRenderer() {
  29252. console.error( 'THREE.CanvasRenderer has been removed' );
  29253. }
  29254. //
  29255. function JSONLoader() {
  29256. console.error( 'THREE.JSONLoader has been removed.' );
  29257. }
  29258. //
  29259. var SceneUtils = {
  29260. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29261. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29262. },
  29263. detach: function ( /* child, parent, scene */ ) {
  29264. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29265. },
  29266. attach: function ( /* child, scene, parent */ ) {
  29267. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29268. }
  29269. };
  29270. //
  29271. function LensFlare() {
  29272. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  29273. }
  29274. export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveBlending, AlphaFormat, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightProbe, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrowHelper, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, AxisHelper, BackSide, BasicDepthPacking, BasicShadowMap, BinaryTextureLoader, Bone, BooleanKeyframeTrack, BoundingBoxHelper, Box2, Box3, Box3Helper, BoxBufferGeometry, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasRenderer, CanvasTexture, CatmullRomCurve3, CineonToneMapping, CircleBufferGeometry, CircleGeometry, ClampToEdgeWrapping, Clock, ClosedSplineCurve3, Color, ColorKeyframeTrack, CompressedTexture, CompressedTextureLoader, ConeBufferGeometry, ConeGeometry, CubeCamera, BoxGeometry as CubeGeometry, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubeUVRefractionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CylinderBufferGeometry, CylinderGeometry, Cylindrical, DataTexture, DataTexture2DArray, DataTexture3D, DataTextureLoader, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightHelper, DirectionalLightShadow, DiscreteInterpolant, DodecahedronBufferGeometry, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicBufferAttribute, EdgesGeometry, EdgesHelper, EllipseCurve, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeBufferGeometry, ExtrudeGeometry, Face3, Face4, FaceColors, FaceNormalsHelper, FileLoader, FlatShading, Float32Attribute, Float32BufferAttribute, Float64Attribute, Float64BufferAttribute, FloatType, Fog, FogExp2, Font, FontLoader, FrontFaceDirectionCCW, FrontFaceDirectionCW, FrontSide, Frustum, GammaEncoding, Geometry, GeometryUtils, GreaterDepth, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, HemisphereLightProbe, IcosahedronBufferGeometry, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, ImmediateRenderObject, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, Int16Attribute, Int16BufferAttribute, Int32Attribute, Int32BufferAttribute, Int8Attribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, JSONLoader, KeepStencilOp, KeyframeTrack, LOD, LatheBufferGeometry, LatheGeometry, Layers, LensFlare, LessDepth, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, LightProbeHelper, LightShadow, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LinePieces, LineSegments, LineStrip, LinearEncoding, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearToneMapping, Loader, LoaderUtils, LoadingManager, LogLuvEncoding, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, MOUSE, Material, MaterialLoader, _Math as Math, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshFaceMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiMaterial, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeverDepth, NeverStencilFunc, NoBlending, NoColors, NoToneMapping, NormalBlending, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronBufferGeometry, OctahedronGeometry, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, ParametricBufferGeometry, ParametricGeometry, Particle, ParticleBasicMaterial, ParticleSystem, ParticleSystemMaterial, Path, PerspectiveCamera, Plane, PlaneBufferGeometry, PlaneGeometry, PlaneHelper, PointCloud, PointCloudMaterial, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronBufferGeometry, PolyhedronGeometry, PositionalAudio, PositionalAudioHelper, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, REVISION, RGBADepthPacking, RGBAFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDEncoding, RGBEEncoding, RGBEFormat, RGBFormat, RGBM16Encoding, RGBM7Encoding, RGB_ETC1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RectAreaLightHelper, RedFormat, ReinhardToneMapping, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingBufferGeometry, RingGeometry, Scene, SceneUtils, ShaderChunk, ShaderLib, ShaderMaterial, ShadowMaterial, Shape, ShapeBufferGeometry, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, SmoothShading, Sphere, SphereBufferGeometry, SphereGeometry, Spherical, SphericalHarmonics3, SphericalReflectionMapping, Spline, SplineCurve, SplineCurve3, SpotLight, SpotLightHelper, SpotLightShadow, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StereoCamera, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronBufferGeometry, TetrahedronGeometry, TextBufferGeometry, TextGeometry, Texture, TextureLoader, TorusBufferGeometry, TorusGeometry, TorusKnotBufferGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeBufferGeometry, TubeGeometry, UVMapping, Uint16Attribute, Uint16BufferAttribute, Uint32Attribute, Uint32BufferAttribute, Uint8Attribute, Uint8BufferAttribute, Uint8ClampedAttribute, Uint8ClampedBufferAttribute, Uncharted2ToneMapping, Uniform, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedShortType, Vector2, Vector3, Vector4, VectorKeyframeTrack, Vertex, VertexColors, VertexNormalsHelper, VideoTexture, WebGLMultisampleRenderTarget, WebGLRenderTarget, WebGLRenderTargetCube, WebGLRenderer, WebGLUtils, WireframeGeometry, WireframeHelper, WrapAroundEnding, XHRLoader, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, sRGBEncoding };